diff --git a/common/include/PS2Edefs.h b/common/include/PS2Edefs.h index 1b27e0c3dd..97b135e683 100644 --- a/common/include/PS2Edefs.h +++ b/common/include/PS2Edefs.h @@ -63,68 +63,70 @@ /////////////////////////////////////////////////////////////////////// // freeze modes: -#define FREEZE_LOAD 0 -#define FREEZE_SAVE 1 -#define FREEZE_SIZE 2 +#define FREEZE_LOAD 0 +#define FREEZE_SAVE 1 +#define FREEZE_SIZE 2 // event values: -#define KEYPRESS 1 -#define KEYRELEASE 2 +#define KEYPRESS 1 +#define KEYRELEASE 2 -typedef struct { - int size; - s8 *data; +typedef struct +{ + int size; + s8 *data; } freezeData; -typedef struct _keyEvent { - u32 key; - u32 evt; +typedef struct _keyEvent +{ + u32 key; + u32 evt; } keyEvent; /////////////////////////////////////////////////////////////////////// -#if defined(GSdefs) || defined(PADdefs) || defined(SIOdefs) || \ +#if defined(GSdefs) || defined(PADdefs) || defined(SIOdefs) || \ defined(SPU2defs) || defined(CDVDdefs) || defined(DEV9defs) || \ - defined(USBdefs) || defined(FWdefs) + defined(USBdefs) || defined(FWdefs) #define COMMONdefs #endif // PS2EgetLibType returns (may be OR'd) -#define PS2E_LT_GS 0x01 -#define PS2E_LT_PAD 0x02 // -=[ OBSOLETE ]=- +#define PS2E_LT_GS 0x01 +#define PS2E_LT_PAD 0x02 // -=[ OBSOLETE ]=- #define PS2E_LT_SPU2 0x04 #define PS2E_LT_CDVD 0x08 #define PS2E_LT_DEV9 0x10 -#define PS2E_LT_USB 0x20 -#define PS2E_LT_FW 0x40 -#define PS2E_LT_SIO 0x80 +#define PS2E_LT_USB 0x20 +#define PS2E_LT_FW 0x40 +#define PS2E_LT_SIO 0x80 // PS2EgetLibVersion2 (high 16 bits) -#define PS2E_GS_VERSION 0x0006 -#define PS2E_PAD_VERSION 0x0002 // -=[ OBSOLETE ]=- +#define PS2E_GS_VERSION 0x0006 +#define PS2E_PAD_VERSION 0x0002 // -=[ OBSOLETE ]=- #ifdef ENABLE_NEW_IOPDMA_SPU2 -# define PS2E_SPU2_VERSION 0x0006 +#define PS2E_SPU2_VERSION 0x0006 #else -# define PS2E_SPU2_VERSION 0x0005 +#define PS2E_SPU2_VERSION 0x0005 #endif #define PS2E_CDVD_VERSION 0x0005 #ifdef ENABLE_NEW_IOPDMA_DEV9 -# define PS2E_DEV9_VERSION 0x0004 +#define PS2E_DEV9_VERSION 0x0004 #else -# define PS2E_DEV9_VERSION 0x0003 +#define PS2E_DEV9_VERSION 0x0003 #endif -#define PS2E_USB_VERSION 0x0003 -#define PS2E_FW_VERSION 0x0002 -#define PS2E_SIO_VERSION 0x0001 +#define PS2E_USB_VERSION 0x0003 +#define PS2E_FW_VERSION 0x0002 +#define PS2E_SIO_VERSION 0x0001 #ifdef COMMONdefs #ifdef __cplusplus extern "C" { #endif -u32 CALLBACK PS2EgetLibType(void); -u32 CALLBACK PS2EgetLibVersion2(u32 type); -char* CALLBACK PS2EgetLibName(void); +u32 CALLBACK PS2EgetLibType(void); +u32 CALLBACK PS2EgetLibVersion2(u32 type); +char *CALLBACK PS2EgetLibName(void); #ifdef __cplusplus } @@ -139,85 +141,89 @@ char* CALLBACK PS2EgetLibName(void); */ // for 64bit compilers -typedef char __keyEvent_Size__[(sizeof(keyEvent) == 8)?1:-1]; +typedef char __keyEvent_Size__[(sizeof(keyEvent) == 8) ? 1 : -1]; // plugin types -#define SIO_TYPE_PAD 0x00000001 -#define SIO_TYPE_MTAP 0x00000004 -#define SIO_TYPE_RM 0x00000040 -#define SIO_TYPE_MC 0x00000100 +#define SIO_TYPE_PAD 0x00000001 +#define SIO_TYPE_MTAP 0x00000004 +#define SIO_TYPE_RM 0x00000040 +#define SIO_TYPE_MC 0x00000100 -typedef int (CALLBACK * SIOchangeSlotCB)(int slot); +typedef int(CALLBACK *SIOchangeSlotCB)(int slot); -typedef struct _cdvdSubQ { - u8 ctrl:4; // control and mode bits - u8 mode:4; // control and mode bits - u8 trackNum; // current track number (1 to 99) - u8 trackIndex; // current index within track (0 to 99) - u8 trackM; // current minute location on the disc (BCD encoded) - u8 trackS; // current sector location on the disc (BCD encoded) - u8 trackF; // current frame location on the disc (BCD encoded) - u8 pad; // unused - u8 discM; // current minute offset from first track (BCD encoded) - u8 discS; // current sector offset from first track (BCD encoded) - u8 discF; // current frame offset from first track (BCD encoded) +typedef struct _cdvdSubQ +{ + u8 ctrl : 4; // control and mode bits + u8 mode : 4; // control and mode bits + u8 trackNum; // current track number (1 to 99) + u8 trackIndex; // current index within track (0 to 99) + u8 trackM; // current minute location on the disc (BCD encoded) + u8 trackS; // current sector location on the disc (BCD encoded) + u8 trackF; // current frame location on the disc (BCD encoded) + u8 pad; // unused + u8 discM; // current minute offset from first track (BCD encoded) + u8 discS; // current sector offset from first track (BCD encoded) + u8 discF; // current frame offset from first track (BCD encoded) } cdvdSubQ; -typedef struct _cdvdTD { // NOT bcd coded - u32 lsn; - u8 type; +typedef struct _cdvdTD +{ // NOT bcd coded + u32 lsn; + u8 type; } cdvdTD; -typedef struct _cdvdTN { - u8 strack; //number of the first track (usually 1) - u8 etrack; //number of the last track +typedef struct _cdvdTN +{ + u8 strack; //number of the first track (usually 1) + u8 etrack; //number of the last track } cdvdTN; // CDVDreadTrack mode values: -#define CDVD_MODE_2352 0 // full 2352 bytes -#define CDVD_MODE_2340 1 // skip sync (12) bytes -#define CDVD_MODE_2328 2 // skip sync+head+sub (24) bytes -#define CDVD_MODE_2048 3 // skip sync+head+sub (24) bytes -#define CDVD_MODE_2368 4 // full 2352 bytes + 16 subq +#define CDVD_MODE_2352 0 // full 2352 bytes +#define CDVD_MODE_2340 1 // skip sync (12) bytes +#define CDVD_MODE_2328 2 // skip sync+head+sub (24) bytes +#define CDVD_MODE_2048 3 // skip sync+head+sub (24) bytes +#define CDVD_MODE_2368 4 // full 2352 bytes + 16 subq // CDVDgetDiskType returns: -#define CDVD_TYPE_ILLEGAL 0xff // Illegal Disc -#define CDVD_TYPE_DVDV 0xfe // DVD Video -#define CDVD_TYPE_CDDA 0xfd // Audio CD -#define CDVD_TYPE_PS2DVD 0x14 // PS2 DVD -#define CDVD_TYPE_PS2CDDA 0x13 // PS2 CD (with audio) -#define CDVD_TYPE_PS2CD 0x12 // PS2 CD -#define CDVD_TYPE_PSCDDA 0x11 // PS CD (with audio) -#define CDVD_TYPE_PSCD 0x10 // PS CD -#define CDVD_TYPE_UNKNOWN 0x05 // Unknown -#define CDVD_TYPE_DETCTDVDD 0x04 // Detecting Dvd Dual Sided -#define CDVD_TYPE_DETCTDVDS 0x03 // Detecting Dvd Single Sided -#define CDVD_TYPE_DETCTCD 0x02 // Detecting Cd -#define CDVD_TYPE_DETCT 0x01 // Detecting -#define CDVD_TYPE_NODISC 0x00 // No Disc +#define CDVD_TYPE_ILLEGAL 0xff // Illegal Disc +#define CDVD_TYPE_DVDV 0xfe // DVD Video +#define CDVD_TYPE_CDDA 0xfd // Audio CD +#define CDVD_TYPE_PS2DVD 0x14 // PS2 DVD +#define CDVD_TYPE_PS2CDDA 0x13 // PS2 CD (with audio) +#define CDVD_TYPE_PS2CD 0x12 // PS2 CD +#define CDVD_TYPE_PSCDDA 0x11 // PS CD (with audio) +#define CDVD_TYPE_PSCD 0x10 // PS CD +#define CDVD_TYPE_UNKNOWN 0x05 // Unknown +#define CDVD_TYPE_DETCTDVDD 0x04 // Detecting Dvd Dual Sided +#define CDVD_TYPE_DETCTDVDS 0x03 // Detecting Dvd Single Sided +#define CDVD_TYPE_DETCTCD 0x02 // Detecting Cd +#define CDVD_TYPE_DETCT 0x01 // Detecting +#define CDVD_TYPE_NODISC 0x00 // No Disc // CDVDgetTrayStatus returns: -#define CDVD_TRAY_CLOSE 0x00 -#define CDVD_TRAY_OPEN 0x01 +#define CDVD_TRAY_CLOSE 0x00 +#define CDVD_TRAY_OPEN 0x01 // cdvdTD.type (track types for cds) -#define CDVD_AUDIO_TRACK 0x01 -#define CDVD_MODE1_TRACK 0x41 -#define CDVD_MODE2_TRACK 0x61 +#define CDVD_AUDIO_TRACK 0x01 +#define CDVD_MODE1_TRACK 0x41 +#define CDVD_MODE2_TRACK 0x61 -#define CDVD_AUDIO_MASK 0x00 -#define CDVD_DATA_MASK 0x40 +#define CDVD_AUDIO_MASK 0x00 +#define CDVD_DATA_MASK 0x40 // CDROM_DATA_TRACK 0x04 //do not enable this! (from linux kernel) typedef void (*DEV9callback)(int cycles); -typedef int (*DEV9handler)(void); +typedef int (*DEV9handler)(void); typedef void (*USBcallback)(int cycles); -typedef int (*USBhandler)(void); +typedef int (*USBhandler)(void); -typedef struct _GSdriverInfo { - char name[8]; - void *common; +typedef struct _GSdriverInfo +{ + char name[8]; + void *common; } GSdriverInfo; #ifdef __cplusplus @@ -232,19 +238,19 @@ extern "C" { // basic funcs -s32 CALLBACK GSinit(); -s32 CALLBACK GSopen(void *pDsp, const char *Title, int multithread); +s32 CALLBACK GSinit(); +s32 CALLBACK GSopen(void *pDsp, const char *Title, int multithread); void CALLBACK GSclose(); void CALLBACK GSshutdown(); -void CALLBACK GSsetSettingsDir( const char* dir ); -void CALLBACK GSsetLogDir( const char* dir ); +void CALLBACK GSsetSettingsDir(const char *dir); +void CALLBACK GSsetLogDir(const char *dir); void CALLBACK GSvsync(int field); void CALLBACK GSgifTransfer(const u32 *pMem, u32 addr); void CALLBACK GSgifTransfer1(u32 *pMem, u32 addr); void CALLBACK GSgifTransfer2(u32 *pMem, u32 size); void CALLBACK GSgifTransfer3(u32 *pMem, u32 size); -void CALLBACK GSgetLastTag(u64* ptag); // returns the last tag processed (64 bits) +void CALLBACK GSgetLastTag(u64 *ptag); // returns the last tag processed (64 bits) void CALLBACK GSgifSoftReset(u32 mask); void CALLBACK GSreadFIFO(u64 *mem); void CALLBACK GSinitReadFIFO(u64 *mem); @@ -255,12 +261,12 @@ void CALLBACK GSinitReadFIFO2(u64 *mem, int qwc); // GSkeyEvent gets called when there is a keyEvent from the PAD plugin void CALLBACK GSkeyEvent(keyEvent *ev); -void CALLBACK GSchangeSaveState(int, const char* filename); +void CALLBACK GSchangeSaveState(int, const char *filename); void CALLBACK GSmakeSnapshot(char *path); -void CALLBACK GSmakeSnapshot2(char *pathname, int* snapdone, int savejpg); +void CALLBACK GSmakeSnapshot2(char *pathname, int *snapdone, int savejpg); void CALLBACK GSirqCallback(void (*callback)()); void CALLBACK GSprintf(int timeout, char *fmt, ...); -void CALLBACK GSsetBaseMem(void*); +void CALLBACK GSsetBaseMem(void *); void CALLBACK GSsetGameCRC(int crc, int gameoptions); // controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done @@ -269,17 +275,17 @@ void CALLBACK GSsetFrameSkip(int frameskip); // if start is 1, starts recording spu2 data, else stops // returns a non zero value if successful // for now, pData is not used -int CALLBACK GSsetupRecording(int start, void* pData); +int CALLBACK GSsetupRecording(int start, void *pData); void CALLBACK GSreset(); //deprecated: GSgetTitleInfo was used in PCSX2 but no plugin supported it prior to r4070: //void CALLBACK GSgetTitleInfo( char dest[128] ); -void CALLBACK GSgetTitleInfo2( char* dest, size_t length ); +void CALLBACK GSgetTitleInfo2(char *dest, size_t length); void CALLBACK GSwriteCSR(u32 value); -s32 CALLBACK GSfreeze(int mode, freezeData *data); +s32 CALLBACK GSfreeze(int mode, freezeData *data); void CALLBACK GSconfigure(); void CALLBACK GSabout(); -s32 CALLBACK GStest(); +s32 CALLBACK GStest(); #endif @@ -291,21 +297,21 @@ s32 CALLBACK GStest(); // basic funcs -s32 CALLBACK PADinit(u32 flags); -s32 CALLBACK PADopen(void *pDsp); +s32 CALLBACK PADinit(u32 flags); +s32 CALLBACK PADopen(void *pDsp); void CALLBACK PADclose(); void CALLBACK PADshutdown(); -void CALLBACK PADsetSettingsDir( const char* dir ); -void CALLBACK PADsetLogDir( const char* dir ); +void CALLBACK PADsetSettingsDir(const char *dir); +void CALLBACK PADsetLogDir(const char *dir); // PADkeyEvent is called every vsync (return NULL if no event) -keyEvent* CALLBACK PADkeyEvent(); -u8 CALLBACK PADstartPoll(int pad); -u8 CALLBACK PADpoll(u8 value); +keyEvent *CALLBACK PADkeyEvent(); +u8 CALLBACK PADstartPoll(int pad); +u8 CALLBACK PADpoll(u8 value); // returns: 1 if supported pad1 // 2 if supported pad2 // 3 if both are supported -u32 CALLBACK PADquery(); +u32 CALLBACK PADquery(); // call to give a hint to the PAD plugin to query for the keyboard state. A // good plugin will query the OS for keyboard state ONLY in this function. @@ -326,7 +332,7 @@ void CALLBACK PADWriteEvent(keyEvent &evt); void CALLBACK PADgsDriverInfo(GSdriverInfo *info); void CALLBACK PADconfigure(); void CALLBACK PADabout(); -s32 CALLBACK PADtest(); +s32 CALLBACK PADtest(); #endif @@ -338,20 +344,20 @@ s32 CALLBACK PADtest(); // basic funcs -s32 CALLBACK SPU2init(); -s32 CALLBACK SPU2open(void *pDsp); +s32 CALLBACK SPU2init(); +s32 CALLBACK SPU2open(void *pDsp); void CALLBACK SPU2close(); void CALLBACK SPU2shutdown(); -void CALLBACK SPU2setSettingsDir( const char* dir ); -void CALLBACK SPU2setLogDir( const char* dir ); +void CALLBACK SPU2setSettingsDir(const char *dir); +void CALLBACK SPU2setLogDir(const char *dir); void CALLBACK SPU2reset(); void CALLBACK SPU2write(u32 mem, u16 value); -u16 CALLBACK SPU2read(u32 mem); +u16 CALLBACK SPU2read(u32 mem); #ifdef ENABLE_NEW_IOPDMA_SPU2 -s32 CALLBACK SPU2dmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); -s32 CALLBACK SPU2dmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); +s32 CALLBACK SPU2dmaRead(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed); +s32 CALLBACK SPU2dmaWrite(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed); void CALLBACK SPU2dmaInterrupt(s32 channel); // dma irq callbacks not needed anymore, they are handled by the dmac @@ -360,7 +366,7 @@ void CALLBACK SPU2irqCallback(void (*SPU2callback)()); void CALLBACK SPU2readDMA4Mem(u16 *pMem, int size); void CALLBACK SPU2writeDMA4Mem(u16 *pMem, int size); void CALLBACK SPU2interruptDMA4(); -void CALLBACK SPU2readDMA7Mem(u16* pMem, int size); +void CALLBACK SPU2readDMA7Mem(u16 *pMem, int size); void CALLBACK SPU2writeDMA7Mem(u16 *pMem, int size); // all addresses passed by dma will be pointers to the array starting at baseaddr @@ -370,25 +376,25 @@ void CALLBACK SPU2setDMABaseAddr(uptr baseaddr); void CALLBACK SPU2interruptDMA7(); u32 CALLBACK SPU2ReadMemAddr(int core); -void CALLBACK SPU2WriteMemAddr(int core,u32 value); +void CALLBACK SPU2WriteMemAddr(int core, u32 value); -void CALLBACK SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)()); +void CALLBACK SPU2irqCallback(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)()); #endif // extended funcs // if start is 1, starts recording spu2 data, else stops // returns a non zero value if successful // for now, pData is not used -int CALLBACK SPU2setupRecording(int start, void* pData); +int CALLBACK SPU2setupRecording(int start, void *pData); -void CALLBACK SPU2setClockPtr(u32* ptr); +void CALLBACK SPU2setClockPtr(u32 *ptr); void CALLBACK SPU2setTimeStretcher(short int enable); void CALLBACK SPU2async(u32 cycles); -s32 CALLBACK SPU2freeze(int mode, freezeData *data); +s32 CALLBACK SPU2freeze(int mode, freezeData *data); void CALLBACK SPU2configure(); void CALLBACK SPU2about(); -s32 CALLBACK SPU2test(); +s32 CALLBACK SPU2test(); #endif @@ -400,44 +406,44 @@ s32 CALLBACK SPU2test(); // basic funcs -s32 CALLBACK CDVDinit(); -s32 CALLBACK CDVDopen(const char* pTitleFilename); +s32 CALLBACK CDVDinit(); +s32 CALLBACK CDVDopen(const char *pTitleFilename); void CALLBACK CDVDclose(); void CALLBACK CDVDshutdown(); -void CALLBACK CDVDsetSettingsDir( const char* dir ); -void CALLBACK CDVDsetLogDir( const char* dir ); +void CALLBACK CDVDsetSettingsDir(const char *dir); +void CALLBACK CDVDsetLogDir(const char *dir); -s32 CALLBACK CDVDreadTrack(u32 lsn, int mode); +s32 CALLBACK CDVDreadTrack(u32 lsn, int mode); // return can be NULL (for async modes) -u8* CALLBACK CDVDgetBuffer(); +u8 *CALLBACK CDVDgetBuffer(); -s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq);//read subq from disc (only cds have subq data) -s32 CALLBACK CDVDgetTN(cdvdTN *Buffer); //disk information -s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type -s32 CALLBACK CDVDgetTOC(void* toc); //gets ps2 style toc from disc -s32 CALLBACK CDVDgetDiskType(); //CDVD_TYPE_xxxx -s32 CALLBACK CDVDgetTrayStatus(); //CDVD_TRAY_xxxx -s32 CALLBACK CDVDctrlTrayOpen(); //open disc tray -s32 CALLBACK CDVDctrlTrayClose(); //close disc tray +s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ *subq); //read subq from disc (only cds have subq data) +s32 CALLBACK CDVDgetTN(cdvdTN *Buffer); //disk information +s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type +s32 CALLBACK CDVDgetTOC(void *toc); //gets ps2 style toc from disc +s32 CALLBACK CDVDgetDiskType(); //CDVD_TYPE_xxxx +s32 CALLBACK CDVDgetTrayStatus(); //CDVD_TRAY_xxxx +s32 CALLBACK CDVDctrlTrayOpen(); //open disc tray +s32 CALLBACK CDVDctrlTrayClose(); //close disc tray // extended funcs void CALLBACK CDVDconfigure(); void CALLBACK CDVDabout(); -s32 CALLBACK CDVDtest(); +s32 CALLBACK CDVDtest(); void CALLBACK CDVDnewDiskCB(void (*callback)()); // new funcs // read a track directly -s32 CALLBACK CDVDreadSector(u8* buffer, s32 lsn, int mode); +s32 CALLBACK CDVDreadSector(u8 *buffer, s32 lsn, int mode); // improved getBuffer -s32 CALLBACK CDVDgetBuffer2(u8* buffer); +s32 CALLBACK CDVDgetBuffer2(u8 *buffer); // tool function -s32 CALLBACK CDVDgetDualInfo(s32* dualType, u32* _layer1start); +s32 CALLBACK CDVDgetDualInfo(s32 *dualType, u32 *_layer1start); #endif @@ -451,22 +457,22 @@ s32 CALLBACK CDVDgetDualInfo(s32* dualType, u32* _layer1start); // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -s32 CALLBACK DEV9init(); -s32 CALLBACK DEV9open(void *pDsp); +s32 CALLBACK DEV9init(); +s32 CALLBACK DEV9open(void *pDsp); void CALLBACK DEV9close(); void CALLBACK DEV9shutdown(); -void CALLBACK DEV9setSettingsDir( const char* dir ); -void CALLBACK DEV9setLogDir( const char* dir ); +void CALLBACK DEV9setSettingsDir(const char *dir); +void CALLBACK DEV9setLogDir(const char *dir); -u8 CALLBACK DEV9read8(u32 addr); -u16 CALLBACK DEV9read16(u32 addr); -u32 CALLBACK DEV9read32(u32 addr); -void CALLBACK DEV9write8(u32 addr, u8 value); +u8 CALLBACK DEV9read8(u32 addr); +u16 CALLBACK DEV9read16(u32 addr); +u32 CALLBACK DEV9read32(u32 addr); +void CALLBACK DEV9write8(u32 addr, u8 value); void CALLBACK DEV9write16(u32 addr, u16 value); void CALLBACK DEV9write32(u32 addr, u32 value); #ifdef ENABLE_NEW_IOPDMA_DEV9 -s32 CALLBACK DEV9dmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); -s32 CALLBACK DEV9dmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); +s32 CALLBACK DEV9dmaRead(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed); +s32 CALLBACK DEV9dmaWrite(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed); void CALLBACK DEV9dmaInterrupt(s32 channel); #else void CALLBACK DEV9readDMA8Mem(u32 *pMem, int size); @@ -479,10 +485,10 @@ DEV9handler CALLBACK DEV9irqHandler(void); // extended funcs -s32 CALLBACK DEV9freeze(int mode, freezeData *data); +s32 CALLBACK DEV9freeze(int mode, freezeData *data); void CALLBACK DEV9configure(); void CALLBACK DEV9about(); -s32 CALLBACK DEV9test(); +s32 CALLBACK DEV9test(); #endif @@ -494,17 +500,17 @@ s32 CALLBACK DEV9test(); // basic funcs -s32 CALLBACK USBinit(); -s32 CALLBACK USBopen(void *pDsp); +s32 CALLBACK USBinit(); +s32 CALLBACK USBopen(void *pDsp); void CALLBACK USBclose(); void CALLBACK USBshutdown(); -void CALLBACK USBsetSettingsDir( const char* dir ); -void CALLBACK USBsetLogDir( const char* dir ); +void CALLBACK USBsetSettingsDir(const char *dir); +void CALLBACK USBsetLogDir(const char *dir); -u8 CALLBACK USBread8(u32 addr); -u16 CALLBACK USBread16(u32 addr); -u32 CALLBACK USBread32(u32 addr); -void CALLBACK USBwrite8(u32 addr, u8 value); +u8 CALLBACK USBread8(u32 addr); +u16 CALLBACK USBread16(u32 addr); +u32 CALLBACK USBread32(u32 addr); +void CALLBACK USBwrite8(u32 addr, u8 value); void CALLBACK USBwrite16(u32 addr, u16 value); void CALLBACK USBwrite32(u32 addr, u32 value); void CALLBACK USBasync(u32 cycles); @@ -517,10 +523,10 @@ void CALLBACK USBsetRAM(void *mem); // extended funcs -s32 CALLBACK USBfreeze(int mode, freezeData *data); +s32 CALLBACK USBfreeze(int mode, freezeData *data); void CALLBACK USBconfigure(); void CALLBACK USBabout(); -s32 CALLBACK USBtest(); +s32 CALLBACK USBtest(); #endif @@ -533,324 +539,324 @@ s32 CALLBACK USBtest(); // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -s32 CALLBACK FWinit(); -s32 CALLBACK FWopen(void *pDsp); +s32 CALLBACK FWinit(); +s32 CALLBACK FWopen(void *pDsp); void CALLBACK FWclose(); void CALLBACK FWshutdown(); -void CALLBACK FWsetSettingsDir( const char* dir ); -void CALLBACK FWsetLogDir( const char* dir ); +void CALLBACK FWsetSettingsDir(const char *dir); +void CALLBACK FWsetLogDir(const char *dir); -u32 CALLBACK FWread32(u32 addr); +u32 CALLBACK FWread32(u32 addr); void CALLBACK FWwrite32(u32 addr, u32 value); void CALLBACK FWirqCallback(void (*callback)()); // extended funcs -s32 CALLBACK FWfreeze(int mode, freezeData *data); +s32 CALLBACK FWfreeze(int mode, freezeData *data); void CALLBACK FWconfigure(); void CALLBACK FWabout(); -s32 CALLBACK FWtest(); +s32 CALLBACK FWtest(); #endif // might be useful for emulators #ifdef PLUGINtypedefs -typedef u32 (CALLBACK* _PS2EgetLibType)(void); -typedef u32 (CALLBACK* _PS2EgetLibVersion2)(u32 type); -typedef char*(CALLBACK* _PS2EgetLibName)(void); +typedef u32(CALLBACK *_PS2EgetLibType)(void); +typedef u32(CALLBACK *_PS2EgetLibVersion2)(u32 type); +typedef char *(CALLBACK *_PS2EgetLibName)(void); -typedef void (CALLBACK* _PS2EsetEmuVersion)(const char* emuId, u32 version); // HACK to let some plugins know it's 0.9.7 PCSX2 --air +typedef void(CALLBACK *_PS2EsetEmuVersion)(const char *emuId, u32 version); // HACK to let some plugins know it's 0.9.7 PCSX2 --air // GS // NOTE: GSreadFIFOX/GSwriteCSR functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _GSopen)(void *pDsp, const char *Title, int multithread); -typedef s32 (CALLBACK* _GSopen2)( void *pDsp, u32 flags ); -typedef void (CALLBACK* _GSvsync)(int field); -typedef void (CALLBACK* _GSgifTransfer)(const u32 *pMem, u32 size); -typedef void (CALLBACK* _GSgifTransfer1)(u32 *pMem, u32 addr); -typedef void (CALLBACK* _GSgifTransfer2)(u32 *pMem, u32 size); -typedef void (CALLBACK* _GSgifTransfer3)(u32 *pMem, u32 size); -typedef void (CALLBACK* _GSgifSoftReset)(u32 mask); -typedef void (CALLBACK* _GSreadFIFO)(u64 *pMem); -typedef void (CALLBACK* _GSreadFIFO2)(u64 *pMem, int qwc); -typedef void (CALLBACK* _GSinitReadFIFO)(u64 *pMem); -typedef void (CALLBACK* _GSinitReadFIFO2)(u64 *pMem, int qwc); +typedef s32(CALLBACK *_GSopen)(void *pDsp, const char *Title, int multithread); +typedef s32(CALLBACK *_GSopen2)(void *pDsp, u32 flags); +typedef void(CALLBACK *_GSvsync)(int field); +typedef void(CALLBACK *_GSgifTransfer)(const u32 *pMem, u32 size); +typedef void(CALLBACK *_GSgifTransfer1)(u32 *pMem, u32 addr); +typedef void(CALLBACK *_GSgifTransfer2)(u32 *pMem, u32 size); +typedef void(CALLBACK *_GSgifTransfer3)(u32 *pMem, u32 size); +typedef void(CALLBACK *_GSgifSoftReset)(u32 mask); +typedef void(CALLBACK *_GSreadFIFO)(u64 *pMem); +typedef void(CALLBACK *_GSreadFIFO2)(u64 *pMem, int qwc); +typedef void(CALLBACK *_GSinitReadFIFO)(u64 *pMem); +typedef void(CALLBACK *_GSinitReadFIFO2)(u64 *pMem, int qwc); -typedef void (CALLBACK* _GSchangeSaveState)(int, const char* filename); -typedef void (CALLBACK* _GSgetTitleInfo2)(char* dest, size_t length); -typedef void (CALLBACK* _GSirqCallback)(void (*callback)()); -typedef void (CALLBACK* _GSprintf)(int timeout, char *fmt, ...); -typedef void (CALLBACK* _GSsetBaseMem)(void*); -typedef void (CALLBACK* _GSsetGameCRC)(int, int); -typedef void (CALLBACK* _GSsetFrameSkip)(int frameskip); -typedef void (CALLBACK* _GSsetFrameLimit)(int limit); -typedef void (CALLBACK* _GSsetVsync)(int enabled); -typedef void (CALLBACK* _GSsetExclusive)(int isExclusive); -typedef int (CALLBACK* _GSsetupRecording)(int, void*); -typedef void (CALLBACK* _GSreset)(); -typedef void (CALLBACK* _GSwriteCSR)(u32 value); -typedef void (CALLBACK* _GSmakeSnapshot)(const char *path); -typedef void (CALLBACK* _GSmakeSnapshot2)(const char *path, int*, int); +typedef void(CALLBACK *_GSchangeSaveState)(int, const char *filename); +typedef void(CALLBACK *_GSgetTitleInfo2)(char *dest, size_t length); +typedef void(CALLBACK *_GSirqCallback)(void (*callback)()); +typedef void(CALLBACK *_GSprintf)(int timeout, char *fmt, ...); +typedef void(CALLBACK *_GSsetBaseMem)(void *); +typedef void(CALLBACK *_GSsetGameCRC)(int, int); +typedef void(CALLBACK *_GSsetFrameSkip)(int frameskip); +typedef void(CALLBACK *_GSsetFrameLimit)(int limit); +typedef void(CALLBACK *_GSsetVsync)(int enabled); +typedef void(CALLBACK *_GSsetExclusive)(int isExclusive); +typedef int(CALLBACK *_GSsetupRecording)(int, void *); +typedef void(CALLBACK *_GSreset)(); +typedef void(CALLBACK *_GSwriteCSR)(u32 value); +typedef void(CALLBACK *_GSmakeSnapshot)(const char *path); +typedef void(CALLBACK *_GSmakeSnapshot2)(const char *path, int *, int); // PAD -typedef s32 (CALLBACK* _PADinit)(u32 flags); -typedef s32 (CALLBACK* _PADopen)(void *pDsp); -typedef u8 (CALLBACK* _PADstartPoll)(int pad); -typedef u8 (CALLBACK* _PADpoll)(u8 value); -typedef u32 (CALLBACK* _PADquery)(int pad); -typedef void (CALLBACK* _PADupdate)(int pad); -typedef keyEvent* (CALLBACK* _PADkeyEvent)(); -typedef void (CALLBACK* _PADgsDriverInfo)(GSdriverInfo *info); -typedef s32 (CALLBACK* _PADsetSlot)(u8 port, u8 slot); -typedef s32 (CALLBACK* _PADqueryMtap)(u8 port); -typedef void (CALLBACK* _PADWriteEvent)(keyEvent &evt); +typedef s32(CALLBACK *_PADinit)(u32 flags); +typedef s32(CALLBACK *_PADopen)(void *pDsp); +typedef u8(CALLBACK *_PADstartPoll)(int pad); +typedef u8(CALLBACK *_PADpoll)(u8 value); +typedef u32(CALLBACK *_PADquery)(int pad); +typedef void(CALLBACK *_PADupdate)(int pad); +typedef keyEvent *(CALLBACK *_PADkeyEvent)(); +typedef void(CALLBACK *_PADgsDriverInfo)(GSdriverInfo *info); +typedef s32(CALLBACK *_PADsetSlot)(u8 port, u8 slot); +typedef s32(CALLBACK *_PADqueryMtap)(u8 port); +typedef void(CALLBACK *_PADWriteEvent)(keyEvent &evt); // SPU2 -typedef s32 (CALLBACK* _SPU2open)(void *pDsp); -typedef void (CALLBACK* _SPU2reset)(); -typedef void (CALLBACK* _SPU2write)(u32 mem, u16 value); -typedef u16 (CALLBACK* _SPU2read)(u32 mem); +typedef s32(CALLBACK *_SPU2open)(void *pDsp); +typedef void(CALLBACK *_SPU2reset)(); +typedef void(CALLBACK *_SPU2write)(u32 mem, u16 value); +typedef u16(CALLBACK *_SPU2read)(u32 mem); #ifdef ENABLE_NEW_IOPDMA_SPU2 -typedef s32 (CALLBACK* _SPU2dmaRead)(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); -typedef s32 (CALLBACK* _SPU2dmaWrite)(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); -typedef void (CALLBACK* _SPU2dmaInterrupt)(s32 channel); +typedef s32(CALLBACK *_SPU2dmaRead)(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed); +typedef s32(CALLBACK *_SPU2dmaWrite)(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed); +typedef void(CALLBACK *_SPU2dmaInterrupt)(s32 channel); // dma irq callbacks not needed anymore, they are handled by the dmac -typedef void (CALLBACK* _SPU2irqCallback)(void (*SPU2callback)()); +typedef void(CALLBACK *_SPU2irqCallback)(void (*SPU2callback)()); #else -typedef void (CALLBACK* _SPU2readDMA4Mem)(u16 *pMem, int size); -typedef void (CALLBACK* _SPU2writeDMA4Mem)(u16 *pMem, int size); -typedef void (CALLBACK* _SPU2interruptDMA4)(); -typedef void (CALLBACK* _SPU2readDMA7Mem)(u16 *pMem, int size); -typedef void (CALLBACK* _SPU2writeDMA7Mem)(u16 *pMem, int size); -typedef void (CALLBACK* _SPU2setDMABaseAddr)(uptr baseaddr); -typedef void (CALLBACK* _SPU2interruptDMA7)(); -typedef void (CALLBACK* _SPU2irqCallback)(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)()); -typedef u32 (CALLBACK* _SPU2ReadMemAddr)(int core); -typedef void (CALLBACK* _SPU2WriteMemAddr)(int core,u32 value); +typedef void(CALLBACK *_SPU2readDMA4Mem)(u16 *pMem, int size); +typedef void(CALLBACK *_SPU2writeDMA4Mem)(u16 *pMem, int size); +typedef void(CALLBACK *_SPU2interruptDMA4)(); +typedef void(CALLBACK *_SPU2readDMA7Mem)(u16 *pMem, int size); +typedef void(CALLBACK *_SPU2writeDMA7Mem)(u16 *pMem, int size); +typedef void(CALLBACK *_SPU2setDMABaseAddr)(uptr baseaddr); +typedef void(CALLBACK *_SPU2interruptDMA7)(); +typedef void(CALLBACK *_SPU2irqCallback)(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)()); +typedef u32(CALLBACK *_SPU2ReadMemAddr)(int core); +typedef void(CALLBACK *_SPU2WriteMemAddr)(int core, u32 value); #endif -typedef int (CALLBACK* _SPU2setupRecording)(int, void*); +typedef int(CALLBACK *_SPU2setupRecording)(int, void *); -typedef void (CALLBACK* _SPU2setClockPtr)(u32*ptr); -typedef void (CALLBACK* _SPU2setTimeStretcher)(short int enable); +typedef void(CALLBACK *_SPU2setClockPtr)(u32 *ptr); +typedef void(CALLBACK *_SPU2setTimeStretcher)(short int enable); -typedef void (CALLBACK* _SPU2async)(u32 cycles); +typedef void(CALLBACK *_SPU2async)(u32 cycles); // CDVD // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _CDVDopen)(const char* pTitleFilename); +typedef s32(CALLBACK *_CDVDopen)(const char *pTitleFilename); // Initiates an asynchronous track read operation. // Returns -1 on error (invalid track) // Returns 0 on success. -typedef s32 (CALLBACK* _CDVDreadTrack)(u32 lsn, int mode); +typedef s32(CALLBACK *_CDVDreadTrack)(u32 lsn, int mode); // *OBSOLETE* returns a pointer to the buffer, or NULL if data hasn't finished // loading yet. -typedef u8* (CALLBACK* _CDVDgetBuffer)(); +typedef u8 *(CALLBACK *_CDVDgetBuffer)(); // Copies loaded data to the target buffer. // Returns -2 if the asynchronous read is still pending. // Returns -1 if the asyncronous read failed. // Returns 0 on success. -typedef s32 (CALLBACK* _CDVDgetBuffer2)(u8* buffer); +typedef s32(CALLBACK *_CDVDgetBuffer2)(u8 *buffer); -typedef s32 (CALLBACK* _CDVDreadSubQ)(u32 lsn, cdvdSubQ* subq); -typedef s32 (CALLBACK* _CDVDgetTN)(cdvdTN *Buffer); -typedef s32 (CALLBACK* _CDVDgetTD)(u8 Track, cdvdTD *Buffer); -typedef s32 (CALLBACK* _CDVDgetTOC)(void* toc); -typedef s32 (CALLBACK* _CDVDgetDiskType)(); -typedef s32 (CALLBACK* _CDVDgetTrayStatus)(); -typedef s32 (CALLBACK* _CDVDctrlTrayOpen)(); -typedef s32 (CALLBACK* _CDVDctrlTrayClose)(); -typedef s32 (CALLBACK* _CDVDreadSector)(u8* buffer, u32 lsn, int mode); -typedef s32 (CALLBACK* _CDVDgetDualInfo)(s32* dualType, u32* _layer1start); +typedef s32(CALLBACK *_CDVDreadSubQ)(u32 lsn, cdvdSubQ *subq); +typedef s32(CALLBACK *_CDVDgetTN)(cdvdTN *Buffer); +typedef s32(CALLBACK *_CDVDgetTD)(u8 Track, cdvdTD *Buffer); +typedef s32(CALLBACK *_CDVDgetTOC)(void *toc); +typedef s32(CALLBACK *_CDVDgetDiskType)(); +typedef s32(CALLBACK *_CDVDgetTrayStatus)(); +typedef s32(CALLBACK *_CDVDctrlTrayOpen)(); +typedef s32(CALLBACK *_CDVDctrlTrayClose)(); +typedef s32(CALLBACK *_CDVDreadSector)(u8 *buffer, u32 lsn, int mode); +typedef s32(CALLBACK *_CDVDgetDualInfo)(s32 *dualType, u32 *_layer1start); -typedef void (CALLBACK* _CDVDnewDiskCB)(void (*callback)()); +typedef void(CALLBACK *_CDVDnewDiskCB)(void (*callback)()); // DEV9 // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _DEV9open)(void *pDsp); -typedef u8 (CALLBACK* _DEV9read8)(u32 mem); -typedef u16 (CALLBACK* _DEV9read16)(u32 mem); -typedef u32 (CALLBACK* _DEV9read32)(u32 mem); -typedef void (CALLBACK* _DEV9write8)(u32 mem, u8 value); -typedef void (CALLBACK* _DEV9write16)(u32 mem, u16 value); -typedef void (CALLBACK* _DEV9write32)(u32 mem, u32 value); +typedef s32(CALLBACK *_DEV9open)(void *pDsp); +typedef u8(CALLBACK *_DEV9read8)(u32 mem); +typedef u16(CALLBACK *_DEV9read16)(u32 mem); +typedef u32(CALLBACK *_DEV9read32)(u32 mem); +typedef void(CALLBACK *_DEV9write8)(u32 mem, u8 value); +typedef void(CALLBACK *_DEV9write16)(u32 mem, u16 value); +typedef void(CALLBACK *_DEV9write32)(u32 mem, u32 value); #ifdef ENABLE_NEW_IOPDMA_DEV9 -typedef s32 (CALLBACK* _DEV9dmaRead)(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); -typedef s32 (CALLBACK* _DEV9dmaWrite)(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); -typedef void (CALLBACK* _DEV9dmaInterrupt)(s32 channel); +typedef s32(CALLBACK *_DEV9dmaRead)(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed); +typedef s32(CALLBACK *_DEV9dmaWrite)(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed); +typedef void(CALLBACK *_DEV9dmaInterrupt)(s32 channel); #else -typedef void (CALLBACK* _DEV9readDMA8Mem)(u32 *pMem, int size); -typedef void (CALLBACK* _DEV9writeDMA8Mem)(u32 *pMem, int size); +typedef void(CALLBACK *_DEV9readDMA8Mem)(u32 *pMem, int size); +typedef void(CALLBACK *_DEV9writeDMA8Mem)(u32 *pMem, int size); #endif -typedef void (CALLBACK* _DEV9irqCallback)(DEV9callback callback); -typedef DEV9handler (CALLBACK* _DEV9irqHandler)(void); -typedef void (CALLBACK* _DEV9async)(u32 cycles); +typedef void(CALLBACK *_DEV9irqCallback)(DEV9callback callback); +typedef DEV9handler(CALLBACK *_DEV9irqHandler)(void); +typedef void(CALLBACK *_DEV9async)(u32 cycles); // USB // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -typedef s32 (CALLBACK* _USBopen)(void *pDsp); -typedef u8 (CALLBACK* _USBread8)(u32 mem); -typedef u16 (CALLBACK* _USBread16)(u32 mem); -typedef u32 (CALLBACK* _USBread32)(u32 mem); -typedef void (CALLBACK* _USBwrite8)(u32 mem, u8 value); -typedef void (CALLBACK* _USBwrite16)(u32 mem, u16 value); -typedef void (CALLBACK* _USBwrite32)(u32 mem, u32 value); -typedef void (CALLBACK* _USBasync)(u32 cycles); +typedef s32(CALLBACK *_USBopen)(void *pDsp); +typedef u8(CALLBACK *_USBread8)(u32 mem); +typedef u16(CALLBACK *_USBread16)(u32 mem); +typedef u32(CALLBACK *_USBread32)(u32 mem); +typedef void(CALLBACK *_USBwrite8)(u32 mem, u8 value); +typedef void(CALLBACK *_USBwrite16)(u32 mem, u16 value); +typedef void(CALLBACK *_USBwrite32)(u32 mem, u32 value); +typedef void(CALLBACK *_USBasync)(u32 cycles); -typedef void (CALLBACK* _USBirqCallback)(USBcallback callback); -typedef USBhandler (CALLBACK* _USBirqHandler)(void); -typedef void (CALLBACK* _USBsetRAM)(void *mem); +typedef void(CALLBACK *_USBirqCallback)(USBcallback callback); +typedef USBhandler(CALLBACK *_USBirqHandler)(void); +typedef void(CALLBACK *_USBsetRAM)(void *mem); //FW -typedef s32 (CALLBACK* _FWopen)(void *pDsp); -typedef u32 (CALLBACK* _FWread32)(u32 mem); -typedef void (CALLBACK* _FWwrite32)(u32 mem, u32 value); -typedef void (CALLBACK* _FWirqCallback)(void (*callback)()); +typedef s32(CALLBACK *_FWopen)(void *pDsp); +typedef u32(CALLBACK *_FWread32)(u32 mem); +typedef void(CALLBACK *_FWwrite32)(u32 mem, u32 value); +typedef void(CALLBACK *_FWirqCallback)(void (*callback)()); #endif #ifdef PLUGINfuncs // GS #ifndef BUILTIN_GS_PLUGIN -extern _GSopen GSopen; -extern _GSopen2 GSopen2; -extern _GSvsync GSvsync; -extern _GSgifTransfer GSgifTransfer; -extern _GSgifTransfer1 GSgifTransfer1; -extern _GSgifTransfer2 GSgifTransfer2; -extern _GSgifTransfer3 GSgifTransfer3; -extern _GSgifSoftReset GSgifSoftReset; -extern _GSreadFIFO GSreadFIFO; -extern _GSinitReadFIFO GSinitReadFIFO; -extern _GSreadFIFO2 GSreadFIFO2; -extern _GSinitReadFIFO2 GSinitReadFIFO2; +extern _GSopen GSopen; +extern _GSopen2 GSopen2; +extern _GSvsync GSvsync; +extern _GSgifTransfer GSgifTransfer; +extern _GSgifTransfer1 GSgifTransfer1; +extern _GSgifTransfer2 GSgifTransfer2; +extern _GSgifTransfer3 GSgifTransfer3; +extern _GSgifSoftReset GSgifSoftReset; +extern _GSreadFIFO GSreadFIFO; +extern _GSinitReadFIFO GSinitReadFIFO; +extern _GSreadFIFO2 GSreadFIFO2; +extern _GSinitReadFIFO2 GSinitReadFIFO2; extern _GSchangeSaveState GSchangeSaveState; -extern _GSgetTitleInfo2 GSgetTitleInfo2; -extern _GSmakeSnapshot GSmakeSnapshot; -extern _GSmakeSnapshot2 GSmakeSnapshot2; -extern _GSirqCallback GSirqCallback; -extern _GSprintf GSprintf; -extern _GSsetBaseMem GSsetBaseMem; -extern _GSsetGameCRC GSsetGameCRC; -extern _GSsetFrameSkip GSsetFrameSkip; -extern _GSsetFrameLimit GSsetFrameLimit; -extern _GSsetVsync GSsetVsync; -extern _GSsetupRecording GSsetupRecording; -extern _GSreset GSreset; -extern _GSwriteCSR GSwriteCSR; +extern _GSgetTitleInfo2 GSgetTitleInfo2; +extern _GSmakeSnapshot GSmakeSnapshot; +extern _GSmakeSnapshot2 GSmakeSnapshot2; +extern _GSirqCallback GSirqCallback; +extern _GSprintf GSprintf; +extern _GSsetBaseMem GSsetBaseMem; +extern _GSsetGameCRC GSsetGameCRC; +extern _GSsetFrameSkip GSsetFrameSkip; +extern _GSsetFrameLimit GSsetFrameLimit; +extern _GSsetVsync GSsetVsync; +extern _GSsetupRecording GSsetupRecording; +extern _GSreset GSreset; +extern _GSwriteCSR GSwriteCSR; #endif // PAD #ifndef BUILTIN_PAD_PLUGIN -extern _PADopen PADopen; -extern _PADstartPoll PADstartPoll; -extern _PADpoll PADpoll; -extern _PADquery PADquery; -extern _PADupdate PADupdate; -extern _PADkeyEvent PADkeyEvent; -extern _PADgsDriverInfo PADgsDriverInfo; -extern _PADsetSlot PADsetSlot; -extern _PADqueryMtap PADqueryMtap; -extern _PADWriteEvent PADWriteEvent; +extern _PADopen PADopen; +extern _PADstartPoll PADstartPoll; +extern _PADpoll PADpoll; +extern _PADquery PADquery; +extern _PADupdate PADupdate; +extern _PADkeyEvent PADkeyEvent; +extern _PADgsDriverInfo PADgsDriverInfo; +extern _PADsetSlot PADsetSlot; +extern _PADqueryMtap PADqueryMtap; +extern _PADWriteEvent PADWriteEvent; #endif // SPU2 #ifndef BUILTIN_SPU2_PLUGIN -extern _SPU2open SPU2open; -extern _SPU2reset SPU2reset; -extern _SPU2write SPU2write; -extern _SPU2read SPU2read; +extern _SPU2open SPU2open; +extern _SPU2reset SPU2reset; +extern _SPU2write SPU2write; +extern _SPU2read SPU2read; #ifdef ENABLE_NEW_IOPDMA_SPU2 -extern _SPU2dmaRead SPU2dmaRead; -extern _SPU2dmaWrite SPU2dmaWrite; -extern _SPU2dmaInterrupt SPU2dmaInterrupt; +extern _SPU2dmaRead SPU2dmaRead; +extern _SPU2dmaWrite SPU2dmaWrite; +extern _SPU2dmaInterrupt SPU2dmaInterrupt; #else -extern _SPU2readDMA4Mem SPU2readDMA4Mem; -extern _SPU2writeDMA4Mem SPU2writeDMA4Mem; +extern _SPU2readDMA4Mem SPU2readDMA4Mem; +extern _SPU2writeDMA4Mem SPU2writeDMA4Mem; extern _SPU2interruptDMA4 SPU2interruptDMA4; -extern _SPU2readDMA7Mem SPU2readDMA7Mem; -extern _SPU2writeDMA7Mem SPU2writeDMA7Mem; +extern _SPU2readDMA7Mem SPU2readDMA7Mem; +extern _SPU2writeDMA7Mem SPU2writeDMA7Mem; extern _SPU2setDMABaseAddr SPU2setDMABaseAddr; extern _SPU2interruptDMA7 SPU2interruptDMA7; -extern _SPU2ReadMemAddr SPU2ReadMemAddr; +extern _SPU2ReadMemAddr SPU2ReadMemAddr; extern _SPU2setupRecording SPU2setupRecording; -extern _SPU2WriteMemAddr SPU2WriteMemAddr; -extern _SPU2irqCallback SPU2irqCallback; +extern _SPU2WriteMemAddr SPU2WriteMemAddr; +extern _SPU2irqCallback SPU2irqCallback; #endif -extern _SPU2irqCallback SPU2irqCallback; +extern _SPU2irqCallback SPU2irqCallback; extern _SPU2setupRecording SPU2setupRecording; -extern _SPU2setClockPtr SPU2setClockPtr; +extern _SPU2setClockPtr SPU2setClockPtr; extern _SPU2setTimeStretcher SPU2setTimeStretcher; -extern _SPU2async SPU2async; +extern _SPU2async SPU2async; #endif // DEV9 #ifndef BUILTIN_DEV9_PLUGIN -extern _DEV9open DEV9open; -extern _DEV9read8 DEV9read8; -extern _DEV9read16 DEV9read16; -extern _DEV9read32 DEV9read32; -extern _DEV9write8 DEV9write8; -extern _DEV9write16 DEV9write16; -extern _DEV9write32 DEV9write32; +extern _DEV9open DEV9open; +extern _DEV9read8 DEV9read8; +extern _DEV9read16 DEV9read16; +extern _DEV9read32 DEV9read32; +extern _DEV9write8 DEV9write8; +extern _DEV9write16 DEV9write16; +extern _DEV9write32 DEV9write32; #ifdef ENABLE_NEW_IOPDMA_DEV9 -extern _DEV9dmaRead DEV9dmaRead; -extern _DEV9dmaWrite DEV9dmaWrite; -extern _DEV9dmaInterrupt DEV9dmaInterrupt; +extern _DEV9dmaRead DEV9dmaRead; +extern _DEV9dmaWrite DEV9dmaWrite; +extern _DEV9dmaInterrupt DEV9dmaInterrupt; #else -extern _DEV9readDMA8Mem DEV9readDMA8Mem; -extern _DEV9writeDMA8Mem DEV9writeDMA8Mem; +extern _DEV9readDMA8Mem DEV9readDMA8Mem; +extern _DEV9writeDMA8Mem DEV9writeDMA8Mem; #endif -extern _DEV9irqCallback DEV9irqCallback; -extern _DEV9irqHandler DEV9irqHandler; -extern _DEV9async DEV9async; +extern _DEV9irqCallback DEV9irqCallback; +extern _DEV9irqHandler DEV9irqHandler; +extern _DEV9async DEV9async; #endif // USB #ifndef BUILTIN_USB_PLUGIN -extern _USBopen USBopen; -extern _USBread8 USBread8; -extern _USBread16 USBread16; -extern _USBread32 USBread32; -extern _USBwrite8 USBwrite8; -extern _USBwrite16 USBwrite16; -extern _USBwrite32 USBwrite32; -extern _USBasync USBasync; +extern _USBopen USBopen; +extern _USBread8 USBread8; +extern _USBread16 USBread16; +extern _USBread32 USBread32; +extern _USBwrite8 USBwrite8; +extern _USBwrite16 USBwrite16; +extern _USBwrite32 USBwrite32; +extern _USBasync USBasync; -extern _USBirqCallback USBirqCallback; -extern _USBirqHandler USBirqHandler; -extern _USBsetRAM USBsetRAM; +extern _USBirqCallback USBirqCallback; +extern _USBirqHandler USBirqHandler; +extern _USBsetRAM USBsetRAM; #endif // FW #ifndef BUILTIN_FW_PLUGIN -extern _FWopen FWopen; -extern _FWread32 FWread32; -extern _FWwrite32 FWwrite32; -extern _FWirqCallback FWirqCallback; +extern _FWopen FWopen; +extern _FWread32 FWread32; +extern _FWwrite32 FWwrite32; +extern _FWirqCallback FWirqCallback; #endif #endif #ifdef __cplusplus -} // End extern "C" +} // End extern "C" #endif #endif /* __PS2EDEFS_H__ */ diff --git a/common/include/PS2Eext.h b/common/include/PS2Eext.h index 2c0412517e..ec378bf261 100644 --- a/common/include/PS2Eext.h +++ b/common/include/PS2Eext.h @@ -55,8 +55,7 @@ static void __forceinline PluginNullConfigure(std::wstring desc, s32 &log); static void __forceinline PluginNullAbout(const wchar_t *aboutText); #endif -enum FileMode -{ +enum FileMode { READ_FILE = 0, WRITE_FILE }; @@ -70,9 +69,8 @@ struct PluginLog { LogFile = fopen(logname.c_str(), "w"); - if (LogFile) - { - setvbuf(LogFile, NULL, _IONBF, 0); + if (LogFile) { + setvbuf(LogFile, NULL, _IONBF, 0); return true; } return false; @@ -90,11 +88,14 @@ struct PluginLog { va_list list; - if (LogFile == NULL) return; + if (LogFile == NULL) + return; va_start(list, fmt); - if (WriteToFile) vfprintf(LogFile, fmt, list); - if (WriteToConsole) vfprintf(stdout, fmt, list); + if (WriteToFile) + vfprintf(LogFile, fmt, list); + if (WriteToConsole) + vfprintf(stdout, fmt, list); va_end(list); } @@ -102,15 +103,20 @@ struct PluginLog { va_list list; - if (LogFile == NULL) return; + if (LogFile == NULL) + return; va_start(list, fmt); - if (WriteToFile) vfprintf(LogFile, fmt, list); - if (WriteToConsole) vfprintf(stdout, fmt, list); + if (WriteToFile) + vfprintf(LogFile, fmt, list); + if (WriteToConsole) + vfprintf(stdout, fmt, list); va_end(list); - if (WriteToFile) fprintf(LogFile, "\n"); - if (WriteToConsole) fprintf(stdout, "\n"); + if (WriteToFile) + fprintf(LogFile, "\n"); + if (WriteToConsole) + fprintf(stdout, "\n"); } #if !defined(_MSC_VER) || !defined(UNICODE) @@ -119,7 +125,8 @@ struct PluginLog va_list list; char buf[256]; - if (LogFile == NULL) return; + if (LogFile == NULL) + return; va_start(list, fmt); vsprintf(buf, fmt, list); @@ -128,19 +135,20 @@ struct PluginLog SysMessage(buf); } #else - void Message(const wchar_t *fmt, ...) - { - va_list list; - wchar_t buf[256]; + void Message(const wchar_t *fmt, ...) + { + va_list list; + wchar_t buf[256]; - if (LogFile == NULL) return; + if (LogFile == NULL) + return; - va_start(list, fmt); - vswprintf(buf, 256, fmt, list); - va_end(list); + va_start(list, fmt); + vswprintf(buf, 256, fmt, list); + va_end(list); - SysMessage(buf); - } + SysMessage(buf); + } #endif }; @@ -151,16 +159,14 @@ struct PluginConf bool Open(std::string name, FileMode mode = READ_FILE) { - if (mode == READ_FILE) - { + if (mode == READ_FILE) { ConfFile = fopen(name.c_str(), "r"); - } - else - { + } else { ConfFile = fopen(name.c_str(), "w"); } - if (ConfFile == NULL) return false; + if (ConfFile == NULL) + return false; return true; } @@ -173,14 +179,14 @@ struct PluginConf } } - int ReadInt(const std::string& item, int defval) + int ReadInt(const std::string &item, int defval) { int value = defval; std::string buf = item + " = %d\n"; if (ConfFile) - if (fscanf(ConfFile, buf.c_str(), &value) < 0) - fprintf(stderr, "Error reading %s\n", item.c_str()); + if (fscanf(ConfFile, buf.c_str(), &value) < 0) + fprintf(stderr, "Error reading %s\n", item.c_str()); return value; } @@ -189,7 +195,8 @@ struct PluginConf { std::string buf = item + " = %d\n"; - if (ConfFile) fprintf(ConfFile, buf.c_str(), value); + if (ConfFile) + fprintf(ConfFile, buf.c_str(), value); } }; @@ -204,19 +211,20 @@ static void SysMessage(const char *fmt, ...) vsprintf(msg, fmt, list); va_end(list); - if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; + if (msg[strlen(msg) - 1] == '\n') + msg[strlen(msg) - 1] = 0; GtkWidget *dialog; - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "%s", msg); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "%s", msg); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); } -static void __forceinline set_logging(GtkToggleButton *check, int& log) +static void __forceinline set_logging(GtkToggleButton *check, int &log) { log = gtk_toggle_button_get_active(check); } @@ -227,7 +235,7 @@ static void __forceinline PluginNullConfigure(std::string desc, int &log) /* Create the widgets */ dialog = gtk_dialog_new(); - label = gtk_label_new (desc.c_str()); + label = gtk_label_new(desc.c_str()); check_box = gtk_check_button_new_with_label("Logging"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), (log != 0)); @@ -236,14 +244,14 @@ static void __forceinline PluginNullConfigure(std::string desc, int &log) g_signal_connect(check_box, "toggled", G_CALLBACK(set_logging), &log); /* Add all our widgets, and show everything we've added to the dialog. */ - gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label); - gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), check_box); + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label); + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), check_box); gtk_dialog_add_button(GTK_DIALOG(dialog), "Ok", 0); - gtk_widget_show_all (dialog); + gtk_widget_show_all(dialog); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); } static void __forceinline PluginNullAbout(const char *aboutText) @@ -265,7 +273,8 @@ static void SysMessage(const char *fmt, ...) vsprintf(msg, fmt, list); va_end(list); - if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; + if (msg[strlen(msg) - 1] == '\n') + msg[strlen(msg) - 1] = 0; // TODO OSX can we use WX MessageBox here or should Cocoa MessageBox used? } @@ -297,7 +306,7 @@ static void __forceinline PluginNullAbout(const char *aboutText) #else -#define usleep(x) Sleep(x / 1000) +#define usleep(x) Sleep(x / 1000) #ifndef UNICODE @@ -305,15 +314,15 @@ static void __forceinline SysMessage(const char *fmt, ...) { va_list list; char tmp[512]; - va_start(list,fmt); - vsprintf(tmp,fmt,list); + va_start(list, fmt); + vsprintf(tmp, fmt, list); va_end(list); - MessageBox( GetActiveWindow(), tmp, "Message", MB_SETFOREGROUND | MB_OK ); + MessageBox(GetActiveWindow(), tmp, "Message", MB_SETFOREGROUND | MB_OK); } static void __forceinline PluginNullConfigure(std::string desc, s32 &log) { - /* To do: Write a dialog box that displays a dialog box with the text in desc, + /* To do: Write a dialog box that displays a dialog box with the text in desc, and a check box that says "Logging", checked if log !=0, and set log to 1 if it is checked on return, and 0 if it isn't. */ SysMessage("This space is intentionally left blank."); @@ -327,39 +336,39 @@ static void __forceinline PluginNullAbout(const char *aboutText) static void __forceinline SysMessage(const wchar_t *fmt, ...) { - va_list list; - wchar_t tmp[512]; - va_start(list, fmt); - vswprintf(tmp, 512, fmt, list); - va_end(list); - MessageBox(GetActiveWindow(), tmp, L"Message", MB_SETFOREGROUND | MB_OK); + va_list list; + wchar_t tmp[512]; + va_start(list, fmt); + vswprintf(tmp, 512, fmt, list); + va_end(list); + MessageBox(GetActiveWindow(), tmp, L"Message", MB_SETFOREGROUND | MB_OK); } static void __forceinline PluginNullConfigure(std::string desc, s32 &log) { - /* To do: Write a dialog box that displays a dialog box with the text in desc, + /* To do: Write a dialog box that displays a dialog box with the text in desc, and a check box that says "Logging", checked if log !=0, and set log to 1 if it is checked on return, and 0 if it isn't. */ - SysMessage(L"This space is intentionally left blank."); + SysMessage(L"This space is intentionally left blank."); } static void __forceinline PluginNullAbout(const wchar_t *aboutText) { - SysMessage(aboutText); + SysMessage(aboutText); } #endif -#define ENTRY_POINT \ -HINSTANCE hInst; \ -\ -BOOL APIENTRY DllMain(HANDLE hModule, /* DLL INIT*/ \ - DWORD dwReason, \ - LPVOID lpReserved) \ -{ \ - hInst = (HINSTANCE)hModule; \ - return TRUE; /* very quick :)*/ \ -} +#define ENTRY_POINT \ + HINSTANCE hInst; \ + \ + BOOL APIENTRY DllMain(HANDLE hModule, /* DLL INIT*/ \ + DWORD dwReason, \ + LPVOID lpReserved) \ + { \ + hInst = (HINSTANCE)hModule; \ + return TRUE; /* very quick :)*/ \ + } #endif #endif // PS2EEXT_H_INCLUDED diff --git a/common/include/PS2Etypes.h b/common/include/PS2Etypes.h index 930596a598..cc7f2ce49b 100644 --- a/common/include/PS2Etypes.h +++ b/common/include/PS2Etypes.h @@ -13,7 +13,7 @@ * If not, see . */ - // This file is just for backwards compatibility. +// This file is just for backwards compatibility. #ifndef __PS2ETYPES_H__ #define __PS2ETYPES_H__ diff --git a/common/include/Pcsx2Api.h b/common/include/Pcsx2Api.h index 06b1240d3c..0e27865f67 100644 --- a/common/include/Pcsx2Api.h +++ b/common/include/Pcsx2Api.h @@ -35,64 +35,71 @@ #ifdef _MSC_VER #define EXPORT_C(type) extern "C" type CALLBACK #else -#define EXPORT_C(type) extern "C" __attribute__((externally_visible,visibility("default"))) type +#define EXPORT_C(type) extern "C" __attribute__((externally_visible, visibility("default"))) type #endif -EXPORT_C(u32) PS2EgetLibType(void); -EXPORT_C(u32) PS2EgetLibVersion2(u32 type); -EXPORT_C(char*) PS2EgetLibName(void); +EXPORT_C(u32) +PS2EgetLibType(void); +EXPORT_C(u32) +PS2EgetLibVersion2(u32 type); +EXPORT_C(char *) +PS2EgetLibName(void); // Extended functions. // allows the plugin to see the whole configuration when started up. // Intended for them to get the ini and plugin paths, but could allow for other things as well. -EXPORT_C_(void) PS2EpassConfig(PcsxConfig Config); +EXPORT_C_(void) +PS2EpassConfig(PcsxConfig Config); // Alternately, this function serves the same purpose, but would work for emulators outside // of pcsx2. -EXPORT_C_(void) PS2EpassIniPath(const char *path); +EXPORT_C_(void) +PS2EpassIniPath(const char *path); // PS2EgetLibType returns (may be OR'd) enum { -PS2E_LT_GS = 0x01, -PS2E_LT_PAD = 0x02, // -=[ OBSOLETE ]=- -PS2E_LT_SPU2 = 0x04, -PS2E_LT_CDVD = 0x08, -PS2E_LT_DEV9 = 0x10, -PS2E_LT_USB = 0x20, -PS2E_LT_FW = 0x40, -PS2E_LT_SIO = 0x80 + PS2E_LT_GS = 0x01, + PS2E_LT_PAD = 0x02, // -=[ OBSOLETE ]=- + PS2E_LT_SPU2 = 0x04, + PS2E_LT_CDVD = 0x08, + PS2E_LT_DEV9 = 0x10, + PS2E_LT_USB = 0x20, + PS2E_LT_FW = 0x40, + PS2E_LT_SIO = 0x80 } PluginLibType; // PS2EgetLibVersion2 (high 16 bits) enum { -PS2E_GS_VERSION = 0x0006, -PS2E_PAD_VERSION = 0x0002, // -=[ OBSOLETE ]=- -PS2E_SPU2_VERSION = 0x0005, -PS2E_CDVD_VERSION = 0x0005, -PS2E_DEV9_VERSION = 0x0003, -PS2E_USB_VERSION = 0x0003, -PS2E_FW_VERSION = 0x0002, -PS2E_SIO_VERSION = 0x0001 + PS2E_GS_VERSION = 0x0006, + PS2E_PAD_VERSION = 0x0002, // -=[ OBSOLETE ]=- + PS2E_SPU2_VERSION = 0x0005, + PS2E_CDVD_VERSION = 0x0005, + PS2E_DEV9_VERSION = 0x0003, + PS2E_USB_VERSION = 0x0003, + PS2E_FW_VERSION = 0x0002, + PS2E_SIO_VERSION = 0x0001 } PluginLibVersion; // freeze modes: enum { -FREEZE_LOAD = 0, -FREEZE_SAVE = 1, -FREEZE_SIZE = 2 + FREEZE_LOAD = 0, + FREEZE_SAVE = 1, + FREEZE_SIZE = 2 } FreezeModes; -typedef struct _GSdriverInfo { - char name[8]; - void *common; +typedef struct _GSdriverInfo +{ + char name[8]; + void *common; } GSdriverInfo; #ifdef _MSC_VER -typedef struct _winInfo { // unsupported values must be set to zero - HWND hWnd; - HMENU hMenu; - HWND hStatusWnd; +typedef struct _winInfo +{ // unsupported values must be set to zero + HWND hWnd; + HMENU hMenu; + HWND hStatusWnd; } winInfo; #endif diff --git a/common/include/Pcsx2Defs.h b/common/include/Pcsx2Defs.h index 6f4bd4ec5a..dd3ea4fcfe 100644 --- a/common/include/Pcsx2Defs.h +++ b/common/include/Pcsx2Defs.h @@ -26,9 +26,9 @@ // make sure __POSIX__ is defined for all systems where we assume POSIX // compliance #if defined(__linux__) || defined(__APPLE__) || defined(__unix__) || defined(__CYGWIN__) || defined(__LINUX__) -# if !defined(__POSIX__) -# define __POSIX__ 1 -# endif +#if !defined(__POSIX__) +#define __POSIX__ 1 +#endif #endif #include "Pcsx2Types.h" @@ -39,7 +39,7 @@ // Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with // that as well. >_< #ifndef ArraySize -# define ArraySize(x) (sizeof(x)/sizeof((x)[0])) +#define ArraySize(x) (sizeof(x) / sizeof((x)[0])) #endif // -------------------------------------------------------------------------------------- @@ -51,51 +51,51 @@ // some tight loops it will likely make debug builds unusably slow. // #ifdef __cplusplus -# ifdef PCSX2_DEVBUILD - static const bool IsDevBuild = true; -# else - static const bool IsDevBuild = false; -# endif - -# ifdef PCSX2_DEBUG - static const bool IsDebugBuild = true; -# else - static const bool IsDebugBuild = false; -# endif - +#ifdef PCSX2_DEVBUILD +static const bool IsDevBuild = true; #else - -# ifdef PCSX2_DEVBUILD - static const u8 IsDevBuild = 1; -# else - static const u8 IsDevBuild = 0; -# endif - -# ifdef PCSX2_DEBUG - static const u8 IsDebugBuild = 1; -# else - static const u8 IsDebugBuild = 0; -# endif +static const bool IsDevBuild = false; #endif #ifdef PCSX2_DEBUG -# define pxDebugCode(code) code +static const bool IsDebugBuild = true; #else -# define pxDebugCode(code) +static const bool IsDebugBuild = false; +#endif + +#else + +#ifdef PCSX2_DEVBUILD +static const u8 IsDevBuild = 1; +#else +static const u8 IsDevBuild = 0; +#endif + +#ifdef PCSX2_DEBUG +static const u8 IsDebugBuild = 1; +#else +static const u8 IsDebugBuild = 0; +#endif +#endif + +#ifdef PCSX2_DEBUG +#define pxDebugCode(code) code +#else +#define pxDebugCode(code) #endif #ifdef PCSX2_DEVBUILD -# define pxDevelCode(code) code +#define pxDevelCode(code) code #else -# define pxDevelCode(code) +#define pxDevelCode(code) #endif #if defined(PCSX2_DEBUG) || defined(PCSX2_DEVBUILD) -# define pxReleaseCode(code) -# define pxNonReleaseCode(code) code +#define pxReleaseCode(code) +#define pxNonReleaseCode(code) code #else -# define pxReleaseCode(code) code -# define pxNonReleaseCode(code) +#define pxReleaseCode(code) code +#define pxNonReleaseCode(code) #endif // -------------------------------------------------------------------------------------- @@ -116,8 +116,8 @@ // Defines the memory page size for the target platform at compilation. All supported platforms // (which means Intel only right now) have a 4k granularity. -#define PCSX2_PAGESIZE 0x1000 -static const int __pagesize = PCSX2_PAGESIZE; +#define PCSX2_PAGESIZE 0x1000 +static const int __pagesize = PCSX2_PAGESIZE; // -------------------------------------------------------------------------------------- // Structure Packing (__packed) @@ -154,27 +154,27 @@ static const int __pagesize = PCSX2_PAGESIZE; // This is the 2005/earlier compatible packing define, which must be used in conjunction // with #ifdef _MSC_VER/#pragma pack() directives (ugly). -# define __packed +#define __packed -# define __aligned(alig) __declspec(align(alig)) -# define __aligned16 __declspec(align(16)) -# define __aligned32 __declspec(align(32)) -# define __pagealigned __declspec(align(PCSX2_PAGESIZE)) +#define __aligned(alig) __declspec(align(alig)) +#define __aligned16 __declspec(align(16)) +#define __aligned32 __declspec(align(32)) +#define __pagealigned __declspec(align(PCSX2_PAGESIZE)) - // Deprecated; use __align instead. -# define PCSX2_ALIGNED(alig,x) __declspec(align(alig)) x -# define PCSX2_ALIGNED_EXTERN(alig,x) extern __declspec(align(alig)) x -# define PCSX2_ALIGNED16(x) __declspec(align(16)) x -# define PCSX2_ALIGNED16_EXTERN(x) extern __declspec(align(16)) x +// Deprecated; use __align instead. +#define PCSX2_ALIGNED(alig, x) __declspec(align(alig)) x +#define PCSX2_ALIGNED_EXTERN(alig, x) extern __declspec(align(alig)) x +#define PCSX2_ALIGNED16(x) __declspec(align(16)) x +#define PCSX2_ALIGNED16_EXTERN(x) extern __declspec(align(16)) x -# define __noinline __declspec(noinline) -# define __threadlocal __declspec(thread) +#define __noinline __declspec(noinline) +#define __threadlocal __declspec(thread) // Don't know if there are Visual C++ equivalents of these. -# define likely(x) (!!(x)) -# define unlikely(x) (!!(x)) +#define likely(x) (!!(x)) +#define unlikely(x) (!!(x)) -# define CALLBACK __stdcall +#define CALLBACK __stdcall #else @@ -183,42 +183,42 @@ static const int __pagesize = PCSX2_PAGESIZE; // -------------------------------------------------------------------------------------- #ifndef __packed -# define __packed __attribute__((packed)) +#define __packed __attribute__((packed)) #endif #ifndef __aligned -# define __aligned(alig) __attribute__((aligned(alig))) +#define __aligned(alig) __attribute__((aligned(alig))) #endif -# define __aligned16 __attribute__((aligned(16))) -# define __aligned32 __attribute__((aligned(32))) -# define __pagealigned __attribute__((aligned(PCSX2_PAGESIZE))) - // Deprecated; use __align instead. -# define PCSX2_ALIGNED(alig,x) x __attribute((aligned(alig))) -# define PCSX2_ALIGNED16(x) x __attribute((aligned(16))) -# define PCSX2_ALIGNED_EXTERN(alig,x) extern x __attribute((aligned(alig))) -# define PCSX2_ALIGNED16_EXTERN(x) extern x __attribute((aligned(16))) +#define __aligned16 __attribute__((aligned(16))) +#define __aligned32 __attribute__((aligned(32))) +#define __pagealigned __attribute__((aligned(PCSX2_PAGESIZE))) +// Deprecated; use __align instead. +#define PCSX2_ALIGNED(alig, x) x __attribute((aligned(alig))) +#define PCSX2_ALIGNED16(x) x __attribute((aligned(16))) +#define PCSX2_ALIGNED_EXTERN(alig, x) extern x __attribute((aligned(alig))) +#define PCSX2_ALIGNED16_EXTERN(x) extern x __attribute((aligned(16))) -# define __assume(cond) ((void)0) // GCC has no equivalent for __assume -# define CALLBACK __attribute__((stdcall)) +#define __assume(cond) ((void)0) // GCC has no equivalent for __assume +#define CALLBACK __attribute__((stdcall)) // Inlining note: GCC needs ((unused)) attributes defined on inlined functions to suppress // warnings when a static inlined function isn't used in the scope of a single file (which // happens *by design* like all the friggen time >_<) #ifndef __fastcall -# define __fastcall __attribute__((fastcall)) +#define __fastcall __attribute__((fastcall)) +#endif +#define _inline __inline__ __attribute__((unused)) +#ifdef NDEBUG +#define __forceinline __attribute__((always_inline, unused)) +#else +#define __forceinline __attribute__((unused)) #endif -# define _inline __inline__ __attribute__((unused)) -# ifdef NDEBUG -# define __forceinline __attribute__((always_inline,unused)) -# else -# define __forceinline __attribute__((unused)) -# endif #ifndef __noinline -# define __noinline __attribute__((noinline)) +#define __noinline __attribute__((noinline)) #endif -# define __threadlocal __thread -# define likely(x) __builtin_expect(!!(x), 1) -# define unlikely(x) __builtin_expect(!!(x), 0) +#define __threadlocal __thread +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) #endif // -------------------------------------------------------------------------------------- @@ -233,13 +233,13 @@ static const int __pagesize = PCSX2_PAGESIZE; // environment. // #ifdef PCSX2_DEVBUILD -# define __releaseinline +#define __releaseinline #else -# define __releaseinline __forceinline +#define __releaseinline __forceinline #endif -#define __ri __releaseinline -#define __fi __forceinline -#define __fc __fastcall +#define __ri __releaseinline +#define __fi __forceinline +#define __fc __fastcall #endif diff --git a/common/include/Pcsx2Types.h b/common/include/Pcsx2Types.h index e6ab7c57d0..aba0f212f2 100644 --- a/common/include/Pcsx2Types.h +++ b/common/include/Pcsx2Types.h @@ -24,9 +24,9 @@ // depend on these types will not be usable (they will yield linker errors). #ifdef __cplusplus - class wxString; - class FastFormatAscii; - class FastFormatUnicode; +class wxString; +class FastFormatAscii; +class FastFormatUnicode; #endif @@ -65,116 +65,116 @@ typedef unsigned int uint; #ifdef __cplusplus union u128 { - struct - { - u64 lo; - u64 hi; - }; + struct + { + u64 lo; + u64 hi; + }; - u64 _u64[2]; - u32 _u32[4]; - u16 _u16[8]; - u8 _u8[16]; + u64 _u64[2]; + u32 _u32[4]; + u16 _u16[8]; + u8 _u8[16]; - // Explicit conversion from u64. Zero-extends the source through 128 bits. - static u128 From64( u64 src ) - { - u128 retval; - retval.lo = src; - retval.hi = 0; - return retval; - } + // Explicit conversion from u64. Zero-extends the source through 128 bits. + static u128 From64(u64 src) + { + u128 retval; + retval.lo = src; + retval.hi = 0; + return retval; + } - // Explicit conversion from u32. Zero-extends the source through 128 bits. - static u128 From32( u32 src ) - { - u128 retval; - retval._u32[0] = src; - retval._u32[1] = 0; - retval.hi = 0; - return retval; - } + // Explicit conversion from u32. Zero-extends the source through 128 bits. + static u128 From32(u32 src) + { + u128 retval; + retval._u32[0] = src; + retval._u32[1] = 0; + retval.hi = 0; + return retval; + } - operator u32() const { return _u32[0]; } - operator u16() const { return _u16[0]; } - operator u8() const { return _u8[0]; } - - bool operator==( const u128& right ) const - { - return (lo == right.lo) && (hi == right.hi); - } + operator u32() const { return _u32[0]; } + operator u16() const { return _u16[0]; } + operator u8() const { return _u8[0]; } - bool operator!=( const u128& right ) const - { - return (lo != right.lo) || (hi != right.hi); - } + bool operator==(const u128 &right) const + { + return (lo == right.lo) && (hi == right.hi); + } - // In order for the following ToString() and WriteTo methods to be available, you must - // be linking to both wxWidgets and the pxWidgets extension library. If you are not - // using them, then you will need to provide your own implementations of these methods. - wxString ToString() const; - wxString ToString64() const; - wxString ToString8() const; - - void WriteTo( FastFormatAscii& dest ) const; - void WriteTo8( FastFormatAscii& dest ) const; - void WriteTo64( FastFormatAscii& dest ) const; + bool operator!=(const u128 &right) const + { + return (lo != right.lo) || (hi != right.hi); + } + + // In order for the following ToString() and WriteTo methods to be available, you must + // be linking to both wxWidgets and the pxWidgets extension library. If you are not + // using them, then you will need to provide your own implementations of these methods. + wxString ToString() const; + wxString ToString64() const; + wxString ToString8() const; + + void WriteTo(FastFormatAscii &dest) const; + void WriteTo8(FastFormatAscii &dest) const; + void WriteTo64(FastFormatAscii &dest) const; }; struct s128 { - s64 lo; - s64 hi; + s64 lo; + s64 hi; - // explicit conversion from s64, with sign extension. - static s128 From64( s64 src ) - { - s128 retval = { src, (src < 0) ? -1 : 0 }; - return retval; - } + // explicit conversion from s64, with sign extension. + static s128 From64(s64 src) + { + s128 retval = {src, (src < 0) ? -1 : 0}; + return retval; + } - // explicit conversion from s32, with sign extension. - static s128 From64( s32 src ) - { - s128 retval = { src, (src < 0) ? -1 : 0 }; - return retval; - } + // explicit conversion from s32, with sign extension. + static s128 From64(s32 src) + { + s128 retval = {src, (src < 0) ? -1 : 0}; + return retval; + } - operator u32() const { return (s32)lo; } - operator u16() const { return (s16)lo; } - operator u8() const { return (s8)lo; } + operator u32() const { return (s32)lo; } + operator u16() const { return (s16)lo; } + operator u8() const { return (s8)lo; } - bool operator==( const s128& right ) const - { - return (lo == right.lo) && (hi == right.hi); - } + bool operator==(const s128 &right) const + { + return (lo == right.lo) && (hi == right.hi); + } - bool operator!=( const s128& right ) const - { - return (lo != right.lo) || (hi != right.hi); - } + bool operator!=(const s128 &right) const + { + return (lo != right.lo) || (hi != right.hi); + } }; #else typedef union _u128_t { - struct - { - u64 lo; - u64 hi; - }; + struct + { + u64 lo; + u64 hi; + }; - u64 _u64[2]; - u32 _u32[4]; - u16 _u16[8]; - u8 _u8[16]; + u64 _u64[2]; + u32 _u32[4]; + u16 _u16[8]; + u8 _u8[16]; } u128; typedef union _s128_t { - u64 lo; - s64 hi; + u64 lo; + s64 hi; } s128; #endif diff --git a/common/include/PluginCallbacks.h b/common/include/PluginCallbacks.h index db4635d927..7717001bae 100644 --- a/common/include/PluginCallbacks.h +++ b/common/include/PluginCallbacks.h @@ -107,7 +107,7 @@ #ifndef BOOL - typedef int BOOL; +typedef int BOOL; #endif // -------------------------------------------------------------------------------------- @@ -122,15 +122,15 @@ // on its HWND define that could be useful, and well it's probably good practice to use // platform available defines when they exist. // -#if defined( _WX_DEFS_H_ ) - typedef WXWidget PS2E_HWND; -#elif defined( _WINDEF_ ) - // For Windows let's use HWND, since it has some type strictness applied to it. - typedef HWND PS2E_HWND; +#if defined(_WX_DEFS_H_) +typedef WXWidget PS2E_HWND; +#elif defined(_WINDEF_) +// For Windows let's use HWND, since it has some type strictness applied to it. +typedef HWND PS2E_HWND; #else - // Unsupported platform... use void* as a best guess. Should work fine for almost - // any GUI platform, and certainly works for any currently supported one. - typedef void* PS2E_HWND; +// Unsupported platform... use void* as a best guess. Should work fine for almost +// any GUI platform, and certainly works for any currently supported one. +typedef void *PS2E_HWND; #endif // -------------------------------------------------------------------------------------- @@ -144,20 +144,20 @@ // pointer type. // #ifndef PS2E_THISPTR -# define PS2E_THISPTR struct _PS2E_ComponentAPI* +#define PS2E_THISPTR struct _PS2E_ComponentAPI * #else - // Ensure the user's defined PS2E_THISPTR retains the correct signature for our - // plugin API. - static_assert( sizeof(PS2E_THISPTR) == sizeof(void*), "Incorrect signature for PS2E_THISPTR" ); +// Ensure the user's defined PS2E_THISPTR retains the correct signature for our +// plugin API. +static_assert(sizeof(PS2E_THISPTR) == sizeof(void *), "Incorrect signature for PS2E_THISPTR"); #endif // PS2E_LIB_THISPTR - (library scope version of PS2E_THISPTR) #ifndef PS2E_LIB_THISPTR -# define PS2E_LIB_THISPTR void* +#define PS2E_LIB_THISPTR void * #else - // Ensure the user's defined PS2E_THISPTR retains the correct signature for our - // plugin API. - static_assert( sizeof(PS2E_LIB_THISPTR) == sizeof(void*), "Incorrect signature for PS2E_LIB_THISPTR" ); +// Ensure the user's defined PS2E_THISPTR retains the correct signature for our +// plugin API. +static_assert(sizeof(PS2E_LIB_THISPTR) == sizeof(void *), "Incorrect signature for PS2E_LIB_THISPTR"); #endif // Use fastcall by default, since under most circumstances the object-model approach of the @@ -174,58 +174,54 @@ extern "C" { // Plugin Type / Version Enumerations // ------------------------------------------------------------------------------------ -enum PS2E_ComponentTypes -{ - PS2E_TYPE_GS = 0, - PS2E_TYPE_PAD, - PS2E_TYPE_SPU2, - PS2E_TYPE_CDVD, - PS2E_TYPE_DEV9, - PS2E_TYPE_USB, - PS2E_TYPE_FW, - PS2E_TYPE_SIO, - PS2E_TYPE_Mcd, +enum PS2E_ComponentTypes { + PS2E_TYPE_GS = 0, + PS2E_TYPE_PAD, + PS2E_TYPE_SPU2, + PS2E_TYPE_CDVD, + PS2E_TYPE_DEV9, + PS2E_TYPE_USB, + PS2E_TYPE_FW, + PS2E_TYPE_SIO, + PS2E_TYPE_Mcd, }; -enum PluginLibVersion -{ - PS2E_VER_GS = 0x1000, - PS2E_VER_PAD = 0x1000, - PS2E_VER_SPU2 = 0x1000, - PS2E_VER_CDVD = 0x1000, - PS2E_VER_DEV9 = 0x1000, - PS2E_VER_USB = 0x1000, - PS2E_VER_FW = 0x1000, - PS2E_VER_SIO = 0x1000 +enum PluginLibVersion { + PS2E_VER_GS = 0x1000, + PS2E_VER_PAD = 0x1000, + PS2E_VER_SPU2 = 0x1000, + PS2E_VER_CDVD = 0x1000, + PS2E_VER_DEV9 = 0x1000, + PS2E_VER_USB = 0x1000, + PS2E_VER_FW = 0x1000, + PS2E_VER_SIO = 0x1000 }; -enum OSDIconTypes -{ - OSD_Icon_None = 0, - OSD_Icon_Error, - OSD_Icon_Notice, // An exclamation point maybe? +enum OSDIconTypes { + OSD_Icon_None = 0, + OSD_Icon_Error, + OSD_Icon_Notice, // An exclamation point maybe? - // [TODO] -- dunno. What else? + // [TODO] -- dunno. What else? - // Emulators implementing their own custom non-standard icon extensions should do so - // somewhere after OSD_Icon_ReserveEnd. All values below this are reserved. - // . - // . - // . - OSD_Icon_ReserveEnd = 0x1000 + // Emulators implementing their own custom non-standard icon extensions should do so + // somewhere after OSD_Icon_ReserveEnd. All values below this are reserved. + // . + // . + // . + OSD_Icon_ReserveEnd = 0x1000 }; -enum PS2E_MenuItemStyle -{ - MenuType_Normal = 0, - MenuType_Checked, - MenuType_Radio, - MenuType_Separator +enum PS2E_MenuItemStyle { + MenuType_Normal = 0, + MenuType_Checked, + MenuType_Radio, + MenuType_Separator }; -typedef void* PS2E_MenuHandle; -typedef void* PS2E_MenuItemHandle; -typedef void PS2E_CALLBACK PS2E_OnMenuItemClicked( PS2E_THISPTR* thisptr, void* userptr ); +typedef void *PS2E_MenuHandle; +typedef void *PS2E_MenuItemHandle; +typedef void PS2E_CALLBACK PS2E_OnMenuItemClicked(PS2E_THISPTR *thisptr, void *userptr); // -------------------------------------------------------------------------------------- // PS2E_ConsoleWriterAPI @@ -249,19 +245,19 @@ typedef void PS2E_CALLBACK PS2E_OnMenuItemClicked( PS2E_THISPTR* thisptr, void* // typedef struct _PS2E_ConsoleWriterAPI { - // Writes text to console; no newline is appended. - void (PS2E_CALLBACK* Write)( const char* fmt, ... ); + // Writes text to console; no newline is appended. + void(PS2E_CALLBACK *Write)(const char *fmt, ...); - // Appends an automatic newline to the specified formatted output. - void (PS2E_CALLBACK* WriteLn)( const char* fmt, ... ); + // Appends an automatic newline to the specified formatted output. + void(PS2E_CALLBACK *WriteLn)(const char *fmt, ...); - // This function always appends a newline. - void (PS2E_CALLBACK* Error)( const char* fmt, ... ); + // This function always appends a newline. + void(PS2E_CALLBACK *Error)(const char *fmt, ...); - // This function always appends a newline. - void (PS2E_CALLBACK* Warning)( const char* fmt, ... ); + // This function always appends a newline. + void(PS2E_CALLBACK *Warning)(const char *fmt, ...); - void* reserved[4]; + void *reserved[4]; } PS2E_ConsoleWriterAPI; @@ -278,19 +274,19 @@ typedef struct _PS2E_ConsoleWriterAPI // typedef struct _PS2E_ConsoleWriterWideAPI { - // Writes text to console; no newline is appended. - void (PS2E_CALLBACK* Write)( const wchar_t* fmt, ... ); + // Writes text to console; no newline is appended. + void(PS2E_CALLBACK *Write)(const wchar_t *fmt, ...); - // Appends an automatic newline to the specified formatted output. - void (PS2E_CALLBACK* WriteLn)( const wchar_t* fmt, ... ); + // Appends an automatic newline to the specified formatted output. + void(PS2E_CALLBACK *WriteLn)(const wchar_t *fmt, ...); - // This function always appends a newline. - void (PS2E_CALLBACK* Error)( const wchar_t* fmt, ... ); + // This function always appends a newline. + void(PS2E_CALLBACK *Error)(const wchar_t *fmt, ...); - // This function always appends a newline. - void (PS2E_CALLBACK* Warning)( const wchar_t* fmt, ... ); + // This function always appends a newline. + void(PS2E_CALLBACK *Warning)(const wchar_t *fmt, ...); - void* reserved[4]; + void *reserved[4]; } PS2E_ConsoleWriterWideAPI; @@ -305,9 +301,9 @@ typedef struct _PS2E_ConsoleWriterWideAPI // typedef struct _PS2E_Image { - u32 width; - u32 height; - u8* data; // RGBA data. top to bottom. + u32 width; + u32 height; + u8 *data; // RGBA data. top to bottom. } PS2E_Image; @@ -316,38 +312,38 @@ typedef struct _PS2E_Image // -------------------------------------------------------------------------------------- typedef struct _PS2E_MenuItemInfo { - const char* LabelText; - const char* HelpText; + const char *LabelText; + const char *HelpText; - // Optional image displayed with the menu option. The emulator may not support - // this option, or may choose to ignore or resize the image if the size parameters - // are outside a valid threshold. - const PS2E_Image* Image; + // Optional image displayed with the menu option. The emulator may not support + // this option, or may choose to ignore or resize the image if the size parameters + // are outside a valid threshold. + const PS2E_Image *Image; - // Specifies the style of the menu, either Normal, Checked, Radio, or Separator. - // This option is overridden if the SubMenu field is non-NULL (in such case the - // menu assumes submenu mode). - PS2E_MenuItemStyle Style; + // Specifies the style of the menu, either Normal, Checked, Radio, or Separator. + // This option is overridden if the SubMenu field is non-NULL (in such case the + // menu assumes submenu mode). + PS2E_MenuItemStyle Style; - // Specifies the handle of a sub menu to bind to this menu. If NULL, the menu is - // created normally. If non-NULL, the menu item will use sub-menu mode and will - // ignore the Style field. - PS2E_MenuHandle SubMenu; + // Specifies the handle of a sub menu to bind to this menu. If NULL, the menu is + // created normally. If non-NULL, the menu item will use sub-menu mode and will + // ignore the Style field. + PS2E_MenuHandle SubMenu; - // Menu that this item is attached to. When this struct is passed into AddMenuItem, - // the menu item will be automatically appended to the menu specified in this field - // if the field is non-NULL (if the field is NULL, then no action is taken). - PS2E_MenuHandle OwnerMenu; + // Menu that this item is attached to. When this struct is passed into AddMenuItem, + // the menu item will be automatically appended to the menu specified in this field + // if the field is non-NULL (if the field is NULL, then no action is taken). + PS2E_MenuHandle OwnerMenu; - // When FALSE the menu item will appear grayed out to the user, and unselectable. - BOOL Enabled; + // When FALSE the menu item will appear grayed out to the user, and unselectable. + BOOL Enabled; - // Optional user data pointer (or typecast integer value) - void* UserPtr; + // Optional user data pointer (or typecast integer value) + void *UserPtr; - // Callback issued when the menu is clicked/activated. If NULL, the menu will be - // disabled (grayed). - PS2E_OnMenuItemClicked* OnClicked; + // Callback issued when the menu is clicked/activated. If NULL, the menu will be + // disabled (grayed). + PS2E_OnMenuItemClicked *OnClicked; } PS2E_MenuItemInfo; @@ -356,72 +352,75 @@ typedef struct _PS2E_MenuItemInfo // -------------------------------------------------------------------------------------- typedef struct _PS2E_MenuItemAPI { - // Allocates a new MenuItem and returns its handle. The returned item can be added to any - // menu. - PS2E_MenuItemHandle (PS2E_CALLBACK* MenuItem_Create)( PS2E_THISPTR thisptr ); + // Allocates a new MenuItem and returns its handle. The returned item can be added to any + // menu. + PS2E_MenuItemHandle(PS2E_CALLBACK *MenuItem_Create)(PS2E_THISPTR thisptr); - // Deletes the menu item and frees allocated resources. The menu item will be removed from - // whatever menu it is attached to. If the menu item has a SubMenu, the SubMenu is not - // deleted. - void (PS2E_CALLBACK* MenuItem_Delete)( PS2E_MenuItemHandle mitem ); + // Deletes the menu item and frees allocated resources. The menu item will be removed from + // whatever menu it is attached to. If the menu item has a SubMenu, the SubMenu is not + // deleted. + void(PS2E_CALLBACK *MenuItem_Delete)(PS2E_MenuItemHandle mitem); - // (Re-)Assigns all properties for a menu. Assignment generally takes effect immediately. - void (PS2E_CALLBACK* MenuItem_SetEverything)( PS2E_MenuItemHandle mitem, const PS2E_MenuItemInfo* info ); + // (Re-)Assigns all properties for a menu. Assignment generally takes effect immediately. + void(PS2E_CALLBACK *MenuItem_SetEverything)(PS2E_MenuItemHandle mitem, const PS2E_MenuItemInfo *info); - // Sets the text label of a menu item. - void (PS2E_CALLBACK* MenuItem_SetText)( PS2E_MenuItemHandle mitem, const char* text ); + // Sets the text label of a menu item. + void(PS2E_CALLBACK *MenuItem_SetText)(PS2E_MenuItemHandle mitem, const char *text); - // Assigns the help text for a menu item. This text is typically shown in a status - // bar at the bottom of the current window. This value may be ignored if the emu - // interface does not have a context for help text. - void (PS2E_CALLBACK* MenuItem_SetHelpText)( PS2E_MenuItemHandle mitem, const char* helptxt ); + // Assigns the help text for a menu item. This text is typically shown in a status + // bar at the bottom of the current window. This value may be ignored if the emu + // interface does not have a context for help text. + void(PS2E_CALLBACK *MenuItem_SetHelpText)(PS2E_MenuItemHandle mitem, const char *helptxt); - // Gives the menu item an accompanying image (orientation of the image may depend - // on the operating system platform). - void (PS2E_CALLBACK* MenuItem_SetImage)( PS2E_MenuItemHandle mitem, const PS2E_Image* image ); + // Gives the menu item an accompanying image (orientation of the image may depend + // on the operating system platform). + void(PS2E_CALLBACK *MenuItem_SetImage)(PS2E_MenuItemHandle mitem, const PS2E_Image *image); - // Gives the menu item an accompanying image (orientation of the image may depend - // on the operating system platform). - // - // Returns: - // TRUE if the image was loaded successfully, or FALSE if the image was not found, - // could not be opened, or the image data is invalid (not a PNG, or data corrupted). - BOOL (PS2E_CALLBACK* MenuItem_SetImagePng_FromFile)( PS2E_MenuItemHandle mitem, const char* filename ); + // Gives the menu item an accompanying image (orientation of the image may depend + // on the operating system platform). + // + // Returns: + // TRUE if the image was loaded successfully, or FALSE if the image was not found, + // could not be opened, or the image data is invalid (not a PNG, or data corrupted). + BOOL(PS2E_CALLBACK *MenuItem_SetImagePng_FromFile) + (PS2E_MenuItemHandle mitem, const char *filename); - // Gives the menu item an accompanying image (orientation of the image may depend on - // the operating system platform). Image is loaded from memory using a memory stream - // reader. This method is useful for loading image data embedded into the dll. - // - // Returns: - // TRUE if the image was loaded successfully, or FALSE if the image data is invalid - // (not a PNG, or data corrupted). - BOOL (PS2E_CALLBACK* MenuItem_SetImagePng_FromMemory)( PS2E_MenuItemHandle mitem, const u8* data ); + // Gives the menu item an accompanying image (orientation of the image may depend on + // the operating system platform). Image is loaded from memory using a memory stream + // reader. This method is useful for loading image data embedded into the dll. + // + // Returns: + // TRUE if the image was loaded successfully, or FALSE if the image data is invalid + // (not a PNG, or data corrupted). + BOOL(PS2E_CALLBACK *MenuItem_SetImagePng_FromMemory) + (PS2E_MenuItemHandle mitem, const u8 *data); - // Assigns the menu item's style. - void (PS2E_CALLBACK* MenuItem_SetStyle)( PS2E_MenuItemHandle mitem, PS2E_MenuItemStyle style ); + // Assigns the menu item's style. + void(PS2E_CALLBACK *MenuItem_SetStyle)(PS2E_MenuItemHandle mitem, PS2E_MenuItemStyle style); - // Assigns a pointer value that the plugin can use to attach user-defined data to - // specific menu items. The value can be any integer typecast if you don't actually - // need more than an integers worth of data. - void (PS2E_CALLBACK* MenuItem_SetUserData)( PS2E_MenuItemHandle mitem, void* dataptr ); + // Assigns a pointer value that the plugin can use to attach user-defined data to + // specific menu items. The value can be any integer typecast if you don't actually + // need more than an integers worth of data. + void(PS2E_CALLBACK *MenuItem_SetUserData)(PS2E_MenuItemHandle mitem, void *dataptr); - // Assigns a submenu to the menu item, causing it to open the sub menu in cascade - // fashion. When a submenu is assigned, the Style attribute of the menu will be - // ignored. Passing NULL into this function will clear the submenu and return the - // menu item to whatever its current Style attribute is set to. - void (PS2E_CALLBACK* MenuItem_SetSubMenu)( PS2E_MenuItemHandle mitem, PS2E_MenuHandle submenu ); + // Assigns a submenu to the menu item, causing it to open the sub menu in cascade + // fashion. When a submenu is assigned, the Style attribute of the menu will be + // ignored. Passing NULL into this function will clear the submenu and return the + // menu item to whatever its current Style attribute is set to. + void(PS2E_CALLBACK *MenuItem_SetSubMenu)(PS2E_MenuItemHandle mitem, PS2E_MenuHandle submenu); - // Assigns the callback function for this menu (important!). If passed NULL, the menu - // item will be automatically disabled (grayed out) by the emulator. - void (PS2E_CALLBACK* MenuItem_SetCallback)( PS2E_MenuItemHandle mitem, PS2E_OnMenuItemClicked* onClickedCallback ); + // Assigns the callback function for this menu (important!). If passed NULL, the menu + // item will be automatically disabled (grayed out) by the emulator. + void(PS2E_CALLBACK *MenuItem_SetCallback)(PS2E_MenuItemHandle mitem, PS2E_OnMenuItemClicked *onClickedCallback); - // Assigns the enabled status of a MenuItem. Use FALSE to gray out the menuitem option. - void (PS2E_CALLBACK* MenuItem_Enable)( PS2E_MenuItemHandle mitem, BOOL enable ); + // Assigns the enabled status of a MenuItem. Use FALSE to gray out the menuitem option. + void(PS2E_CALLBACK *MenuItem_Enable)(PS2E_MenuItemHandle mitem, BOOL enable); - // Returns the current enable status of the specified menu item. - BOOL (PS2E_CALLBACK* MenuItem_IsEnabled)( PS2E_MenuItemHandle mitem ); + // Returns the current enable status of the specified menu item. + BOOL(PS2E_CALLBACK *MenuItem_IsEnabled) + (PS2E_MenuItemHandle mitem); - void* reserved[4]; + void *reserved[4]; } PS2E_MenuItemAPI; @@ -434,15 +433,15 @@ typedef struct _PS2E_MenuItemAPI // typedef struct _PS2E_VersionInfo { - // Low/Mid/High versions combine to form a number in the format of: 2.3.1 - // ... where 2 is the high version, 3 mid, and 1 low. - s16 VersionHigh; - s16 VersionMid; - s16 VersionLow; + // Low/Mid/High versions combine to form a number in the format of: 2.3.1 + // ... where 2 is the high version, 3 mid, and 1 low. + s16 VersionHigh; + s16 VersionMid; + s16 VersionLow; - // Revision typically refers a revision control system (such as SVN). When displayed - // by the emulator it will have an 'r' prefixed before it. - s64 Revision; + // Revision typically refers a revision control system (such as SVN). When displayed + // by the emulator it will have an 'r' prefixed before it. + s64 Revision; } PS2E_VersionInfo; @@ -454,19 +453,19 @@ typedef struct _PS2E_VersionInfo // typedef struct _PS2E_SessionInfo { - PS2E_HWND window; + PS2E_HWND window; - u32* CycleEE; // current EE cycle count - u32* CycleIOP; // current IOP cycle count + u32 *CycleEE; // current EE cycle count + u32 *CycleIOP; // current IOP cycle count - u32 ElfCRC; // CRC of the ELF header for this app/game + u32 ElfCRC; // CRC of the ELF header for this app/game - // Sony's assigned serial number, valid only for CD/CDVD games (ASCII-Z string). - // Ex: SLUS-2932 - // - // (if the running app is not a sony-registered game, the serial will be a zero - // length string). - char Serial[16]; + // Sony's assigned serial number, valid only for CD/CDVD games (ASCII-Z string). + // Ex: SLUS-2932 + // + // (if the running app is not a sony-registered game, the serial will be a zero + // length string). + char Serial[16]; } PS2E_SessionInfo; @@ -490,134 +489,137 @@ typedef struct _PS2E_SessionInfo // typedef struct _PS2E_EmulatorInfo { - // Brief name of the emulator (ex: "PCSX2") [required] - // Depending on the design of the emulator, this string may optionally include version - // information, however that is not recommended since it can inhibit backward support. - const char* EmuName; + // Brief name of the emulator (ex: "PCSX2") [required] + // Depending on the design of the emulator, this string may optionally include version + // information, however that is not recommended since it can inhibit backward support. + const char *EmuName; - // Version information. All fields besides the emulator's name are optional. - PS2E_VersionInfo EmuVersion; + // Version information. All fields besides the emulator's name are optional. + PS2E_VersionInfo EmuVersion; - // Number of Physical Cores, as detected by the emulator. - // This should always match the real # of cores supported by hardware. - int PhysicalCores; + // Number of Physical Cores, as detected by the emulator. + // This should always match the real # of cores supported by hardware. + int PhysicalCores; - // Number of Logical Cores, as detected and/or managed by the emulator. - // This is not necessarily a reflection of real hardware capabilities. The emu reserves - // the right to report this value as it deems appropriate, in management of threading - // resources. - int LogicalCores; + // Number of Logical Cores, as detected and/or managed by the emulator. + // This is not necessarily a reflection of real hardware capabilities. The emu reserves + // the right to report this value as it deems appropriate, in management of threading + // resources. + int LogicalCores; - // Specifies the size of the wchar_t of the emulator, in bytes. Plugin authors should be - // sure to check this against your own sizeof(wchar_t) before using any API that has - // a wchar_t parameter (such as the ConsoleWriterWide interface). wchar_t is a loosely - // defined type that can range from 8 bits to 32 bits (realistically, although there is - // no actual limit on size), and can vary between compilers for the same platform. - int Sizeof_wchar_t; + // Specifies the size of the wchar_t of the emulator, in bytes. Plugin authors should be + // sure to check this against your own sizeof(wchar_t) before using any API that has + // a wchar_t parameter (such as the ConsoleWriterWide interface). wchar_t is a loosely + // defined type that can range from 8 bits to 32 bits (realistically, although there is + // no actual limit on size), and can vary between compilers for the same platform. + int Sizeof_wchar_t; - // Reserved area for future expansion of the structure (avoids having to upgrade the - // plugin api for amending new extensions). - int reserved1[6]; + // Reserved area for future expansion of the structure (avoids having to upgrade the + // plugin api for amending new extensions). + int reserved1[6]; - // GetInt - // Self-explanatory. - // - // Returns: - // 0 - Value was retrieved successfully. - // 1 - Unknown value. Contents of dest are unchanged. - BOOL (PS2E_CALLBACK* GetInt)( const char* name, int* dest ); + // GetInt + // Self-explanatory. + // + // Returns: + // 0 - Value was retrieved successfully. + // 1 - Unknown value. Contents of dest are unchanged. + BOOL(PS2E_CALLBACK *GetInt) + (const char *name, int *dest); - // GetBoolean - // Assigns *dest either 1 (true) or 0 (false). Note to Emulators: Returning any non- - // zero value for true probably "works" but is not recommended, since C/C++ standard - // specifically defines the result of bool->int conversions as a 0 or 1 result. - // - // Returns: - // 0 - Value was retrieved successfully. - // 1 - Unknown value. Contents of dest are unchanged. - BOOL (PS2E_CALLBACK* GetBoolean)( const char* name, BOOL* result ); + // GetBoolean + // Assigns *dest either 1 (true) or 0 (false). Note to Emulators: Returning any non- + // zero value for true probably "works" but is not recommended, since C/C++ standard + // specifically defines the result of bool->int conversions as a 0 or 1 result. + // + // Returns: + // 0 - Value was retrieved successfully. + // 1 - Unknown value. Contents of dest are unchanged. + BOOL(PS2E_CALLBACK *GetBoolean) + (const char *name, BOOL *result); - // GetString - // Copies an ASCII-Z string into the dest pointer, to max length allowed. The result - // is always safely zero-terminated (none of that snprintf crap where you have to - // zero-terminate yourself >_<). - // - // Returns: - // 0 - Value was retrieved successfully. - // 1 - Unknown value. Contents of dest are unchanged. - BOOL (PS2E_CALLBACK* GetString)( const char* name, char* dest, int maxlen ); + // GetString + // Copies an ASCII-Z string into the dest pointer, to max length allowed. The result + // is always safely zero-terminated (none of that snprintf crap where you have to + // zero-terminate yourself >_<). + // + // Returns: + // 0 - Value was retrieved successfully. + // 1 - Unknown value. Contents of dest are unchanged. + BOOL(PS2E_CALLBACK *GetString) + (const char *name, char *dest, int maxlen); - // GetStringAlloc - // Provides an alternative to GetString, that can retrieve strings of arbitrary length. - // The plugin must provide a valid allocator callback, which takes a size parameter and - // returns a pointer to an allocation large enough to hold the size. - // - // It is then the responsibility of the plugin to free the allocated pointer when it - // is done with it. - // - char* (PS2E_CALLBACK* GetStringAlloc)( const char* name, void* (PS2E_CALLBACK *allocator)(int size) ); + // GetStringAlloc + // Provides an alternative to GetString, that can retrieve strings of arbitrary length. + // The plugin must provide a valid allocator callback, which takes a size parameter and + // returns a pointer to an allocation large enough to hold the size. + // + // It is then the responsibility of the plugin to free the allocated pointer when it + // is done with it. + // + char *(PS2E_CALLBACK *GetStringAlloc)(const char *name, void *(PS2E_CALLBACK *allocator)(int size)); - // OSD_WriteLn - // This function allows the plugin to post messages to the emulator's On-Screen Display. - // The OSD message will be displayed with the specified icon (optional) for the duration - // of a few seconds, or until other messages have scrolled it out of view. - // Implementation of the OSD is emulator specific, and there is no guarantee that the - // OSD will be honored at all. If the emulator does not support OSD then this function - // call is treated as a NOP. - // - // Typically a plugin author should only use the OSD for infrequent notices that are - // potentially useful to users playing games (particularly at fullscreen). Trouble- - // shooting and debug information is best dumped to console or to disk log, or displayed - // using a native popup window managed by the plugin. - // - // Parameters: - // icon - an icon identifier, typically from the PS2E_OSDIconTypes enumeration. Specific - // versions of emulators may provide their own icon extensions. The emulator will - // silently ignore unrecognized icon identifiers, thus retaining cross-compat. - // - // msg - string message displayed to the user. - // - void (PS2E_CALLBACK* OSD_WriteLn)( int icon, const char* msg ); + // OSD_WriteLn + // This function allows the plugin to post messages to the emulator's On-Screen Display. + // The OSD message will be displayed with the specified icon (optional) for the duration + // of a few seconds, or until other messages have scrolled it out of view. + // Implementation of the OSD is emulator specific, and there is no guarantee that the + // OSD will be honored at all. If the emulator does not support OSD then this function + // call is treated as a NOP. + // + // Typically a plugin author should only use the OSD for infrequent notices that are + // potentially useful to users playing games (particularly at fullscreen). Trouble- + // shooting and debug information is best dumped to console or to disk log, or displayed + // using a native popup window managed by the plugin. + // + // Parameters: + // icon - an icon identifier, typically from the PS2E_OSDIconTypes enumeration. Specific + // versions of emulators may provide their own icon extensions. The emulator will + // silently ignore unrecognized icon identifiers, thus retaining cross-compat. + // + // msg - string message displayed to the user. + // + void(PS2E_CALLBACK *OSD_WriteLn)(int icon, const char *msg); - // ---------------------------------------------------------------------------- - // Menu / MenuItem Section - // ---------------------------------------------------------------------------- + // ---------------------------------------------------------------------------- + // Menu / MenuItem Section + // ---------------------------------------------------------------------------- - void (PS2E_CALLBACK* AddMenuItem)( const PS2E_MenuItemInfo* item ); + void(PS2E_CALLBACK *AddMenuItem)(const PS2E_MenuItemInfo *item); - // Allocates a new menu handle and returns it. The returned menu can have any valid existing - // menu items bound to it, and can be assigned as a submenu to any created MenuItem. The menu - // can belong to multiple menu items, however menu items can only belong to a single menu. - PS2E_MenuHandle (PS2E_CALLBACK* Menu_Create)( PS2E_THISPTR thisptr ); + // Allocates a new menu handle and returns it. The returned menu can have any valid existing + // menu items bound to it, and can be assigned as a submenu to any created MenuItem. The menu + // can belong to multiple menu items, however menu items can only belong to a single menu. + PS2E_MenuHandle(PS2E_CALLBACK *Menu_Create)(PS2E_THISPTR thisptr); - // Deletes the specified menu and frees its allocated memory resources. NULL pointers are - // safely ignored. Any menu items also attached to this menu will be deleted. Even if you - // do not explicitly delete your plugin's menu resources, the emulator will do automatic - // cleanup after the plugin's instance is freed. - void (PS2E_CALLBACK* Menu_Delete)( PS2E_MenuHandle handle ); + // Deletes the specified menu and frees its allocated memory resources. NULL pointers are + // safely ignored. Any menu items also attached to this menu will be deleted. Even if you + // do not explicitly delete your plugin's menu resources, the emulator will do automatic + // cleanup after the plugin's instance is freed. + void(PS2E_CALLBACK *Menu_Delete)(PS2E_MenuHandle handle); - // Adds the specified menu item to this menu. Menu items can only belong to one menu at a - // time. If you assign an item to a created menu that already belongs to another menu, it - // will be removed from the other menu and moved to this one. To append a menu item to - // multiple menus, you will need to create multiple instances of the item. - void (PS2E_CALLBACK* Menu_AddItem)( PS2E_MenuHandle menu, PS2E_MenuItemHandle mitem ); + // Adds the specified menu item to this menu. Menu items can only belong to one menu at a + // time. If you assign an item to a created menu that already belongs to another menu, it + // will be removed from the other menu and moved to this one. To append a menu item to + // multiple menus, you will need to create multiple instances of the item. + void(PS2E_CALLBACK *Menu_AddItem)(PS2E_MenuHandle menu, PS2E_MenuItemHandle mitem); - // Interface for creating menu items and modifying their properties. - PS2E_MenuItemAPI MenuItem; + // Interface for creating menu items and modifying their properties. + PS2E_MenuItemAPI MenuItem; - // Provides a set of basic console functions for writing text to the emulator's - // console. Some emulators may not support a console, in which case these functions - // will be NOPs. For plain and simple to-disk logging, plugins should create and use - // their own logging facilities. - PS2E_ConsoleWriterAPI Console; + // Provides a set of basic console functions for writing text to the emulator's + // console. Some emulators may not support a console, in which case these functions + // will be NOPs. For plain and simple to-disk logging, plugins should create and use + // their own logging facilities. + PS2E_ConsoleWriterAPI Console; - // Optional wide-version of the Console API. Use with caution -- wchar_t is platform and - // compiler dependent, and so plugin authors should be sure to check the emulator's wchar_t - // side before using this interface. See PS2E_ConsoleWriterWideAPI comments for more info. - PS2E_ConsoleWriterWideAPI ConsoleW; + // Optional wide-version of the Console API. Use with caution -- wchar_t is platform and + // compiler dependent, and so plugin authors should be sure to check the emulator's wchar_t + // side before using this interface. See PS2E_ConsoleWriterWideAPI comments for more info. + PS2E_ConsoleWriterWideAPI ConsoleW; - void* reserved2[8]; + void *reserved2[8]; } PS2E_EmulatorInfo; @@ -629,8 +631,8 @@ typedef struct _PS2E_EmulatorInfo // typedef struct _PS2E_FreezeData { - u32 Size; // size of the data being frozen or thawed. This value is allowed to be changed by Freeze(). - void* Data; // pointer to the data target (freeze) or source (thaw) + u32 Size; // size of the data being frozen or thawed. This value is allowed to be changed by Freeze(). + void *Data; // pointer to the data target (freeze) or source (thaw) } PS2E_FreezeData; @@ -649,115 +651,115 @@ typedef struct _PS2E_FreezeData // typedef struct _PS2E_ComponentAPI { - // EmuOpen - // This function is called by the emulator when an emulation session is started. The - // plugin should take this opportunity to bind itself to the given window handle, open - // necessary audio/video/input devices, etc. - // - // Parameters: - // session - provides relevant emulation session information. Provided pointer is - // valid until after the subsequent call to EmuClose() - // - // Threading: EmuOpen is called from the GUI thread. All other emulation threads are - // guaranteed to be suspended or closed at the time of this call (no locks required). - // - void (PS2E_CALLBACK* EmuOpen)( PS2E_THISPTR thisptr, const PS2E_SessionInfo *session ); + // EmuOpen + // This function is called by the emulator when an emulation session is started. The + // plugin should take this opportunity to bind itself to the given window handle, open + // necessary audio/video/input devices, etc. + // + // Parameters: + // session - provides relevant emulation session information. Provided pointer is + // valid until after the subsequent call to EmuClose() + // + // Threading: EmuOpen is called from the GUI thread. All other emulation threads are + // guaranteed to be suspended or closed at the time of this call (no locks required). + // + void(PS2E_CALLBACK *EmuOpen)(PS2E_THISPTR thisptr, const PS2E_SessionInfo *session); - // EmuClose - // This function is called by the emulator prior to stopping emulation. The window - // handle specified in EmuOpen is guaranteed to be valid at the time EmuClose is called, - // and the plugin should unload/unbind all window dependencies at this time. - // - // Threading: EmuClose is called from the GUI thread. All other emulation threads are - // guaranteed to be suspended or closed at the time of this call (no locks required). - // - void (PS2E_CALLBACK* EmuClose)( PS2E_THISPTR thisptr ); + // EmuClose + // This function is called by the emulator prior to stopping emulation. The window + // handle specified in EmuOpen is guaranteed to be valid at the time EmuClose is called, + // and the plugin should unload/unbind all window dependencies at this time. + // + // Threading: EmuClose is called from the GUI thread. All other emulation threads are + // guaranteed to be suspended or closed at the time of this call (no locks required). + // + void(PS2E_CALLBACK *EmuClose)(PS2E_THISPTR thisptr); - // CalcFreezeSize - // This function should calculate and return the amount of memory needed for the plugin - // to freeze its complete emulation state. The value can be larger than the required - // amount of space, but cannot be smaller. - // - // The emulation state when this function is called is guaranteed to be the same as - // the following call to Freeze. - // - // Thread Safety: - // May be called from any thread (GUI, Emu, GS, Unknown, etc). - // All Emulation threads are halted at a PS2 logical vsync-end event. - // No locking is necessary. - u32 (PS2E_CALLBACK* CalcFreezeSize)( PS2E_THISPTR thisptr ); + // CalcFreezeSize + // This function should calculate and return the amount of memory needed for the plugin + // to freeze its complete emulation state. The value can be larger than the required + // amount of space, but cannot be smaller. + // + // The emulation state when this function is called is guaranteed to be the same as + // the following call to Freeze. + // + // Thread Safety: + // May be called from any thread (GUI, Emu, GS, Unknown, etc). + // All Emulation threads are halted at a PS2 logical vsync-end event. + // No locking is necessary. + u32(PS2E_CALLBACK *CalcFreezeSize)(PS2E_THISPTR thisptr); - // Freeze - // This function should make a complete copy of the plugin's emulation state into the - // provided dest->Data pointer. The plugin is allowed to reduce the dest->Size value - // but is not allowed to make it larger. The plugin will only receive calls to Freeze - // and Thaw while a plugin is in an EmuOpen() state. - // - // Parameters: - // dest - a pointer to the Data/Size destination buffer (never NULL). - // - // Thread Safety: - // May be called from any thread (GUI, Emu, GS, Unknown, etc). - // All Emulation threads are halted at a PS2 logical vsync-end event. - // No locking is necessary. - void (PS2E_CALLBACK* Freeze)( PS2E_THISPTR thisptr, PS2E_FreezeData* dest ); + // Freeze + // This function should make a complete copy of the plugin's emulation state into the + // provided dest->Data pointer. The plugin is allowed to reduce the dest->Size value + // but is not allowed to make it larger. The plugin will only receive calls to Freeze + // and Thaw while a plugin is in an EmuOpen() state. + // + // Parameters: + // dest - a pointer to the Data/Size destination buffer (never NULL). + // + // Thread Safety: + // May be called from any thread (GUI, Emu, GS, Unknown, etc). + // All Emulation threads are halted at a PS2 logical vsync-end event. + // No locking is necessary. + void(PS2E_CALLBACK *Freeze)(PS2E_THISPTR thisptr, PS2E_FreezeData *dest); - // Thaw - // Plugin should restore a complete emulation state from the given FreezeData. The - // plugin will only receive calls to Freeze and Thaw while a plugin is in an EmuOpen() - // state. - // - // Thread Safety: - // May be called from any thread (GUI, Emu, GS, Unknown, etc). - // All Emulation threads are halted at a PS2 logical vsync-end event. - // No locking is necessary. - void (PS2E_CALLBACK* Thaw)( PS2E_THISPTR thisptr, const PS2E_FreezeData* src ); + // Thaw + // Plugin should restore a complete emulation state from the given FreezeData. The + // plugin will only receive calls to Freeze and Thaw while a plugin is in an EmuOpen() + // state. + // + // Thread Safety: + // May be called from any thread (GUI, Emu, GS, Unknown, etc). + // All Emulation threads are halted at a PS2 logical vsync-end event. + // No locking is necessary. + void(PS2E_CALLBACK *Thaw)(PS2E_THISPTR thisptr, const PS2E_FreezeData *src); - // Configure - // The plugin should open a modal dialog box with plugin-specific settings and prop- - // erties. This function can be NULL, in which case the user's Configure option for - // this plugin is grayed out. - // - // All emulation is suspended and the plugin's state is saved to memory prior to this - // function being called. Configure is only called outside the context of EmuOpen() - // (after a call to EmuClose()). - // - // Plugin authors should ensure to re-read and re-apply all settings on EmuOpen(), - // which will ensure that any user changes will be applied immediately. For changes - // that can be applied without emulation suspension, see/use the GUI extensions for - // menu and toolbar shortcuts. - // - // Thread Safety: - // Always called from the GUI thread, with emulation in a halted state (no locks - // needed). - void (PS2E_CALLBACK* Configure)( PS2E_THISPTR thisptr ); + // Configure + // The plugin should open a modal dialog box with plugin-specific settings and prop- + // erties. This function can be NULL, in which case the user's Configure option for + // this plugin is grayed out. + // + // All emulation is suspended and the plugin's state is saved to memory prior to this + // function being called. Configure is only called outside the context of EmuOpen() + // (after a call to EmuClose()). + // + // Plugin authors should ensure to re-read and re-apply all settings on EmuOpen(), + // which will ensure that any user changes will be applied immediately. For changes + // that can be applied without emulation suspension, see/use the GUI extensions for + // menu and toolbar shortcuts. + // + // Thread Safety: + // Always called from the GUI thread, with emulation in a halted state (no locks + // needed). + void(PS2E_CALLBACK *Configure)(PS2E_THISPTR thisptr); - // GetLastError - // This is an optional method with allows the emulator to retrieve extended formatted - // error information about a recent failed plugin call. If implemented by the plugin, - // it should store message information in it's PS2E_THISPTR allocation, and free the - // string buffers when the plugin's instance is deleted. - // - // The plugin is allowed to return NULL for either msg_diag or msg_user (or both). - // Returned pointers should be static global arrays, and must be NULL terminated. If - // only one message is provided, it will be used for both console log and popup. - // - // Parameters: - // msg_diag - diagnostic message, which is english only and typically intended for - // console or disk logging. - // - // msg_user - optional translated user message, which is displayed as a popup to explain - // to the user why the plugin failed to initialize. - // - // Thread safety: - // * Thread Affinity: none. May be called from any thread. - // * Interlocking: Instance. All calls from the emu are fully interlocked against - // the plugin instance. - // - void (PS2E_CALLBACK* GetLastError)( PS2E_THISPTR thisptr, char* const* msg_diag, wchar_t* const* msg_user ); + // GetLastError + // This is an optional method with allows the emulator to retrieve extended formatted + // error information about a recent failed plugin call. If implemented by the plugin, + // it should store message information in it's PS2E_THISPTR allocation, and free the + // string buffers when the plugin's instance is deleted. + // + // The plugin is allowed to return NULL for either msg_diag or msg_user (or both). + // Returned pointers should be static global arrays, and must be NULL terminated. If + // only one message is provided, it will be used for both console log and popup. + // + // Parameters: + // msg_diag - diagnostic message, which is english only and typically intended for + // console or disk logging. + // + // msg_user - optional translated user message, which is displayed as a popup to explain + // to the user why the plugin failed to initialize. + // + // Thread safety: + // * Thread Affinity: none. May be called from any thread. + // * Interlocking: Instance. All calls from the emu are fully interlocked against + // the plugin instance. + // + void(PS2E_CALLBACK *GetLastError)(PS2E_THISPTR thisptr, char *const *msg_diag, wchar_t *const *msg_user); - // Reserved area at the end of the structure, for future API expansion. - void* reserved[8]; + // Reserved area at the end of the structure, for future API expansion. + void *reserved[8]; } PS2E_ComponentAPI; @@ -780,111 +782,113 @@ typedef struct _PS2E_ComponentAPI // typedef struct _PS2E_LibraryAPI { - // GetName - // Returns an ASCII-Z (zero-terminated) string name of the plugin. The name should - // *not* include version or build information. That info is returned separately - // via GetVersion. The return value cannot be NULL (if it is NULL, the emulator - // will assume the DLL is invalid and ignore it). - // - // The pointer should reference a static/global scope char array, or an allocated - // heap pointer (not recommended). - // - // This function may be called multiple times by the emulator, so it should accommodate - // for such if it performs heap allocations or other initialization procedures. - const char* (PS2E_CALLBACK* GetName)(); + // GetName + // Returns an ASCII-Z (zero-terminated) string name of the plugin. The name should + // *not* include version or build information. That info is returned separately + // via GetVersion. The return value cannot be NULL (if it is NULL, the emulator + // will assume the DLL is invalid and ignore it). + // + // The pointer should reference a static/global scope char array, or an allocated + // heap pointer (not recommended). + // + // This function may be called multiple times by the emulator, so it should accommodate + // for such if it performs heap allocations or other initialization procedures. + const char *(PS2E_CALLBACK *GetName)(); - // GetVersion - // This function returns name and version information for the requested PS2 component. - // If the plugin does not support the requested component, it should return NULL. - // The returned pointer, if non-NULL, must be either a static value [recommended] or a - // heap-allocated value, and valid for the lifetime of the plugin. - // - // This function may be called multiple times by the emulator, so it should accommodate - // for such if it performs heap allocations or other initialization procedures. - // - // Typically a plugin will return the same version for all supported components. The - // component parameter is mostly provided to allow this function to serve a dual purpose - // of both component versioning and as a component enumerator. - // - // See PS2E_VersionInfo for more details. - // - // Parameters: - // component - indicates the ps2 component plugin to be versioned. If the plugin - // does not support the requested component, the function should return NULL. - // - const PS2E_VersionInfo* (PS2E_CALLBACK* GetVersion)( u32 component ); + // GetVersion + // This function returns name and version information for the requested PS2 component. + // If the plugin does not support the requested component, it should return NULL. + // The returned pointer, if non-NULL, must be either a static value [recommended] or a + // heap-allocated value, and valid for the lifetime of the plugin. + // + // This function may be called multiple times by the emulator, so it should accommodate + // for such if it performs heap allocations or other initialization procedures. + // + // Typically a plugin will return the same version for all supported components. The + // component parameter is mostly provided to allow this function to serve a dual purpose + // of both component versioning and as a component enumerator. + // + // See PS2E_VersionInfo for more details. + // + // Parameters: + // component - indicates the ps2 component plugin to be versioned. If the plugin + // does not support the requested component, the function should return NULL. + // + const PS2E_VersionInfo *(PS2E_CALLBACK *GetVersion)(u32 component); - // Test - // Called by the plugin enumerator to check the hardware availability of the specified - // component. The function should return 1 if the plugin appears to be supported, or - // 0 if the test failed. - // - // While a plugin is welcome to use its own CPU capabilities information, it is recommended - // that you use the emulator provided CPU capabilities structure instead. The emulator may - // have provisions in its interface to allow for the forced disabling of extended CPU cap- - // abilities, for testing purposes. - // - BOOL (PS2E_CALLBACK* Test)( u32 component, const PS2E_EmulatorInfo* xinfo ); + // Test + // Called by the plugin enumerator to check the hardware availability of the specified + // component. The function should return 1 if the plugin appears to be supported, or + // 0 if the test failed. + // + // While a plugin is welcome to use its own CPU capabilities information, it is recommended + // that you use the emulator provided CPU capabilities structure instead. The emulator may + // have provisions in its interface to allow for the forced disabling of extended CPU cap- + // abilities, for testing purposes. + // + BOOL(PS2E_CALLBACK *Test) + (u32 component, const PS2E_EmulatorInfo *xinfo); - // NewComponentInstance - // The emulator calls this function to fetch the API for the requested component. - // The plugin is expected to perform an "availability test" (the same test as performed - // by Test()) and return NULL if the plugin does not support the host machine's hardware - // or software installations. - // - // This function is only called for components which the plugin returned a non-NULL - // version information struct for in GetVersion(). - // - // Plugin Allocation Strategy: - // The Component API has been designed with function invocation efficiency in mind. - // To allocate your plugin's component instance you should create a structure that - // contains PS2E_ComponentAPI_* as the first member (where * refers to the PS2 - // component type), and plugin-specific instance data is stored as any number of - // subsequent members in the struct. - // - // Parameters: - // component - indicates the ps2 component API to return. - // dest - structure to fill with plugin function implementations. Dest should - // be manually typecast by the plugin to match the requested component. - // - // OnError: - // Plugins may optionally prepare more detailed information on why the plugin failed - // it's availability test which the emu can request via GetLastError. - // - PS2E_THISPTR (PS2E_CALLBACK* NewComponentInstance)( u32 component ); + // NewComponentInstance + // The emulator calls this function to fetch the API for the requested component. + // The plugin is expected to perform an "availability test" (the same test as performed + // by Test()) and return NULL if the plugin does not support the host machine's hardware + // or software installations. + // + // This function is only called for components which the plugin returned a non-NULL + // version information struct for in GetVersion(). + // + // Plugin Allocation Strategy: + // The Component API has been designed with function invocation efficiency in mind. + // To allocate your plugin's component instance you should create a structure that + // contains PS2E_ComponentAPI_* as the first member (where * refers to the PS2 + // component type), and plugin-specific instance data is stored as any number of + // subsequent members in the struct. + // + // Parameters: + // component - indicates the ps2 component API to return. + // dest - structure to fill with plugin function implementations. Dest should + // be manually typecast by the plugin to match the requested component. + // + // OnError: + // Plugins may optionally prepare more detailed information on why the plugin failed + // it's availability test which the emu can request via GetLastError. + // + PS2E_THISPTR(PS2E_CALLBACK *NewComponentInstance) + (u32 component); - // DeleteComponentInstance - // Called by the emulator when the plugin component is to be shutdown. The component API - // instance pointer can be safely deleted here. - void (PS2E_CALLBACK* DeleteComponentInstance)( PS2E_THISPTR instance ); + // DeleteComponentInstance + // Called by the emulator when the plugin component is to be shutdown. The component API + // instance pointer can be safely deleted here. + void(PS2E_CALLBACK *DeleteComponentInstance)(PS2E_THISPTR instance); - // SetSettingsFolder - // Callback is passed an ASCII-Z string representing the folder where the emulator's - // settings files are stored (may either be under the user's documents folder, or a - // location relative to the CWD of the emu application). - // - // Typically this callback is only issued once per plugin session, aand prior to the - // opening of any PS2 components. It is the responsibility of the emu to save the - // emulation state, shutdown plugins, and restart everything anew from the new settings - // in such an event as a dynamic change of the settings folder. - // - void (PS2E_CALLBACK* SetSettingsFolder)( const char* folder ); + // SetSettingsFolder + // Callback is passed an ASCII-Z string representing the folder where the emulator's + // settings files are stored (may either be under the user's documents folder, or a + // location relative to the CWD of the emu application). + // + // Typically this callback is only issued once per plugin session, aand prior to the + // opening of any PS2 components. It is the responsibility of the emu to save the + // emulation state, shutdown plugins, and restart everything anew from the new settings + // in such an event as a dynamic change of the settings folder. + // + void(PS2E_CALLBACK *SetSettingsFolder)(const char *folder); - // SetLogFolder - // This callback may be issued at any time. It is the responsibility of the plugin - // to do the necessary actions to close existing disk logging facilities and re-open - // new facilities. - // - // Thread Safety: - // This function is always called from the GUI thread. All emulation threads are - // suspended during the call, so no locking is required. - // - void (PS2E_CALLBACK* SetLogFolder)( const char* folder ); + // SetLogFolder + // This callback may be issued at any time. It is the responsibility of the plugin + // to do the necessary actions to close existing disk logging facilities and re-open + // new facilities. + // + // Thread Safety: + // This function is always called from the GUI thread. All emulation threads are + // suspended during the call, so no locking is required. + // + void(PS2E_CALLBACK *SetLogFolder)(const char *folder); - // Reserved area at the end of the structure, for future API expansion. This area - // should always be zeroed out, so that future versions of emulators that may have - // defined functions here will recognize the functions as not supported by the plugin. - void* reserved[12]; + // Reserved area at the end of the structure, for future API expansion. This area + // should always be zeroed out, so that future versions of emulators that may have + // defined functions here will recognize the functions as not supported by the plugin. + void *reserved[12]; } PS2E_LibraryAPI; @@ -899,117 +903,119 @@ typedef struct _PS2E_LibraryAPI // typedef struct _PS2E_ComponentAPI_GS { - // Base Component API (inherited structure) - struct _PS2E_ComponentAPI Base; + // Base Component API (inherited structure) + struct _PS2E_ComponentAPI Base; - // SetSnapshotsFolder - // Callback is passed an ASCII-Z string representing the folder where the emulator's - // snapshots are to be saved (typically located under user documents, but may be CWD - // or any user-specified location). - // - // Thread Safety: - // This function may be called from either GUI thread or GS thread. Emulators calling - // it from non-GS threads must ensure mutex locking with TakeSnapshot (meaning the - // plugin should be free to disregard threading concerns). - void (PS2E_CALLBACK* GsSetSnapshotsFolder)( PS2E_THISPTR thisptr, const char* folder ); + // SetSnapshotsFolder + // Callback is passed an ASCII-Z string representing the folder where the emulator's + // snapshots are to be saved (typically located under user documents, but may be CWD + // or any user-specified location). + // + // Thread Safety: + // This function may be called from either GUI thread or GS thread. Emulators calling + // it from non-GS threads must ensure mutex locking with TakeSnapshot (meaning the + // plugin should be free to disregard threading concerns). + void(PS2E_CALLBACK *GsSetSnapshotsFolder)(PS2E_THISPTR thisptr, const char *folder); - // TakeSnapshot - // The GS plugin is to save the current frame into the given target image. This - // function is always called immediately after a GSvsync(), ensuring that the current - // framebuffer is safely intact for capture. - // - // Returns TRUE if the snapshot succeeded, or FALSE if it failed (contents of dest - // are considered indeterminate and will be ignored by the emu). - BOOL (PS2E_CALLBACK* GsTakeSnapshot)( PS2E_THISPTR thisptr, PS2E_Image* dest ); + // TakeSnapshot + // The GS plugin is to save the current frame into the given target image. This + // function is always called immediately after a GSvsync(), ensuring that the current + // framebuffer is safely intact for capture. + // + // Returns TRUE if the snapshot succeeded, or FALSE if it failed (contents of dest + // are considered indeterminate and will be ignored by the emu). + BOOL(PS2E_CALLBACK *GsTakeSnapshot) + (PS2E_THISPTR thisptr, PS2E_Image *dest); - // OSD_QueueMessage - // Queues a message to the GS for display to the user. The GS can print the message - // where-ever it pleases, though it's suggested that the messages be printed either - // near the top or the bottom of the window (and in the black/empty area if the - // game's display is letterboxed). - // - // Parameters: - // message - text to queue (UTF8 format); will always be a single line (emulator - // is responsible for pre-processing linebreaks into multiple messages). The pointer - // will become invalid after this call retunrs, so be sure to make a local copy of the - // text. - // - // timeout - Suggested timeout period, in milliseconds. This is a hint and need - // not be strictly adhered to by the GS. - // - void (PS2E_CALLBACK* OSD_QueueMessage)( PS2E_THISPTR thisptr, const char* msg, int timeout ); + // OSD_QueueMessage + // Queues a message to the GS for display to the user. The GS can print the message + // where-ever it pleases, though it's suggested that the messages be printed either + // near the top or the bottom of the window (and in the black/empty area if the + // game's display is letterboxed). + // + // Parameters: + // message - text to queue (UTF8 format); will always be a single line (emulator + // is responsible for pre-processing linebreaks into multiple messages). The pointer + // will become invalid after this call retunrs, so be sure to make a local copy of the + // text. + // + // timeout - Suggested timeout period, in milliseconds. This is a hint and need + // not be strictly adhered to by the GS. + // + void(PS2E_CALLBACK *OSD_QueueMessage)(PS2E_THISPTR thisptr, const char *msg, int timeout); - // OSD_IconStatus - // Sets the visibility status of an icon. Icon placement can be determined by the GS, - // although it's recommended that the icon be displayed near a corner of the screen, and - // be displayed in the empty/black areas if present (letterboxing). - // - // Parameters: - // iconId - Icon status to change - // alpha - 0.0 is hdden, 1.0 is visible. Other alpha values may be used as either - // transparency or as a scrolling factor (ie, to scroll the icon in and out of view, in - // any way the GS plugin sees fit). - void (PS2E_CALLBACK* OSD_IconStatus)( PS2E_THISPTR thisptr, OSDIconTypes iconId, float alpha ); + // OSD_IconStatus + // Sets the visibility status of an icon. Icon placement can be determined by the GS, + // although it's recommended that the icon be displayed near a corner of the screen, and + // be displayed in the empty/black areas if present (letterboxing). + // + // Parameters: + // iconId - Icon status to change + // alpha - 0.0 is hdden, 1.0 is visible. Other alpha values may be used as either + // transparency or as a scrolling factor (ie, to scroll the icon in and out of view, in + // any way the GS plugin sees fit). + void(PS2E_CALLBACK *OSD_IconStatus)(PS2E_THISPTR thisptr, OSDIconTypes iconId, float alpha); - // GSvsync - // - // Returns FALSE if the plugin encountered a critical error while updating the display; - // indicating a device or emulation failure that should terminate the current emulation. - // (if any critical errors accumulated during GStransferTags or GStransferImage, they - // should also be handled here by returning FALSE) - // - BOOL (PS2E_CALLBACK* GsVsync)(int field); + // GSvsync + // + // Returns FALSE if the plugin encountered a critical error while updating the display; + // indicating a device or emulation failure that should terminate the current emulation. + // (if any critical errors accumulated during GStransferTags or GStransferImage, they + // should also be handled here by returning FALSE) + // + BOOL(PS2E_CALLBACK *GsVsync) + (int field); - // GSwriteRegs - // Sends a GIFtag and associated register data. This is the main transfer method for all - // GIF register data. REGLIST mode is unpacked into the forat described below. - // - // Note that SIGNAL, FINISH, and LABEL tags are handled internally by the emulator in a - // thread-safe manner -- the GS plugin should ignore those tags when processing. - // - // Returns FALSE if the plugin encountered a critical error while setting texture; - // indicating a device failure. - // - // Parameters: - // pMem - pointer to source memory for the register descriptors and register data. - // The first 128 bits (1 qwc) is the descriptors unrolled into 16x8 format. The - // following data is (regcnt x tagcnt) QWCs in length. - // - // regcnt - number of registers per loop packet (register descriptors are filled - // low->high). Valid range is 1->16, and will never be zero. - // - // nloop - number of loops of register data. Valid range is 1->32767 (upper 17 - // bits are always zero). This value will never be zero. - void (PS2E_CALLBACK* GsWriteRegs)(const u128 *pMem, int regcnt, int nloop); + // GSwriteRegs + // Sends a GIFtag and associated register data. This is the main transfer method for all + // GIF register data. REGLIST mode is unpacked into the forat described below. + // + // Note that SIGNAL, FINISH, and LABEL tags are handled internally by the emulator in a + // thread-safe manner -- the GS plugin should ignore those tags when processing. + // + // Returns FALSE if the plugin encountered a critical error while setting texture; + // indicating a device failure. + // + // Parameters: + // pMem - pointer to source memory for the register descriptors and register data. + // The first 128 bits (1 qwc) is the descriptors unrolled into 16x8 format. The + // following data is (regcnt x tagcnt) QWCs in length. + // + // regcnt - number of registers per loop packet (register descriptors are filled + // low->high). Valid range is 1->16, and will never be zero. + // + // nloop - number of loops of register data. Valid range is 1->32767 (upper 17 + // bits are always zero). This value will never be zero. + void(PS2E_CALLBACK *GsWriteRegs)(const u128 *pMem, int regcnt, int nloop); - // GSwritePrim - // Starts a new prim by sending the specified value to the PRIM register. The emulator - // only posts this data to the GS s per the rules of GIFpath processing (note however - // that packed register data can also contain PRIM writes). - // - // Parameters: - // primData - value to write to the PRIM register. Only the bottom 10 bits are - // valid. Upper bits are always zero. - void (PS2E_CALLBACK* GsWritePrim)(int primData); + // GSwritePrim + // Starts a new prim by sending the specified value to the PRIM register. The emulator + // only posts this data to the GS s per the rules of GIFpath processing (note however + // that packed register data can also contain PRIM writes). + // + // Parameters: + // primData - value to write to the PRIM register. Only the bottom 10 bits are + // valid. Upper bits are always zero. + void(PS2E_CALLBACK *GsWritePrim)(int primData); - // GSwriteImage - // Uploads new image data. Data uploaded may be in any number of partial chunks, for - // which the GS is responsible for managing the state machine for writes to GS memory. - // - // Plugin authors: Note that it is valid for games to only modify a small portion of a - // larger texture buffer, or for games to modify several portions of a single large - // buffer, by using mid-transfer writes to TRXPOS and TRXDIR (TRXPOS writes only become - // effective once TRXDIR has been written). - void (PS2E_CALLBACK* GsWriteImage)(const u128 *pMem, int qwc_cnt); + // GSwriteImage + // Uploads new image data. Data uploaded may be in any number of partial chunks, for + // which the GS is responsible for managing the state machine for writes to GS memory. + // + // Plugin authors: Note that it is valid for games to only modify a small portion of a + // larger texture buffer, or for games to modify several portions of a single large + // buffer, by using mid-transfer writes to TRXPOS and TRXDIR (TRXPOS writes only become + // effective once TRXDIR has been written). + void(PS2E_CALLBACK *GsWriteImage)(const u128 *pMem, int qwc_cnt); - // GSreadImage - // This special callback is for implementing the Read mode direction of the GIFpath. - // The GS plugin writes the texture data as requested by it's internally managed state - // values for TRXPOS/TRXREG to the buffer provided by pMem. The buffer size is qwc_cnt - // and the GS must not write more than that. - void (PS2E_CALLBACK* GsReadImage)(u128 *pMem, int qwc_cnt); + // GSreadImage + // This special callback is for implementing the Read mode direction of the GIFpath. + // The GS plugin writes the texture data as requested by it's internally managed state + // values for TRXPOS/TRXREG to the buffer provided by pMem. The buffer size is qwc_cnt + // and the GS must not write more than that. + void(PS2E_CALLBACK *GsReadImage)(u128 *pMem, int qwc_cnt); - void* reserved[8]; + void *reserved[8]; } PS2E_ComponentAPI_GS; @@ -1019,10 +1025,10 @@ typedef struct _PS2E_ComponentAPI_GS // -------------------------------------------------------------------------------------- struct PS2E_McdSizeInfo { - u16 SectorSize; // Size of each sector, in bytes. (only 512 and 1024 are valid) - u16 EraseBlockSizeInSectors; // Size of the erase block, in sectors (max is 16) - u32 McdSizeInSectors; // Total size of the card, in sectors (no upper limit) - u8 Xor; // Checksum of previous data + u16 SectorSize; // Size of each sector, in bytes. (only 512 and 1024 are valid) + u16 EraseBlockSizeInSectors; // Size of the erase block, in sectors (max is 16) + u32 McdSizeInSectors; // Total size of the card, in sectors (no upper limit) + u8 Xor; // Checksum of previous data }; // -------------------------------------------------------------------------------------- @@ -1036,82 +1042,86 @@ struct PS2E_McdSizeInfo // typedef struct _PS2E_ComponentAPI_Mcd { - // Base Component API (inherited structure) - struct _PS2E_ComponentAPI Base; + // Base Component API (inherited structure) + struct _PS2E_ComponentAPI Base; - // McdIsPresent - // Called by the emulator to detect the availability of a memory card. This function - // will be called frequently -- essentially whenever the SIO port for the memory card - // has its status polled - so its overhead should be minimal when possible. - // - // Returns: - // False if the card is not available, or True if it is available. - // - BOOL (PS2E_CALLBACK* McdIsPresent)( PS2E_THISPTR thisptr, uint port, uint slot ); + // McdIsPresent + // Called by the emulator to detect the availability of a memory card. This function + // will be called frequently -- essentially whenever the SIO port for the memory card + // has its status polled - so its overhead should be minimal when possible. + // + // Returns: + // False if the card is not available, or True if it is available. + // + BOOL(PS2E_CALLBACK *McdIsPresent) + (PS2E_THISPTR thisptr, uint port, uint slot); - // McdGetSectorSize (can be NULL) - // Requests memorycard formatting information from the Mcd provider. See the description of - // PS2E_McdSizeInfo for details on each field. If the Mcd provider supports only standard 8MB - // carts, then this function can be NULL. - // - // Returns: - // Assigned values for memorycard sector size and sector count in 'outways.' - // - void (PS2E_CALLBACK* McdGetSizeInfo)( PS2E_THISPTR thisptr, uint port, uint slot, PS2E_McdSizeInfo* outways ); + // McdGetSectorSize (can be NULL) + // Requests memorycard formatting information from the Mcd provider. See the description of + // PS2E_McdSizeInfo for details on each field. If the Mcd provider supports only standard 8MB + // carts, then this function can be NULL. + // + // Returns: + // Assigned values for memorycard sector size and sector count in 'outways.' + // + void(PS2E_CALLBACK *McdGetSizeInfo)(PS2E_THISPTR thisptr, uint port, uint slot, PS2E_McdSizeInfo *outways); - // McdIsPSX - // Checks if the memorycard is a PSX one from the Mcd provider. - // - // Returns: - // False: PS2, True: PSX - // - bool (PS2E_CALLBACK* McdIsPSX)( PS2E_THISPTR thisptr, uint port, uint slot ); + // McdIsPSX + // Checks if the memorycard is a PSX one from the Mcd provider. + // + // Returns: + // False: PS2, True: PSX + // + bool(PS2E_CALLBACK *McdIsPSX)(PS2E_THISPTR thisptr, uint port, uint slot); - // McdRead - // Requests that a block of data be loaded from the memorycard into the specified dest - // buffer (which is allocated by the caller). Bytes read should match the requested - // size. Reads *must* be performed synchronously (function cannot return until the - // read op has finished). - // - // Returns: - // False on failure, and True on success. Emulator may use GetLastError to retrieve additional - // information for logging or displaying to the user. - // - BOOL (PS2E_CALLBACK* McdRead)( PS2E_THISPTR thisptr, uint port, uint slot, u8 *dest, u32 adr, int size ); + // McdRead + // Requests that a block of data be loaded from the memorycard into the specified dest + // buffer (which is allocated by the caller). Bytes read should match the requested + // size. Reads *must* be performed synchronously (function cannot return until the + // read op has finished). + // + // Returns: + // False on failure, and True on success. Emulator may use GetLastError to retrieve additional + // information for logging or displaying to the user. + // + BOOL(PS2E_CALLBACK *McdRead) + (PS2E_THISPTR thisptr, uint port, uint slot, u8 *dest, u32 adr, int size); - // McdSave - // Saves the provided block of data to the memorycard at the specified seek address. - // Writes *must* be performed synchronously (function cannot return until the write op - // has finished). Write cache flushing is optional. - // - // Returns: - // False on failure, and True on success. Emulator may use GetLastError to retrieve additional - // information for logging or displaying to the user. - // - BOOL (PS2E_CALLBACK* McdSave)( PS2E_THISPTR thisptr, uint port, uint slot, const u8 *src, u32 adr, int size ); + // McdSave + // Saves the provided block of data to the memorycard at the specified seek address. + // Writes *must* be performed synchronously (function cannot return until the write op + // has finished). Write cache flushing is optional. + // + // Returns: + // False on failure, and True on success. Emulator may use GetLastError to retrieve additional + // information for logging or displaying to the user. + // + BOOL(PS2E_CALLBACK *McdSave) + (PS2E_THISPTR thisptr, uint port, uint slot, const u8 *src, u32 adr, int size); - // McdEraseBlock - // Saves "cleared" data to the memorycard at the specified seek address. Cleared data - // is a series of 0xff values (all bits set to 1). - // Writes *must* be performed synchronously (function cannot return until the write op - // has finished). Write cache flushing is optional. - // - // Returns: - // False on failure, and True on success. Emulator may use GetLastError to retrieve additional - // information for logging or displaying to the user. - // - BOOL (PS2E_CALLBACK* McdEraseBlock)( PS2E_THISPTR thisptr, uint port, uint slot, u32 adr ); + // McdEraseBlock + // Saves "cleared" data to the memorycard at the specified seek address. Cleared data + // is a series of 0xff values (all bits set to 1). + // Writes *must* be performed synchronously (function cannot return until the write op + // has finished). Write cache flushing is optional. + // + // Returns: + // False on failure, and True on success. Emulator may use GetLastError to retrieve additional + // information for logging or displaying to the user. + // + BOOL(PS2E_CALLBACK *McdEraseBlock) + (PS2E_THISPTR thisptr, uint port, uint slot, u32 adr); - u64 (PS2E_CALLBACK* McdGetCRC)( PS2E_THISPTR thisptr, uint port, uint slot ); + u64(PS2E_CALLBACK *McdGetCRC)(PS2E_THISPTR thisptr, uint port, uint slot); - // McdNextFrame - // Inform the memory card that a frame of emulation time has passed. - // Used by the FolderMemoryCard to find a good time to flush written data to the host file system. - void (PS2E_CALLBACK* McdNextFrame)( PS2E_THISPTR thisptr, uint port, uint slot ); + // McdNextFrame + // Inform the memory card that a frame of emulation time has passed. + // Used by the FolderMemoryCard to find a good time to flush written data to the host file system. + void(PS2E_CALLBACK *McdNextFrame)(PS2E_THISPTR thisptr, uint port, uint slot); - bool (PS2E_CALLBACK* McdReIndex)( PS2E_THISPTR thisptr, uint port, uint slot, const wxString& filter ); + bool(PS2E_CALLBACK *McdReIndex)(PS2E_THISPTR thisptr, uint port, uint slot, const wxString &filter); - void* reserved[6]; + void *reserved[6]; } PS2E_ComponentAPI_Mcd; @@ -1120,17 +1130,15 @@ typedef struct _PS2E_ComponentAPI_Mcd // KeyEvent type enumerations // ------------------------------------------------------------------------------------ -enum PS2E_KeyEventTypes -{ - PS2E_KEY_UP = 0, - PS2E_KEY_DOWN +enum PS2E_KeyEventTypes { + PS2E_KEY_UP = 0, + PS2E_KEY_DOWN }; -enum PS2E_KeyModifiers -{ - PS2E_SHIFT = 1, - PS2E_CONTROL = 2, - PS2E_ALT = 4 +enum PS2E_KeyModifiers { + PS2E_SHIFT = 1, + PS2E_CONTROL = 2, + PS2E_ALT = 4 }; // -------------------------------------------------------------------------------------- @@ -1140,14 +1148,14 @@ enum PS2E_KeyModifiers // typedef struct _PS2E_KeyEvent { - PS2E_KeyEventTypes event; + PS2E_KeyEventTypes event; - // Value of the key being pressed or released - uint value; + // Value of the key being pressed or released + uint value; - // Combination of PS2E_SHIFT, PS2E_CONTROL, and/or PS2E_ALT, indicating which - // modifier keys were also down when the key was pressed. - uint flags; + // Combination of PS2E_SHIFT, PS2E_CONTROL, and/or PS2E_ALT, indicating which + // modifier keys were also down when the key was pressed. + uint flags; } PS2E_KeyEvent; @@ -1163,71 +1171,72 @@ typedef struct _PS2E_KeyEvent // typedef struct _PS2E_ComponentAPI_Pad { - // Base Component API (inherited structure) - struct _PS2E_ComponentAPI Base; + // Base Component API (inherited structure) + struct _PS2E_ComponentAPI Base; - // PadIsPresent - // Called by the emulator to detect the availability of a pad. This function will - // be called frequently -- essentially whenever the SIO port for the pad has its - // status polled - so its overhead should be minimal when possible. - // - // A plugin should behave reasonably when a pad that's not plugged in is polled. - // - // Returns: - // False if the card/pad is not available, or True if it is available. - // - BOOL (PS2E_CALLBACK* PadIsPresent)( PS2E_THISPTR thisptr, uint port, uint slot ); + // PadIsPresent + // Called by the emulator to detect the availability of a pad. This function will + // be called frequently -- essentially whenever the SIO port for the pad has its + // status polled - so its overhead should be minimal when possible. + // + // A plugin should behave reasonably when a pad that's not plugged in is polled. + // + // Returns: + // False if the card/pad is not available, or True if it is available. + // + BOOL(PS2E_CALLBACK *PadIsPresent) + (PS2E_THISPTR thisptr, uint port, uint slot); - // PadStartPoll - // Called by the emulator to start polling the specified pad. - // - // Returns: - // First byte in response to the poll (Typically 0xff). - // - // Threading: - // Called from the EEcore thread. The emulator performs no locking of its own, so - // calls to this may occur concurrently with calls to PadUpdate. - // - u8 (PS2E_CALLBACK* PadStartPoll)( PS2E_THISPTR thisptr, uint port, uint slot ); + // PadStartPoll + // Called by the emulator to start polling the specified pad. + // + // Returns: + // First byte in response to the poll (Typically 0xff). + // + // Threading: + // Called from the EEcore thread. The emulator performs no locking of its own, so + // calls to this may occur concurrently with calls to PadUpdate. + // + u8(PS2E_CALLBACK *PadStartPoll)(PS2E_THISPTR thisptr, uint port, uint slot); - // PadPoll - // Continues polling the specified pad, sending the given value. - // - // Returns: - // Next byte in response to the poll. - // - // Threading: - // Called from the EEcore thread. The emulator performs no locking of its own, so - // calls to this may occur concurrently with calls to PadUpdate. - // - u8 (PS2E_CALLBACK* PadPoll)( PS2E_THISPTR thisptr, u8 value ); + // PadPoll + // Continues polling the specified pad, sending the given value. + // + // Returns: + // Next byte in response to the poll. + // + // Threading: + // Called from the EEcore thread. The emulator performs no locking of its own, so + // calls to this may occur concurrently with calls to PadUpdate. + // + u8(PS2E_CALLBACK *PadPoll)(PS2E_THISPTR thisptr, u8 value); - // PadKeyEvent - // Called by the emulator in the gui thread to check for keys being pressed or released. - // - // Returns: - // PS2E_KeyEvent: Key being pressed or released. Should stay valid until next call to - // PadKeyEvent or plugin is closed with EmuClose. - // - // Threading: - // May be called from any thread. The emulator performs no locking of its own, so - // calls to this may occur concurrently with calls to PadUpdate. - // - PS2E_KeyEvent* (PS2E_CALLBACK* PadGetKeyEvent)( PS2E_THISPTR thisptr ); + // PadKeyEvent + // Called by the emulator in the gui thread to check for keys being pressed or released. + // + // Returns: + // PS2E_KeyEvent: Key being pressed or released. Should stay valid until next call to + // PadKeyEvent or plugin is closed with EmuClose. + // + // Threading: + // May be called from any thread. The emulator performs no locking of its own, so + // calls to this may occur concurrently with calls to PadUpdate. + // + PS2E_KeyEvent *(PS2E_CALLBACK *PadGetKeyEvent)(PS2E_THISPTR thisptr); - // PadUpdate - // This callback is issued from the thread that owns the GSwindow, at roughly 50/60hz, - // allowing the Pad plugin to use it for update logic that expects thread affinity with - // the GSwindow. - // - // Threading: - // Called from the same thread that owns the GSwindow (typically either a GUI thread - // or an MTGS thread). The emulator performs no locking of its own, so calls to this - // may occur concurrently with calls to PadKeyEvent and PadPoll. - // - void (PS2E_CALLBACK* PadUpdate)( PS2E_THISPTR thisptr ); + // PadUpdate + // This callback is issued from the thread that owns the GSwindow, at roughly 50/60hz, + // allowing the Pad plugin to use it for update logic that expects thread affinity with + // the GSwindow. + // + // Threading: + // Called from the same thread that owns the GSwindow (typically either a GUI thread + // or an MTGS thread). The emulator performs no locking of its own, so calls to this + // may occur concurrently with calls to PadKeyEvent and PadPoll. + // + void(PS2E_CALLBACK *PadUpdate)(PS2E_THISPTR thisptr); - void* reserved[8]; + void *reserved[8]; } PS2E_ComponentAPI_Pad; @@ -1260,7 +1269,7 @@ typedef struct _PS2E_ComponentAPI_Pad // * Affinity: Called only from the Main/GUI thread. // * Interlocking: Full interlocking garaunteed. // -typedef const PS2E_LibraryAPI* (PS2E_CALLBACK* _PS2E_InitAPI)( const PS2E_EmulatorInfo* emuinfo ); +typedef const PS2E_LibraryAPI *(PS2E_CALLBACK *_PS2E_InitAPI)(const PS2E_EmulatorInfo *emuinfo); // -------------------------------------------------------------------------------------- // PS2E_GetLastError @@ -1277,7 +1286,7 @@ typedef const PS2E_LibraryAPI* (PS2E_CALLBACK* _PS2E_InitAPI)( const PS2E_Emulat // msg_user - optional translated user message, which is displayed as a popup to explain // to the user why the plugin failed to initialize. // -typedef void (PS2E_CALLBACK* _PS2E_GetLastError)( char* const* msg_diag, wchar_t* const* msg_user ); +typedef void(PS2E_CALLBACK *_PS2E_GetLastError)(char *const *msg_diag, wchar_t *const *msg_user); ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/common/include/Utilities/AppTrait.h b/common/include/Utilities/AppTrait.h index 6ddce2658e..3816a9258a 100644 --- a/common/include/Utilities/AppTrait.h +++ b/common/include/Utilities/AppTrait.h @@ -27,14 +27,13 @@ // class Pcsx2AppTraits : public wxGUIAppTraits { - typedef wxGUIAppTraits _parent; + typedef wxGUIAppTraits _parent; public: - virtual ~Pcsx2AppTraits() {} - wxMessageOutput* CreateMessageOutput(); + virtual ~Pcsx2AppTraits() {} + wxMessageOutput *CreateMessageOutput(); #ifdef wxUSE_STDPATHS - wxStandardPaths& GetStandardPaths(); + wxStandardPaths &GetStandardPaths(); #endif }; - diff --git a/common/include/Utilities/Assertions.h b/common/include/Utilities/Assertions.h index 3bdefb7165..c35759c578 100644 --- a/common/include/Utilities/Assertions.h +++ b/common/include/Utilities/Assertions.h @@ -17,14 +17,14 @@ #ifndef __pxFUNCTION__ #if defined(__GNUG__) -# define __pxFUNCTION__ __PRETTY_FUNCTION__ +#define __pxFUNCTION__ __PRETTY_FUNCTION__ #else -# define __pxFUNCTION__ __FUNCTION__ +#define __pxFUNCTION__ __FUNCTION__ #endif #endif #ifndef wxNullChar -# define wxNullChar ((wxChar*)NULL) +#define wxNullChar ((wxChar *)NULL) #endif // FnChar_t - function name char type; typedef'd in case it ever changes between compilers @@ -36,29 +36,29 @@ typedef char FnChar_t; // -------------------------------------------------------------------------------------- struct DiagnosticOrigin { - const wxChar* srcfile; - const FnChar_t* function; - const wxChar* condition; - int line; + const wxChar *srcfile; + const FnChar_t *function; + const wxChar *condition; + int line; - DiagnosticOrigin( const wxChar *_file, int _line, const FnChar_t *_func, const wxChar* _cond = NULL ) - : srcfile( _file ) - , function( _func ) - , condition( _cond ) - , line( _line ) - { - } + DiagnosticOrigin(const wxChar *_file, int _line, const FnChar_t *_func, const wxChar *_cond = NULL) + : srcfile(_file) + , function(_func) + , condition(_cond) + , line(_line) + { + } - wxString ToString( const wxChar* msg=NULL ) const; + wxString ToString(const wxChar *msg = NULL) const; }; // Returns ture if the assertion is to trap into the debugger, or false if execution // of the program should continue unimpeded. -typedef bool pxDoAssertFnType(const DiagnosticOrigin& origin, const wxChar *msg); +typedef bool pxDoAssertFnType(const DiagnosticOrigin &origin, const wxChar *msg); extern pxDoAssertFnType pxAssertImpl_LogIt; -extern pxDoAssertFnType* pxDoAssert; +extern pxDoAssertFnType *pxDoAssert; // ---------------------------------------------------------------------------------------- // pxAssert / pxAssertDev @@ -97,95 +97,99 @@ extern pxDoAssertFnType* pxDoAssert; // it can lead to the compiler optimizing out code and leading to crashes in dev/release // builds. To have code optimized, explicitly use pxAssume(false) or pxAssumeDev(false,msg); -#define pxDiagSpot DiagnosticOrigin( __TFILE__, __LINE__, __pxFUNCTION__ ) -#define pxAssertSpot(cond) DiagnosticOrigin( __TFILE__, __LINE__, __pxFUNCTION__, _T(#cond) ) +#define pxDiagSpot DiagnosticOrigin(__TFILE__, __LINE__, __pxFUNCTION__) +#define pxAssertSpot(cond) DiagnosticOrigin(__TFILE__, __LINE__, __pxFUNCTION__, _T(#cond)) // pxAssertRel -> // Special release-mode assertion. Limited use since stack traces in release mode builds // (especially with LTCG) are highly suspect. But when troubleshooting crashes that only // rear ugly heads in optimized builds, this is one of the few tools we have. -#define pxAssertRel(cond, msg) ( (likely(cond)) || (pxOnAssert(pxAssertSpot(cond), msg), false) ) -#define pxAssumeRel(cond, msg) ((void) ( (!likely(cond)) && (pxOnAssert(pxAssertSpot(cond), msg), false) )) -#define pxFailRel(msg) pxAssertRel(false, msg) +#define pxAssertRel(cond, msg) ((likely(cond)) || (pxOnAssert(pxAssertSpot(cond), msg), false)) +#define pxAssumeRel(cond, msg) ((void)((!likely(cond)) && (pxOnAssert(pxAssertSpot(cond), msg), false))) +#define pxFailRel(msg) pxAssertRel(false, msg) #if defined(PCSX2_DEBUG) -# define pxAssertMsg(cond, msg) pxAssertRel(cond, msg) -# define pxAssertDev(cond, msg) pxAssertMsg(cond, msg) +#define pxAssertMsg(cond, msg) pxAssertRel(cond, msg) +#define pxAssertDev(cond, msg) pxAssertMsg(cond, msg) -# define pxAssumeMsg(cond, msg) pxAssumeRel(cond, msg) -# define pxAssumeDev(cond, msg) pxAssumeRel(cond, msg) +#define pxAssumeMsg(cond, msg) pxAssumeRel(cond, msg) +#define pxAssumeDev(cond, msg) pxAssumeRel(cond, msg) -# define pxFail(msg) pxAssertMsg(false, msg) -# define pxFailDev(msg) pxAssertDev(false, msg) +#define pxFail(msg) pxAssertMsg(false, msg) +#define pxFailDev(msg) pxAssertDev(false, msg) #elif defined(PCSX2_DEVBUILD) - // Devel builds now will give you a release-mode assertion dialog window if any of the - // following macro's 'cond' field is false. - // Note: Only use pxAssume/Msg/Dev if you know what you're doing, __assume is supposed - // to be used as an optimization hint, yet many devs have been using psAssume - // thinking its the same as an assertion. - // __assume(0) is also very dangerous because it is a special case of __assume() which - // tells the compiler that the code path is not reachable, and it can cause unpredictable - // results if the code path can be reached. - // i.e. if (1) { __assume(0); something(); } - // In the above example, something() may never be called. - // __assume(0)'s real use is in optimizing stuff such as "default:" cases on a switch - // statement. See jNO_DEFAULT +// Devel builds now will give you a release-mode assertion dialog window if any of the +// following macro's 'cond' field is false. +// Note: Only use pxAssume/Msg/Dev if you know what you're doing, __assume is supposed +// to be used as an optimization hint, yet many devs have been using psAssume +// thinking its the same as an assertion. +// __assume(0) is also very dangerous because it is a special case of __assume() which +// tells the compiler that the code path is not reachable, and it can cause unpredictable +// results if the code path can be reached. +// i.e. if (1) { __assume(0); something(); } +// In the above example, something() may never be called. +// __assume(0)'s real use is in optimizing stuff such as "default:" cases on a switch +// statement. See jNO_DEFAULT -# define pxAssertMsg(cond, msg) pxAssertRel(cond, msg) -# define pxAssertDev(cond, msg) pxAssertRel(cond, msg) +#define pxAssertMsg(cond, msg) pxAssertRel(cond, msg) +#define pxAssertDev(cond, msg) pxAssertRel(cond, msg) -# define pxAssumeMsg(cond, msg) pxAssumeRel(cond, msg) //(__assume(cond)) -# define pxAssumeDev(cond, msg) pxAssumeRel(cond, msg) +#define pxAssumeMsg(cond, msg) pxAssumeRel(cond, msg) //(__assume(cond)) +#define pxAssumeDev(cond, msg) pxAssumeRel(cond, msg) -# define pxFail(msg) pxAssertDev(false, msg) -# define pxFailDev(msg) pxAssertDev(false, msg) +#define pxFail(msg) pxAssertDev(false, msg) +#define pxFailDev(msg) pxAssertDev(false, msg) #else - // Release Builds just use __assume as an optimization, and return the conditional - // as a result (which is optimized to nil if unused). +// Release Builds just use __assume as an optimization, and return the conditional +// as a result (which is optimized to nil if unused). -# define pxAssertMsg(cond, msg) (likely(cond)) -# define pxAssertDev(cond, msg) (likely(cond)) +#define pxAssertMsg(cond, msg) (likely(cond)) +#define pxAssertDev(cond, msg) (likely(cond)) -# define pxAssumeMsg(cond, msg) (__assume(cond)) -# define pxAssumeDev(cond, msg) (__assume(cond)) +#define pxAssumeMsg(cond, msg) (__assume(cond)) +#define pxAssumeDev(cond, msg) (__assume(cond)) -# define pxFail(msg) do{} while(0) -# define pxFailDev(msg) do{} while(0) +#define pxFail(msg) \ + do { \ + } while (0) +#define pxFailDev(msg) \ + do { \ + } while (0) #endif -#define pxAssert(cond) pxAssertMsg(cond, wxNullChar) -#define pxAssume(cond) pxAssumeMsg(cond, wxNullChar) +#define pxAssert(cond) pxAssertMsg(cond, wxNullChar) +#define pxAssume(cond) pxAssumeMsg(cond, wxNullChar) -#define pxAssertRelease( cond, msg ) +#define pxAssertRelease(cond, msg) // Performs an unsigned index bounds check, and generates a debug assertion if the check fails. // For stricter checking in Devel builds as well as debug builds (but possibly slower), use // IndexBoundsCheckDev. -#define IndexBoundsCheck( objname, idx, sze ) pxAssertMsg( (uint)(idx) < (uint)(sze), \ - pxsFmt( L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze) ) ) +#define IndexBoundsCheck(objname, idx, sze) pxAssertMsg((uint)(idx) < (uint)(sze), \ + pxsFmt(L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze))) -#define IndexBoundsCheckDev( objname, idx, sze ) pxAssertDev( (uint)(idx) < (uint)(sze), \ - pxsFmt( L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze) ) ) +#define IndexBoundsCheckDev(objname, idx, sze) pxAssertDev((uint)(idx) < (uint)(sze), \ + pxsFmt(L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze))) -#define IndexBoundsAssume( objname, idx, sze ) pxAssumeMsg( (uint)(idx) < (uint)(sze), \ - pxsFmt( L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze) ) ) +#define IndexBoundsAssume(objname, idx, sze) pxAssumeMsg((uint)(idx) < (uint)(sze), \ + pxsFmt(L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze))) -#define IndexBoundsAssumeDev( objname, idx, sze ) pxAssumeDev( (uint)(idx) < (uint)(sze), \ - pxsFmt( L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze) ) ) +#define IndexBoundsAssumeDev(objname, idx, sze) pxAssumeDev((uint)(idx) < (uint)(sze), \ + pxsFmt(L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze))) -extern void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg=NULL ); -extern void pxOnAssert( const DiagnosticOrigin& origin, const char* msg ); -extern void pxOnAssert( const DiagnosticOrigin& origin, const wxString& msg); -extern void pxOnAssert( const DiagnosticOrigin& origin, const FastFormatUnicode& msg); +extern void pxOnAssert(const DiagnosticOrigin &origin, const wxChar *msg = NULL); +extern void pxOnAssert(const DiagnosticOrigin &origin, const char *msg); +extern void pxOnAssert(const DiagnosticOrigin &origin, const wxString &msg); +extern void pxOnAssert(const DiagnosticOrigin &origin, const FastFormatUnicode &msg); // -------------------------------------------------------------------------------------- // jNO_DEFAULT -- disables the default case in a switch, which improves switch optimization @@ -198,10 +202,9 @@ extern void pxOnAssert( const DiagnosticOrigin& origin, const FastFormatUnicode& // * In debug/devel builds the default case will cause an assertion. // #ifndef jNO_DEFAULT -# define jNO_DEFAULT \ - default: \ - { \ - pxAssumeDev( 0, "Incorrect usage of jNO_DEFAULT detected (default case is not unreachable!)" ); \ - break; \ - } +#define jNO_DEFAULT \ + default: { \ + pxAssumeDev(0, "Incorrect usage of jNO_DEFAULT detected (default case is not unreachable!)"); \ + break; \ + } #endif diff --git a/common/include/Utilities/CheckedStaticBox.h b/common/include/Utilities/CheckedStaticBox.h index df846ec4c3..1ae9c453ad 100644 --- a/common/include/Utilities/CheckedStaticBox.h +++ b/common/include/Utilities/CheckedStaticBox.h @@ -19,19 +19,19 @@ class CheckedStaticBox : public wxPanelWithHelpers { - typedef wxPanelWithHelpers _parent; + typedef wxPanelWithHelpers _parent; public: - wxBoxSizer& ThisSizer; // Boxsizer which holds all child items. - wxCheckBox& ThisToggle; // toggle which can enable/disable all child controls + wxBoxSizer &ThisSizer; // Boxsizer which holds all child items. + wxCheckBox &ThisToggle; // toggle which can enable/disable all child controls public: - CheckedStaticBox( wxWindow* parent, int orientation, const wxString& title=wxEmptyString ); + CheckedStaticBox(wxWindow *parent, int orientation, const wxString &title = wxEmptyString); + + void SetValue(bool val); + bool GetValue() const; + bool Enable(bool enable = true); - void SetValue( bool val ); - bool GetValue() const; - bool Enable( bool enable = true ); - public: - virtual void MainToggle_Click( wxCommandEvent& evt ); + virtual void MainToggle_Click(wxCommandEvent &evt); }; diff --git a/common/include/Utilities/Console.h b/common/include/Utilities/Console.h index ca4b71b1fb..a87f825266 100644 --- a/common/include/Utilities/Console.h +++ b/common/include/Utilities/Console.h @@ -17,46 +17,45 @@ #include "StringHelpers.h" -enum ConsoleColors -{ - Color_Current = -1, +enum ConsoleColors { + Color_Current = -1, - Color_Default = 0, + Color_Default = 0, - Color_Black, - Color_Green, - Color_Red, - Color_Blue, - Color_Magenta, - Color_Orange, - Color_Gray, + Color_Black, + Color_Green, + Color_Red, + Color_Blue, + Color_Magenta, + Color_Orange, + Color_Gray, - Color_Cyan, // faint visibility, intended for logging PS2/IOP output - Color_Yellow, // faint visibility, intended for logging PS2/IOP output - Color_White, // faint visibility, intended for logging PS2/IOP output + Color_Cyan, // faint visibility, intended for logging PS2/IOP output + Color_Yellow, // faint visibility, intended for logging PS2/IOP output + Color_White, // faint visibility, intended for logging PS2/IOP output - // Strong text *may* result in mis-aligned text in the console, depending on the - // font and the platform, so use these with caution. - Color_StrongBlack, - Color_StrongRed, // intended for errors - Color_StrongGreen, // intended for infrequent state information - Color_StrongBlue, // intended for block headings - Color_StrongMagenta, - Color_StrongOrange, // intended for warnings - Color_StrongGray, + // Strong text *may* result in mis-aligned text in the console, depending on the + // font and the platform, so use these with caution. + Color_StrongBlack, + Color_StrongRed, // intended for errors + Color_StrongGreen, // intended for infrequent state information + Color_StrongBlue, // intended for block headings + Color_StrongMagenta, + Color_StrongOrange, // intended for warnings + Color_StrongGray, - Color_StrongCyan, - Color_StrongYellow, - Color_StrongWhite, + Color_StrongCyan, + Color_StrongYellow, + Color_StrongWhite, - ConsoleColors_Count + ConsoleColors_Count }; static const ConsoleColors DefaultConsoleColor = Color_Default; // Use fastcall for the console; should be helpful in most cases -#define __concall __fastcall +#define __concall __fastcall // ---------------------------------------------------------------------------------------- // IConsoleWriter -- For printing messages to the console. @@ -71,60 +70,60 @@ static const ConsoleColors DefaultConsoleColor = Color_Default; // struct IConsoleWriter { - // A direct console write, without tabbing or newlines. Useful to devs who want to do quick - // logging of various junk; but should *not* be used in production code due. - void (__concall *WriteRaw)( const wxString& fmt ); + // A direct console write, without tabbing or newlines. Useful to devs who want to do quick + // logging of various junk; but should *not* be used in production code due. + void(__concall *WriteRaw)(const wxString &fmt); - // WriteLn implementation for internal use only. Bypasses tabbing, prefixing, and other - // formatting. - void (__concall *DoWriteLn)( const wxString& fmt ); + // WriteLn implementation for internal use only. Bypasses tabbing, prefixing, and other + // formatting. + void(__concall *DoWriteLn)(const wxString &fmt); - // SetColor implementation for internal use only. - void (__concall *DoSetColor)( ConsoleColors color ); + // SetColor implementation for internal use only. + void(__concall *DoSetColor)(ConsoleColors color); - // Special implementation of DoWrite that's pretty much for MSVC use only. - // All implementations should map to DoWrite, except Stdio which should map to Null. - // (This avoids circular/recursive stdio output) - void (__concall *DoWriteFromStdout)( const wxString& fmt ); + // Special implementation of DoWrite that's pretty much for MSVC use only. + // All implementations should map to DoWrite, except Stdio which should map to Null. + // (This avoids circular/recursive stdio output) + void(__concall *DoWriteFromStdout)(const wxString &fmt); - void (__concall *Newline)(); - void (__concall *SetTitle)( const wxString& title ); + void(__concall *Newline)(); + void(__concall *SetTitle)(const wxString &title); - // internal value for indentation of individual lines. Use the Indent() member to invoke. - int _imm_indentation; + // internal value for indentation of individual lines. Use the Indent() member to invoke. + int _imm_indentation; - // For internal use only. - wxString _addIndentation( const wxString& src, int glob_indent ) const; + // For internal use only. + wxString _addIndentation(const wxString &src, int glob_indent) const; - // ---------------------------------------------------------------------------- - // Public members; call these to print stuff to console! - // - // All functions always return false. Return value is provided only so that we can easily - // disable logs at compile time using the "0&&action" macro trick. + // ---------------------------------------------------------------------------- + // Public members; call these to print stuff to console! + // + // All functions always return false. Return value is provided only so that we can easily + // disable logs at compile time using the "0&&action" macro trick. - ConsoleColors GetColor() const; - const IConsoleWriter& SetColor( ConsoleColors color ) const; - const IConsoleWriter& ClearColor() const; - const IConsoleWriter& SetIndent( int tabcount=1 ) const; + ConsoleColors GetColor() const; + const IConsoleWriter &SetColor(ConsoleColors color) const; + const IConsoleWriter &ClearColor() const; + const IConsoleWriter &SetIndent(int tabcount = 1) const; - IConsoleWriter Indent( int tabcount=1 ) const; + IConsoleWriter Indent(int tabcount = 1) const; - bool FormatV( const char* fmt, va_list args ) const; - bool WriteLn( ConsoleColors color, const char* fmt, ... ) const; - bool WriteLn( const char* fmt, ... ) const; - bool Error( const char* fmt, ... ) const; - bool Warning( const char* fmt, ... ) const; + bool FormatV(const char *fmt, va_list args) const; + bool WriteLn(ConsoleColors color, const char *fmt, ...) const; + bool WriteLn(const char *fmt, ...) const; + bool Error(const char *fmt, ...) const; + bool Warning(const char *fmt, ...) const; - bool FormatV( const wxChar* fmt, va_list args ) const; - bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const; - bool WriteLn( const wxChar* fmt, ... ) const; - bool Error( const wxChar* fmt, ... ) const; - bool Warning( const wxChar* fmt, ... ) const; + bool FormatV(const wxChar *fmt, va_list args) const; + bool WriteLn(ConsoleColors color, const wxChar *fmt, ...) const; + bool WriteLn(const wxChar *fmt, ...) const; + bool Error(const wxChar *fmt, ...) const; + bool Warning(const wxChar *fmt, ...) const; - bool WriteLn( ConsoleColors color, const wxString fmt, ... ) const; - bool WriteLn( const wxString fmt, ... ) const; - bool Error( const wxString fmt, ... ) const; - bool Warning( const wxString fmt, ... ) const; + bool WriteLn(ConsoleColors color, const wxString fmt, ...) const; + bool WriteLn(const wxString fmt, ...) const; + bool Error(const wxString fmt, ...) const; + bool Warning(const wxString fmt, ...) const; }; // -------------------------------------------------------------------------------------- @@ -134,37 +133,37 @@ struct IConsoleWriter // struct NullConsoleWriter { - void WriteRaw( const wxString& fmt ) {} - void DoWriteLn( const wxString& fmt ) {} - void DoSetColor( ConsoleColors color ) {} - void DoWriteFromStdout( const wxString& fmt ) {} - void Newline() {} - void SetTitle( const wxString& title ) {} + void WriteRaw(const wxString &fmt) {} + void DoWriteLn(const wxString &fmt) {} + void DoSetColor(ConsoleColors color) {} + void DoWriteFromStdout(const wxString &fmt) {} + void Newline() {} + void SetTitle(const wxString &title) {} - ConsoleColors GetColor() const { return Color_Current; } - const NullConsoleWriter& SetColor( ConsoleColors color ) const { return *this; } - const NullConsoleWriter& ClearColor() const { return *this; } - const NullConsoleWriter& SetIndent( int tabcount=1 ) const { return *this; } + ConsoleColors GetColor() const { return Color_Current; } + const NullConsoleWriter &SetColor(ConsoleColors color) const { return *this; } + const NullConsoleWriter &ClearColor() const { return *this; } + const NullConsoleWriter &SetIndent(int tabcount = 1) const { return *this; } - NullConsoleWriter Indent( int tabcount=1 ) const { return NullConsoleWriter(); } + NullConsoleWriter Indent(int tabcount = 1) const { return NullConsoleWriter(); } - bool FormatV( const char* fmt, va_list args ) const { return false; } - bool WriteLn( ConsoleColors color, const char* fmt, ... ) const { return false; } - bool WriteLn( const char* fmt, ... ) const { return false; } - bool Error( const char* fmt, ... ) const { return false; } - bool Warning( const char* fmt, ... ) const { return false; } + bool FormatV(const char *fmt, va_list args) const { return false; } + bool WriteLn(ConsoleColors color, const char *fmt, ...) const { return false; } + bool WriteLn(const char *fmt, ...) const { return false; } + bool Error(const char *fmt, ...) const { return false; } + bool Warning(const char *fmt, ...) const { return false; } - bool FormatV( const wxChar* fmt, va_list args ) const { return false; } - bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const { return false; } - bool WriteLn( const wxChar* fmt, ... ) const { return false; } - bool Error( const wxChar* fmt, ... ) const { return false; } - bool Warning( const wxChar* fmt, ... ) const { return false; } + bool FormatV(const wxChar *fmt, va_list args) const { return false; } + bool WriteLn(ConsoleColors color, const wxChar *fmt, ...) const { return false; } + bool WriteLn(const wxChar *fmt, ...) const { return false; } + bool Error(const wxChar *fmt, ...) const { return false; } + bool Warning(const wxChar *fmt, ...) const { return false; } - bool WriteLn( ConsoleColors color, const wxString fmt, ... ) const { return false; } - bool WriteLn( const wxString fmt, ... ) const { return false; } - bool Error( const wxString fmt, ... ) const { return false; } - bool Warning( const wxString fmt, ... ) const { return false; } + bool WriteLn(ConsoleColors color, const wxString fmt, ...) const { return false; } + bool WriteLn(const wxString fmt, ...) const { return false; } + bool Error(const wxString fmt, ...) const { return false; } + bool Warning(const wxString fmt, ...) const { return false; } }; // -------------------------------------------------------------------------------------- @@ -180,19 +179,19 @@ struct NullConsoleWriter // class ConsoleIndentScope { - DeclareNoncopyableObject( ConsoleIndentScope ); + DeclareNoncopyableObject(ConsoleIndentScope); protected: - int m_amount; - bool m_IsScoped; + int m_amount; + bool m_IsScoped; public: - // Constructor: The specified number of tabs will be appended to the current indentation - // setting. The tabs will be unrolled when the object leaves scope or is destroyed. - ConsoleIndentScope( int tabs=1 ); - virtual ~ConsoleIndentScope() throw(); - void EnterScope(); - void LeaveScope(); + // Constructor: The specified number of tabs will be appended to the current indentation + // setting. The tabs will be unrolled when the object leaves scope or is destroyed. + ConsoleIndentScope(int tabs = 1); + virtual ~ConsoleIndentScope() throw(); + void EnterScope(); + void LeaveScope(); }; // -------------------------------------------------------------------------------------- @@ -200,18 +199,18 @@ public: // -------------------------------------------------------------------------------------- class ConsoleColorScope { - DeclareNoncopyableObject( ConsoleColorScope ); + DeclareNoncopyableObject(ConsoleColorScope); protected: - ConsoleColors m_newcolor; - ConsoleColors m_old_color; - bool m_IsScoped; + ConsoleColors m_newcolor; + ConsoleColors m_old_color; + bool m_IsScoped; public: - ConsoleColorScope( ConsoleColors newcolor ); - virtual ~ConsoleColorScope() throw(); - void EnterScope(); - void LeaveScope(); + ConsoleColorScope(ConsoleColors newcolor); + virtual ~ConsoleColorScope() throw(); + void EnterScope(); + void LeaveScope(); }; // -------------------------------------------------------------------------------------- @@ -221,42 +220,42 @@ public: // class ConsoleAttrScope { - DeclareNoncopyableObject( ConsoleAttrScope ); + DeclareNoncopyableObject(ConsoleAttrScope); protected: - ConsoleColors m_old_color; - int m_tabsize; + ConsoleColors m_old_color; + int m_tabsize; public: - ConsoleAttrScope( ConsoleColors newcolor, int indent=0 ); - virtual ~ConsoleAttrScope() throw(); + ConsoleAttrScope(ConsoleColors newcolor, int indent = 0); + virtual ~ConsoleAttrScope() throw(); }; -extern IConsoleWriter Console; +extern IConsoleWriter Console; #if defined(__unix__) extern void Console_SetStdout(FILE *fp); #endif -extern void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp=NULL ); +extern void Console_SetActiveHandler(const IConsoleWriter &writer, FILE *flushfp = NULL); -extern const IConsoleWriter ConsoleWriter_Null; -extern const IConsoleWriter ConsoleWriter_Stdout; -extern const IConsoleWriter ConsoleWriter_Assert; +extern const IConsoleWriter ConsoleWriter_Null; +extern const IConsoleWriter ConsoleWriter_Stdout; +extern const IConsoleWriter ConsoleWriter_Assert; -extern NullConsoleWriter NullCon; +extern NullConsoleWriter NullCon; -extern IConsoleWriter DevConWriter; -extern bool DevConWriterEnabled; +extern IConsoleWriter DevConWriter; +extern bool DevConWriterEnabled; #ifdef PCSX2_DEVBUILD -# define DevCon DevConWriter +#define DevCon DevConWriter #else -# define DevCon DevConWriterEnabled && DevConWriter +#define DevCon DevConWriterEnabled &&DevConWriter #endif #ifdef PCSX2_DEBUG -extern IConsoleWriter DbgConWriter; -# define DbgCon DbgConWriter +extern IConsoleWriter DbgConWriter; +#define DbgCon DbgConWriter #else -# define DbgCon 0&&NullCon +#define DbgCon 0 && NullCon #endif diff --git a/common/include/Utilities/Dependencies.h b/common/include/Utilities/Dependencies.h index 2ef212067c..714a7f8c0d 100644 --- a/common/include/Utilities/Dependencies.h +++ b/common/include/Utilities/Dependencies.h @@ -24,19 +24,19 @@ #define wxsFormat wxString::Format #ifdef PCSX2_DEBUG -# define tryDEBUG try -# define catchDEBUG(clause) catch(clause) +#define tryDEBUG try +#define catchDEBUG(clause) catch (clause) #else -# define tryDEBUG if(true) -# define catchDEBUG(clause) if(false) +#define tryDEBUG if (true) +#define catchDEBUG(clause) if (false) #endif #if defined(PCSX2_DEVBUILD) || defined(PCSX2_DEBUG) -# define tryDEVEL try -# define catchDEVEL catch(clause) +#define tryDEVEL try +#define catchDEVEL catch (clause) #else -# define tryDEBUG if(true) -# define catchDEBUG(clause) if(false) +#define tryDEBUG if (true) +#define catchDEBUG(clause) if (false) #endif // -------------------------------------------------------------------------------------- @@ -61,24 +61,48 @@ // method is not implemented! You must implement it yourself if you want to use it: // EnumToString(value); // -#define ImplementEnumOperators( enumName ) \ - static __fi enumName& operator++ ( enumName& src ) { src = (enumName)((int)src+1); return src; } \ - static __fi enumName& operator-- ( enumName& src ) { src = (enumName)((int)src-1); return src; } \ - static __fi enumName operator++ ( enumName& src, int ) { enumName orig = src; src = (enumName)((int)src+1); return orig; } \ - static __fi enumName operator-- ( enumName& src, int ) { enumName orig = src; src = (enumName)((int)src-1); return orig; } \ - \ - static __fi bool operator< ( const enumName& left, const pxEnumEnd_t& ) { return (int)left < enumName##_COUNT; } \ - static __fi bool operator!=( const enumName& left, const pxEnumEnd_t& ) { return (int)left != enumName##_COUNT; } \ - static __fi bool operator==( const enumName& left, const pxEnumEnd_t& ) { return (int)left == enumName##_COUNT; } \ - \ - static __fi bool EnumIsValid( enumName id ) { \ - return ((int)id >= enumName##_FIRST) && ((int)id < enumName##_COUNT); } \ - static __fi void EnumAssert( enumName id ) { \ - pxAssert( EnumIsValid(id) ); } \ - \ - extern const wxChar* EnumToString( enumName id ) +#define ImplementEnumOperators(enumName) \ + static __fi enumName &operator++(enumName &src) \ + { \ + src = (enumName)((int)src + 1); \ + return src; \ + } \ + static __fi enumName &operator--(enumName &src) \ + { \ + src = (enumName)((int)src - 1); \ + return src; \ + } \ + static __fi enumName operator++(enumName &src, int) \ + { \ + enumName orig = src; \ + src = (enumName)((int)src + 1); \ + return orig; \ + } \ + static __fi enumName operator--(enumName &src, int) \ + { \ + enumName orig = src; \ + src = (enumName)((int)src - 1); \ + return orig; \ + } \ + \ + static __fi bool operator<(const enumName &left, const pxEnumEnd_t &) { return (int)left < enumName##_COUNT; } \ + static __fi bool operator!=(const enumName &left, const pxEnumEnd_t &) { return (int)left != enumName##_COUNT; } \ + static __fi bool operator==(const enumName &left, const pxEnumEnd_t &) { return (int)left == enumName##_COUNT; } \ + \ + static __fi bool EnumIsValid(enumName id) \ + { \ + return ((int)id >= enumName##_FIRST) && ((int)id < enumName##_COUNT); \ + } \ + static __fi void EnumAssert(enumName id) \ + { \ + pxAssert(EnumIsValid(id)); \ + } \ + \ + extern const wxChar *EnumToString(enumName id) -class pxEnumEnd_t { }; +class pxEnumEnd_t +{ +}; static const pxEnumEnd_t pxEnumEnd = {}; // -------------------------------------------------------------------------------------- @@ -105,10 +129,10 @@ static const pxEnumEnd_t pxEnumEnd = {}; // of wx dependencies though, and has a nicer typeset. :) // #ifndef DeclareNoncopyableObject -# define DeclareNoncopyableObject(classname) \ - private: \ - explicit classname(const classname&); \ - classname& operator=(const classname&) +#define DeclareNoncopyableObject(classname) \ +private: \ + explicit classname(const classname &); \ + classname &operator=(const classname &) #endif @@ -120,19 +144,19 @@ static const pxEnumEnd_t pxEnumEnd = {}; class ScopedBool { protected: - bool* m_boolme; + bool *m_boolme; public: - ScopedBool(bool& boolme) - { - boolme = true; - m_boolme = &boolme; - } + ScopedBool(bool &boolme) + { + boolme = true; + m_boolme = &boolme; + } - ~ScopedBool() throw() - { - *m_boolme = false; - } + ~ScopedBool() throw() + { + *m_boolme = false; + } }; // -------------------------------------------------------------------------------------- @@ -149,15 +173,15 @@ public: #define WXINTL_NO_GETTEXT_MACRO #ifndef _ -# define _(s) pxGetTranslation(_T(s)) +#define _(s) pxGetTranslation(_T(s)) #endif #ifndef _t -# define _t(s) pxGetTranslation(_T(s)) +#define _t(s) pxGetTranslation(_T(s)) #endif #ifndef _d -# define _d(s) pxGetTranslation(_T(s)) +#define _d(s) pxGetTranslation(_T(s)) #endif // pxL / pxLt / pxDt -- macros provided for tagging translation strings, without actually running @@ -167,15 +191,15 @@ public: // debug/devel specific translations. // #ifndef pxL -# define pxL(a) wxT(a) +#define pxL(a) wxT(a) #endif #ifndef pxLt -# define pxLt(a) wxT(a) +#define pxLt(a) wxT(a) #endif #ifndef pxDt -# define pxDt(a) wxT(a) +#define pxDt(a) wxT(a) #endif @@ -193,8 +217,8 @@ public: #endif #include -#include // string.h under c++ -#include // stdio.h under c++ +#include // string.h under c++ +#include // stdio.h under c++ #include #include #include @@ -207,42 +231,42 @@ public: // -------------------------------------------------------------------------------------- // Handy Human-readable constants for common immediate values (_16kb -> _4gb) -static const sptr _1kb = 1024 * 1; -static const sptr _4kb = _1kb * 4; -static const sptr _16kb = _1kb * 16; -static const sptr _32kb = _1kb * 32; -static const sptr _64kb = _1kb * 64; -static const sptr _128kb = _1kb * 128; -static const sptr _256kb = _1kb * 256; +static const sptr _1kb = 1024 * 1; +static const sptr _4kb = _1kb * 4; +static const sptr _16kb = _1kb * 16; +static const sptr _32kb = _1kb * 32; +static const sptr _64kb = _1kb * 64; +static const sptr _128kb = _1kb * 128; +static const sptr _256kb = _1kb * 256; -static const s64 _1mb = 1024 * 1024; -static const s64 _8mb = _1mb * 8; -static const s64 _16mb = _1mb * 16; -static const s64 _32mb = _1mb * 32; -static const s64 _64mb = _1mb * 64; -static const s64 _256mb = _1mb * 256; -static const s64 _1gb = _1mb * 1024; -static const s64 _4gb = _1gb * 4; +static const s64 _1mb = 1024 * 1024; +static const s64 _8mb = _1mb * 8; +static const s64 _16mb = _1mb * 16; +static const s64 _32mb = _1mb * 32; +static const s64 _64mb = _1mb * 64; +static const s64 _256mb = _1mb * 256; +static const s64 _1gb = _1mb * 1024; +static const s64 _4gb = _1gb * 4; // -------------------------------------------------------------------------------------- // pxE(msg) and pxEt(msg) [macros] => now same as _/_t/_d // -------------------------------------------------------------------------------------- -#define pxE(english) pxExpandMsg( (english) ) +#define pxE(english) pxExpandMsg((english)) // For use with tertiary translations (low priority). -#define pxEt(english) pxExpandMsg( (english) ) +#define pxEt(english) pxExpandMsg((english)) // For use with Dev/debug build translations (low priority). -#define pxE_dev(english) pxExpandMsg( (english) ) +#define pxE_dev(english) pxExpandMsg((english)) -extern const wxChar* __fastcall pxExpandMsg( const wxChar* englishContent ); -extern const wxChar* __fastcall pxGetTranslation( const wxChar* message ); -extern bool pxIsEnglish( int id ); +extern const wxChar *__fastcall pxExpandMsg(const wxChar *englishContent); +extern const wxChar *__fastcall pxGetTranslation(const wxChar *message); +extern bool pxIsEnglish(int id); -extern wxString fromUTF8( const char* src ); -extern wxString fromAscii( const char* src ); +extern wxString fromUTF8(const char *src); +extern wxString fromAscii(const char *src); #include "Utilities/Assertions.h" diff --git a/common/include/Utilities/EmbeddedImage.h b/common/include/Utilities/EmbeddedImage.h index 91051ecd08..488efa6a9c 100644 --- a/common/include/Utilities/EmbeddedImage.h +++ b/common/include/Utilities/EmbeddedImage.h @@ -25,8 +25,8 @@ class IEmbeddedImage { public: - virtual const wxImage& Get()=0; - virtual wxImage Scale( int width, int height )=0; + virtual const wxImage &Get() = 0; + virtual wxImage Scale(int width, int height) = 0; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -38,85 +38,83 @@ public: // Note: Get() only loads the image once. All subsequent calls to Get will use the // previously loaded image data. // -template< typename ImageType > +template class EmbeddedImage : public IEmbeddedImage { protected: - wxImage m_Image; - const wxSize m_ResampleTo; + wxImage m_Image; + const wxSize m_ResampleTo; protected: - // ------------------------------------------------------------------------ - // Internal function used to ensure the image is loaded before returning the image - // handle (called from all methods that return an image handle). - // - void _loadImage() - { - if( !m_Image.Ok() ) - { - wxMemoryInputStream joe( ImageType::Data, ImageType::Length ); - m_Image.LoadFile( joe, ImageType::GetFormat() ); + // ------------------------------------------------------------------------ + // Internal function used to ensure the image is loaded before returning the image + // handle (called from all methods that return an image handle). + // + void _loadImage() + { + if (!m_Image.Ok()) { + wxMemoryInputStream joe(ImageType::Data, ImageType::Length); + m_Image.LoadFile(joe, ImageType::GetFormat()); - if( m_ResampleTo.IsFullySpecified() && ( m_ResampleTo.GetWidth() != m_Image.GetWidth() || m_ResampleTo.GetHeight() != m_Image.GetHeight() ) ) - m_Image.Rescale( m_ResampleTo.GetWidth(), m_ResampleTo.GetHeight(), wxIMAGE_QUALITY_HIGH ); - } - } + if (m_ResampleTo.IsFullySpecified() && (m_ResampleTo.GetWidth() != m_Image.GetWidth() || m_ResampleTo.GetHeight() != m_Image.GetHeight())) + m_Image.Rescale(m_ResampleTo.GetWidth(), m_ResampleTo.GetHeight(), wxIMAGE_QUALITY_HIGH); + } + } public: - EmbeddedImage() : - m_Image() - , m_ResampleTo( wxDefaultSize ) - { - } + EmbeddedImage() + : m_Image() + , m_ResampleTo(wxDefaultSize) + { + } - // ------------------------------------------------------------------------ - // Constructor for creating an embedded image that gets resampled to the specified size when - // loaded. - // - // Implementation Note: This function uses wxWidgets ResamplBox method to resize the image. - // wxWidgets ResampleBicubic appears to be buggy and produces fairly poor results when down- - // sampling images (basically resembles a pixel resize). ResampleBox produces much cleaner - // results. - // - EmbeddedImage( int newWidth, int newHeight ) : - m_Image() - , m_ResampleTo( newWidth, newHeight ) - { - } + // ------------------------------------------------------------------------ + // Constructor for creating an embedded image that gets resampled to the specified size when + // loaded. + // + // Implementation Note: This function uses wxWidgets ResamplBox method to resize the image. + // wxWidgets ResampleBicubic appears to be buggy and produces fairly poor results when down- + // sampling images (basically resembles a pixel resize). ResampleBox produces much cleaner + // results. + // + EmbeddedImage(int newWidth, int newHeight) + : m_Image() + , m_ResampleTo(newWidth, newHeight) + { + } - // ------------------------------------------------------------------------ - // Loads and retrieves the embedded image. The embedded image is only loaded from its em- - // bedded format once. Any subsequent calls to Get(), Rescale(), or Resample() will use - // the pre-loaded copy. Translation: the png/jpeg decoding overhead happens only once, - // and only happens when the image is actually fetched. Simply creating an instance - // of an EmbeddedImage object uses no excess memory nor cpu overhead. :) - // - const wxImage& Get() - { - _loadImage(); - return m_Image; - } + // ------------------------------------------------------------------------ + // Loads and retrieves the embedded image. The embedded image is only loaded from its em- + // bedded format once. Any subsequent calls to Get(), Rescale(), or Resample() will use + // the pre-loaded copy. Translation: the png/jpeg decoding overhead happens only once, + // and only happens when the image is actually fetched. Simply creating an instance + // of an EmbeddedImage object uses no excess memory nor cpu overhead. :) + // + const wxImage &Get() + { + _loadImage(); + return m_Image; + } - wxIcon GetIcon() - { - wxIcon retval; - retval.CopyFromBitmap( Get() ); - return retval; - } + wxIcon GetIcon() + { + wxIcon retval; + retval.CopyFromBitmap(Get()); + return retval; + } - // ------------------------------------------------------------------------ - // Performs a pixel resize of the loaded image and returns a new image handle (EmbeddedImage - // is left unmodified). - // + // ------------------------------------------------------------------------ + // Performs a pixel resize of the loaded image and returns a new image handle (EmbeddedImage + // is left unmodified). + // - wxImage Scale( int width, int height ) - { - _loadImage(); - // Not strictly necessary - wxWidgets does the dimensions check anyway. - if( width != m_Image.GetWidth() || height != m_Image.GetHeight() ) - return m_Image.Scale( width, height, wxIMAGE_QUALITY_HIGH ); - else - return m_Image; - } + wxImage Scale(int width, int height) + { + _loadImage(); + // Not strictly necessary - wxWidgets does the dimensions check anyway. + if (width != m_Image.GetWidth() || height != m_Image.GetHeight()) + return m_Image.Scale(width, height, wxIMAGE_QUALITY_HIGH); + else + return m_Image; + } }; - diff --git a/common/include/Utilities/EventSource.h b/common/include/Utilities/EventSource.h index a61ceeb702..98b1d02797 100644 --- a/common/include/Utilities/EventSource.h +++ b/common/include/Utilities/EventSource.h @@ -22,56 +22,58 @@ // EventSource< template EvtType > // -------------------------------------------------------------------------------------- -template< typename ListenerType > +template class EventSource { public: - typedef typename ListenerType::EvtParams EvtParams; - typedef typename std::list< ListenerType* > ListenerList; - typedef typename ListenerList::iterator ListenerIterator; + typedef typename ListenerType::EvtParams EvtParams; + typedef typename std::list ListenerList; + typedef typename ListenerList::iterator ListenerIterator; protected: - typedef typename ListenerList::const_iterator ConstIterator; + typedef typename ListenerList::const_iterator ConstIterator; - ListenerList m_listeners; + ListenerList m_listeners; - // This is a cached copy of the listener list used to handle standard dispatching, which - // allows for self-modification of the EventSource's listener list by the listeners. - // Translation: The dispatcher uses this copy instead, to avoid iterator invalidation. - ListenerList m_cache_copy; - bool m_cache_valid; + // This is a cached copy of the listener list used to handle standard dispatching, which + // allows for self-modification of the EventSource's listener list by the listeners. + // Translation: The dispatcher uses this copy instead, to avoid iterator invalidation. + ListenerList m_cache_copy; + bool m_cache_valid; - Threading::Mutex m_listeners_lock; + Threading::Mutex m_listeners_lock; public: - EventSource() - { - m_cache_valid = false; - } + EventSource() + { + m_cache_valid = false; + } - virtual ~EventSource() throw() {} + virtual ~EventSource() throw() {} - virtual ListenerIterator Add( ListenerType& listener ); - virtual void Remove( ListenerType& listener ); - virtual void Remove( const ListenerIterator& listenerHandle ); + virtual ListenerIterator Add(ListenerType &listener); + virtual void Remove(ListenerType &listener); + virtual void Remove(const ListenerIterator &listenerHandle); - void Add( ListenerType* listener ) - { - if( listener == NULL ) return; - Add( *listener ); - } + void Add(ListenerType *listener) + { + if (listener == NULL) + return; + Add(*listener); + } - void Remove( ListenerType* listener ) - { - if( listener == NULL ) return; - Remove( *listener ); - } + void Remove(ListenerType *listener) + { + if (listener == NULL) + return; + Remove(*listener); + } - void Dispatch( const EvtParams& params ); + void Dispatch(const EvtParams ¶ms); protected: - virtual ListenerIterator _AddFast_without_lock( ListenerType& listener ); - virtual void _DispatchRaw( ListenerIterator iter, const ListenerIterator& iend, const EvtParams& params ); + virtual ListenerIterator _AddFast_without_lock(ListenerType &listener); + virtual void _DispatchRaw(ListenerIterator iter, const ListenerIterator &iend, const EvtParams ¶ms); }; // -------------------------------------------------------------------------------------- @@ -80,13 +82,13 @@ protected: // This class is used as a base interface for EventListeners. It allows the listeners to do // customized dispatching of several event types into "user friendly" function overrides. // -template< typename EvtParams > +template class IEventDispatcher { protected: - IEventDispatcher() {} + IEventDispatcher() {} public: - virtual ~IEventDispatcher() throw() {} - virtual void DispatchEvent( const EvtParams& params )=0; + virtual ~IEventDispatcher() throw() {} + virtual void DispatchEvent(const EvtParams ¶ms) = 0; }; diff --git a/common/include/Utilities/EventSource.inl b/common/include/Utilities/EventSource.inl index 7cee20b57a..80636684cc 100644 --- a/common/include/Utilities/EventSource.inl +++ b/common/include/Utilities/EventSource.inl @@ -19,88 +19,80 @@ using Threading::ScopedLock; -template< typename ListenerType > -typename EventSource::ListenerIterator EventSource::Add( ListenerType& listener ) +template +typename EventSource::ListenerIterator EventSource::Add(ListenerType &listener) { - ScopedLock locker( m_listeners_lock ); + ScopedLock locker(m_listeners_lock); - // Check for duplicates before adding the event. - if( IsDebugBuild ) - { - ListenerIterator iter = m_listeners.begin(); - while( iter != m_listeners.end() ) - { - if( (*iter) == &listener ) return iter; - ++iter; - } - } - return _AddFast_without_lock( listener ); + // Check for duplicates before adding the event. + if (IsDebugBuild) { + ListenerIterator iter = m_listeners.begin(); + while (iter != m_listeners.end()) { + if ((*iter) == &listener) + return iter; + ++iter; + } + } + return _AddFast_without_lock(listener); } -template< typename ListenerType > -void EventSource::Remove( ListenerType& listener ) +template +void EventSource::Remove(ListenerType &listener) { - ScopedLock locker( m_listeners_lock ); - m_cache_valid = false; - m_listeners.remove( &listener ); + ScopedLock locker(m_listeners_lock); + m_cache_valid = false; + m_listeners.remove(&listener); } -template< typename ListenerType > -void EventSource::Remove( const ListenerIterator& listenerHandle ) +template +void EventSource::Remove(const ListenerIterator &listenerHandle) { - ScopedLock locker( m_listeners_lock ); - m_cache_valid = false; - m_listeners.erase( listenerHandle ); + ScopedLock locker(m_listeners_lock); + m_cache_valid = false; + m_listeners.erase(listenerHandle); } -template< typename ListenerType > -typename EventSource::ListenerIterator EventSource::_AddFast_without_lock( ListenerType& listener ) +template +typename EventSource::ListenerIterator EventSource::_AddFast_without_lock(ListenerType &listener) { - m_cache_valid = false; - m_listeners.push_front( &listener ); - return m_listeners.begin(); + m_cache_valid = false; + m_listeners.push_front(&listener); + return m_listeners.begin(); } -template< typename ListenerType > -__fi void EventSource::_DispatchRaw( ListenerIterator iter, const ListenerIterator& iend, const EvtParams& evtparams ) +template +__fi void EventSource::_DispatchRaw(ListenerIterator iter, const ListenerIterator &iend, const EvtParams &evtparams) { - while( iter != iend ) - { - try { - (*iter)->DispatchEvent( evtparams ); - } - catch( Exception::RuntimeError& ex ) - { - if( IsDevBuild ) { - pxFailDev( L"Ignoring runtime error thrown from event listener (event listeners should not throw exceptions!): " + ex.FormatDiagnosticMessage() ); - } - else { - Console.Error( L"Ignoring runtime error thrown from event listener: " + ex.FormatDiagnosticMessage() ); - } - } - catch( BaseException& ex ) - { - if( IsDevBuild ) - { - ex.DiagMsg() = L"Non-runtime BaseException thrown from event listener .. " + ex.DiagMsg(); - throw; - } - Console.Error( L"Ignoring non-runtime BaseException thrown from event listener: " + ex.FormatDiagnosticMessage() ); - } - ++iter; - } + while (iter != iend) { + try { + (*iter)->DispatchEvent(evtparams); + } catch (Exception::RuntimeError &ex) { + if (IsDevBuild) { + pxFailDev(L"Ignoring runtime error thrown from event listener (event listeners should not throw exceptions!): " + ex.FormatDiagnosticMessage()); + } else { + Console.Error(L"Ignoring runtime error thrown from event listener: " + ex.FormatDiagnosticMessage()); + } + } catch (BaseException &ex) { + if (IsDevBuild) { + ex.DiagMsg() = L"Non-runtime BaseException thrown from event listener .. " + ex.DiagMsg(); + throw; + } + Console.Error(L"Ignoring non-runtime BaseException thrown from event listener: " + ex.FormatDiagnosticMessage()); + } + ++iter; + } } -template< typename ListenerType > -void EventSource::Dispatch( const EvtParams& evtparams ) +template +void EventSource::Dispatch(const EvtParams &evtparams) { - if( !m_cache_valid ) - { - m_cache_copy = m_listeners; - m_cache_valid = true; - } + if (!m_cache_valid) { + m_cache_copy = m_listeners; + m_cache_valid = true; + } - if( m_cache_copy.empty() ) return; - _DispatchRaw( m_cache_copy.begin(), m_cache_copy.end(), evtparams ); + if (m_cache_copy.empty()) + return; + _DispatchRaw(m_cache_copy.begin(), m_cache_copy.end(), evtparams); } diff --git a/common/include/Utilities/Exceptions.h b/common/include/Utilities/Exceptions.h index 9eb3b83a1a..05476615e0 100644 --- a/common/include/Utilities/Exceptions.h +++ b/common/include/Utilities/Exceptions.h @@ -30,112 +30,113 @@ void pxTrap(); // friendly error log in their wake. // // Note: Console can also fire an Exception::OutOfMemory -#define __DESTRUCTOR_CATCHALL( funcname ) \ - catch( BaseException& ex ) \ - { \ - try { \ - Console.Error( "Unhandled BaseException in %s (ignored!):", funcname ); \ - Console.Error( ex.FormatDiagnosticMessage() ); \ - } catch (...) { \ - fprintf(stderr, "ERROR: (out of memory?)\n"); \ - } \ - } \ - catch( std::exception& ex ) \ - { \ - try { \ - Console.Error( "Unhandled std::exception in %s (ignored!):", funcname ); \ - Console.Error( ex.what() ); \ - } catch (...) { \ - fprintf(stderr, "ERROR: (out of memory?)\n"); \ - } \ - } \ - catch(...) { \ - /* Unreachable code */ \ - } +#define __DESTRUCTOR_CATCHALL(funcname) \ + catch (BaseException & ex) \ + { \ + try { \ + Console.Error("Unhandled BaseException in %s (ignored!):", funcname); \ + Console.Error(ex.FormatDiagnosticMessage()); \ + } catch (...) { \ + fprintf(stderr, "ERROR: (out of memory?)\n"); \ + } \ + } \ + catch (std::exception & ex) \ + { \ + try { \ + Console.Error("Unhandled std::exception in %s (ignored!):", funcname); \ + Console.Error(ex.what()); \ + } catch (...) { \ + fprintf(stderr, "ERROR: (out of memory?)\n"); \ + } \ + } \ + catch (...) \ + { \ + /* Unreachable code */ \ + } -#define DESTRUCTOR_CATCHALL __DESTRUCTOR_CATCHALL( __pxFUNCTION__ ) +#define DESTRUCTOR_CATCHALL __DESTRUCTOR_CATCHALL(__pxFUNCTION__) namespace Exception { - int MakeNewType(); - BaseException* FromErrno( const wxString& streamname, int errcode ); +int MakeNewType(); +BaseException *FromErrno(const wxString &streamname, int errcode); - // -------------------------------------------------------------------------------------- - // BaseException - // -------------------------------------------------------------------------------------- - // std::exception sucks, and isn't entirely cross-platform reliable in its implementation, - // so I made a replacement. The internal messages are non-const, which means that a - // catch clause can optionally modify them and then re-throw to a top-level handler. - // - // Note, this class is "abstract" which means you shouldn't use it directly like, ever. - // Use Exception::RuntimeError instead for generic exceptions. - // - // Because exceptions are the (only!) really useful example of multiple inheritance, - // this class has only a trivial constructor, and must be manually initialized using - // InitBaseEx() or by individual member assignments. This is because C++ multiple inheritence - // is, by design, a lot of fail, especially when class initializers are mixed in. - // - // [TODO] : Add an InnerException component, and Clone() facility. - // - class BaseException - { - protected: - wxString m_message_diag; // (untranslated) a "detailed" message of what disastrous thing has occurred! - wxString m_message_user; // (translated) a "detailed" message of what disastrous thing has occurred! +// -------------------------------------------------------------------------------------- +// BaseException +// -------------------------------------------------------------------------------------- +// std::exception sucks, and isn't entirely cross-platform reliable in its implementation, +// so I made a replacement. The internal messages are non-const, which means that a +// catch clause can optionally modify them and then re-throw to a top-level handler. +// +// Note, this class is "abstract" which means you shouldn't use it directly like, ever. +// Use Exception::RuntimeError instead for generic exceptions. +// +// Because exceptions are the (only!) really useful example of multiple inheritance, +// this class has only a trivial constructor, and must be manually initialized using +// InitBaseEx() or by individual member assignments. This is because C++ multiple inheritence +// is, by design, a lot of fail, especially when class initializers are mixed in. +// +// [TODO] : Add an InnerException component, and Clone() facility. +// +class BaseException +{ +protected: + wxString m_message_diag; // (untranslated) a "detailed" message of what disastrous thing has occurred! + wxString m_message_user; // (translated) a "detailed" message of what disastrous thing has occurred! - public: - virtual ~BaseException() throw()=0; // the =0; syntax forces this class into "abstract" mode. +public: + virtual ~BaseException() throw() = 0; // the =0; syntax forces this class into "abstract" mode. - const wxString& DiagMsg() const { return m_message_diag; } - const wxString& UserMsg() const { return m_message_user; } + const wxString &DiagMsg() const { return m_message_diag; } + const wxString &UserMsg() const { return m_message_user; } - wxString& DiagMsg() { return m_message_diag; } - wxString& UserMsg() { return m_message_user; } + wxString &DiagMsg() { return m_message_diag; } + wxString &UserMsg() { return m_message_user; } - BaseException& SetBothMsgs( const wxChar* msg_diag ); - BaseException& SetDiagMsg( const wxString& msg_diag ); - BaseException& SetUserMsg( const wxString& msg_user ); + BaseException &SetBothMsgs(const wxChar *msg_diag); + BaseException &SetDiagMsg(const wxString &msg_diag); + BaseException &SetUserMsg(const wxString &msg_user); - // Returns a message suitable for diagnostic / logging purposes. - // This message is always in English, and includes a full stack trace. - virtual wxString FormatDiagnosticMessage() const; + // Returns a message suitable for diagnostic / logging purposes. + // This message is always in English, and includes a full stack trace. + virtual wxString FormatDiagnosticMessage() const; - // Returns a message suitable for end-user display. - // This message is usually meant for display in a user popup or such. - virtual wxString FormatDisplayMessage() const; + // Returns a message suitable for end-user display. + // This message is usually meant for display in a user popup or such. + virtual wxString FormatDisplayMessage() const; - virtual void Rethrow() const=0; - virtual BaseException* Clone() const=0; - }; + virtual void Rethrow() const = 0; + virtual BaseException *Clone() const = 0; +}; - typedef std::unique_ptr ScopedExcept; +typedef std::unique_ptr ScopedExcept; - // -------------------------------------------------------------------------------------- - // Ps2Generic Exception - // -------------------------------------------------------------------------------------- - // This class is used as a base exception for things tossed by PS2 cpus (EE, IOP, etc). - // - // Implementation note: does not derive from BaseException, so that we can use different - // catch block hierarchies to handle them (if needed). - // - // Translation Note: Currently these exceptions are never translated. English/diagnostic - // format only. :) - // - class Ps2Generic - { - protected: - wxString m_message; // a "detailed" message of what disastrous thing has occurred! +// -------------------------------------------------------------------------------------- +// Ps2Generic Exception +// -------------------------------------------------------------------------------------- +// This class is used as a base exception for things tossed by PS2 cpus (EE, IOP, etc). +// +// Implementation note: does not derive from BaseException, so that we can use different +// catch block hierarchies to handle them (if needed). +// +// Translation Note: Currently these exceptions are never translated. English/diagnostic +// format only. :) +// +class Ps2Generic +{ +protected: + wxString m_message; // a "detailed" message of what disastrous thing has occurred! - public: - virtual ~Ps2Generic() throw() {} +public: + virtual ~Ps2Generic() throw() {} - virtual u32 GetPc() const=0; - virtual bool IsDelaySlot() const=0; - virtual wxString& Message() { return m_message; } + virtual u32 GetPc() const = 0; + virtual bool IsDelaySlot() const = 0; + virtual wxString &Message() { return m_message; } - virtual void Rethrow() const=0; - virtual Ps2Generic* Clone() const=0; - }; + virtual void Rethrow() const = 0; + virtual Ps2Generic *Clone() const = 0; +}; // Some helper macros for defining the standard constructors of internationalized constructors // Parameters: @@ -151,217 +152,239 @@ namespace Exception // // (update: web searches indicate it's MSVC specific -- happens in 2008, not sure about 2010). // -#define DEFINE_EXCEPTION_COPYTORS( classname, parent ) \ -private: \ - typedef parent _parent; \ -public: \ - virtual ~classname() throw() {} \ - virtual void Rethrow() const { throw *this; } \ - virtual classname* Clone() const { return new classname( *this ); } +#define DEFINE_EXCEPTION_COPYTORS(classname, parent) \ +private: \ + typedef parent _parent; \ + \ +public: \ + virtual ~classname() throw() {} \ + virtual void Rethrow() const { throw * this; } \ + virtual classname *Clone() const { return new classname(*this); } -#define DEFINE_EXCEPTION_MESSAGES( classname ) \ -public: \ - classname& SetBothMsgs( const wxChar* msg_diag ) { BaseException::SetBothMsgs(msg_diag); return *this; } \ - classname& SetDiagMsg( const wxString& msg_diag ) { m_message_diag = msg_diag; return *this; } \ - classname& SetUserMsg( const wxString& msg_user ) { m_message_user = msg_user; return *this; } +#define DEFINE_EXCEPTION_MESSAGES(classname) \ +public: \ + classname &SetBothMsgs(const wxChar *msg_diag) \ + { \ + BaseException::SetBothMsgs(msg_diag); \ + return *this; \ + } \ + classname &SetDiagMsg(const wxString &msg_diag) \ + { \ + m_message_diag = msg_diag; \ + return *this; \ + } \ + classname &SetUserMsg(const wxString &msg_user) \ + { \ + m_message_user = msg_user; \ + return *this; \ + } -#define DEFINE_RUNTIME_EXCEPTION( classname, parent, message ) \ - DEFINE_EXCEPTION_COPYTORS( classname, parent ) \ - classname() { SetDiagMsg(message); } \ - DEFINE_EXCEPTION_MESSAGES( classname ) - - - // --------------------------------------------------------------------------------------- - // RuntimeError - Generalized Exceptions with Recoverable Traits! - // --------------------------------------------------------------------------------------- +#define DEFINE_RUNTIME_EXCEPTION(classname, parent, message) \ + DEFINE_EXCEPTION_COPYTORS(classname, parent) \ + classname() { SetDiagMsg(message); } \ + DEFINE_EXCEPTION_MESSAGES(classname) - class RuntimeError : public BaseException - { - DEFINE_EXCEPTION_COPYTORS( RuntimeError, BaseException ) - DEFINE_EXCEPTION_MESSAGES( RuntimeError ) - public: - bool IsSilent; +// --------------------------------------------------------------------------------------- +// RuntimeError - Generalized Exceptions with Recoverable Traits! +// --------------------------------------------------------------------------------------- - RuntimeError() { IsSilent = false; } - RuntimeError( const std::runtime_error& ex, const wxString& prefix=wxEmptyString ); - RuntimeError( const std::exception& ex, const wxString& prefix=wxEmptyString ); - }; +class RuntimeError : public BaseException +{ + DEFINE_EXCEPTION_COPYTORS(RuntimeError, BaseException) + DEFINE_EXCEPTION_MESSAGES(RuntimeError) - // -------------------------------------------------------------------------------------- - // CancelAppEvent - Exception for canceling an event in a non-verbose fashion - // -------------------------------------------------------------------------------------- - // Typically the PCSX2 interface issues popup dialogs for runtime errors. This exception - // instead issues a "silent" cancelation that is handled by the app gracefully (generates - // log, and resumes messages queue processing). - // - // I chose to have this exception derive from RuntimeError, since if one is thrown from outside - // an App message loop we'll still want it to be handled in a reasonably graceful manner. - class CancelEvent : public RuntimeError - { - DEFINE_RUNTIME_EXCEPTION( CancelEvent, RuntimeError, pxLt("No reason given.") ) +public: + bool IsSilent; - public: - explicit CancelEvent( const wxString& logmsg ) - { - m_message_diag = logmsg; - // overridden message formatters only use the diagnostic version... - } + RuntimeError() { IsSilent = false; } + RuntimeError(const std::runtime_error &ex, const wxString &prefix = wxEmptyString); + RuntimeError(const std::exception &ex, const wxString &prefix = wxEmptyString); +}; - virtual wxString FormatDisplayMessage() const; - virtual wxString FormatDiagnosticMessage() const; - }; +// -------------------------------------------------------------------------------------- +// CancelAppEvent - Exception for canceling an event in a non-verbose fashion +// -------------------------------------------------------------------------------------- +// Typically the PCSX2 interface issues popup dialogs for runtime errors. This exception +// instead issues a "silent" cancelation that is handled by the app gracefully (generates +// log, and resumes messages queue processing). +// +// I chose to have this exception derive from RuntimeError, since if one is thrown from outside +// an App message loop we'll still want it to be handled in a reasonably graceful manner. +class CancelEvent : public RuntimeError +{ + DEFINE_RUNTIME_EXCEPTION(CancelEvent, RuntimeError, pxLt("No reason given.")) - // --------------------------------------------------------------------------------------- - // OutOfMemory - // --------------------------------------------------------------------------------------- - // This exception has a custom-formatted Diagnostic string. The parameter give when constructing - // the exception is a block/alloc name, which is used as a formatting parameter in the diagnostic - // output. The default diagnostic message is "Out of memory exception, while allocating the %s." - // where %s is filled in with the block name. - // - // The user string is not custom-formatted, and should contain *NO* %s tags. - // - class OutOfMemory : public RuntimeError - { - DEFINE_RUNTIME_EXCEPTION( OutOfMemory, RuntimeError, wxEmptyString ) +public: + explicit CancelEvent(const wxString &logmsg) + { + m_message_diag = logmsg; + // overridden message formatters only use the diagnostic version... + } - public: - wxString AllocDescription; + virtual wxString FormatDisplayMessage() const; + virtual wxString FormatDiagnosticMessage() const; +}; - public: - OutOfMemory( const wxString& allocdesc ); +// --------------------------------------------------------------------------------------- +// OutOfMemory +// --------------------------------------------------------------------------------------- +// This exception has a custom-formatted Diagnostic string. The parameter give when constructing +// the exception is a block/alloc name, which is used as a formatting parameter in the diagnostic +// output. The default diagnostic message is "Out of memory exception, while allocating the %s." +// where %s is filled in with the block name. +// +// The user string is not custom-formatted, and should contain *NO* %s tags. +// +class OutOfMemory : public RuntimeError +{ + DEFINE_RUNTIME_EXCEPTION(OutOfMemory, RuntimeError, wxEmptyString) - virtual wxString FormatDisplayMessage() const; - virtual wxString FormatDiagnosticMessage() const; - }; +public: + wxString AllocDescription; - class ParseError : public RuntimeError - { - DEFINE_RUNTIME_EXCEPTION( ParseError, RuntimeError, pxL("Parse error") ); - }; +public: + OutOfMemory(const wxString &allocdesc); - // --------------------------------------------------------------------------------------- - // Hardware/OS Exceptions: - // HardwareDeficiency / VirtualMemoryMapConflict - // --------------------------------------------------------------------------------------- + virtual wxString FormatDisplayMessage() const; + virtual wxString FormatDiagnosticMessage() const; +}; - // This exception is a specific type of OutOfMemory error that isn't "really" an out of - // memory error. More likely it's caused by a plugin or driver reserving a range of memory - // we'd really like to have access to. - class VirtualMemoryMapConflict : public OutOfMemory - { - DEFINE_RUNTIME_EXCEPTION( VirtualMemoryMapConflict, OutOfMemory, wxEmptyString ) +class ParseError : public RuntimeError +{ + DEFINE_RUNTIME_EXCEPTION(ParseError, RuntimeError, pxL("Parse error")); +}; - VirtualMemoryMapConflict( const wxString& allocdesc ); +// --------------------------------------------------------------------------------------- +// Hardware/OS Exceptions: +// HardwareDeficiency / VirtualMemoryMapConflict +// --------------------------------------------------------------------------------------- - virtual wxString FormatDisplayMessage() const; - virtual wxString FormatDiagnosticMessage() const; - }; +// This exception is a specific type of OutOfMemory error that isn't "really" an out of +// memory error. More likely it's caused by a plugin or driver reserving a range of memory +// we'd really like to have access to. +class VirtualMemoryMapConflict : public OutOfMemory +{ + DEFINE_RUNTIME_EXCEPTION(VirtualMemoryMapConflict, OutOfMemory, wxEmptyString) - class HardwareDeficiency : public RuntimeError - { - public: - DEFINE_RUNTIME_EXCEPTION( HardwareDeficiency, RuntimeError, pxL("Your machine's hardware is incapable of running PCSX2. Sorry dood.") ); - }; + VirtualMemoryMapConflict(const wxString &allocdesc); - // --------------------------------------------------------------------------------------- - // Streaming (file) Exceptions: - // Stream / BadStream / CannotCreateStream / FileNotFound / AccessDenied / EndOfStream - // --------------------------------------------------------------------------------------- + virtual wxString FormatDisplayMessage() const; + virtual wxString FormatDiagnosticMessage() const; +}; - #define DEFINE_STREAM_EXCEPTION_ACCESSORS( classname ) \ - virtual classname& SetStreamName( const wxString& name ) { StreamName = name; return *this; } \ - virtual classname& SetStreamName( const char* name ) { StreamName = fromUTF8(name); return *this; } +class HardwareDeficiency : public RuntimeError +{ +public: + DEFINE_RUNTIME_EXCEPTION(HardwareDeficiency, RuntimeError, pxL("Your machine's hardware is incapable of running PCSX2. Sorry dood.")); +}; - #define DEFINE_STREAM_EXCEPTION( classname, parent ) \ - DEFINE_RUNTIME_EXCEPTION( classname, parent, wxEmptyString ) \ - classname( const wxString& filename ) { \ - StreamName = filename; \ - } \ - DEFINE_STREAM_EXCEPTION_ACCESSORS( classname ) - - // A generic base error class for bad streams -- corrupted data, sudden closures, loss of - // connection, or anything else that would indicate a failure to open a stream or read the - // data after the stream was successfully opened. - // - class BadStream : public RuntimeError - { - DEFINE_STREAM_EXCEPTION( BadStream, RuntimeError ) +// --------------------------------------------------------------------------------------- +// Streaming (file) Exceptions: +// Stream / BadStream / CannotCreateStream / FileNotFound / AccessDenied / EndOfStream +// --------------------------------------------------------------------------------------- - public: - wxString StreamName; // name of the stream (if applicable) +#define DEFINE_STREAM_EXCEPTION_ACCESSORS(classname) \ + virtual classname &SetStreamName(const wxString &name) \ + { \ + StreamName = name; \ + return *this; \ + } \ + virtual classname &SetStreamName(const char *name) \ + { \ + StreamName = fromUTF8(name); \ + return *this; \ + } - virtual wxString FormatDiagnosticMessage() const; - virtual wxString FormatDisplayMessage() const; +#define DEFINE_STREAM_EXCEPTION(classname, parent) \ + DEFINE_RUNTIME_EXCEPTION(classname, parent, wxEmptyString) \ + classname(const wxString &filename) \ + { \ + StreamName = filename; \ + } \ + DEFINE_STREAM_EXCEPTION_ACCESSORS(classname) - protected: - void _formatDiagMsg( FastFormatUnicode& dest ) const; - void _formatUserMsg( FastFormatUnicode& dest ) const; - }; +// A generic base error class for bad streams -- corrupted data, sudden closures, loss of +// connection, or anything else that would indicate a failure to open a stream or read the +// data after the stream was successfully opened. +// +class BadStream : public RuntimeError +{ + DEFINE_STREAM_EXCEPTION(BadStream, RuntimeError) - // A generic exception for odd-ball stream creation errors. - // - class CannotCreateStream : public BadStream - { - DEFINE_STREAM_EXCEPTION( CannotCreateStream, BadStream ) +public: + wxString StreamName; // name of the stream (if applicable) - virtual wxString FormatDiagnosticMessage() const; - virtual wxString FormatDisplayMessage() const; - }; + virtual wxString FormatDiagnosticMessage() const; + virtual wxString FormatDisplayMessage() const; - // Exception thrown when an attempt to open a non-existent file is made. - // (this exception can also mean file permissions are invalid) - // - class FileNotFound : public CannotCreateStream - { - public: - DEFINE_STREAM_EXCEPTION( FileNotFound, CannotCreateStream ) +protected: + void _formatDiagMsg(FastFormatUnicode &dest) const; + void _formatUserMsg(FastFormatUnicode &dest) const; +}; - virtual wxString FormatDiagnosticMessage() const; - virtual wxString FormatDisplayMessage() const; - }; +// A generic exception for odd-ball stream creation errors. +// +class CannotCreateStream : public BadStream +{ + DEFINE_STREAM_EXCEPTION(CannotCreateStream, BadStream) - class AccessDenied : public CannotCreateStream - { - public: - DEFINE_STREAM_EXCEPTION( AccessDenied, CannotCreateStream ) + virtual wxString FormatDiagnosticMessage() const; + virtual wxString FormatDisplayMessage() const; +}; - virtual wxString FormatDiagnosticMessage() const; - virtual wxString FormatDisplayMessage() const; - }; +// Exception thrown when an attempt to open a non-existent file is made. +// (this exception can also mean file permissions are invalid) +// +class FileNotFound : public CannotCreateStream +{ +public: + DEFINE_STREAM_EXCEPTION(FileNotFound, CannotCreateStream) - // EndOfStream can be used either as an error, or used just as a shortcut for manual - // feof checks. - // - class EndOfStream : public BadStream - { - public: - DEFINE_STREAM_EXCEPTION( EndOfStream, BadStream ) + virtual wxString FormatDiagnosticMessage() const; + virtual wxString FormatDisplayMessage() const; +}; - virtual wxString FormatDiagnosticMessage() const; - virtual wxString FormatDisplayMessage() const; - }; +class AccessDenied : public CannotCreateStream +{ +public: + DEFINE_STREAM_EXCEPTION(AccessDenied, CannotCreateStream) + + virtual wxString FormatDiagnosticMessage() const; + virtual wxString FormatDisplayMessage() const; +}; + +// EndOfStream can be used either as an error, or used just as a shortcut for manual +// feof checks. +// +class EndOfStream : public BadStream +{ +public: + DEFINE_STREAM_EXCEPTION(EndOfStream, BadStream) + + virtual wxString FormatDiagnosticMessage() const; + virtual wxString FormatDisplayMessage() const; +}; #ifdef __WXMSW__ - // -------------------------------------------------------------------------------------- - // Exception::WinApiError - // -------------------------------------------------------------------------------------- - class WinApiError : public RuntimeError - { - DEFINE_EXCEPTION_COPYTORS( WinApiError, RuntimeError ) - DEFINE_EXCEPTION_MESSAGES( WinApiError ) +// -------------------------------------------------------------------------------------- +// Exception::WinApiError +// -------------------------------------------------------------------------------------- +class WinApiError : public RuntimeError +{ + DEFINE_EXCEPTION_COPYTORS(WinApiError, RuntimeError) + DEFINE_EXCEPTION_MESSAGES(WinApiError) - public: - int ErrorId; +public: + int ErrorId; - public: - WinApiError(); +public: + WinApiError(); - wxString GetMsgFromWindows() const; - virtual wxString FormatDisplayMessage() const; - virtual wxString FormatDiagnosticMessage() const; - }; + wxString GetMsgFromWindows() const; + virtual wxString FormatDisplayMessage() const; + virtual wxString FormatDiagnosticMessage() const; +}; #endif } diff --git a/common/include/Utilities/FixedPointTypes.h b/common/include/Utilities/FixedPointTypes.h index 58f2eb6e1b..01de348ec3 100644 --- a/common/include/Utilities/FixedPointTypes.h +++ b/common/include/Utilities/FixedPointTypes.h @@ -17,59 +17,59 @@ #include "Dependencies.h" -template< int Precision > +template struct FixedInt { - s32 Raw; + s32 Raw; - FixedInt(); - FixedInt( int signedval ); - FixedInt( double doubval ); - FixedInt( float floval ); + FixedInt(); + FixedInt(int signedval); + FixedInt(double doubval); + FixedInt(float floval); - bool operator ==( const FixedInt& right ) const { return Raw == right.Raw; } - bool operator !=( const FixedInt& right ) const { return Raw != right.Raw; } + bool operator==(const FixedInt &right) const { return Raw == right.Raw; } + bool operator!=(const FixedInt &right) const { return Raw != right.Raw; } - bool operator>( const FixedInt& right ) const { return Raw > right.Raw; }; - bool operator>=( const FixedInt& right ) const { return Raw >= right.Raw; }; - bool operator<( const FixedInt& right ) const { return Raw < right.Raw; }; - bool operator<=( const FixedInt& right ) const { return Raw <= right.Raw; }; + bool operator>(const FixedInt &right) const { return Raw > right.Raw; }; + bool operator>=(const FixedInt &right) const { return Raw >= right.Raw; }; + bool operator<(const FixedInt &right) const { return Raw < right.Raw; }; + bool operator<=(const FixedInt &right) const { return Raw <= right.Raw; }; - FixedInt operator+( const FixedInt& right ) const; - FixedInt operator-( const FixedInt& right ) const; - FixedInt& operator+=( const FixedInt& right ); - FixedInt& operator-=( const FixedInt& right ); + FixedInt operator+(const FixedInt &right) const; + FixedInt operator-(const FixedInt &right) const; + FixedInt &operator+=(const FixedInt &right); + FixedInt &operator-=(const FixedInt &right); - FixedInt& ConfineTo( const FixedInt& low, const FixedInt& high ); + FixedInt &ConfineTo(const FixedInt &low, const FixedInt &high); - FixedInt operator*( const FixedInt& right ) const; - FixedInt operator/( const FixedInt& right ) const; - FixedInt& operator*=( const FixedInt& right ); - FixedInt& operator/=( const FixedInt& right ); + FixedInt operator*(const FixedInt &right) const; + FixedInt operator/(const FixedInt &right) const; + FixedInt &operator*=(const FixedInt &right); + FixedInt &operator/=(const FixedInt &right); - static bool OverflowCheck( int signedval ); - static bool OverflowCheck( double signedval ); + static bool OverflowCheck(int signedval); + static bool OverflowCheck(double signedval); - int GetWhole() const; - int GetFraction() const; + int GetWhole() const; + int GetFraction() const; - FixedInt& SetRaw( s32 rawsrc ); - FixedInt& Round(); - FixedInt& SetWhole( s32 wholepart ); - FixedInt& SetFraction( u32 fracpart ); + FixedInt &SetRaw(s32 rawsrc); + FixedInt &Round(); + FixedInt &SetWhole(s32 wholepart); + FixedInt &SetFraction(u32 fracpart); - wxString ToString() const; - wxString ToString( int fracDigits ) const; + wxString ToString() const; + wxString ToString(int fracDigits) const; - double ToDouble() const; - float ToFloat() const; - int ToIntTruncated() const; - int ToIntRounded() const; + double ToDouble() const; + float ToFloat() const; + int ToIntTruncated() const; + int ToIntRounded() const; - static bool TryFromString( FixedInt& dest, const wxString& parseFrom ); - static FixedInt FromString( const wxString& parseFrom, const FixedInt& defval ); - static FixedInt FromString( const wxString parseFrom ); + static bool TryFromString(FixedInt &dest, const wxString &parseFrom); + static FixedInt FromString(const wxString &parseFrom, const FixedInt &defval); + static FixedInt FromString(const wxString parseFrom); }; -typedef FixedInt<256> Fixed256; -typedef FixedInt<100> Fixed100; +typedef FixedInt<256> Fixed256; +typedef FixedInt<100> Fixed100; diff --git a/common/include/Utilities/FixedPointTypes.inl b/common/include/Utilities/FixedPointTypes.inl index 2d071f1269..79c2be0d57 100644 --- a/common/include/Utilities/FixedPointTypes.inl +++ b/common/include/Utilities/FixedPointTypes.inl @@ -16,226 +16,237 @@ #pragma once #include "FixedPointTypes.h" -#include // for pow! +#include // for pow! -template< int Precision > +template FixedInt::FixedInt() { - Raw = 0; + Raw = 0; } -template< int Precision > -FixedInt::FixedInt( int signedval ) +template +FixedInt::FixedInt(int signedval) { - Raw = signedval * Precision; + Raw = signedval * Precision; } -template< int Precision > -FixedInt::FixedInt( double doubval ) +template +FixedInt::FixedInt(double doubval) { - Raw = lround(doubval * (double)Precision); + Raw = lround(doubval * (double)Precision); } -template< int Precision > -FixedInt::FixedInt( float floval ) +template +FixedInt::FixedInt(float floval) { - Raw = lroundf(floval * (float)Precision); + Raw = lroundf(floval * (float)Precision); } -template< int Precision > -FixedInt FixedInt::operator+( const FixedInt& right ) const +template +FixedInt FixedInt::operator+(const FixedInt &right) const { - return FixedInt().SetRaw( Raw + right.Raw ); + return FixedInt().SetRaw(Raw + right.Raw); } -template< int Precision > -FixedInt FixedInt::operator-( const FixedInt& right ) const +template +FixedInt FixedInt::operator-(const FixedInt &right) const { - return FixedInt().SetRaw( Raw + right.Raw ); + return FixedInt().SetRaw(Raw + right.Raw); } -template< int Precision > -FixedInt& FixedInt::operator+=( const FixedInt& right ) +template +FixedInt &FixedInt::operator+=(const FixedInt &right) { - return SetRaw( Raw + right.Raw ); + return SetRaw(Raw + right.Raw); } -template< int Precision > -FixedInt& FixedInt::operator-=( const FixedInt& right ) +template +FixedInt &FixedInt::operator-=(const FixedInt &right) { - return SetRaw( Raw + right.Raw ); + return SetRaw(Raw + right.Raw); } -template< int Precision > -FixedInt& FixedInt::ConfineTo( const FixedInt& low, const FixedInt& high ) +template +FixedInt &FixedInt::ConfineTo(const FixedInt &low, const FixedInt &high) { - return SetRaw( std::min( std::max( Raw, low.Raw ), high.Raw ) ); + return SetRaw(std::min(std::max(Raw, low.Raw), high.Raw)); } // Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math // you'll need to use the Raw values directly. -template< int Precision > -FixedInt FixedInt::operator*( const FixedInt& right ) const +template +FixedInt FixedInt::operator*(const FixedInt &right) const { - s64 mulres = (s64)Raw * right.Raw; - return FixedInt().SetRaw( (s32)(mulres / Precision) ); + s64 mulres = (s64)Raw * right.Raw; + return FixedInt().SetRaw((s32)(mulres / Precision)); } // Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math // you'll need to use the Raw values directly. -template< int Precision > -FixedInt FixedInt::operator/( const FixedInt& right ) const +template +FixedInt FixedInt::operator/(const FixedInt &right) const { - s64 divres = Raw * Precision; - return FixedInt().SetRaw( (s32)(divres / right.Raw) ); + s64 divres = Raw * Precision; + return FixedInt().SetRaw((s32)(divres / right.Raw)); } // Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math // you'll need to use the Raw values directly. -template< int Precision > -FixedInt& FixedInt::operator*=( const FixedInt& right ) +template +FixedInt &FixedInt::operator*=(const FixedInt &right) { - s64 mulres = (s64)Raw * right.Raw; - return SetRaw( (s32)(mulres / Precision) ); + s64 mulres = (s64)Raw * right.Raw; + return SetRaw((s32)(mulres / Precision)); } // Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math // you'll need to use the Raw values directly. -template< int Precision > -FixedInt& FixedInt::operator/=( const FixedInt& right ) +template +FixedInt &FixedInt::operator/=(const FixedInt &right) { - s64 divres = Raw * Precision; - return SetRaw( (s32)(divres / right.Raw) ); + s64 divres = Raw * Precision; + return SetRaw((s32)(divres / right.Raw)); } // returns TRUE if the value overflows the legal integer range of this container. -template< int Precision > -bool FixedInt::OverflowCheck( int signedval ) +template +bool FixedInt::OverflowCheck(int signedval) { - return ( signedval >= (INT_MAX / Precision) ); + return (signedval >= (INT_MAX / Precision)); } // returns TRUE if the value overflows the legal integer range of this container. -template< int Precision > -bool FixedInt::OverflowCheck( double signedval ) +template +bool FixedInt::OverflowCheck(double signedval) { - return ( signedval >= (INT_MAX / Precision) ); + return (signedval >= (INT_MAX / Precision)); } -template< int Precision > int FixedInt::GetWhole() const { return Raw / Precision; } -template< int Precision > int FixedInt::GetFraction() const { return Raw % Precision; } - -template< int Precision > -FixedInt& FixedInt::SetRaw( s32 rawsrc ) +template +int FixedInt::GetWhole() const { - Raw = rawsrc; - return *this; + return Raw / Precision; +} +template +int FixedInt::GetFraction() const +{ + return Raw % Precision; } -template< int Precision > -FixedInt& FixedInt::Round() +template +FixedInt &FixedInt::SetRaw(s32 rawsrc) { - Raw = ToIntRounded(); - return *this; + Raw = rawsrc; + return *this; } -template< int Precision > -FixedInt& FixedInt::SetWhole( s32 wholepart ) +template +FixedInt &FixedInt::Round() { - pxAssert( wholepart < (INT_MAX / Precision) ); - Raw = GetFraction() + (wholepart * Precision); - return *this; + Raw = ToIntRounded(); + return *this; } -template< int Precision > -FixedInt& FixedInt::SetFraction( u32 fracpart ) +template +FixedInt &FixedInt::SetWhole(s32 wholepart) { - Raw = (GetWhole() * Precision) + fracpart; - return *this; + pxAssert(wholepart < (INT_MAX / Precision)); + Raw = GetFraction() + (wholepart * Precision); + return *this; } -template< int Precision > +template +FixedInt &FixedInt::SetFraction(u32 fracpart) +{ + Raw = (GetWhole() * Precision) + fracpart; + return *this; +} + +template wxString FixedInt::ToString() const { - return wxsFormat( L"%d.%02d", GetWhole(), (GetFraction() * 100) / Precision ); + return wxsFormat(L"%d.%02d", GetWhole(), (GetFraction() * 100) / Precision); } -template< int Precision > -wxString FixedInt::ToString( int fracDigits ) const +template +wxString FixedInt::ToString(int fracDigits) const { - if( fracDigits == 0 ) return wxsFormat( L"%d", GetWhole() ); + if (fracDigits == 0) + return wxsFormat(L"%d", GetWhole()); - pxAssert( fracDigits <= 7 ); // higher numbers would just cause overflows and bad mojo. - int mulby = (int)pow( 10.0, fracDigits ); - wxString fmt=wxsFormat(L"%%d.%%0%dd", fracDigits); - return wxsFormat( fmt, GetWhole(), (GetFraction() * mulby) / Precision ); + pxAssert(fracDigits <= 7); // higher numbers would just cause overflows and bad mojo. + int mulby = (int)pow(10.0, fracDigits); + wxString fmt = wxsFormat(L"%%d.%%0%dd", fracDigits); + return wxsFormat(fmt, GetWhole(), (GetFraction() * mulby) / Precision); } -template< int Precision > +template double FixedInt::ToDouble() const { - return ((double)Raw / (double)Precision); + return ((double)Raw / (double)Precision); } -template< int Precision > +template float FixedInt::ToFloat() const { - return ((float)Raw / (float)Precision); + return ((float)Raw / (float)Precision); } -template< int Precision > +template int FixedInt::ToIntTruncated() const { - return Raw / Precision; + return Raw / Precision; } -template< int Precision > +template int FixedInt::ToIntRounded() const { - return (Raw + (Precision/2)) / Precision; + return (Raw + (Precision / 2)) / Precision; } -template< int Precision > -bool FixedInt::TryFromString( FixedInt& dest, const wxString& parseFrom ) +template +bool FixedInt::TryFromString(FixedInt &dest, const wxString &parseFrom) { - long whole=0, frac=0; - const wxString beforeFirst( parseFrom.BeforeFirst( L'.' ) ); - const wxString afterFirst( parseFrom.AfterFirst( L'.' ).Mid(0, 5) ); - bool success = true; + long whole = 0, frac = 0; + const wxString beforeFirst(parseFrom.BeforeFirst(L'.')); + const wxString afterFirst(parseFrom.AfterFirst(L'.').Mid(0, 5)); + bool success = true; - if( !beforeFirst.IsEmpty() ) - success = success && beforeFirst.ToLong( &whole ); + if (!beforeFirst.IsEmpty()) + success = success && beforeFirst.ToLong(&whole); - if( !afterFirst.IsEmpty() ) - success = success && afterFirst.ToLong( &frac ); + if (!afterFirst.IsEmpty()) + success = success && afterFirst.ToLong(&frac); - if( !success ) return false; + if (!success) + return false; - dest.SetWhole( whole ); + dest.SetWhole(whole); - if( afterFirst.Length() != 0 && frac != 0 ) - { - int fracPower = (int)pow( 10.0, (int)afterFirst.Length() ); - dest.SetFraction( (frac * Precision) / fracPower ); - } - return true; + if (afterFirst.Length() != 0 && frac != 0) { + int fracPower = (int)pow(10.0, (int)afterFirst.Length()); + dest.SetFraction((frac * Precision) / fracPower); + } + return true; } -template< int Precision > -FixedInt FixedInt::FromString( const wxString& parseFrom, const FixedInt& defval ) +template +FixedInt FixedInt::FromString(const wxString &parseFrom, const FixedInt &defval) { - FixedInt dest; - if( !TryFromString( dest, parseFrom ) ) return defval; - return dest; + FixedInt dest; + if (!TryFromString(dest, parseFrom)) + return defval; + return dest; } // This version of FromString throws a ParseError exception if the conversion fails. -template< int Precision > -FixedInt FixedInt::FromString( const wxString parseFrom ) +template +FixedInt FixedInt::FromString(const wxString parseFrom) { - FixedInt dest; - if( !TryFromString( dest, parseFrom ) ) throw Exception::ParseError() - .SetDiagMsg(wxsFormat(L"Parse error on FixedInt<%d>::FromString", Precision)); + FixedInt dest; + if (!TryFromString(dest, parseFrom)) + throw Exception::ParseError() + .SetDiagMsg(wxsFormat(L"Parse error on FixedInt<%d>::FromString", Precision)); - return dest; + return dest; } diff --git a/common/include/Utilities/General.h b/common/include/Utilities/General.h index 074157fd72..4e51d56485 100644 --- a/common/include/Utilities/General.h +++ b/common/include/Utilities/General.h @@ -17,16 +17,22 @@ // This macro is actually useful for about any and every possible application of C++ // equality operators. -#define OpEqu( field ) (field == right.field) +#define OpEqu(field) (field == right.field) // Macro used for removing some of the redtape involved in defining bitfield/union helpers. // -#define BITFIELD32() \ - union { \ - u32 bitset; \ - struct { +#define BITFIELD32() \ + union \ + { \ + u32 bitset; \ + struct \ + { -#define BITFIELD_END }; }; +#define BITFIELD_END \ + } \ + ; \ + } \ + ; // ---------------------------------------------------------------------------------------- @@ -42,15 +48,20 @@ class RecursionGuard { public: - int& Counter; + int &Counter; - RecursionGuard( int& counter ) : Counter( counter ) - { ++Counter; } + RecursionGuard(int &counter) + : Counter(counter) + { + ++Counter; + } - virtual ~RecursionGuard() throw() - { --Counter; } + virtual ~RecursionGuard() throw() + { + --Counter; + } - bool IsReentrant() const { return Counter > 1; } + bool IsReentrant() const { return Counter > 1; } }; // -------------------------------------------------------------------------------------- @@ -59,30 +70,30 @@ public: class IActionInvocation { public: - virtual ~IActionInvocation() throw() {} - virtual void InvokeAction()=0; + virtual ~IActionInvocation() throw() {} + virtual void InvokeAction() = 0; }; class ICloneable { public: - virtual ICloneable* Clone() const=0; + virtual ICloneable *Clone() const = 0; }; class IDeletableObject { public: - virtual ~IDeletableObject() throw() {} + virtual ~IDeletableObject() throw() {} - virtual void DeleteSelf()=0; - virtual bool IsBeingDeleted()=0; + virtual void DeleteSelf() = 0; + virtual bool IsBeingDeleted() = 0; protected: - // This function is GUI implementation dependent! It's implemented by PCSX2's AppHost, - // but if the SysCore is being linked to another front end, you'll need to implement this - // yourself. Most GUIs have built in message pumps. If a platform lacks one then you'll - // need to implement one yourself (yay?). - virtual void DoDeletion()=0; + // This function is GUI implementation dependent! It's implemented by PCSX2's AppHost, + // but if the SysCore is being linked to another front end, you'll need to implement this + // yourself. Most GUIs have built in message pumps. If a platform lacks one then you'll + // need to implement one yourself (yay?). + virtual void DoDeletion() = 0; }; // -------------------------------------------------------------------------------------- @@ -111,26 +122,26 @@ protected: class BaseDeletableObject : public virtual IDeletableObject { protected: - std::atomic m_IsBeingDeleted; + std::atomic m_IsBeingDeleted; public: - BaseDeletableObject(); - virtual ~BaseDeletableObject() throw(); + BaseDeletableObject(); + virtual ~BaseDeletableObject() throw(); - void DeleteSelf(); - bool IsBeingDeleted() { return !!m_IsBeingDeleted; } + void DeleteSelf(); + bool IsBeingDeleted() { return !!m_IsBeingDeleted; } - // Returns FALSE if the object is already marked for deletion, or TRUE if the app - // should schedule the object for deletion. Only schedule if TRUE is returned, otherwise - // the object could get deleted twice if two threads try to schedule it at the same time. - bool MarkForDeletion(); + // Returns FALSE if the object is already marked for deletion, or TRUE if the app + // should schedule the object for deletion. Only schedule if TRUE is returned, otherwise + // the object could get deleted twice if two threads try to schedule it at the same time. + bool MarkForDeletion(); protected: - // This function is GUI implementation dependent! It's implemented by PCSX2's AppHost, - // but if the SysCore is being linked to another front end, you'll need to implement this - // yourself. Most GUIs have built in message pumps. If a platform lacks one then you'll - // need to implement one yourself (yay?). - virtual void DoDeletion(); + // This function is GUI implementation dependent! It's implemented by PCSX2's AppHost, + // but if the SysCore is being linked to another front end, you'll need to implement this + // yourself. Most GUIs have built in message pumps. If a platform lacks one then you'll + // need to implement one yourself (yay?). + virtual void DoDeletion(); }; // -------------------------------------------------------------------------------------- @@ -139,76 +150,76 @@ protected: class PageProtectionMode { protected: - bool m_read; - bool m_write; - bool m_exec; + bool m_read; + bool m_write; + bool m_exec; public: - PageProtectionMode() - { - All( false ); - } + PageProtectionMode() + { + All(false); + } - PageProtectionMode& Read( bool allow=true ) - { - m_read = allow; - return *this; - } + PageProtectionMode &Read(bool allow = true) + { + m_read = allow; + return *this; + } - PageProtectionMode& Write( bool allow=true ) - { - m_write = allow; - return *this; - } + PageProtectionMode &Write(bool allow = true) + { + m_write = allow; + return *this; + } - PageProtectionMode& Execute( bool allow=true ) - { - m_exec = allow; - return *this; - } - - PageProtectionMode& All( bool allow=true ) - { - m_read = m_write = m_exec = allow; - return *this; - } + PageProtectionMode &Execute(bool allow = true) + { + m_exec = allow; + return *this; + } - bool CanRead() const { return m_read; } - bool CanWrite() const { return m_write; } - bool CanExecute() const { return m_exec && m_read; } - bool IsNone() const { return !m_read && !m_write; } - - wxString ToString() const; + PageProtectionMode &All(bool allow = true) + { + m_read = m_write = m_exec = allow; + return *this; + } + + bool CanRead() const { return m_read; } + bool CanWrite() const { return m_write; } + bool CanExecute() const { return m_exec && m_read; } + bool IsNone() const { return !m_read && !m_write; } + + wxString ToString() const; }; static __fi PageProtectionMode PageAccess_None() { - return PageProtectionMode(); + return PageProtectionMode(); } static __fi PageProtectionMode PageAccess_ReadOnly() { - return PageProtectionMode().Read(); + return PageProtectionMode().Read(); } static __fi PageProtectionMode PageAccess_WriteOnly() { - return PageProtectionMode().Write(); + return PageProtectionMode().Write(); } static __fi PageProtectionMode PageAccess_ReadWrite() { - return PageAccess_ReadOnly().Write(); + return PageAccess_ReadOnly().Write(); } static __fi PageProtectionMode PageAccess_ExecOnly() { - return PageAccess_ReadOnly().Execute(); + return PageAccess_ReadOnly().Execute(); } static __fi PageProtectionMode PageAccess_Any() { - return PageProtectionMode().All(); + return PageProtectionMode().All(); } // -------------------------------------------------------------------------------------- @@ -218,39 +229,39 @@ static __fi PageProtectionMode PageAccess_Any() // platform prior to wxWidgets .. it should prolly be removed -- air) namespace HostSys { - void* MmapReserve(uptr base, size_t size); - bool MmapCommit(uptr base, size_t size, const PageProtectionMode& mode); - void MmapReset(uptr base, size_t size); +void *MmapReserve(uptr base, size_t size); +bool MmapCommit(uptr base, size_t size, const PageProtectionMode &mode); +void MmapReset(uptr base, size_t size); - void* MmapReservePtr(void* base, size_t size); - bool MmapCommitPtr(void* base, size_t size, const PageProtectionMode& mode); - void MmapResetPtr(void* base, size_t size); +void *MmapReservePtr(void *base, size_t size); +bool MmapCommitPtr(void *base, size_t size, const PageProtectionMode &mode); +void MmapResetPtr(void *base, size_t size); - // Maps a block of memory for use as a recompiled code buffer. - // Returns NULL on allocation failure. - extern void* Mmap(uptr base, size_t size); +// Maps a block of memory for use as a recompiled code buffer. +// Returns NULL on allocation failure. +extern void *Mmap(uptr base, size_t size); - // Unmaps a block allocated by SysMmap - extern void Munmap(uptr base, size_t size); +// Unmaps a block allocated by SysMmap +extern void Munmap(uptr base, size_t size); - extern void MemProtect( void* baseaddr, size_t size, const PageProtectionMode& mode ); +extern void MemProtect(void *baseaddr, size_t size, const PageProtectionMode &mode); - extern void Munmap( void* base, size_t size ); +extern void Munmap(void *base, size_t size); - template< uint size > - void MemProtectStatic( u8 (&arr)[size], const PageProtectionMode& mode ) - { - MemProtect( arr, size, mode ); - } +template +void MemProtectStatic(u8 (&arr)[size], const PageProtectionMode &mode) +{ + MemProtect(arr, size, mode); +} } // Safe version of Munmap -- NULLs the pointer variable immediately after free'ing it. -#define SafeSysMunmap( ptr, size ) \ - ((void) ( HostSys::Munmap( (uptr)(ptr), size ), (ptr) = NULL )) +#define SafeSysMunmap(ptr, size) \ + ((void)(HostSys::Munmap((uptr)(ptr), size), (ptr) = NULL)) extern void InitCPUTicks(); -extern u64 GetTickFrequency(); -extern u64 GetCPUTicks(); +extern u64 GetTickFrequency(); +extern u64 GetCPUTicks(); extern u64 GetPhysicalMemory(); extern wxString GetOSVersionString(); diff --git a/common/include/Utilities/HashMap.h b/common/include/Utilities/HashMap.h index cf28157252..528fa0357f 100644 --- a/common/include/Utilities/HashMap.h +++ b/common/include/Utilities/HashMap.h @@ -15,7 +15,8 @@ #pragma once -namespace HashTools { +namespace HashTools +{ /// /// Type that represents a hashcode; returned by all hash functions. @@ -26,7 +27,5 @@ namespace HashTools { /// typedef u32 hash_key_t; -hash_key_t Hash(const char* data, int len); - +hash_key_t Hash(const char *data, int len); } - diff --git a/common/include/Utilities/IniInterface.h b/common/include/Utilities/IniInterface.h index c29c3fe30a..34f386f85a 100644 --- a/common/include/Utilities/IniInterface.h +++ b/common/include/Utilities/IniInterface.h @@ -21,7 +21,7 @@ #include // -------------------------------------------------------------------------------------- -// IniInterface (abstract base class) +// IniInterface (abstract base class) // -------------------------------------------------------------------------------------- // This is used as an interchangable interface for both loading and saving options from an // ini/configuration file. The LoadSave code takes an IniInterface, and the interface @@ -32,53 +32,57 @@ class IniInterface { protected: - wxConfigBase* m_Config; + wxConfigBase *m_Config; public: - virtual ~IniInterface(); - explicit IniInterface(); - explicit IniInterface( wxConfigBase& config ); - explicit IniInterface( wxConfigBase* config ); + virtual ~IniInterface(); + explicit IniInterface(); + explicit IniInterface(wxConfigBase &config); + explicit IniInterface(wxConfigBase *config); - void SetPath( const wxString& path ); - void Flush(); + void SetPath(const wxString &path); + void Flush(); - wxConfigBase& GetConfig() { pxAssert( m_Config ); return *m_Config; } - bool IsOk() const { return m_Config != NULL; } + wxConfigBase &GetConfig() + { + pxAssert(m_Config); + return *m_Config; + } + bool IsOk() const { return m_Config != NULL; } - virtual bool IsLoading() const=0; - bool IsSaving() const { return !IsLoading(); } + virtual bool IsLoading() const = 0; + bool IsSaving() const { return !IsLoading(); } - virtual void Entry( const wxString& var, wxString& value, const wxString defvalue=wxString() )=0; - virtual void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName(), bool isAllowRelative=false )=0; - virtual void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName(), bool isAllowRelative=false )=0; - virtual void Entry( const wxString& var, int& value, const int defvalue=0 )=0; - virtual void Entry( const wxString& var, uint& value, const uint defvalue=0 )=0; - virtual void Entry( const wxString& var, bool& value, const bool defvalue=false )=0; + virtual void Entry(const wxString &var, wxString &value, const wxString defvalue = wxString()) = 0; + virtual void Entry(const wxString &var, wxDirName &value, const wxDirName defvalue = wxDirName(), bool isAllowRelative = false) = 0; + virtual void Entry(const wxString &var, wxFileName &value, const wxFileName defvalue = wxFileName(), bool isAllowRelative = false) = 0; + virtual void Entry(const wxString &var, int &value, const int defvalue = 0) = 0; + virtual void Entry(const wxString &var, uint &value, const uint defvalue = 0) = 0; + virtual void Entry(const wxString &var, bool &value, const bool defvalue = false) = 0; - // This special form of Entry is provided for bitfields, which cannot be passed by reference. - virtual bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false )=0; - virtual int EntryBitfield( const wxString& var, int value, const int defvalue=0 )=0; + // This special form of Entry is provided for bitfields, which cannot be passed by reference. + virtual bool EntryBitBool(const wxString &var, bool value, const bool defvalue = false) = 0; + virtual int EntryBitfield(const wxString &var, int value, const int defvalue = 0) = 0; - virtual void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() )=0; + virtual void Entry(const wxString &var, Fixed100 &value, const Fixed100 defvalue = Fixed100()) = 0; - virtual void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition )=0; - virtual void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize )=0; - virtual void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect )=0; + virtual void Entry(const wxString &var, wxPoint &value, const wxPoint defvalue = wxDefaultPosition) = 0; + virtual void Entry(const wxString &var, wxSize &value, const wxSize defvalue = wxDefaultSize) = 0; + virtual void Entry(const wxString &var, wxRect &value, const wxRect defvalue = wxDefaultRect) = 0; - template< typename T > - void EnumEntry( const wxString& var, T& value, const wxChar* const* enumArray=NULL, const T defvalue=(T)0 ) - { - int tstore = (int)value; - if( enumArray == NULL ) - Entry( var, tstore, defvalue ); - else - _EnumEntry( var, tstore, enumArray, defvalue ); - value = (T)tstore; - } + template + void EnumEntry(const wxString &var, T &value, const wxChar *const *enumArray = NULL, const T defvalue = (T)0) + { + int tstore = (int)value; + if (enumArray == NULL) + Entry(var, tstore, defvalue); + else + _EnumEntry(var, tstore, enumArray, defvalue); + value = (T)tstore; + } protected: - virtual void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue )=0; + virtual void _EnumEntry(const wxString &var, int &value, const wxChar *const *enumArray, int defvalue) = 0; }; // -------------------------------------------------------------------------------------- @@ -87,11 +91,11 @@ protected: class ScopedIniGroup { protected: - IniInterface& m_mom; + IniInterface &m_mom; public: - ScopedIniGroup( IniInterface& mommy, const wxString& group ); - virtual ~ScopedIniGroup(); + ScopedIniGroup(IniInterface &mommy, const wxString &group); + virtual ~ScopedIniGroup(); }; // -------------------------------------------------------------------------------------- @@ -105,31 +109,31 @@ public: class IniLoader : public IniInterface { public: - virtual ~IniLoader() throw(); - explicit IniLoader(); - explicit IniLoader( wxConfigBase& config ); - explicit IniLoader( wxConfigBase* config ); + virtual ~IniLoader() throw(); + explicit IniLoader(); + explicit IniLoader(wxConfigBase &config); + explicit IniLoader(wxConfigBase *config); - bool IsLoading() const { return true; } + bool IsLoading() const { return true; } - void Entry( const wxString& var, wxString& value, const wxString defvalue=wxEmptyString ); - void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName(), bool isAllowRelative=false ); - void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName(), bool isAllowRelative=false ); - void Entry( const wxString& var, int& value, const int defvalue=0 ); - void Entry( const wxString& var, uint& value, const uint defvalue=0 ); - void Entry( const wxString& var, bool& value, const bool defvalue=false ); + void Entry(const wxString &var, wxString &value, const wxString defvalue = wxEmptyString); + void Entry(const wxString &var, wxDirName &value, const wxDirName defvalue = wxDirName(), bool isAllowRelative = false); + void Entry(const wxString &var, wxFileName &value, const wxFileName defvalue = wxFileName(), bool isAllowRelative = false); + void Entry(const wxString &var, int &value, const int defvalue = 0); + void Entry(const wxString &var, uint &value, const uint defvalue = 0); + void Entry(const wxString &var, bool &value, const bool defvalue = false); - bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false ); - int EntryBitfield( const wxString& var, int value, const int defvalue=0 ); + bool EntryBitBool(const wxString &var, bool value, const bool defvalue = false); + int EntryBitfield(const wxString &var, int value, const int defvalue = 0); - void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() ); + void Entry(const wxString &var, Fixed100 &value, const Fixed100 defvalue = Fixed100()); - void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition ); - void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize ); - void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect ); + void Entry(const wxString &var, wxPoint &value, const wxPoint defvalue = wxDefaultPosition); + void Entry(const wxString &var, wxSize &value, const wxSize defvalue = wxDefaultSize); + void Entry(const wxString &var, wxRect &value, const wxRect defvalue = wxDefaultRect); protected: - void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue ); + void _EnumEntry(const wxString &var, int &value, const wxChar *const *enumArray, int defvalue); }; // -------------------------------------------------------------------------------------- @@ -143,45 +147,45 @@ protected: class IniSaver : public IniInterface { public: - virtual ~IniSaver(); - explicit IniSaver(); - explicit IniSaver( wxConfigBase& config ); - explicit IniSaver( wxConfigBase* config ); + virtual ~IniSaver(); + explicit IniSaver(); + explicit IniSaver(wxConfigBase &config); + explicit IniSaver(wxConfigBase *config); - bool IsLoading() const { return false; } + bool IsLoading() const { return false; } - void Entry( const wxString& var, wxString& value, const wxString defvalue=wxString() ); - void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName(), bool isAllowRelative=false ); - void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName(), bool isAllowRelative=false ); - void Entry( const wxString& var, int& value, const int defvalue=0 ); - void Entry( const wxString& var, uint& value, const uint defvalue=0 ); - void Entry( const wxString& var, bool& value, const bool defvalue=false ); + void Entry(const wxString &var, wxString &value, const wxString defvalue = wxString()); + void Entry(const wxString &var, wxDirName &value, const wxDirName defvalue = wxDirName(), bool isAllowRelative = false); + void Entry(const wxString &var, wxFileName &value, const wxFileName defvalue = wxFileName(), bool isAllowRelative = false); + void Entry(const wxString &var, int &value, const int defvalue = 0); + void Entry(const wxString &var, uint &value, const uint defvalue = 0); + void Entry(const wxString &var, bool &value, const bool defvalue = false); - bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false ); - int EntryBitfield( const wxString& var, int value, const int defvalue=0 ); + bool EntryBitBool(const wxString &var, bool value, const bool defvalue = false); + int EntryBitfield(const wxString &var, int value, const int defvalue = 0); - void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() ); + void Entry(const wxString &var, Fixed100 &value, const Fixed100 defvalue = Fixed100()); - void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition ); - void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize ); - void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect ); + void Entry(const wxString &var, wxPoint &value, const wxPoint defvalue = wxDefaultPosition); + void Entry(const wxString &var, wxSize &value, const wxSize defvalue = wxDefaultSize); + void Entry(const wxString &var, wxRect &value, const wxRect defvalue = wxDefaultRect); protected: - void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue ); + void _EnumEntry(const wxString &var, int &value, const wxChar *const *enumArray, int defvalue); }; // ------------------------------------------------------------------------ // GCC Note: wxT() macro is required when using string token pasting. For some reason L generates // syntax errors. >_< // -#define IniEntry( varname ) ini.Entry( wxT(#varname), varname, varname ) -#define IniEntryDirFile( varname, isAllowRelative ) ini.Entry( wxT(#varname), varname, varname, isAllowRelative ) -#define IniBitfield( varname ) varname = ini.EntryBitfield( wxT(#varname), varname, varname ) -#define IniBitBool( varname ) varname = ini.EntryBitBool( wxT(#varname), !!varname, varname ) +#define IniEntry(varname) ini.Entry(wxT(#varname), varname, varname) +#define IniEntryDirFile(varname, isAllowRelative) ini.Entry(wxT(#varname), varname, varname, isAllowRelative) +#define IniBitfield(varname) varname = ini.EntryBitfield(wxT(#varname), varname, varname) +#define IniBitBool(varname) varname = ini.EntryBitBool(wxT(#varname), !!varname, varname) -#define IniBitfieldEx( varname, textname ) varname = ini.EntryBitfield( wxT(textname), varname, varname ) -#define IniBitBoolEx( varname, textname ) varname = ini.EntryBitBool( wxT(textname), !!varname, varname ) +#define IniBitfieldEx(varname, textname) varname = ini.EntryBitfield(wxT(textname), varname, varname) +#define IniBitBoolEx(varname, textname) varname = ini.EntryBitBool(wxT(textname), !!varname, varname) //used for filenames and folder names as ini values. //Set to app root folder, so all files and folders which are inside appRoot will be written as relative. -void SetFullBaseDir( wxDirName appRoot ); +void SetFullBaseDir(wxDirName appRoot); diff --git a/common/include/Utilities/MathUtils.h b/common/include/Utilities/MathUtils.h index f9ab252922..e2e8cf57f4 100644 --- a/common/include/Utilities/MathUtils.h +++ b/common/include/Utilities/MathUtils.h @@ -20,22 +20,22 @@ #include "Pcsx2Defs.h" // On GCC >= 4.7, this is equivalent to __builtin_clrsb(n); -inline u32 count_leading_sign_bits(s32 n) { - // If the sign bit is 1, we invert the bits to 0 for count-leading-zero. - if (n < 0) - n = ~n; +inline u32 count_leading_sign_bits(s32 n) +{ + // If the sign bit is 1, we invert the bits to 0 for count-leading-zero. + if (n < 0) + n = ~n; - // If BSR is used directly, it would have an undefined value for 0. - if (n == 0) - return 32; + // If BSR is used directly, it would have an undefined value for 0. + if (n == 0) + return 32; - // Perform our count leading zero. +// Perform our count leading zero. #ifdef _MSC_VER - unsigned long ret; - _BitScanReverse(&ret, n); - return 31 - (u32)ret; + unsigned long ret; + _BitScanReverse(&ret, n); + return 31 - (u32)ret; #else - return __builtin_clz(n); + return __builtin_clz(n); #endif } - diff --git a/common/include/Utilities/MemcpyFast.h b/common/include/Utilities/MemcpyFast.h index 3efa3bbf2d..13a2561e0d 100644 --- a/common/include/Utilities/MemcpyFast.h +++ b/common/include/Utilities/MemcpyFast.h @@ -16,15 +16,15 @@ #pragma once #if defined(__POSIX__) -# include "lnx_memzero.h" +#include "lnx_memzero.h" #else -# include "win_memzero.h" +#include "win_memzero.h" #endif // For 32-bit MSVC compiles, memcmp performs much worse than memcmp_mmx and // other implementations. So for this combination only, prefer memcmp_mmx #if defined(_MSC_VER) && !defined(_M_X86_64) -extern u8 memcmp_mmx(const void* src1, const void* src2, int cmpsize); +extern u8 memcmp_mmx(const void *src1, const void *src2, int cmpsize); #else #define memcmp_mmx memcmp #endif diff --git a/common/include/Utilities/MemsetFast.inl b/common/include/Utilities/MemsetFast.inl index 788488c658..fa046c85d3 100644 --- a/common/include/Utilities/MemsetFast.inl +++ b/common/include/Utilities/MemsetFast.inl @@ -17,69 +17,67 @@ #include -#define StoreDestIdx(idx) case idx: _mm_store_ps(&destxmm[idx-1][0], srcreg) - - template< u8 data > -__noinline void memset_sse_a( void* dest, const size_t size ) +#define StoreDestIdx(idx) \ + case idx: \ + _mm_store_ps(&destxmm[idx - 1][0], srcreg) + +template +__noinline void memset_sse_a(void *dest, const size_t size) { - const uint MZFqwc = size / 16; + const uint MZFqwc = size / 16; - pxAssert( (size & 0xf) == 0 ); + pxAssert((size & 0xf) == 0); - __m128 srcreg; + __m128 srcreg; - if (data != 0) - { - static __aligned16 const u8 loadval[8] = { data,data,data,data,data,data,data,data }; - srcreg = _mm_loadh_pi( _mm_load_ps( (float*)loadval ), (__m64*)loadval ); - } - else - srcreg = _mm_setzero_ps(); + if (data != 0) { + static __aligned16 const u8 loadval[8] = {data, data, data, data, data, data, data, data}; + srcreg = _mm_loadh_pi(_mm_load_ps((float *)loadval), (__m64 *)loadval); + } else + srcreg = _mm_setzero_ps(); - float (*destxmm)[4] = (float(*)[4])dest; + float(*destxmm)[4] = (float(*)[4])dest; - switch( MZFqwc & 0x07 ) - { - StoreDestIdx(0x07); - StoreDestIdx(0x06); - StoreDestIdx(0x05); - StoreDestIdx(0x04); - StoreDestIdx(0x03); - StoreDestIdx(0x02); - StoreDestIdx(0x01); - } + switch (MZFqwc & 0x07) { + StoreDestIdx(0x07); + StoreDestIdx(0x06); + StoreDestIdx(0x05); + StoreDestIdx(0x04); + StoreDestIdx(0x03); + StoreDestIdx(0x02); + StoreDestIdx(0x01); + } - destxmm += (MZFqwc & 0x07); - for( uint i=0; i( dest, size ); + memset_sse_a<0>(dest, size); } #undef StoreDestIdx -template< u8 data, typename T > -__noinline void memset_sse_a( T& dest ) +template +__noinline void memset_sse_a(T &dest) { - static_assert( (sizeof(dest) & 0xf) == 0, "Bad size for SSE memset" ); - memset_sse_a( &dest, sizeof(dest) ); + static_assert((sizeof(dest) & 0xf) == 0, "Bad size for SSE memset"); + memset_sse_a(&dest, sizeof(dest)); } -template< typename T > -void memzero_sse_a( T& dest ) +template +void memzero_sse_a(T &dest) { - static_assert( (sizeof(dest) & 0xf) == 0, "Bad size for SSE memset" ); - memset_sse_a<0>( &dest, sizeof(dest) ); + static_assert((sizeof(dest) & 0xf) == 0, "Bad size for SSE memset"); + memset_sse_a<0>(&dest, sizeof(dest)); } diff --git a/common/include/Utilities/PageFaultSource.h b/common/include/Utilities/PageFaultSource.h index 8868c8f3df..631e839a68 100644 --- a/common/include/Utilities/PageFaultSource.h +++ b/common/include/Utilities/PageFaultSource.h @@ -28,12 +28,12 @@ struct PageFaultInfo { - uptr addr; + uptr addr; - PageFaultInfo( uptr address ) - { - addr = address; - } + PageFaultInfo(uptr address) + { + addr = address; + } }; // -------------------------------------------------------------------------------------- @@ -42,22 +42,22 @@ struct PageFaultInfo class IEventListener_PageFault : public IEventDispatcher { public: - typedef PageFaultInfo EvtParams; + typedef PageFaultInfo EvtParams; public: - virtual ~IEventListener_PageFault() throw() {} + virtual ~IEventListener_PageFault() throw() {} - virtual void DispatchEvent( const PageFaultInfo& evtinfo, bool& handled ) - { - OnPageFaultEvent( evtinfo, handled ); - } + virtual void DispatchEvent(const PageFaultInfo &evtinfo, bool &handled) + { + OnPageFaultEvent(evtinfo, handled); + } - virtual void DispatchEvent( const PageFaultInfo& evtinfo ) - { - pxFailRel( "Don't call me, damnit. Use DispatchException instead." ); - } + virtual void DispatchEvent(const PageFaultInfo &evtinfo) + { + pxFailRel("Don't call me, damnit. Use DispatchException instead."); + } - virtual void OnPageFaultEvent( const PageFaultInfo& evtinfo, bool& handled ) {} + virtual void OnPageFaultEvent(const PageFaultInfo &evtinfo, bool &handled) {} }; // -------------------------------------------------------------------------------------- @@ -66,35 +66,34 @@ public: class EventListener_PageFault : public IEventListener_PageFault { public: - EventListener_PageFault(); - virtual ~EventListener_PageFault() throw(); + EventListener_PageFault(); + virtual ~EventListener_PageFault() throw(); }; -template< typename TypeToDispatchTo > +template class EventListenerHelper_PageFault : public EventListener_PageFault { public: - TypeToDispatchTo* Owner; + TypeToDispatchTo *Owner; public: - EventListenerHelper_PageFault( TypeToDispatchTo& dispatchTo ) - { - Owner = &dispatchTo; - } + EventListenerHelper_PageFault(TypeToDispatchTo &dispatchTo) + { + Owner = &dispatchTo; + } - EventListenerHelper_PageFault( TypeToDispatchTo* dispatchTo ) - { - Owner = dispatchTo; - } + EventListenerHelper_PageFault(TypeToDispatchTo *dispatchTo) + { + Owner = dispatchTo; + } - virtual ~EventListenerHelper_PageFault() throw() {} + virtual ~EventListenerHelper_PageFault() throw() {} protected: - virtual void OnPageFaultEvent( const PageFaultInfo& info, bool& handled ) - { - Owner->OnPageFaultEvent( info, handled ); - } - + virtual void OnPageFaultEvent(const PageFaultInfo &info, bool &handled) + { + Owner->OnPageFaultEvent(info, handled); + } }; // -------------------------------------------------------------------------------------- @@ -103,20 +102,23 @@ protected: class SrcType_PageFault : public EventSource { protected: - typedef EventSource _parent; + typedef EventSource _parent; protected: - bool m_handled; + bool m_handled; public: - SrcType_PageFault() : m_handled(false) {} - virtual ~SrcType_PageFault() throw() { } + SrcType_PageFault() + : m_handled(false) + { + } + virtual ~SrcType_PageFault() throw() {} - bool WasHandled() const { return m_handled; } - virtual void Dispatch( const PageFaultInfo& params ); + bool WasHandled() const { return m_handled; } + virtual void Dispatch(const PageFaultInfo ¶ms); protected: - virtual void _DispatchRaw( ListenerIterator iter, const ListenerIterator& iend, const PageFaultInfo& evt ); + virtual void _DispatchRaw(ListenerIterator iter, const ListenerIterator &iend, const PageFaultInfo &evt); }; @@ -125,92 +127,92 @@ protected: // -------------------------------------------------------------------------------------- class VirtualMemoryReserve { - DeclareNoncopyableObject( VirtualMemoryReserve ); + DeclareNoncopyableObject(VirtualMemoryReserve); protected: - wxString m_name; + wxString m_name; - // Default size of the reserve, in bytes. Can be specified when the object is constructed. - // Is used as the reserve size when Reserve() is called, unless an override is specified - // in the Reserve parameters. - size_t m_defsize; + // Default size of the reserve, in bytes. Can be specified when the object is constructed. + // Is used as the reserve size when Reserve() is called, unless an override is specified + // in the Reserve parameters. + size_t m_defsize; - void* m_baseptr; + void *m_baseptr; - // reserved memory (in pages). - uptr m_pages_reserved; + // reserved memory (in pages). + uptr m_pages_reserved; - // Records the number of pages committed to memory. - // (metric for analysis of buffer usage) - uptr m_pages_commited; + // Records the number of pages committed to memory. + // (metric for analysis of buffer usage) + uptr m_pages_commited; - // Protection mode to be applied to committed blocks. - PageProtectionMode m_prot_mode; - - // Controls write access to the entire reserve. When true (the default), the reserve - // operates normally. When set to false, all committed blocks are re-protected with - // write disabled, and accesses to uncommitted blocks (read or write) will cause a GPF - // as well. - bool m_allow_writes; + // Protection mode to be applied to committed blocks. + PageProtectionMode m_prot_mode; + + // Controls write access to the entire reserve. When true (the default), the reserve + // operates normally. When set to false, all committed blocks are re-protected with + // write disabled, and accesses to uncommitted blocks (read or write) will cause a GPF + // as well. + bool m_allow_writes; public: - VirtualMemoryReserve( const wxString& name=wxEmptyString, size_t size = 0 ); - virtual ~VirtualMemoryReserve() throw() - { - Release(); - } + VirtualMemoryReserve(const wxString &name = wxEmptyString, size_t size = 0); + virtual ~VirtualMemoryReserve() throw() + { + Release(); + } - virtual void* Reserve( size_t size = 0, uptr base = 0, uptr upper_bounds = 0 ); - virtual void* ReserveAt( uptr base = 0, uptr upper_bounds = 0 ) - { - return Reserve(m_defsize, base, upper_bounds); - } + virtual void *Reserve(size_t size = 0, uptr base = 0, uptr upper_bounds = 0); + virtual void *ReserveAt(uptr base = 0, uptr upper_bounds = 0) + { + return Reserve(m_defsize, base, upper_bounds); + } - virtual void Reset(); - virtual void Release(); - virtual bool TryResize( uint newsize ); - virtual bool Commit(); - - virtual void ForbidModification(); - virtual void AllowModification(); + virtual void Reset(); + virtual void Release(); + virtual bool TryResize(uint newsize); + virtual bool Commit(); - bool IsOk() const { return m_baseptr != NULL; } - wxString GetName() const { return m_name; } + virtual void ForbidModification(); + virtual void AllowModification(); - uptr GetReserveSizeInBytes() const { return m_pages_reserved * __pagesize; } - uptr GetReserveSizeInPages() const { return m_pages_reserved; } - uint GetCommittedPageCount() const { return m_pages_commited; } - uint GetCommittedBytes() const { return m_pages_commited * __pagesize; } + bool IsOk() const { return m_baseptr != NULL; } + wxString GetName() const { return m_name; } - u8* GetPtr() { return (u8*)m_baseptr; } - const u8* GetPtr() const { return (u8*)m_baseptr; } - u8* GetPtrEnd() { return (u8*)m_baseptr + (m_pages_reserved * __pagesize); } - const u8* GetPtrEnd() const { return (u8*)m_baseptr + (m_pages_reserved * __pagesize); } + uptr GetReserveSizeInBytes() const { return m_pages_reserved * __pagesize; } + uptr GetReserveSizeInPages() const { return m_pages_reserved; } + uint GetCommittedPageCount() const { return m_pages_commited; } + uint GetCommittedBytes() const { return m_pages_commited * __pagesize; } - VirtualMemoryReserve& SetName( const wxString& newname ); - VirtualMemoryReserve& SetBaseAddr( uptr newaddr ); - VirtualMemoryReserve& SetPageAccessOnCommit( const PageProtectionMode& mode ); + u8 *GetPtr() { return (u8 *)m_baseptr; } + const u8 *GetPtr() const { return (u8 *)m_baseptr; } + u8 *GetPtrEnd() { return (u8 *)m_baseptr + (m_pages_reserved * __pagesize); } + const u8 *GetPtrEnd() const { return (u8 *)m_baseptr + (m_pages_reserved * __pagesize); } - operator void*() { return m_baseptr; } - operator const void*() const { return m_baseptr; } + VirtualMemoryReserve &SetName(const wxString &newname); + VirtualMemoryReserve &SetBaseAddr(uptr newaddr); + VirtualMemoryReserve &SetPageAccessOnCommit(const PageProtectionMode &mode); - operator u8*() { return (u8*)m_baseptr; } - operator const u8*() const { return (u8*)m_baseptr; } + operator void *() { return m_baseptr; } + operator const void *() const { return m_baseptr; } - u8& operator[](uint idx) - { - pxAssert(idx < (m_pages_reserved * __pagesize)); - return *((u8*)m_baseptr + idx); - } + operator u8 *() { return (u8 *)m_baseptr; } + operator const u8 *() const { return (u8 *)m_baseptr; } - const u8& operator[](uint idx) const - { - pxAssert(idx < (m_pages_reserved * __pagesize)); - return *((u8*)m_baseptr + idx); - } + u8 &operator[](uint idx) + { + pxAssert(idx < (m_pages_reserved * __pagesize)); + return *((u8 *)m_baseptr + idx); + } + + const u8 &operator[](uint idx) const + { + pxAssert(idx < (m_pages_reserved * __pagesize)); + return *((u8 *)m_baseptr + idx); + } protected: - virtual void ReprotectCommittedBlocks( const PageProtectionMode& newmode ); + virtual void ReprotectCommittedBlocks(const PageProtectionMode &newmode); }; // -------------------------------------------------------------------------------------- @@ -218,80 +220,79 @@ protected: // -------------------------------------------------------------------------------------- class BaseVmReserveListener : public VirtualMemoryReserve { - DeclareNoncopyableObject( BaseVmReserveListener ); + DeclareNoncopyableObject(BaseVmReserveListener); - typedef VirtualMemoryReserve _parent; + typedef VirtualMemoryReserve _parent; protected: - EventListenerHelper_PageFault m_pagefault_listener; + EventListenerHelper_PageFault m_pagefault_listener; - // Incremental size by which the buffer grows (in pages) - uptr m_blocksize; + // Incremental size by which the buffer grows (in pages) + uptr m_blocksize; public: - BaseVmReserveListener( const wxString& name, size_t size = 0 ); - virtual ~BaseVmReserveListener() throw() { } + BaseVmReserveListener(const wxString &name, size_t size = 0); + virtual ~BaseVmReserveListener() throw() {} - operator void*() { return m_baseptr; } - operator const void*() const { return m_baseptr; } + operator void *() { return m_baseptr; } + operator const void *() const { return m_baseptr; } - operator u8*() { return (u8*)m_baseptr; } - operator const u8*() const { return (u8*)m_baseptr; } + operator u8 *() { return (u8 *)m_baseptr; } + operator const u8 *() const { return (u8 *)m_baseptr; } - using _parent::operator[]; + using _parent::operator[]; - void OnPageFaultEvent( const PageFaultInfo& info, bool& handled ); + void OnPageFaultEvent(const PageFaultInfo &info, bool &handled); - virtual uptr SetBlockSize( uptr bytes ) - { - m_blocksize = (bytes + __pagesize - 1) / __pagesize; - return m_blocksize * __pagesize; - } + virtual uptr SetBlockSize(uptr bytes) + { + m_blocksize = (bytes + __pagesize - 1) / __pagesize; + return m_blocksize * __pagesize; + } + + virtual void Reset() + { + _parent::Reset(); + } - virtual void Reset() - { - _parent::Reset(); - } - protected: + // This function is called from OnPageFaultEvent after the address has been translated + // and confirmed to apply to this reserved area in question. OnPageFaultEvent contains + // a try/catch exception handler, which ensures "reasonable" error response behavior if + // this function throws exceptions. + // + // Important: This method is called from the context of an exception/signal handler. On + // Windows this isn't a big deal (most operations are ok). On Linux, however, logging + // and other facilities are probably not a good idea. + virtual void DoCommitAndProtect(uptr offset) = 0; - // This function is called from OnPageFaultEvent after the address has been translated - // and confirmed to apply to this reserved area in question. OnPageFaultEvent contains - // a try/catch exception handler, which ensures "reasonable" error response behavior if - // this function throws exceptions. - // - // Important: This method is called from the context of an exception/signal handler. On - // Windows this isn't a big deal (most operations are ok). On Linux, however, logging - // and other facilities are probably not a good idea. - virtual void DoCommitAndProtect( uptr offset )=0; + // This function is called for every committed block. + virtual void OnCommittedBlock(void *block) = 0; - // This function is called for every committed block. - virtual void OnCommittedBlock( void* block )=0; - - virtual void CommitBlocks( uptr page, uint blocks ); + virtual void CommitBlocks(uptr page, uint blocks); }; #ifdef __POSIX__ -# define PCSX2_PAGEFAULT_PROTECT -# define PCSX2_PAGEFAULT_EXCEPT +#define PCSX2_PAGEFAULT_PROTECT +#define PCSX2_PAGEFAULT_EXCEPT -#elif defined( _WIN32 ) +#elif defined(_WIN32) struct _EXCEPTION_POINTERS; -extern int SysPageFaultExceptionFilter(struct _EXCEPTION_POINTERS* eps); +extern int SysPageFaultExceptionFilter(struct _EXCEPTION_POINTERS *eps); -# define PCSX2_PAGEFAULT_PROTECT __try -# define PCSX2_PAGEFAULT_EXCEPT __except(SysPageFaultExceptionFilter(GetExceptionInformation())) {} +#define PCSX2_PAGEFAULT_PROTECT __try +#define PCSX2_PAGEFAULT_EXCEPT \ + __except (SysPageFaultExceptionFilter(GetExceptionInformation())) {} #else -# error PCSX2 - Unsupported operating system platform. +#error PCSX2 - Unsupported operating system platform. #endif extern void pxInstallSignalHandler(); extern void _platform_InstallSignalHandler(); #include "Threading.h" -extern SrcType_PageFault* Source_PageFault; -extern Threading::Mutex PageFault_Mutex; - +extern SrcType_PageFault *Source_PageFault; +extern Threading::Mutex PageFault_Mutex; diff --git a/common/include/Utilities/Path.h b/common/include/Utilities/Path.h index 0517a9ebce..2face02584 100644 --- a/common/include/Utilities/Path.h +++ b/common/include/Utilities/Path.h @@ -18,7 +18,7 @@ #include #include "StringHelpers.h" -#define g_MaxPath 255 // 255 is safer with antiquated Win32 ASCII APIs. +#define g_MaxPath 255 // 255 is safer with antiquated Win32 ASCII APIs. // -------------------------------------------------------------------------------------- // wxDirName @@ -26,164 +26,180 @@ class wxDirName : protected wxFileName { public: - explicit wxDirName( const wxFileName& src ) - { - Assign( src.GetPath(), wxEmptyString ); - } + explicit wxDirName(const wxFileName &src) + { + Assign(src.GetPath(), wxEmptyString); + } - wxDirName() : wxFileName() {} - wxDirName( const wxDirName& src ) : wxFileName( src ) { } - explicit wxDirName( const char* src ) { Assign( fromUTF8(src) ); } - explicit wxDirName( const wxString& src ) { Assign( src ); } + wxDirName() + : wxFileName() + { + } + wxDirName(const wxDirName &src) + : wxFileName(src) + { + } + explicit wxDirName(const char *src) { Assign(fromUTF8(src)); } + explicit wxDirName(const wxString &src) { Assign(src); } - // ------------------------------------------------------------------------ - void Assign( const wxString& volume, const wxString& path ) - { - wxFileName::Assign( volume, path, wxEmptyString ); - } + // ------------------------------------------------------------------------ + void Assign(const wxString &volume, const wxString &path) + { + wxFileName::Assign(volume, path, wxEmptyString); + } - void Assign( const wxString& path ) - { - wxFileName::Assign( path, wxEmptyString ); - } + void Assign(const wxString &path) + { + wxFileName::Assign(path, wxEmptyString); + } - void Assign( const wxDirName& path ) - { - wxFileName::Assign( path ); - } + void Assign(const wxDirName &path) + { + wxFileName::Assign(path); + } - void Clear() { wxFileName::Clear(); } + void Clear() { wxFileName::Clear(); } - wxCharBuffer ToUTF8() const { return GetPath().ToUTF8(); } - wxCharBuffer ToAscii() const { return GetPath().ToAscii(); } - wxString ToString() const { return GetPath(); } + wxCharBuffer ToUTF8() const { return GetPath().ToUTF8(); } + wxCharBuffer ToAscii() const { return GetPath().ToAscii(); } + wxString ToString() const { return GetPath(); } - // ------------------------------------------------------------------------ - bool IsWritable() const { return IsDirWritable(); } - bool IsReadable() const { return IsDirReadable(); } - bool Exists() const { return DirExists(); } - bool FileExists() const { return wxFileName::FileExists(); } - bool IsOk() const { return wxFileName::IsOk(); } - bool IsRelative() const { return wxFileName::IsRelative(); } - bool IsAbsolute() const { return wxFileName::IsAbsolute(); } + // ------------------------------------------------------------------------ + bool IsWritable() const { return IsDirWritable(); } + bool IsReadable() const { return IsDirReadable(); } + bool Exists() const { return DirExists(); } + bool FileExists() const { return wxFileName::FileExists(); } + bool IsOk() const { return wxFileName::IsOk(); } + bool IsRelative() const { return wxFileName::IsRelative(); } + bool IsAbsolute() const { return wxFileName::IsAbsolute(); } - bool SameAs( const wxDirName& filepath ) const - { - return wxFileName::SameAs( filepath ); - } + bool SameAs(const wxDirName &filepath) const + { + return wxFileName::SameAs(filepath); + } - //Returns true if the file is somewhere inside this directory (and both file and directory are not relative). - bool IsContains( const wxFileName& file ) const - { - if( this->IsRelative() || file.IsRelative() ) - return false; + //Returns true if the file is somewhere inside this directory (and both file and directory are not relative). + bool IsContains(const wxFileName &file) const + { + if (this->IsRelative() || file.IsRelative()) + return false; - wxFileName f( file ); + wxFileName f(file); - while( 1 ) - { - if( this->SameAs( wxDirName(f.GetPath()) ) ) - return true; + while (1) { + if (this->SameAs(wxDirName(f.GetPath()))) + return true; - if( f.GetDirCount() == 0 ) - return false; + if (f.GetDirCount() == 0) + return false; - f.RemoveLastDir(); - } + f.RemoveLastDir(); + } - return false; - } + return false; + } - bool IsContains( const wxDirName& dir ) const - { - return IsContains( (wxFileName)dir ); - } + bool IsContains(const wxDirName &dir) const + { + return IsContains((wxFileName)dir); + } - //Auto relative works as follows: - // 1. if either base or subject are relative, return subject (should never be used with relative paths). - // 2. else if subject is somewhere inside base folder, then result is subject relative to base. - // 3. (windows only, implicitly) else if subject is on the same driveletter as base, result is absolute path of subject without the driveletter. - // 4. else, result is absolute path of subject. - // - // returns ok if both this and base are absolute paths. - static wxString MakeAutoRelativeTo(const wxFileName _subject, const wxString& pathbase) - { - wxFileName subject( _subject ); - wxDirName base ( pathbase ); - if( base.IsRelative() || subject.IsRelative() ) - return subject.GetFullPath(); + //Auto relative works as follows: + // 1. if either base or subject are relative, return subject (should never be used with relative paths). + // 2. else if subject is somewhere inside base folder, then result is subject relative to base. + // 3. (windows only, implicitly) else if subject is on the same driveletter as base, result is absolute path of subject without the driveletter. + // 4. else, result is absolute path of subject. + // + // returns ok if both this and base are absolute paths. + static wxString MakeAutoRelativeTo(const wxFileName _subject, const wxString &pathbase) + { + wxFileName subject(_subject); + wxDirName base(pathbase); + if (base.IsRelative() || subject.IsRelative()) + return subject.GetFullPath(); - wxString bv( base.GetVolume() ); bv.MakeUpper(); - wxString sv( subject.GetVolume() ); sv.MakeUpper(); + wxString bv(base.GetVolume()); + bv.MakeUpper(); + wxString sv(subject.GetVolume()); + sv.MakeUpper(); - if( base.IsContains( subject ) ) - { - subject.MakeRelativeTo( base.GetFullPath() ); - } - else if( base.HasVolume() && subject.HasVolume() && bv == sv ) - { - wxString unusedVolume; - wxString pathSansVolume; - subject.SplitVolume(subject.GetFullPath(), &unusedVolume, &pathSansVolume); - subject = pathSansVolume; - } - //implicit else: this stays fully absolute + if (base.IsContains(subject)) { + subject.MakeRelativeTo(base.GetFullPath()); + } else if (base.HasVolume() && subject.HasVolume() && bv == sv) { + wxString unusedVolume; + wxString pathSansVolume; + subject.SplitVolume(subject.GetFullPath(), &unusedVolume, &pathSansVolume); + subject = pathSansVolume; + } + //implicit else: this stays fully absolute - return subject.GetFullPath(); - } + return subject.GetFullPath(); + } - static wxString MakeAutoRelativeTo(const wxDirName subject, const wxString& pathbase) - { - return MakeAutoRelativeTo( wxFileName( subject ), pathbase ); - } + static wxString MakeAutoRelativeTo(const wxDirName subject, const wxString &pathbase) + { + return MakeAutoRelativeTo(wxFileName(subject), pathbase); + } - // Returns the number of sub folders in this directory path - size_t GetCount() const { return GetDirCount(); } + // Returns the number of sub folders in this directory path + size_t GetCount() const { return GetDirCount(); } - // ------------------------------------------------------------------------ - wxFileName Combine( const wxFileName& right ) const; - wxDirName Combine( const wxDirName& right ) const; + // ------------------------------------------------------------------------ + wxFileName Combine(const wxFileName &right) const; + wxDirName Combine(const wxDirName &right) const; - // removes the lastmost directory from the path - void RemoveLast() { wxFileName::RemoveDir(GetCount() - 1); } + // removes the lastmost directory from the path + void RemoveLast() { wxFileName::RemoveDir(GetCount() - 1); } - wxDirName& Normalize( int flags = wxPATH_NORM_ALL, const wxString& cwd = wxEmptyString ); - wxDirName& MakeRelativeTo( const wxString& pathBase = wxEmptyString ); - wxDirName& MakeAbsolute( const wxString& cwd = wxEmptyString ); + wxDirName &Normalize(int flags = wxPATH_NORM_ALL, const wxString &cwd = wxEmptyString); + wxDirName &MakeRelativeTo(const wxString &pathBase = wxEmptyString); + wxDirName &MakeAbsolute(const wxString &cwd = wxEmptyString); - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ - void AssignCwd( const wxString& volume = wxEmptyString ) { wxFileName::AssignCwd( volume ); } - bool SetCwd() { return wxFileName::SetCwd(); } + void AssignCwd(const wxString &volume = wxEmptyString) { wxFileName::AssignCwd(volume); } + bool SetCwd() { return wxFileName::SetCwd(); } - // wxWidgets is missing the const qualifier for this one! Shame! - void Rmdir(); - bool Mkdir(); + // wxWidgets is missing the const qualifier for this one! Shame! + void Rmdir(); + bool Mkdir(); - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ - wxDirName& operator=(const wxDirName& dirname) { Assign( dirname ); return *this; } - wxDirName& operator=(const wxString& dirname) { Assign( dirname ); return *this; } - wxDirName& operator=(const char* dirname) { Assign( fromUTF8(dirname) ); return *this; } + wxDirName &operator=(const wxDirName &dirname) + { + Assign(dirname); + return *this; + } + wxDirName &operator=(const wxString &dirname) + { + Assign(dirname); + return *this; + } + wxDirName &operator=(const char *dirname) + { + Assign(fromUTF8(dirname)); + return *this; + } - wxFileName operator+( const wxFileName& right ) const { return Combine( right ); } - wxDirName operator+( const wxDirName& right ) const { return Combine( right ); } - wxFileName operator+( const wxString& right ) const { return Combine( wxFileName(right) ); } - wxFileName operator+( const char* right ) const { return Combine( wxFileName(fromUTF8(right)) ); } + wxFileName operator+(const wxFileName &right) const { return Combine(right); } + wxDirName operator+(const wxDirName &right) const { return Combine(right); } + wxFileName operator+(const wxString &right) const { return Combine(wxFileName(right)); } + wxFileName operator+(const char *right) const { return Combine(wxFileName(fromUTF8(right))); } - bool operator==(const wxDirName& filename) const { return SameAs(filename); } - bool operator!=(const wxDirName& filename) const { return !SameAs(filename); } + bool operator==(const wxDirName &filename) const { return SameAs(filename); } + bool operator!=(const wxDirName &filename) const { return !SameAs(filename); } - bool operator==(const wxFileName& filename) const { return SameAs(wxDirName(filename)); } - bool operator!=(const wxFileName& filename) const { return !SameAs(wxDirName(filename)); } + bool operator==(const wxFileName &filename) const { return SameAs(wxDirName(filename)); } + bool operator!=(const wxFileName &filename) const { return !SameAs(wxDirName(filename)); } - // compare with a filename string interpreted as a native file name - bool operator==(const wxString& filename) const { return SameAs(wxDirName(filename)); } - bool operator!=(const wxString& filename) const { return !SameAs(wxDirName(filename)); } + // compare with a filename string interpreted as a native file name + bool operator==(const wxString &filename) const { return SameAs(wxDirName(filename)); } + bool operator!=(const wxString &filename) const { return !SameAs(wxDirName(filename)); } - const wxFileName& GetFilename() const { return *this; } - wxFileName& GetFilename() { return *this; } + const wxFileName &GetFilename() const { return *this; } + wxFileName &GetFilename() { return *this; } }; // -------------------------------------------------------------------------------------- @@ -195,20 +211,20 @@ public: // namespace Path { - extern bool IsRelative( const wxString& path ); - extern s64 GetFileSize( const wxString& path ); +extern bool IsRelative(const wxString &path); +extern s64 GetFileSize(const wxString &path); - extern wxString Normalize( const wxString& srcpath ); - extern wxString Normalize( const wxDirName& srcpath ); - extern wxString MakeAbsolute( const wxString& srcpath ); +extern wxString Normalize(const wxString &srcpath); +extern wxString Normalize(const wxDirName &srcpath); +extern wxString MakeAbsolute(const wxString &srcpath); - extern wxString Combine( const wxString& srcPath, const wxString& srcFile ); - extern wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile ); - extern wxString Combine( const wxString& srcPath, const wxDirName& srcFile ); - extern wxString ReplaceExtension( const wxString& src, const wxString& ext ); - extern wxString ReplaceFilename( const wxString& src, const wxString& newfilename ); - extern wxString GetFilename( const wxString& src ); - extern wxString GetDirectory( const wxString& src ); - extern wxString GetFilenameWithoutExt( const wxString& src ); - extern wxString GetRootDirectory( const wxString& src ); +extern wxString Combine(const wxString &srcPath, const wxString &srcFile); +extern wxString Combine(const wxDirName &srcPath, const wxFileName &srcFile); +extern wxString Combine(const wxString &srcPath, const wxDirName &srcFile); +extern wxString ReplaceExtension(const wxString &src, const wxString &ext); +extern wxString ReplaceFilename(const wxString &src, const wxString &newfilename); +extern wxString GetFilename(const wxString &src); +extern wxString GetDirectory(const wxString &src); +extern wxString GetFilenameWithoutExt(const wxString &src); +extern wxString GetRootDirectory(const wxString &src); } diff --git a/common/include/Utilities/Perf.h b/common/include/Utilities/Perf.h index f24e897df2..3c83982fb9 100644 --- a/common/include/Utilities/Perf.h +++ b/common/include/Utilities/Perf.h @@ -15,43 +15,42 @@ #pragma once -namespace Perf { +namespace Perf +{ - struct Info - { - uptr m_x86; - u32 m_size; - char m_symbol[20]; - // The idea is to keep static zones that are set only - // once. - bool m_dynamic; +struct Info +{ + uptr m_x86; + u32 m_size; + char m_symbol[20]; + // The idea is to keep static zones that are set only + // once. + bool m_dynamic; - Info(uptr x86, u32 size, const char* symbol); - Info(uptr x86, u32 size, const char* symbol, u32 pc); - void Print(FILE* fp); - }; + Info(uptr x86, u32 size, const char *symbol); + Info(uptr x86, u32 size, const char *symbol, u32 pc); + void Print(FILE *fp); +}; - class InfoVector - { - std::vector m_v; - char m_prefix[20]; +class InfoVector +{ + std::vector m_v; + char m_prefix[20]; - public: +public: + InfoVector(const char *prefix); - InfoVector(const char* prefix); + void print(FILE *fp); + void map(uptr x86, u32 size, const char *symbol); + void map(uptr x86, u32 size, u32 pc); + void reset(); +}; - void print(FILE* fp); - void map(uptr x86, u32 size, const char* symbol); - void map(uptr x86, u32 size, u32 pc); - void reset(); +void dump(); +void dump_and_reset(); - }; - - void dump(); - void dump_and_reset(); - - extern InfoVector any; - extern InfoVector ee; - extern InfoVector iop; - extern InfoVector vu; +extern InfoVector any; +extern InfoVector ee; +extern InfoVector iop; +extern InfoVector vu; } diff --git a/common/include/Utilities/PersistentThread.h b/common/include/Utilities/PersistentThread.h index 491930855f..1617819baa 100644 --- a/common/include/Utilities/PersistentThread.h +++ b/common/include/Utilities/PersistentThread.h @@ -25,38 +25,38 @@ namespace Threading // -------------------------------------------------------------------------------------- // ThreadDeleteEvent // -------------------------------------------------------------------------------------- - class EventListener_Thread : public IEventDispatcher - { - public: - typedef int EvtParams; +class EventListener_Thread : public IEventDispatcher +{ +public: + typedef int EvtParams; - protected: - pxThread* m_thread; +protected: + pxThread *m_thread; - public: - EventListener_Thread() - { - m_thread = NULL; - } +public: + EventListener_Thread() + { + m_thread = NULL; + } - virtual ~EventListener_Thread() throw() {} + virtual ~EventListener_Thread() throw() {} - void SetThread( pxThread& thr ) { m_thread = &thr; } - void SetThread( pxThread* thr ) { m_thread = thr; } + void SetThread(pxThread &thr) { m_thread = &thr; } + void SetThread(pxThread *thr) { m_thread = thr; } - void DispatchEvent( const int& params ) - { - OnThreadCleanup(); - } + void DispatchEvent(const int ¶ms) + { + OnThreadCleanup(); + } - protected: - // Invoked by the pxThread when the thread execution is ending. This is - // typically more useful than a delete listener since the extended thread information - // provided by virtualized functions/methods will be available. - // Important! This event is executed *by the thread*, so care must be taken to ensure - // thread sync when necessary (posting messages to the main thread, etc). - virtual void OnThreadCleanup()=0; - }; +protected: + // Invoked by the pxThread when the thread execution is ending. This is + // typically more useful than a delete listener since the extended thread information + // provided by virtualized functions/methods will be available. + // Important! This event is executed *by the thread*, so care must be taken to ensure + // thread sync when necessary (posting messages to the main thread, etc). + virtual void OnThreadCleanup() = 0; +}; // -------------------------------------------------------------------------------------- // pxThread - Helper class for the basics of starting/managing persistent threads. @@ -85,122 +85,123 @@ namespace Threading // no dependency options for ensuring correct static var initializations). Use heap // allocation to create thread objects instead. // - class pxThread - { - DeclareNoncopyableObject(pxThread); +class pxThread +{ + DeclareNoncopyableObject(pxThread); - friend void pxYield( int ms ); + friend void pxYield(int ms); - protected: - wxString m_name; // diagnostic name for our thread. - pthread_t m_thread; - uptr m_native_id; // typically an id, but implementing platforms can do whatever. - uptr m_native_handle; // typically a pointer/handle, but implementing platforms can do whatever. +protected: + wxString m_name; // diagnostic name for our thread. + pthread_t m_thread; + uptr m_native_id; // typically an id, but implementing platforms can do whatever. + uptr m_native_handle; // typically a pointer/handle, but implementing platforms can do whatever. - Semaphore m_sem_event; // general wait event that's needed by most threads - Semaphore m_sem_startup; // startup sync tool - Mutex m_mtx_InThread; // used for canceling and closing threads in a deadlock-safe manner - MutexRecursive m_mtx_start; // used to lock the Start() code from starting simultaneous threads accidentally. - Mutex m_mtx_ThreadName; + Semaphore m_sem_event; // general wait event that's needed by most threads + Semaphore m_sem_startup; // startup sync tool + Mutex m_mtx_InThread; // used for canceling and closing threads in a deadlock-safe manner + MutexRecursive m_mtx_start; // used to lock the Start() code from starting simultaneous threads accidentally. + Mutex m_mtx_ThreadName; - std::atomic m_detached; // a boolean value which indicates if the m_thread handle is valid - std::atomic m_running; // set true by Start(), and set false by Cancel(), Block(), etc. + std::atomic m_detached; // a boolean value which indicates if the m_thread handle is valid + std::atomic m_running; // set true by Start(), and set false by Cancel(), Block(), etc. - // exception handle, set non-NULL if the thread terminated with an exception - // Use RethrowException() to re-throw the exception using its original exception type. - ScopedPtrMT m_except; + // exception handle, set non-NULL if the thread terminated with an exception + // Use RethrowException() to re-throw the exception using its original exception type. + ScopedPtrMT m_except; - EventSource m_evtsrc_OnDelete; + EventSource m_evtsrc_OnDelete; - public: - virtual ~pxThread() throw(); - pxThread( const wxString& name=L"pxThread" ); +public: + virtual ~pxThread() throw(); + pxThread(const wxString &name = L"pxThread"); - pthread_t GetId() const { return m_thread; } - u64 GetCpuTime() const; + pthread_t GetId() const { return m_thread; } + u64 GetCpuTime() const; - virtual void Start(); - virtual void Cancel( bool isBlocking = true ); - virtual bool Cancel( const wxTimeSpan& timeout ); - virtual bool Detach(); - virtual void Block(); - virtual bool Block( const wxTimeSpan& timeout ); - virtual void RethrowException() const; + virtual void Start(); + virtual void Cancel(bool isBlocking = true); + virtual bool Cancel(const wxTimeSpan &timeout); + virtual bool Detach(); + virtual void Block(); + virtual bool Block(const wxTimeSpan &timeout); + virtual void RethrowException() const; - void AddListener( EventListener_Thread& evt ); - void AddListener( EventListener_Thread* evt ) - { - if( evt == NULL ) return; - AddListener( *evt ); - } + void AddListener(EventListener_Thread &evt); + void AddListener(EventListener_Thread *evt) + { + if (evt == NULL) + return; + AddListener(*evt); + } - void WaitOnSelf( Semaphore& mutex ) const; - void WaitOnSelf( Mutex& mutex ) const; - bool WaitOnSelf( Semaphore& mutex, const wxTimeSpan& timeout ) const; - bool WaitOnSelf( Mutex& mutex, const wxTimeSpan& timeout ) const; + void WaitOnSelf(Semaphore &mutex) const; + void WaitOnSelf(Mutex &mutex) const; + bool WaitOnSelf(Semaphore &mutex, const wxTimeSpan &timeout) const; + bool WaitOnSelf(Mutex &mutex, const wxTimeSpan &timeout) const; - bool IsRunning() const; - bool IsSelf() const; - bool HasPendingException() const { return !!m_except; } + bool IsRunning() const; + bool IsSelf() const; + bool HasPendingException() const { return !!m_except; } - wxString GetName() const; - void SetName( const wxString& newname ); + wxString GetName() const; + void SetName(const wxString &newname); - protected: - // Extending classes should always implement your own OnStart(), which is called by - // Start() once necessary locks have been obtained. Do not override Start() directly - // unless you're really sure that's what you need to do. ;) - virtual void OnStart(); +protected: + // Extending classes should always implement your own OnStart(), which is called by + // Start() once necessary locks have been obtained. Do not override Start() directly + // unless you're really sure that's what you need to do. ;) + virtual void OnStart(); - virtual void OnStartInThread(); + virtual void OnStartInThread(); - // This is called when the thread has been canceled or exits normally. The pxThread - // automatically binds it to the pthread cleanup routines as soon as the thread starts. - virtual void OnCleanupInThread(); + // This is called when the thread has been canceled or exits normally. The pxThread + // automatically binds it to the pthread cleanup routines as soon as the thread starts. + virtual void OnCleanupInThread(); - // Implemented by derived class to perform actual threaded task! - virtual void ExecuteTaskInThread()=0; + // Implemented by derived class to perform actual threaded task! + virtual void ExecuteTaskInThread() = 0; - void TestCancel() const; + void TestCancel() const; - // Yields this thread to other threads and checks for cancellation. A sleeping thread should - // always test for cancellation, however if you really don't want to, you can use Threading::Sleep() - // or better yet, disable cancellation of the thread completely with DisableCancellation(). - // - // Parameters: - // ms - 'minimum' yield time in milliseconds (rough -- typically yields are longer by 1-5ms - // depending on operating system/platform). If ms is 0 or unspecified, then a single - // timeslice is yielded to other contending threads. If no threads are contending for - // time when ms==0, then no yield is done, but cancellation is still tested. - void Yield( int ms = 0 ) - { - pxAssert( IsSelf() ); - Threading::Sleep( ms ); - TestCancel(); - } + // Yields this thread to other threads and checks for cancellation. A sleeping thread should + // always test for cancellation, however if you really don't want to, you can use Threading::Sleep() + // or better yet, disable cancellation of the thread completely with DisableCancellation(). + // + // Parameters: + // ms - 'minimum' yield time in milliseconds (rough -- typically yields are longer by 1-5ms + // depending on operating system/platform). If ms is 0 or unspecified, then a single + // timeslice is yielded to other contending threads. If no threads are contending for + // time when ms==0, then no yield is done, but cancellation is still tested. + void Yield(int ms = 0) + { + pxAssert(IsSelf()); + Threading::Sleep(ms); + TestCancel(); + } - void FrankenMutex( Mutex& mutex ); + void FrankenMutex(Mutex &mutex); - bool AffinityAssert_AllowFromSelf( const DiagnosticOrigin& origin ) const; - bool AffinityAssert_DisallowFromSelf( const DiagnosticOrigin& origin ) const; + bool AffinityAssert_AllowFromSelf(const DiagnosticOrigin &origin) const; + bool AffinityAssert_DisallowFromSelf(const DiagnosticOrigin &origin) const; - // ---------------------------------------------------------------------------- - // Section of methods for internal use only. + // ---------------------------------------------------------------------------- + // Section of methods for internal use only. - void _platform_specific_OnStartInThread(); - void _platform_specific_OnCleanupInThread(); - bool _basecancel(); - void _selfRunningTest( const wxChar* name ) const; - void _DoSetThreadName( const wxString& name ); - void _DoSetThreadName( const char* name ); - void _internal_execute(); - void _try_virtual_invoke( void (pxThread::*method)() ); - void _ThreadCleanup(); + void _platform_specific_OnStartInThread(); + void _platform_specific_OnCleanupInThread(); + bool _basecancel(); + void _selfRunningTest(const wxChar *name) const; + void _DoSetThreadName(const wxString &name); + void _DoSetThreadName(const char *name); + void _internal_execute(); + void _try_virtual_invoke(void (pxThread::*method)()); + void _ThreadCleanup(); - static void* _internal_callback( void* func ); - static void _pt_callback_cleanup( void* handle ); - }; + static void *_internal_callback(void *func); + static void _pt_callback_cleanup(void *handle); +}; // -------------------------------------------------------------------------------------- @@ -240,32 +241,32 @@ namespace Threading // into smaller sections. For example, if you have 20,000 items to process, the task // can be divided into two threads of 10,000 items each. // - class BaseTaskThread : public pxThread - { - protected: - std::atomic m_Done; - std::atomic m_TaskPending; - Semaphore m_post_TaskComplete; - Mutex m_lock_TaskComplete; +class BaseTaskThread : public pxThread +{ +protected: + std::atomic m_Done; + std::atomic m_TaskPending; + Semaphore m_post_TaskComplete; + Mutex m_lock_TaskComplete; - public: - virtual ~BaseTaskThread() throw() {} - BaseTaskThread() : - m_Done( false ) - , m_TaskPending( false ) - , m_post_TaskComplete() - { - } +public: + virtual ~BaseTaskThread() throw() {} + BaseTaskThread() + : m_Done(false) + , m_TaskPending(false) + , m_post_TaskComplete() + { + } - void Block(); - void PostTask(); - void WaitForResult(); + void Block(); + void PostTask(); + void WaitForResult(); - protected: - // Abstract method run when a task has been posted. Implementing classes should do - // all your necessary processing work here. - virtual void Task()=0; +protected: + // Abstract method run when a task has been posted. Implementing classes should do + // all your necessary processing work here. + virtual void Task() = 0; - virtual void ExecuteTaskInThread(); - }; + virtual void ExecuteTaskInThread(); +}; } diff --git a/common/include/Utilities/RedtapeWindows.h b/common/include/Utilities/RedtapeWindows.h index 6850e9156e..36baed02bb 100644 --- a/common/include/Utilities/RedtapeWindows.h +++ b/common/include/Utilities/RedtapeWindows.h @@ -16,7 +16,7 @@ #pragma once #ifdef __WXMSW__ -# include +#include #else ////////////////////////////////////////////////////////////////////////////////////////// @@ -27,7 +27,7 @@ // check, so that we don't have to do it explicitly in every instance where it might // be needed from non-Win32-specific files -#define NOMINMAX // Disables other libs inclusion of their own min/max macros (we use std instead) +#define NOMINMAX // Disables other libs inclusion of their own min/max macros (we use std instead) #ifdef _WIN32 diff --git a/common/include/Utilities/RwMutex.h b/common/include/Utilities/RwMutex.h index 444040e9ed..d84813f781 100644 --- a/common/include/Utilities/RwMutex.h +++ b/common/include/Utilities/RwMutex.h @@ -22,69 +22,69 @@ namespace Threading // -------------------------------------------------------------------------------------- // RwMutex // -------------------------------------------------------------------------------------- - class RwMutex - { - DeclareNoncopyableObject(RwMutex); +class RwMutex +{ + DeclareNoncopyableObject(RwMutex); - protected: - pthread_rwlock_t m_rwlock; +protected: + pthread_rwlock_t m_rwlock; - public: - RwMutex(); - virtual ~RwMutex() throw(); - - virtual void AcquireRead(); - virtual void AcquireWrite(); - virtual bool TryAcquireRead(); - virtual bool TryAcquireWrite(); +public: + RwMutex(); + virtual ~RwMutex() throw(); - virtual void Release(); - }; + virtual void AcquireRead(); + virtual void AcquireWrite(); + virtual bool TryAcquireRead(); + virtual bool TryAcquireWrite(); + + virtual void Release(); +}; // -------------------------------------------------------------------------------------- // BaseScopedReadWriteLock // -------------------------------------------------------------------------------------- - class BaseScopedReadWriteLock - { - DeclareNoncopyableObject(BaseScopedReadWriteLock); +class BaseScopedReadWriteLock +{ + DeclareNoncopyableObject(BaseScopedReadWriteLock); - protected: - RwMutex& m_lock; - bool m_IsLocked; +protected: + RwMutex &m_lock; + bool m_IsLocked; - public: - BaseScopedReadWriteLock( RwMutex& locker ) - : m_lock( locker ) - { - } +public: + BaseScopedReadWriteLock(RwMutex &locker) + : m_lock(locker) + { + } - virtual ~BaseScopedReadWriteLock() throw(); + virtual ~BaseScopedReadWriteLock() throw(); - void Release(); - bool IsLocked() const { return m_IsLocked; } - }; + void Release(); + bool IsLocked() const { return m_IsLocked; } +}; // -------------------------------------------------------------------------------------- // ScopedReadLock / ScopedWriteLock // -------------------------------------------------------------------------------------- - class ScopedReadLock : public BaseScopedReadWriteLock - { - public: - ScopedReadLock( RwMutex& locker ); - virtual ~ScopedReadLock() throw() {} +class ScopedReadLock : public BaseScopedReadWriteLock +{ +public: + ScopedReadLock(RwMutex &locker); + virtual ~ScopedReadLock() throw() {} - void Acquire(); - }; + void Acquire(); +}; - class ScopedWriteLock : public BaseScopedReadWriteLock - { - public: - ScopedWriteLock( RwMutex& locker ); - virtual ~ScopedWriteLock() throw() {} +class ScopedWriteLock : public BaseScopedReadWriteLock +{ +public: + ScopedWriteLock(RwMutex &locker); + virtual ~ScopedWriteLock() throw() {} - void Acquire(); + void Acquire(); - protected: - ScopedWriteLock( RwMutex& locker, bool isTryLock ); - }; +protected: + ScopedWriteLock(RwMutex &locker, bool isTryLock); +}; } diff --git a/common/include/Utilities/SafeArray.h b/common/include/Utilities/SafeArray.h index 1e46d299bc..4251ff7fea 100644 --- a/common/include/Utilities/SafeArray.h +++ b/common/include/Utilities/SafeArray.h @@ -23,8 +23,8 @@ // Microsoft Windows only macro, useful for freeing out COM objects: -#define safe_release( ptr ) \ - ((void) (( ( (ptr) != NULL ) && ((ptr)->Release(), !!0) ), (ptr) = NULL)) +#define safe_release(ptr) \ + ((void)((((ptr) != NULL) && ((ptr)->Release(), !!0)), (ptr) = NULL)) // -------------------------------------------------------------------------------------- // SafeArray @@ -32,75 +32,75 @@ // Handy little class for allocating a resizable memory block, complete with exception // error handling and automatic cleanup. A lightweight alternative to std::vector. // -template< typename T > +template class SafeArray { - DeclareNoncopyableObject(SafeArray); + DeclareNoncopyableObject(SafeArray); public: - static const int DefaultChunkSize = 0x1000 * sizeof(T); + static const int DefaultChunkSize = 0x1000 * sizeof(T); public: - wxString Name; // user-assigned block name - int ChunkSize; + wxString Name; // user-assigned block name + int ChunkSize; protected: - T* m_ptr; - int m_size; // size of the allocation of memory + T *m_ptr; + int m_size; // size of the allocation of memory protected: - SafeArray( const wxChar* name, T* allocated_mem, int initSize ); - virtual T* _virtual_realloc( int newsize ); + SafeArray(const wxChar *name, T *allocated_mem, int initSize); + virtual T *_virtual_realloc(int newsize); - // A safe array index fetcher. Asserts if the index is out of bounds (dev and debug - // builds only -- no bounds checking is done in release builds). - T* _getPtr( uint i ) const; + // A safe array index fetcher. Asserts if the index is out of bounds (dev and debug + // builds only -- no bounds checking is done in release builds). + T *_getPtr(uint i) const; public: - virtual ~SafeArray() throw(); + virtual ~SafeArray() throw(); - explicit SafeArray( const wxChar* name=L"Unnamed" ); - explicit SafeArray( int initialSize, const wxChar* name=L"Unnamed" ); - - void Dispose(); - void ExactAlloc( int newsize ); - void MakeRoomFor( int newsize ) - { - if( newsize > m_size ) - ExactAlloc( newsize ); - } + explicit SafeArray(const wxChar *name = L"Unnamed"); + explicit SafeArray(int initialSize, const wxChar *name = L"Unnamed"); - bool IsDisposed() const { return (m_ptr==NULL); } + void Dispose(); + void ExactAlloc(int newsize); + void MakeRoomFor(int newsize) + { + if (newsize > m_size) + ExactAlloc(newsize); + } - // Returns the size of the memory allocation, as according to the array type. - int GetLength() const { return m_size; } - // Returns the size of the memory allocation in bytes. - int GetSizeInBytes() const { return m_size * sizeof(T); } + bool IsDisposed() const { return (m_ptr == NULL); } - // Extends the containment area of the array. Extensions are performed - // in chunks. - void GrowBy( int items ) - { - MakeRoomFor( m_size + ChunkSize + items + 1 ); - } + // Returns the size of the memory allocation, as according to the array type. + int GetLength() const { return m_size; } + // Returns the size of the memory allocation in bytes. + int GetSizeInBytes() const { return m_size * sizeof(T); } - // Gets a pointer to the requested allocation index. - // DevBuilds : Generates assertion if the index is invalid. - T* GetPtr( uint idx=0 ) { return _getPtr( idx ); } - const T* GetPtr( uint idx=0 ) const { return _getPtr( idx ); } + // Extends the containment area of the array. Extensions are performed + // in chunks. + void GrowBy(int items) + { + MakeRoomFor(m_size + ChunkSize + items + 1); + } - // Gets a pointer to the element directly after the last element in the array. - // This is equivalent to doing GetPtr(GetLength()), except that this call *avoids* - // the out-of-bounds assertion check that typically occurs when you do that. :) - T* GetPtrEnd() { return &m_ptr[m_size]; } - const T* GetPtrEnd() const { return &m_ptr[m_size]; } + // Gets a pointer to the requested allocation index. + // DevBuilds : Generates assertion if the index is invalid. + T *GetPtr(uint idx = 0) { return _getPtr(idx); } + const T *GetPtr(uint idx = 0) const { return _getPtr(idx); } - // Gets an element of this memory allocation much as if it were an array. - // DevBuilds : Generates assertion if the index is invalid. - T& operator[]( int idx ) { return *_getPtr( (uint)idx ); } - const T& operator[]( int idx ) const { return *_getPtr( (uint)idx ); } + // Gets a pointer to the element directly after the last element in the array. + // This is equivalent to doing GetPtr(GetLength()), except that this call *avoids* + // the out-of-bounds assertion check that typically occurs when you do that. :) + T *GetPtrEnd() { return &m_ptr[m_size]; } + const T *GetPtrEnd() const { return &m_ptr[m_size]; } - virtual SafeArray* Clone() const; + // Gets an element of this memory allocation much as if it were an array. + // DevBuilds : Generates assertion if the index is invalid. + T &operator[](int idx) { return *_getPtr((uint)idx); } + const T &operator[](int idx) const { return *_getPtr((uint)idx); } + + virtual SafeArray *Clone() const; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -113,76 +113,76 @@ public: // * Classes with copy constructors (copying is done using performance memcpy) // * Classes with destructors (they're not called, sorry!) // -template< typename T > +template class SafeList { - DeclareNoncopyableObject(SafeList); + DeclareNoncopyableObject(SafeList); public: - static const int DefaultChunkSize = 0x80 * sizeof(T); + static const int DefaultChunkSize = 0x80 * sizeof(T); public: - wxString Name; // user-assigned block name - int ChunkSize; // assigned DefaultChunkSize on init, reconfigurable at any time. + wxString Name; // user-assigned block name + int ChunkSize; // assigned DefaultChunkSize on init, reconfigurable at any time. protected: - T* m_ptr; - int m_allocsize; // size of the allocation of memory - uint m_length; // length of the array (active items, not buffer allocation) + T *m_ptr; + int m_allocsize; // size of the allocation of memory + uint m_length; // length of the array (active items, not buffer allocation) protected: - virtual T* _virtual_realloc( int newsize ); - void _MakeRoomFor_threshold( int newsize ); + virtual T *_virtual_realloc(int newsize); + void _MakeRoomFor_threshold(int newsize); - T* _getPtr( uint i ) const; + T *_getPtr(uint i) const; public: - virtual ~SafeList() throw(); - explicit SafeList( const wxChar* name=L"Unnamed" ); - explicit SafeList( int initialSize, const wxChar* name=L"Unnamed" ); - virtual SafeList* Clone() const; + virtual ~SafeList() throw(); + explicit SafeList(const wxChar *name = L"Unnamed"); + explicit SafeList(int initialSize, const wxChar *name = L"Unnamed"); + virtual SafeList *Clone() const; - void Remove( int index ); - void MakeRoomFor( int blockSize ); + void Remove(int index); + void MakeRoomFor(int blockSize); - T& New(); - int Add( const T& src ); - T& AddNew( const T& src ); + T &New(); + int Add(const T &src); + T &AddNew(const T &src); - // Returns the size of the list, as according to the array type. This includes - // mapped items only. The actual size of the allocation may differ. - int GetLength() const { return m_length; } + // Returns the size of the list, as according to the array type. This includes + // mapped items only. The actual size of the allocation may differ. + int GetLength() const { return m_length; } - // Returns the size of the list, in bytes. This includes mapped items only. - // The actual size of the allocation may differ. - int GetSizeInBytes() const { return m_length * sizeof(T); } + // Returns the size of the list, in bytes. This includes mapped items only. + // The actual size of the allocation may differ. + int GetSizeInBytes() const { return m_length * sizeof(T); } - void MatchLengthToAllocatedSize() - { - m_length = m_allocsize; - } + void MatchLengthToAllocatedSize() + { + m_length = m_allocsize; + } - void GrowBy( int items ) - { - MakeRoomFor( m_length + ChunkSize + items + 1 ); - } + void GrowBy(int items) + { + MakeRoomFor(m_length + ChunkSize + items + 1); + } - // Sets the item length to zero. Does not free memory allocations. - void Clear() - { - m_length = 0; - } + // Sets the item length to zero. Does not free memory allocations. + void Clear() + { + m_length = 0; + } - // Gets an element of this memory allocation much as if it were an array. - // DevBuilds : Generates assertion if the index is invalid. - T& operator[]( int idx ) { return *_getPtr( (uint)idx ); } - const T& operator[]( int idx ) const { return *_getPtr( (uint)idx ); } + // Gets an element of this memory allocation much as if it were an array. + // DevBuilds : Generates assertion if the index is invalid. + T &operator[](int idx) { return *_getPtr((uint)idx); } + const T &operator[](int idx) const { return *_getPtr((uint)idx); } - T* GetPtr() { return m_ptr; } - const T* GetPtr() const { return m_ptr; } + T *GetPtr() { return m_ptr; } + const T *GetPtr() const { return m_ptr; } - T& GetLast() { return m_ptr[m_length-1]; } - const T& GetLast() const{ return m_ptr[m_length-1]; } + T &GetLast() { return m_ptr[m_length - 1]; } + const T &GetLast() const { return m_ptr[m_length - 1]; } }; // -------------------------------------------------------------------------------------- @@ -192,25 +192,24 @@ public: // exception-based error handling and automatic cleanup. // This one supports aligned data allocations too! -template< typename T, uint Alignment > +template class SafeAlignedArray : public SafeArray { - typedef SafeArray _parent; + typedef SafeArray _parent; protected: - T* _virtual_realloc( int newsize ); + T *_virtual_realloc(int newsize); public: - using _parent::operator[]; + using _parent::operator[]; - virtual ~SafeAlignedArray() throw(); + virtual ~SafeAlignedArray() throw(); - explicit SafeAlignedArray( const wxChar* name=L"Unnamed" ) : - SafeArray::SafeArray( name ) - { - } + explicit SafeAlignedArray(const wxChar *name = L"Unnamed") + : SafeArray::SafeArray(name) + { + } - explicit SafeAlignedArray( int initialSize, const wxChar* name=L"Unnamed" ); - virtual SafeAlignedArray* Clone() const; + explicit SafeAlignedArray(int initialSize, const wxChar *name = L"Unnamed"); + virtual SafeAlignedArray *Clone() const; }; - diff --git a/common/include/Utilities/SafeArray.inl b/common/include/Utilities/SafeArray.inl index 5e18ab890e..6d447271ce 100644 --- a/common/include/Utilities/SafeArray.inl +++ b/common/include/Utilities/SafeArray.inl @@ -21,104 +21,104 @@ // use its own memory allocation (with an aligned memory, for example). // Throws: // Exception::OutOfMemory if the allocated_mem pointer is NULL. -template< typename T > -SafeArray::SafeArray( const wxChar* name, T* allocated_mem, int initSize ) - : Name( name ) +template +SafeArray::SafeArray(const wxChar *name, T *allocated_mem, int initSize) + : Name(name) { - ChunkSize = DefaultChunkSize; - m_ptr = allocated_mem; - m_size = initSize; + ChunkSize = DefaultChunkSize; + m_ptr = allocated_mem; + m_size = initSize; - if( m_ptr == NULL ) - throw Exception::OutOfMemory(name) - .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initSize)); + if (m_ptr == NULL) + throw Exception::OutOfMemory(name) + .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initSize)); } -template< typename T > -T* SafeArray::_virtual_realloc( int newsize ) +template +T *SafeArray::_virtual_realloc(int newsize) { - T* retval = (T*)((m_ptr == NULL) ? - malloc( newsize * sizeof(T) ) : - realloc( m_ptr, newsize * sizeof(T) ) - ); - - if( IsDebugBuild && (retval != NULL)) - { - // Zero everything out to 0xbaadf00d, so that its obviously uncleared - // to a debuggee + T *retval = (T *)((m_ptr == NULL) ? + malloc(newsize * sizeof(T)) : + realloc(m_ptr, newsize * sizeof(T))); - u32* fill = (u32*)&retval[m_size]; - const u32* end = (u32*)((((uptr)&retval[newsize-1])-3) & ~0x3); - for( ; fill +template SafeArray::~SafeArray() throw() { - safe_free( m_ptr ); + safe_free(m_ptr); } -template< typename T > -SafeArray::SafeArray( const wxChar* name ) - : Name( name ) +template +SafeArray::SafeArray(const wxChar *name) + : Name(name) { - ChunkSize = DefaultChunkSize; - m_ptr = NULL; - m_size = 0; + ChunkSize = DefaultChunkSize; + m_ptr = NULL; + m_size = 0; } -template< typename T > -SafeArray::SafeArray( int initialSize, const wxChar* name ) - : Name( name ) +template +SafeArray::SafeArray(int initialSize, const wxChar *name) + : Name(name) { - ChunkSize = DefaultChunkSize; - m_ptr = (initialSize==0) ? NULL : (T*)malloc( initialSize * sizeof(T) ); - m_size = initialSize; + ChunkSize = DefaultChunkSize; + m_ptr = (initialSize == 0) ? NULL : (T *)malloc(initialSize * sizeof(T)); + m_size = initialSize; - if( (initialSize != 0) && (m_ptr == NULL) ) - throw Exception::OutOfMemory(name) - .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initialSize)); + if ((initialSize != 0) && (m_ptr == NULL)) + throw Exception::OutOfMemory(name) + .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initialSize)); } // Clears the contents of the array to zero, and frees all memory allocations. -template< typename T > +template void SafeArray::Dispose() { - m_size = 0; - safe_free( m_ptr ); + m_size = 0; + safe_free(m_ptr); } -template< typename T > -T* SafeArray::_getPtr( uint i ) const +template +T *SafeArray::_getPtr(uint i) const { - IndexBoundsAssumeDev( WX_STR(Name), i, m_size ); - return &m_ptr[i]; + IndexBoundsAssumeDev(WX_STR(Name), i, m_size); + return &m_ptr[i]; } // reallocates the array to the explicit size. Can be used to shrink or grow an // array, and bypasses the internal threshold growth indicators. -template< typename T > -void SafeArray::ExactAlloc( int newsize ) +template +void SafeArray::ExactAlloc(int newsize) { - if( newsize == m_size ) return; + if (newsize == m_size) + return; - m_ptr = _virtual_realloc( newsize ); - if( m_ptr == NULL ) - throw Exception::OutOfMemory(Name) - .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ExactAlloc' [oldsize=%d] [newsize=%d]", m_size, newsize)); + m_ptr = _virtual_realloc(newsize); + if (m_ptr == NULL) + throw Exception::OutOfMemory(Name) + .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ExactAlloc' [oldsize=%d] [newsize=%d]", m_size, newsize)); - m_size = newsize; + m_size = newsize; } -template< typename T > -SafeArray* SafeArray::Clone() const +template +SafeArray *SafeArray::Clone() const { - SafeArray* retval = new SafeArray( m_size ); - memcpy( retval->GetPtr(), m_ptr, sizeof(T) * m_size ); - return retval; + SafeArray *retval = new SafeArray(m_size); + memcpy(retval->GetPtr(), m_ptr, sizeof(T) * m_size); + return retval; } @@ -126,164 +126,158 @@ SafeArray* SafeArray::Clone() const // SafeAlignedArray (implementations) // -------------------------------------------------------------------------------------- -template< typename T, uint Alignment > -T* SafeAlignedArray::_virtual_realloc( int newsize ) +template +T *SafeAlignedArray::_virtual_realloc(int newsize) { - return (T*)( ( this->m_ptr == NULL ) ? - _aligned_malloc( newsize * sizeof(T), Alignment ) : - pcsx2_aligned_realloc( this->m_ptr, newsize * sizeof(T), Alignment, this->m_size * sizeof(T) ) - ); + return (T *)((this->m_ptr == NULL) ? + _aligned_malloc(newsize * sizeof(T), Alignment) : + pcsx2_aligned_realloc(this->m_ptr, newsize * sizeof(T), Alignment, this->m_size * sizeof(T))); } // Appends "(align: xx)" to the name of the allocation in devel builds. // Maybe useful,maybe not... no harm in attaching it. :D -template< typename T, uint Alignment > -SafeAlignedArray::~SafeAlignedArray() throw() +template +SafeAlignedArray::~SafeAlignedArray() throw() { - safe_aligned_free( this->m_ptr ); - // mptr is set to null, so the parent class's destructor won't re-free it. + safe_aligned_free(this->m_ptr); + // mptr is set to null, so the parent class's destructor won't re-free it. } -template< typename T, uint Alignment > -SafeAlignedArray::SafeAlignedArray( int initialSize, const wxChar* name ) : - SafeArray::SafeArray( - name, - (T*)_aligned_malloc( initialSize * sizeof(T), Alignment ), - initialSize - ) +template +SafeAlignedArray::SafeAlignedArray(int initialSize, const wxChar *name) + : SafeArray::SafeArray( + name, + (T *)_aligned_malloc(initialSize * sizeof(T), Alignment), + initialSize) { } -template< typename T, uint Alignment > -SafeAlignedArray* SafeAlignedArray::Clone() const +template +SafeAlignedArray *SafeAlignedArray::Clone() const { - SafeAlignedArray* retval = new SafeAlignedArray( this->m_size ); - memcpy( retval->GetPtr(), this->m_ptr, sizeof(T) * this->m_size ); - return retval; + SafeAlignedArray *retval = new SafeAlignedArray(this->m_size); + memcpy(retval->GetPtr(), this->m_ptr, sizeof(T) * this->m_size); + return retval; } // -------------------------------------------------------------------------------------- // SafeList (implementations) // -------------------------------------------------------------------------------------- -template< typename T > -T* SafeList::_virtual_realloc( int newsize ) +template +T *SafeList::_virtual_realloc(int newsize) { - return (T*)realloc( m_ptr, newsize * sizeof(T) ); + return (T *)realloc(m_ptr, newsize * sizeof(T)); } -template< typename T > +template SafeList::~SafeList() throw() { - safe_free( m_ptr ); + safe_free(m_ptr); } -template< typename T > -SafeList::SafeList( const wxChar* name ) - : Name( name ) +template +SafeList::SafeList(const wxChar *name) + : Name(name) { - ChunkSize = DefaultChunkSize; - m_ptr = NULL; - m_allocsize = 0; - m_length = 0; + ChunkSize = DefaultChunkSize; + m_ptr = NULL; + m_allocsize = 0; + m_length = 0; } -template< typename T > -SafeList::SafeList( int initialSize, const wxChar* name ) - : Name( name ) +template +SafeList::SafeList(int initialSize, const wxChar *name) + : Name(name) { - ChunkSize = DefaultChunkSize; - m_allocsize = initialSize; - m_length = 0; - m_ptr = (T*)malloc( initialSize * sizeof(T) ); + ChunkSize = DefaultChunkSize; + m_allocsize = initialSize; + m_length = 0; + m_ptr = (T *)malloc(initialSize * sizeof(T)); - if( m_ptr == NULL ) - throw Exception::OutOfMemory(Name) - .SetDiagMsg(wxsFormat(L"called from 'SafeList::ctor' [length=%d]", m_length)); - - for( int i=0; i -T* SafeList::_getPtr( uint i ) const +template +T *SafeList::_getPtr(uint i) const { - IndexBoundsAssumeDev( WX_STR(Name), i, m_length ); - return &m_ptr[i]; + IndexBoundsAssumeDev(WX_STR(Name), i, m_length); + return &m_ptr[i]; } // Ensures that the allocation is large enough to fit data of the // amount requested. The memory allocation is not resized smaller. -template< typename T > -void SafeList::MakeRoomFor( int blockSize ) +template +void SafeList::MakeRoomFor(int blockSize) { - if( blockSize > m_allocsize ) - { - const int newalloc = blockSize + ChunkSize; - m_ptr = _virtual_realloc( newalloc ); - if( m_ptr == NULL ) - throw Exception::OutOfMemory(Name) - .SetDiagMsg(wxsFormat(L"Called from 'SafeList::MakeRoomFor' [oldlen=%d] [newlen=%d]", m_length, blockSize)); + if (blockSize > m_allocsize) { + const int newalloc = blockSize + ChunkSize; + m_ptr = _virtual_realloc(newalloc); + if (m_ptr == NULL) + throw Exception::OutOfMemory(Name) + .SetDiagMsg(wxsFormat(L"Called from 'SafeList::MakeRoomFor' [oldlen=%d] [newlen=%d]", m_length, blockSize)); - for( ; m_allocsize -T& SafeList::New() +template +T &SafeList::New() { - _MakeRoomFor_threshold( m_length + 1 ); - return m_ptr[m_length++]; + _MakeRoomFor_threshold(m_length + 1); + return m_ptr[m_length++]; } -template< typename T > -int SafeList::Add( const T& src ) +template +int SafeList::Add(const T &src) { - _MakeRoomFor_threshold( m_length + 1 ); - m_ptr[m_length] = src; - return m_length++; + _MakeRoomFor_threshold(m_length + 1); + m_ptr[m_length] = src; + return m_length++; } // Same as Add, but returns the handle of the new object instead of it's array index. -template< typename T > -T& SafeList::AddNew( const T& src ) +template +T &SafeList::AddNew(const T &src) { - _MakeRoomFor_threshold( m_length + 1 ); - m_ptr[m_length] = src; - return m_ptr[m_length]; + _MakeRoomFor_threshold(m_length + 1); + m_ptr[m_length] = src; + return m_ptr[m_length]; } // Performs a standard array-copy removal of the given item. All items past the // given item are copied over. // DevBuilds : Generates assertion if the index is invalid. -template< typename T > -void SafeList::Remove( int index ) +template +void SafeList::Remove(int index) { - IndexBoundsAssumeDev( Name.c_str(), index, m_length ); + IndexBoundsAssumeDev(Name.c_str(), index, m_length); - int copylen = m_length - index; - if( copylen > 0 ) - memcpy( &m_ptr[index], &m_ptr[index+1], copylen ); + int copylen = m_length - index; + if (copylen > 0) + memcpy(&m_ptr[index], &m_ptr[index + 1], copylen); } -template< typename T > -SafeList* SafeList::Clone() const +template +SafeList *SafeList::Clone() const { - SafeList* retval = new SafeList( m_length ); - memcpy( retval->m_ptr, m_ptr, sizeof(T) * m_length ); - return retval; + SafeList *retval = new SafeList(m_length); + memcpy(retval->m_ptr, m_ptr, sizeof(T) * m_length); + return retval; } -template< typename T > -void SafeList::_MakeRoomFor_threshold( int newsize ) +template +void SafeList::_MakeRoomFor_threshold(int newsize) { - MakeRoomFor( newsize + ChunkSize ); + MakeRoomFor(newsize + ChunkSize); } diff --git a/common/include/Utilities/ScopedAlloc.h b/common/include/Utilities/ScopedAlloc.h index a772caf36d..973882ab5b 100644 --- a/common/include/Utilities/ScopedAlloc.h +++ b/common/include/Utilities/ScopedAlloc.h @@ -27,43 +27,43 @@ // Safe deallocation macros -- checks pointer validity (non-null) when needed, and sets // pointer to null after deallocation. -#define safe_delete( ptr ) \ - ((void) (delete (ptr)), (ptr) = NULL) +#define safe_delete(ptr) \ + ((void)(delete (ptr)), (ptr) = NULL) -#define safe_delete_array( ptr ) \ - ((void) (delete[] (ptr)), (ptr) = NULL) +#define safe_delete_array(ptr) \ + ((void)(delete[](ptr)), (ptr) = NULL) -// No checks for NULL -- wxWidgets says it's safe to skip NULL checks and it runs on +// No checks for NULL -- wxWidgets says it's safe to skip NULL checks and it runs on // just about every compiler and libc implementation of any recentness. -#define safe_free( ptr ) \ - ( (void) (free( ptr ), !!0), (ptr) = NULL ) +#define safe_free(ptr) \ + ((void)(free(ptr), !!0), (ptr) = NULL) //((void) (( ( (ptr) != NULL ) && (free( ptr ), !!0) ), (ptr) = NULL)) -#define safe_fclose( ptr ) \ - ((void) (( ( (ptr) != NULL ) && (fclose( ptr ), !!0) ), (ptr) = NULL)) +#define safe_fclose(ptr) \ + ((void)((((ptr) != NULL) && (fclose(ptr), !!0)), (ptr) = NULL)) // Implementation note: all known implementations of _aligned_free check the pointer for // NULL status (our implementation under GCC, and microsoft's under MSVC), so no need to // do it here. -#define safe_aligned_free( ptr ) \ - ((void) ( _aligned_free( ptr ), (ptr) = NULL )) +#define safe_aligned_free(ptr) \ + ((void)(_aligned_free(ptr), (ptr) = NULL)) // aligned_malloc: Implement/declare linux equivalents here! #if !defined(_MSC_VER) -extern void* __fastcall _aligned_malloc(size_t size, size_t align); -extern void* __fastcall pcsx2_aligned_realloc(void* handle, size_t new_size, size_t align, size_t old_size); -extern void _aligned_free(void* pmem); +extern void *__fastcall _aligned_malloc(size_t size, size_t align); +extern void *__fastcall pcsx2_aligned_realloc(void *handle, size_t new_size, size_t align, size_t old_size); +extern void _aligned_free(void *pmem); #else #define pcsx2_aligned_realloc(handle, new_size, align, old_size) \ - _aligned_realloc(handle, new_size, align) + _aligned_realloc(handle, new_size, align) #endif // -------------------------------------------------------------------------------------- // pxDoOutOfMemory // -------------------------------------------------------------------------------------- -typedef void FnType_OutOfMemory( uptr blocksize ); -typedef FnType_OutOfMemory* Fnptr_OutOfMemory; +typedef void FnType_OutOfMemory(uptr blocksize); +typedef FnType_OutOfMemory *Fnptr_OutOfMemory; // This method is meant to be assigned by applications that link against pxWex. It is called // (invoked) prior to most pxWex built-in memory/array classes throwing exceptions, and can be @@ -89,77 +89,78 @@ extern Fnptr_OutOfMemory pxDoOutOfMemory; // destructing container for malloc. The entire class is almost completely dependency free, // and thus can be included everywhere and anywhere without dependency hassles. // -template< typename T > +template class BaseScopedAlloc { protected: - T* m_buffer; - uint m_size; + T *m_buffer; + uint m_size; public: - BaseScopedAlloc() - { - m_buffer = NULL; - m_size = 0; - } + BaseScopedAlloc() + { + m_buffer = NULL; + m_size = 0; + } - virtual ~BaseScopedAlloc() throw() - { - //pxAssert(m_buffer==NULL); - } + virtual ~BaseScopedAlloc() throw() + { + //pxAssert(m_buffer==NULL); + } public: - size_t GetSize() const { return m_size; } - size_t GetLength() const { return m_size; } - - // Allocates the object to the specified size. If an existing allocation is in - // place, it is freed and replaced with the new allocation, and all data is lost. - // Parameter: - // newSize - size of the new allocation, in elements (not bytes!). If the specified - // size is 0, the the allocation is freed, same as calling Free(). - virtual void Alloc( size_t newsize )=0; + size_t GetSize() const { return m_size; } + size_t GetLength() const { return m_size; } - // Re-sizes the allocation to the requested size, without any data loss. - // Parameter: - // newSize - size of the new allocation, in elements (not bytes!). If the specified - // size is 0, the the allocation is freed, same as calling Free(). - virtual void Resize( size_t newsize )=0; + // Allocates the object to the specified size. If an existing allocation is in + // place, it is freed and replaced with the new allocation, and all data is lost. + // Parameter: + // newSize - size of the new allocation, in elements (not bytes!). If the specified + // size is 0, the the allocation is freed, same as calling Free(). + virtual void Alloc(size_t newsize) = 0; - void Free() - { - Alloc( 0 ); - } - - // Makes enough room for the requested size. Existing data in the array is retained. - void MakeRoomFor( uint size ) - { - if (size <= m_size) return; - Resize( size ); - } + // Re-sizes the allocation to the requested size, without any data loss. + // Parameter: + // newSize - size of the new allocation, in elements (not bytes!). If the specified + // size is 0, the the allocation is freed, same as calling Free(). + virtual void Resize(size_t newsize) = 0; - T* GetPtr( uint idx=0 ) const - { - #if pxUSE_SECURE_MALLOC - IndexBoundsAssumeDev( "ScopedAlloc", idx, m_size ); - #endif - return &m_buffer[idx]; - } + void Free() + { + Alloc(0); + } - T& operator[]( uint idx ) - { - #if pxUSE_SECURE_MALLOC - IndexBoundsAssumeDev( "ScopedAlloc", idx, m_size ); - #endif - return m_buffer[idx]; - } + // Makes enough room for the requested size. Existing data in the array is retained. + void MakeRoomFor(uint size) + { + if (size <= m_size) + return; + Resize(size); + } - const T& operator[]( uint idx ) const - { - #if pxUSE_SECURE_MALLOC - IndexBoundsAssumeDev( "ScopedAlloc", idx, m_size ); - #endif - return m_buffer[idx]; - } + T *GetPtr(uint idx = 0) const + { +#if pxUSE_SECURE_MALLOC + IndexBoundsAssumeDev("ScopedAlloc", idx, m_size); +#endif + return &m_buffer[idx]; + } + + T &operator[](uint idx) + { +#if pxUSE_SECURE_MALLOC + IndexBoundsAssumeDev("ScopedAlloc", idx, m_size); +#endif + return m_buffer[idx]; + } + + const T &operator[](uint idx) const + { +#if pxUSE_SECURE_MALLOC + IndexBoundsAssumeDev("ScopedAlloc", idx, m_size); +#endif + return m_buffer[idx]; + } }; // -------------------------------------------------------------------------------------- @@ -171,43 +172,45 @@ public: // // See docs for BaseScopedAlloc for details and rationale. // -template< typename T > +template class ScopedAlloc : public BaseScopedAlloc { - typedef BaseScopedAlloc _parent; + typedef BaseScopedAlloc _parent; public: - ScopedAlloc( size_t size=0 ) : _parent() - { - Alloc(size); - } + ScopedAlloc(size_t size = 0) + : _parent() + { + Alloc(size); + } - virtual ~ScopedAlloc() throw() - { - safe_free(this->m_buffer); - } + virtual ~ScopedAlloc() throw() + { + safe_free(this->m_buffer); + } - virtual void Alloc( size_t newsize ) - { - safe_free(this->m_buffer); - this->m_size = newsize; - if (!this->m_size) return; + virtual void Alloc(size_t newsize) + { + safe_free(this->m_buffer); + this->m_size = newsize; + if (!this->m_size) + return; - this->m_buffer = (T*)malloc( this->m_size * sizeof(T) ); - if (!this->m_buffer) - throw Exception::OutOfMemory(L"ScopedAlloc"); - } + this->m_buffer = (T *)malloc(this->m_size * sizeof(T)); + if (!this->m_buffer) + throw Exception::OutOfMemory(L"ScopedAlloc"); + } - virtual void Resize( size_t newsize ) - { - this->m_size = newsize; - this->m_buffer = (T*)realloc(this->m_buffer, this->m_size * sizeof(T)); + virtual void Resize(size_t newsize) + { + this->m_size = newsize; + this->m_buffer = (T *)realloc(this->m_buffer, this->m_size * sizeof(T)); - if (!this->m_buffer) - throw Exception::OutOfMemory(L"ScopedAlloc::Resize"); - } - - using _parent::operator[]; + if (!this->m_buffer) + throw Exception::OutOfMemory(L"ScopedAlloc::Resize"); + } + + using _parent::operator[]; }; // -------------------------------------------------------------------------------------- @@ -219,41 +222,43 @@ public: // // See docs for BaseScopedAlloc for details and rationale. // -template< typename T, uint align > +template class ScopedAlignedAlloc : public BaseScopedAlloc { - typedef BaseScopedAlloc _parent; + typedef BaseScopedAlloc _parent; public: - ScopedAlignedAlloc( size_t size=0 ) : _parent() - { - Alloc(size); - } - - virtual ~ScopedAlignedAlloc() throw() - { - safe_aligned_free(this->m_buffer); - } + ScopedAlignedAlloc(size_t size = 0) + : _parent() + { + Alloc(size); + } - virtual void Alloc( size_t newsize ) - { - safe_aligned_free(this->m_buffer); - this->m_size = newsize; - if (!this->m_size) return; + virtual ~ScopedAlignedAlloc() throw() + { + safe_aligned_free(this->m_buffer); + } - this->m_buffer = (T*)_aligned_malloc( this->m_size * sizeof(T), align ); - if (!this->m_buffer) - throw Exception::OutOfMemory(L"ScopedAlignedAlloc"); - } + virtual void Alloc(size_t newsize) + { + safe_aligned_free(this->m_buffer); + this->m_size = newsize; + if (!this->m_size) + return; - virtual void Resize( size_t newsize ) - { - this->m_buffer = (T*)pcsx2_aligned_realloc(this->m_buffer, newsize * sizeof(T), align, this->m_size * sizeof(T)); - this->m_size = newsize; + this->m_buffer = (T *)_aligned_malloc(this->m_size * sizeof(T), align); + if (!this->m_buffer) + throw Exception::OutOfMemory(L"ScopedAlignedAlloc"); + } - if (!this->m_buffer) - throw Exception::OutOfMemory(L"ScopedAlignedAlloc::Resize"); - } - - using _parent::operator[]; + virtual void Resize(size_t newsize) + { + this->m_buffer = (T *)pcsx2_aligned_realloc(this->m_buffer, newsize * sizeof(T), align, this->m_size * sizeof(T)); + this->m_size = newsize; + + if (!this->m_buffer) + throw Exception::OutOfMemory(L"ScopedAlignedAlloc::Resize"); + } + + using _parent::operator[]; }; diff --git a/common/include/Utilities/ScopedPtrMT.h b/common/include/Utilities/ScopedPtrMT.h index 9c5c0dc1db..376648bceb 100644 --- a/common/include/Utilities/ScopedPtrMT.h +++ b/common/include/Utilities/ScopedPtrMT.h @@ -22,95 +22,96 @@ using Threading::ScopedLock; // ScopedPtrMT // -------------------------------------------------------------------------------------- -template< typename T > +template class ScopedPtrMT { - DeclareNoncopyableObject(ScopedPtrMT); + DeclareNoncopyableObject(ScopedPtrMT); protected: - std::atomic m_ptr; - Threading::Mutex m_mtx; + std::atomic m_ptr; + Threading::Mutex m_mtx; public: - typedef T element_type; + typedef T element_type; - wxEXPLICIT ScopedPtrMT(T * ptr = nullptr) - { - m_ptr = ptr; - } + wxEXPLICIT ScopedPtrMT(T *ptr = nullptr) + { + m_ptr = ptr; + } - ~ScopedPtrMT() throw() { _Delete_unlocked(); } + ~ScopedPtrMT() throw() { _Delete_unlocked(); } - ScopedPtrMT& Reassign(T * ptr = nullptr) - { - T* doh = m_ptr.exchange(ptr); - if ( ptr != doh ) delete doh; - return *this; - } + ScopedPtrMT &Reassign(T *ptr = nullptr) + { + T *doh = m_ptr.exchange(ptr); + if (ptr != doh) + delete doh; + return *this; + } - ScopedPtrMT& Delete() throw() - { - ScopedLock lock( m_mtx ); - _Delete_unlocked(); - } + ScopedPtrMT &Delete() throw() + { + ScopedLock lock(m_mtx); + _Delete_unlocked(); + } - // Removes the pointer from scoped management, but does not delete! - // (ScopedPtr will be nullptr after this method) - T *DetachPtr() - { - ScopedLock lock( m_mtx ); + // Removes the pointer from scoped management, but does not delete! + // (ScopedPtr will be nullptr after this method) + T *DetachPtr() + { + ScopedLock lock(m_mtx); - return m_ptr.exchange(nullptr); - } + return m_ptr.exchange(nullptr); + } - // Returns the managed pointer. Can return nullptr as a valid result if the ScopedPtrMT - // has no object in management. - T* GetPtr() const - { - return m_ptr; - } + // Returns the managed pointer. Can return nullptr as a valid result if the ScopedPtrMT + // has no object in management. + T *GetPtr() const + { + return m_ptr; + } - void SwapPtr(ScopedPtrMT& other) - { - ScopedLock lock( m_mtx ); - m_ptr.exchange(other.m_ptr.exchange(m_ptr.load())); - T * const tmp = other.m_ptr; - other.m_ptr = m_ptr; - m_ptr = tmp; - } + void SwapPtr(ScopedPtrMT &other) + { + ScopedLock lock(m_mtx); + m_ptr.exchange(other.m_ptr.exchange(m_ptr.load())); + T *const tmp = other.m_ptr; + other.m_ptr = m_ptr; + m_ptr = tmp; + } - // ---------------------------------------------------------------------------- - // ScopedPtrMT Operators - // ---------------------------------------------------------------------------- - // I've decided to use the ATL's approach to pointer validity tests, opposed to - // the wx/boost approach (which uses some bizarre member method pointer crap, and can't - // allow the T* implicit casting. + // ---------------------------------------------------------------------------- + // ScopedPtrMT Operators + // ---------------------------------------------------------------------------- + // I've decided to use the ATL's approach to pointer validity tests, opposed to + // the wx/boost approach (which uses some bizarre member method pointer crap, and can't + // allow the T* implicit casting. - bool operator!() const throw() - { - return m_ptr.load() == nullptr; - } + bool operator!() const throw() + { + return m_ptr.load() == nullptr; + } - // Equality - bool operator==(T* pT) const throw() - { - return m_ptr == pT; - } + // Equality + bool operator==(T *pT) const throw() + { + return m_ptr == pT; + } - // Inequality - bool operator!=(T* pT) const throw() - { - return !operator==(pT); - } + // Inequality + bool operator!=(T *pT) const throw() + { + return !operator==(pT); + } - // Convenient assignment operator. ScopedPtrMT = nullptr will issue an automatic deletion - // of the managed pointer. - ScopedPtrMT& operator=( T* src ) - { - return Reassign( src ); - } + // Convenient assignment operator. ScopedPtrMT = nullptr will issue an automatic deletion + // of the managed pointer. + ScopedPtrMT &operator=(T *src) + { + return Reassign(src); + } - #if 0 +#if 0 operator T*() const { return m_ptr; @@ -129,11 +130,11 @@ public: pxAssert(m_ptr != nullptr); return m_ptr; } - #endif +#endif protected: - void _Delete_unlocked() throw() - { - delete m_ptr.exchange(nullptr); - } + void _Delete_unlocked() throw() + { + delete m_ptr.exchange(nullptr); + } }; diff --git a/common/include/Utilities/StringHelpers.h b/common/include/Utilities/StringHelpers.h index 8f3899cf67..209b9e269e 100644 --- a/common/include/Utilities/StringHelpers.h +++ b/common/include/Utilities/StringHelpers.h @@ -22,10 +22,10 @@ #include #if _WIN32 - #define WX_STR(str) (str.wc_str()) +#define WX_STR(str) (str.wc_str()) #else // Stupid wx3.0 doesn't support c_str for vararg function - #define WX_STR(str) (static_cast(str.c_str())) +#define WX_STR(str) (static_cast(str.c_str())) #endif // -------------------------------------------------------------------------------------- @@ -34,59 +34,59 @@ // Converts a string to UTF8 and provides an interface for getting its length. class pxToUTF8 { - DeclareNoncopyableObject( pxToUTF8 ); + DeclareNoncopyableObject(pxToUTF8); protected: - wxCharBuffer m_result; - int m_length; + wxCharBuffer m_result; + int m_length; public: - explicit pxToUTF8(const wxString& src) - : m_result( src.ToUTF8() ) - { - m_length = -1; - } + explicit pxToUTF8(const wxString &src) + : m_result(src.ToUTF8()) + { + m_length = -1; + } - size_t Length() - { - if( -1 == m_length ) - m_length = strlen( m_result ); - return m_length; - } + size_t Length() + { + if (-1 == m_length) + m_length = strlen(m_result); + return m_length; + } - void Convert( const wxString& src ) - { - m_result = src.ToUTF8(); - m_length = -1; - } - - const char* data() const { return m_result; } - - operator const char*() const - { - return m_result.data(); - } + void Convert(const wxString &src) + { + m_result = src.ToUTF8(); + m_length = -1; + } + + const char *data() const { return m_result; } + + operator const char *() const + { + return m_result.data(); + } }; -extern void px_fputs( FILE* fp, const char* src ); +extern void px_fputs(FILE *fp, const char *src); // wxWidgets lacks one of its own... extern const wxRect wxDefaultRect; -extern void SplitString( wxArrayString& dest, const wxString& src, const wxString& delims, wxStringTokenizerMode mode = wxTOKEN_RET_EMPTY_ALL ); -extern wxString JoinString( const wxArrayString& src, const wxString& separator ); -extern wxString JoinString( const wxChar** src, const wxString& separator ); +extern void SplitString(wxArrayString &dest, const wxString &src, const wxString &delims, wxStringTokenizerMode mode = wxTOKEN_RET_EMPTY_ALL); +extern wxString JoinString(const wxArrayString &src, const wxString &separator); +extern wxString JoinString(const wxChar **src, const wxString &separator); -extern wxString ToString( const wxPoint& src, const wxString& separator=L"," ); -extern wxString ToString( const wxSize& src, const wxString& separator=L"," ); -extern wxString ToString( const wxRect& src, const wxString& separator=L"," ); +extern wxString ToString(const wxPoint &src, const wxString &separator = L","); +extern wxString ToString(const wxSize &src, const wxString &separator = L","); +extern wxString ToString(const wxRect &src, const wxString &separator = L","); -extern bool TryParse( wxPoint& dest, const wxStringTokenizer& parts ); -extern bool TryParse( wxSize& dest, const wxStringTokenizer& parts ); +extern bool TryParse(wxPoint &dest, const wxStringTokenizer &parts); +extern bool TryParse(wxSize &dest, const wxStringTokenizer &parts); -extern bool TryParse( wxPoint& dest, const wxString& src, const wxPoint& defval=wxDefaultPosition, const wxString& separators=L","); -extern bool TryParse( wxSize& dest, const wxString& src, const wxSize& defval=wxDefaultSize, const wxString& separators=L","); -extern bool TryParse( wxRect& dest, const wxString& src, const wxRect& defval=wxDefaultRect, const wxString& separators=L","); +extern bool TryParse(wxPoint &dest, const wxString &src, const wxPoint &defval = wxDefaultPosition, const wxString &separators = L","); +extern bool TryParse(wxSize &dest, const wxString &src, const wxSize &defval = wxDefaultSize, const wxString &separators = L","); +extern bool TryParse(wxRect &dest, const wxString &src, const wxRect &defval = wxDefaultRect, const wxString &separators = L","); // -------------------------------------------------------------------------------------- // ParsedAssignmentString @@ -104,11 +104,11 @@ extern bool TryParse( wxRect& dest, const wxString& src, const wxRect& defval=wx // struct ParsedAssignmentString { - wxString lvalue; - wxString rvalue; - bool IsComment; + wxString lvalue; + wxString rvalue; + bool IsComment; - ParsedAssignmentString( const wxString& src ); + ParsedAssignmentString(const wxString &src); }; // ====================================================================================== @@ -134,46 +134,46 @@ struct ParsedAssignmentString typedef ScopedAlignedAlloc CharBufferType; // -------------------------------------------------------------------------------------- -// FastFormatAscii +// FastFormatAscii // -------------------------------------------------------------------------------------- class FastFormatAscii { protected: - CharBufferType m_dest; + CharBufferType m_dest; public: - FastFormatAscii(); - ~FastFormatAscii() throw(); - FastFormatAscii& Write( const char* fmt, ... ); - FastFormatAscii& WriteV( const char* fmt, va_list argptr ); + FastFormatAscii(); + ~FastFormatAscii() throw(); + FastFormatAscii &Write(const char *fmt, ...); + FastFormatAscii &WriteV(const char *fmt, va_list argptr); - void Clear(); - bool IsEmpty() const; + void Clear(); + bool IsEmpty() const; - const char* c_str() const { return m_dest.GetPtr(); } - operator const char*() const { return m_dest.GetPtr(); } + const char *c_str() const { return m_dest.GetPtr(); } + operator const char *() const { return m_dest.GetPtr(); } - const wxString GetString() const; - //operator wxString() const; + const wxString GetString() const; + //operator wxString() const; - FastFormatAscii& operator+=(const wxString& s) - { - Write( "%s", WX_STR(s) ); - return *this; - } + FastFormatAscii &operator+=(const wxString &s) + { + Write("%s", WX_STR(s)); + return *this; + } - FastFormatAscii& operator+=(const wxChar* psz ) - { - Write( "%ls", psz ); - return *this; - } + FastFormatAscii &operator+=(const wxChar *psz) + { + Write("%ls", psz); + return *this; + } - FastFormatAscii& operator+=(const char* psz ) - { - Write( "%s", psz ); - return *this; - } + FastFormatAscii &operator+=(const char *psz) + { + Write("%s", psz); + return *this; + } }; // -------------------------------------------------------------------------------------- @@ -182,57 +182,57 @@ public: class FastFormatUnicode { protected: - CharBufferType m_dest; - uint m_Length; + CharBufferType m_dest; + uint m_Length; public: - FastFormatUnicode(); - ~FastFormatUnicode() throw(); + FastFormatUnicode(); + ~FastFormatUnicode() throw(); - FastFormatUnicode& Write( const char* fmt, ... ); - FastFormatUnicode& Write( const wxChar* fmt, ... ); - FastFormatUnicode& Write( const wxString fmt, ... ); - FastFormatUnicode& WriteV( const char* fmt, va_list argptr ); - FastFormatUnicode& WriteV( const wxChar* fmt, va_list argptr ); + FastFormatUnicode &Write(const char *fmt, ...); + FastFormatUnicode &Write(const wxChar *fmt, ...); + FastFormatUnicode &Write(const wxString fmt, ...); + FastFormatUnicode &WriteV(const char *fmt, va_list argptr); + FastFormatUnicode &WriteV(const wxChar *fmt, va_list argptr); - void Clear(); - bool IsEmpty() const; - uint Length() const { return m_Length; } + void Clear(); + bool IsEmpty() const; + uint Length() const { return m_Length; } - FastFormatUnicode& ToUpper(); - FastFormatUnicode& ToLower(); + FastFormatUnicode &ToUpper(); + FastFormatUnicode &ToLower(); - const wxChar* c_str() const { return (const wxChar*)m_dest.GetPtr(); } - operator const wxChar*() const { return (const wxChar*)m_dest.GetPtr(); } - operator wxString() const { return (const wxChar*)m_dest.GetPtr(); } + const wxChar *c_str() const { return (const wxChar *)m_dest.GetPtr(); } + operator const wxChar *() const { return (const wxChar *)m_dest.GetPtr(); } + operator wxString() const { return (const wxChar *)m_dest.GetPtr(); } - FastFormatUnicode& operator+=(const wxString& s) - { - Write( L"%s", WX_STR(s) ); - return *this; - } + FastFormatUnicode &operator+=(const wxString &s) + { + Write(L"%s", WX_STR(s)); + return *this; + } - FastFormatUnicode& operator+=(const wxChar* psz ) - { - Write( L"%s", psz ); - return *this; - } + FastFormatUnicode &operator+=(const wxChar *psz) + { + Write(L"%s", psz); + return *this; + } - FastFormatUnicode& operator+=(const char* psz ); + FastFormatUnicode &operator+=(const char *psz); }; -extern bool pxParseAssignmentString( const wxString& src, wxString& ldest, wxString& rdest ); +extern bool pxParseAssignmentString(const wxString &src, wxString &ldest, wxString &rdest); -#define pxsFmt FastFormatUnicode().Write -#define pxsFmtV FastFormatUnicode().WriteV +#define pxsFmt FastFormatUnicode().Write +#define pxsFmtV FastFormatUnicode().WriteV -#define pxsPtr(ptr) pxsFmt("0x%08X", (ptr)).c_str() +#define pxsPtr(ptr) pxsFmt("0x%08X", (ptr)).c_str() -extern wxString& operator+=(wxString& str1, const FastFormatUnicode& str2); -extern wxString operator+(const wxString& str1, const FastFormatUnicode& str2); -extern wxString operator+(const wxChar* str1, const FastFormatUnicode& str2); -extern wxString operator+(const FastFormatUnicode& str1, const wxString& str2); -extern wxString operator+(const FastFormatUnicode& str1, const wxChar* str2); +extern wxString &operator+=(wxString &str1, const FastFormatUnicode &str2); +extern wxString operator+(const wxString &str1, const FastFormatUnicode &str2); +extern wxString operator+(const wxChar *str1, const FastFormatUnicode &str2); +extern wxString operator+(const FastFormatUnicode &str1, const wxString &str2); +extern wxString operator+(const FastFormatUnicode &str1, const wxChar *str2); ////////////////////////////////////////////////////////////////////////////////////////// @@ -241,4 +241,4 @@ extern wxString operator+(const FastFormatUnicode& str1, const wxChar* str2); // These functions are useful since they are ASCII always, even under Unicode. Typically // even in a unicode app. -extern void ssappendf(std::string& dest, const char* format, ...); +extern void ssappendf(std::string &dest, const char *format, ...); diff --git a/common/include/Utilities/Threading.h b/common/include/Utilities/Threading.h index 69d119d543..eb9e442c9f 100644 --- a/common/include/Utilities/Threading.h +++ b/common/include/Utilities/Threading.h @@ -26,10 +26,10 @@ #include "Pcsx2Defs.h" #include "TraceLog.h" -#undef Yield // release the burden of windows.h global namespace spam. +#undef Yield // release the burden of windows.h global namespace spam. #define AffinityAssert_AllowFrom_MainUI() \ - pxAssertMsg( wxThread::IsMain(), "Thread affinity violation: Call allowed from main thread only." ) + pxAssertMsg(wxThread::IsMain(), "Thread affinity violation: Call allowed from main thread only.") // -------------------------------------------------------------------------------------- // pxThreadLog / ConsoleLogSource_Threading @@ -37,22 +37,25 @@ class ConsoleLogSource_Threading : ConsoleLogSource { - typedef ConsoleLogSource _parent; + typedef ConsoleLogSource _parent; public: - using _parent::IsActive; + using _parent::IsActive; - ConsoleLogSource_Threading(); + ConsoleLogSource_Threading(); - bool Write( const wxString& thrname, const wxChar* msg ) { - return _parent::Write( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg ); - } - bool Warn( const wxString& thrname, const wxChar* msg ) { - return _parent::Warn( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg ); - } - bool Error( const wxString& thrname, const wxChar* msg ) { - return _parent::Error( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg ); - } + bool Write(const wxString &thrname, const wxChar *msg) + { + return _parent::Write(wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg); + } + bool Warn(const wxString &thrname, const wxChar *msg) + { + return _parent::Warn(wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg); + } + bool Error(const wxString &thrname, const wxChar *msg) + { + return _parent::Error(wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg); + } }; extern ConsoleLogSource_Threading pxConLog_Thread; @@ -69,79 +72,80 @@ extern ConsoleLogSource_Threading pxConLog_Thread; //#define PCSX2_THREAD_LOCAL 0 // uncomment this line to force-disable native TLS (useful for testing TlsVariable on windows/linux) #ifndef PCSX2_THREAD_LOCAL -# define PCSX2_THREAD_LOCAL 1 +#define PCSX2_THREAD_LOCAL 1 #endif class wxTimeSpan; namespace Threading { - class pxThread; - class RwMutex; +class pxThread; +class RwMutex; - extern void pxTestCancel(); - extern pxThread* pxGetCurrentThread(); - extern wxString pxGetCurrentThreadName(); - extern u64 GetThreadCpuTime(); - extern u64 GetThreadTicksPerSecond(); +extern void pxTestCancel(); +extern pxThread *pxGetCurrentThread(); +extern wxString pxGetCurrentThreadName(); +extern u64 GetThreadCpuTime(); +extern u64 GetThreadTicksPerSecond(); - // Yields the current thread and provides cancellation points if the thread is managed by - // pxThread. Unmanaged threads use standard Sleep. - extern void pxYield( int ms ); +// Yields the current thread and provides cancellation points if the thread is managed by +// pxThread. Unmanaged threads use standard Sleep. +extern void pxYield(int ms); } namespace Exception { - class BaseThreadError : public RuntimeError - { - DEFINE_EXCEPTION_COPYTORS( BaseThreadError, RuntimeError ) - DEFINE_EXCEPTION_MESSAGES( BaseThreadError ) +class BaseThreadError : public RuntimeError +{ + DEFINE_EXCEPTION_COPYTORS(BaseThreadError, RuntimeError) + DEFINE_EXCEPTION_MESSAGES(BaseThreadError) - public: - Threading::pxThread* m_thread; +public: + Threading::pxThread *m_thread; - protected: - BaseThreadError() { - m_thread = NULL; - } +protected: + BaseThreadError() + { + m_thread = NULL; + } - public: - explicit BaseThreadError( Threading::pxThread* _thread ) - { - m_thread = _thread; - m_message_diag = L"An unspecified thread-related error occurred (thread=%s)"; - } +public: + explicit BaseThreadError(Threading::pxThread *_thread) + { + m_thread = _thread; + m_message_diag = L"An unspecified thread-related error occurred (thread=%s)"; + } - explicit BaseThreadError( Threading::pxThread& _thread ) - { - m_thread = &_thread; - m_message_diag = L"An unspecified thread-related error occurred (thread=%s)"; - } + explicit BaseThreadError(Threading::pxThread &_thread) + { + m_thread = &_thread; + m_message_diag = L"An unspecified thread-related error occurred (thread=%s)"; + } - virtual wxString FormatDiagnosticMessage() const; - virtual wxString FormatDisplayMessage() const; + virtual wxString FormatDiagnosticMessage() const; + virtual wxString FormatDisplayMessage() const; - Threading::pxThread& Thread(); - const Threading::pxThread& Thread() const; - }; + Threading::pxThread &Thread(); + const Threading::pxThread &Thread() const; +}; - class ThreadCreationError : public BaseThreadError - { - DEFINE_EXCEPTION_COPYTORS( ThreadCreationError, BaseThreadError ) +class ThreadCreationError : public BaseThreadError +{ + DEFINE_EXCEPTION_COPYTORS(ThreadCreationError, BaseThreadError) - public: - explicit ThreadCreationError( Threading::pxThread* _thread ) - { - m_thread = _thread; - SetBothMsgs( L"Thread creation failure. An unspecified error occurred while trying to create the %s thread." ); - } +public: + explicit ThreadCreationError(Threading::pxThread *_thread) + { + m_thread = _thread; + SetBothMsgs(L"Thread creation failure. An unspecified error occurred while trying to create the %s thread."); + } - explicit ThreadCreationError( Threading::pxThread& _thread ) - { - m_thread = &_thread; - SetBothMsgs( L"Thread creation failure. An unspecified error occurred while trying to create the %s thread." ); - } - }; + explicit ThreadCreationError(Threading::pxThread &_thread) + { + m_thread = &_thread; + SetBothMsgs(L"Thread creation failure. An unspecified error occurred while trying to create the %s thread."); + } +}; } @@ -153,22 +157,22 @@ namespace Threading // The following set of documented functions have Linux/Win32 specific implementations, // which are found in WinThreads.cpp and LnxThreads.cpp - // Releases a timeslice to other threads. - extern void Timeslice(); +// Releases a timeslice to other threads. +extern void Timeslice(); - // For use in spin/wait loops. - extern void SpinWait(); +// For use in spin/wait loops. +extern void SpinWait(); - // Optional implementation to enable hires thread/process scheduler for the operating system. - // Needed by Windows, but might not be relevant to other platforms. - extern void EnableHiresScheduler(); - extern void DisableHiresScheduler(); +// Optional implementation to enable hires thread/process scheduler for the operating system. +// Needed by Windows, but might not be relevant to other platforms. +extern void EnableHiresScheduler(); +extern void DisableHiresScheduler(); - // sleeps the current thread for the given number of milliseconds. - extern void Sleep( int ms ); +// sleeps the current thread for the given number of milliseconds. +extern void Sleep(int ms); - // pthread Cond is an evil api that is not suited for Pcsx2 needs. - // Let's not use it. Use mutexes and semaphores instead to create waits. (Air) +// pthread Cond is an evil api that is not suited for Pcsx2 needs. +// Let's not use it. Use mutexes and semaphores instead to create waits. (Air) #if 0 struct WaitEvent { @@ -194,181 +198,187 @@ namespace Threading // If TryAcquire() returns true, you've locked the object and are *responsible* for unlocking // it later. // - class NonblockingMutex - { - protected: - std::atomic_flag val; +class NonblockingMutex +{ +protected: + std::atomic_flag val; - public: - NonblockingMutex() { val.clear(); } - virtual ~NonblockingMutex() throw() {} +public: + NonblockingMutex() { val.clear(); } + virtual ~NonblockingMutex() throw() {} - bool TryAcquire() throw() - { - return !val.test_and_set(); - } + bool TryAcquire() throw() + { + return !val.test_and_set(); + } - // Can be done with a TryAcquire/Release but it is likely better to do it outside of the object - bool IsLocked() - { pxAssertMsg(0, "IsLocked isn't supported for NonblockingMutex"); return false; } + // Can be done with a TryAcquire/Release but it is likely better to do it outside of the object + bool IsLocked() + { + pxAssertMsg(0, "IsLocked isn't supported for NonblockingMutex"); + return false; + } - void Release() - { - val.clear(); - } - }; + void Release() + { + val.clear(); + } +}; - class Semaphore - { - protected: +class Semaphore +{ +protected: #ifdef __APPLE__ - semaphore_t m_sema; - int m_counter; + semaphore_t m_sema; + int m_counter; #else - sem_t m_sema; + sem_t m_sema; #endif - public: - Semaphore(); - virtual ~Semaphore() throw(); +public: + Semaphore(); + virtual ~Semaphore() throw(); - void Reset(); - void Post(); - void Post( int multiple ); + void Reset(); + void Post(); + void Post(int multiple); - void WaitWithoutYield(); - bool WaitWithoutYield( const wxTimeSpan& timeout ); - void WaitNoCancel(); - void WaitNoCancel( const wxTimeSpan& timeout ); - int Count(); + void WaitWithoutYield(); + bool WaitWithoutYield(const wxTimeSpan &timeout); + void WaitNoCancel(); + void WaitNoCancel(const wxTimeSpan &timeout); + int Count(); - void Wait(); - bool Wait( const wxTimeSpan& timeout ); - }; + void Wait(); + bool Wait(const wxTimeSpan &timeout); +}; - class Mutex - { - protected: - pthread_mutex_t m_mutex; +class Mutex +{ +protected: + pthread_mutex_t m_mutex; - public: - Mutex(); - virtual ~Mutex() throw(); - virtual bool IsRecursive() const { return false; } +public: + Mutex(); + virtual ~Mutex() throw(); + virtual bool IsRecursive() const { return false; } - void Recreate(); - bool RecreateIfLocked(); - void Detach(); + void Recreate(); + bool RecreateIfLocked(); + void Detach(); - void Acquire(); - bool Acquire( const wxTimeSpan& timeout ); - bool TryAcquire(); - void Release(); + void Acquire(); + bool Acquire(const wxTimeSpan &timeout); + bool TryAcquire(); + void Release(); - void AcquireWithoutYield(); - bool AcquireWithoutYield( const wxTimeSpan& timeout ); + void AcquireWithoutYield(); + bool AcquireWithoutYield(const wxTimeSpan &timeout); - void Wait(); - bool Wait( const wxTimeSpan& timeout ); - void WaitWithoutYield(); - bool WaitWithoutYield( const wxTimeSpan& timeout ); + void Wait(); + bool Wait(const wxTimeSpan &timeout); + void WaitWithoutYield(); + bool WaitWithoutYield(const wxTimeSpan &timeout); - protected: - // empty constructor used by MutexLockRecursive - Mutex( bool ) {} - }; +protected: + // empty constructor used by MutexLockRecursive + Mutex(bool) {} +}; - class MutexRecursive : public Mutex - { - public: - MutexRecursive(); - virtual ~MutexRecursive() throw(); - virtual bool IsRecursive() const { return true; } - }; +class MutexRecursive : public Mutex +{ +public: + MutexRecursive(); + virtual ~MutexRecursive() throw(); + virtual bool IsRecursive() const { return true; } +}; - // -------------------------------------------------------------------------------------- - // ScopedLock - // -------------------------------------------------------------------------------------- - // Helper class for using Mutexes. Using this class provides an exception-safe (and - // generally clean) method of locking code inside a function or conditional block. The lock - // will be automatically released on any return or exit from the function. - // - // Const qualification note: - // ScopedLock takes const instances of the mutex, even though the mutex is modified - // by locking and unlocking. Two rationales: - // - // 1) when designing classes with accessors (GetString, GetValue, etc) that need mutexes, - // this class needs a const hack to allow those accessors to be const (which is typically - // *very* important). - // - // 2) The state of the Mutex is guaranteed to be unchanged when the calling function or - // scope exits, by any means. Only via manual calls to Release or Acquire does that - // change, and typically those are only used in very special circumstances of their own. - // - class ScopedLock - { - DeclareNoncopyableObject(ScopedLock); +// -------------------------------------------------------------------------------------- +// ScopedLock +// -------------------------------------------------------------------------------------- +// Helper class for using Mutexes. Using this class provides an exception-safe (and +// generally clean) method of locking code inside a function or conditional block. The lock +// will be automatically released on any return or exit from the function. +// +// Const qualification note: +// ScopedLock takes const instances of the mutex, even though the mutex is modified +// by locking and unlocking. Two rationales: +// +// 1) when designing classes with accessors (GetString, GetValue, etc) that need mutexes, +// this class needs a const hack to allow those accessors to be const (which is typically +// *very* important). +// +// 2) The state of the Mutex is guaranteed to be unchanged when the calling function or +// scope exits, by any means. Only via manual calls to Release or Acquire does that +// change, and typically those are only used in very special circumstances of their own. +// +class ScopedLock +{ + DeclareNoncopyableObject(ScopedLock); - protected: - Mutex* m_lock; - bool m_IsLocked; +protected: + Mutex *m_lock; + bool m_IsLocked; - public: - virtual ~ScopedLock() throw(); - explicit ScopedLock( const Mutex* locker=NULL ); - explicit ScopedLock( const Mutex& locker ); - void AssignAndLock( const Mutex& locker ); - void AssignAndLock( const Mutex* locker ); +public: + virtual ~ScopedLock() throw(); + explicit ScopedLock(const Mutex *locker = NULL); + explicit ScopedLock(const Mutex &locker); + void AssignAndLock(const Mutex &locker); + void AssignAndLock(const Mutex *locker); - void Assign( const Mutex& locker ); - void Assign( const Mutex* locker ); + void Assign(const Mutex &locker); + void Assign(const Mutex *locker); - void Release(); - void Acquire(); + void Release(); + void Acquire(); - bool IsLocked() const { return m_IsLocked; } + bool IsLocked() const { return m_IsLocked; } - protected: - // Special constructor used by ScopedTryLock - ScopedLock( const Mutex& locker, bool isTryLock ); - }; +protected: + // Special constructor used by ScopedTryLock + ScopedLock(const Mutex &locker, bool isTryLock); +}; - class ScopedTryLock : public ScopedLock - { - public: - ScopedTryLock( const Mutex& locker ) : ScopedLock( locker, true ) { } - virtual ~ScopedTryLock() throw() {} - bool Failed() const { return !m_IsLocked; } - }; +class ScopedTryLock : public ScopedLock +{ +public: + ScopedTryLock(const Mutex &locker) + : ScopedLock(locker, true) + { + } + virtual ~ScopedTryLock() throw() {} + bool Failed() const { return !m_IsLocked; } +}; // -------------------------------------------------------------------------------------- // ScopedNonblockingLock // -------------------------------------------------------------------------------------- // A ScopedTryLock branded for use with Nonblocking mutexes. See ScopedTryLock for details. // - class ScopedNonblockingLock - { - DeclareNoncopyableObject(ScopedNonblockingLock); +class ScopedNonblockingLock +{ + DeclareNoncopyableObject(ScopedNonblockingLock); - protected: - NonblockingMutex& m_lock; - bool m_IsLocked; +protected: + NonblockingMutex &m_lock; + bool m_IsLocked; - public: - ScopedNonblockingLock( NonblockingMutex& locker ) : - m_lock( locker ) - , m_IsLocked( m_lock.TryAcquire() ) - { - } +public: + ScopedNonblockingLock(NonblockingMutex &locker) + : m_lock(locker) + , m_IsLocked(m_lock.TryAcquire()) + { + } - virtual ~ScopedNonblockingLock() throw() - { - if( m_IsLocked ) - m_lock.Release(); - } + virtual ~ScopedNonblockingLock() throw() + { + if (m_IsLocked) + m_lock.Release(); + } - bool Failed() const { return !m_IsLocked; } - }; + bool Failed() const { return !m_IsLocked; } +}; // -------------------------------------------------------------------------------------- // ScopedLockBool @@ -377,26 +387,30 @@ namespace Threading // Note that the isLockedBool should only be used as an indicator for the locked status, // and not actually depended on for thread synchronization... - struct ScopedLockBool { - ScopedLock m_lock; - std::atomic& m_bool; +struct ScopedLockBool +{ + ScopedLock m_lock; + std::atomic &m_bool; - ScopedLockBool(Mutex& mutexToLock, std::atomic& isLockedBool) - : m_lock(mutexToLock), - m_bool(isLockedBool) { - m_bool.store(m_lock.IsLocked(), std::memory_order_relaxed); - } - virtual ~ScopedLockBool() throw() { - m_bool.store(false, std::memory_order_relaxed); - } - void Acquire() { - m_lock.Acquire(); - m_bool.store(m_lock.IsLocked(), std::memory_order_relaxed); - } - void Release() { - m_bool.store(false, std::memory_order_relaxed); - m_lock.Release(); - } - }; + ScopedLockBool(Mutex &mutexToLock, std::atomic &isLockedBool) + : m_lock(mutexToLock) + , m_bool(isLockedBool) + { + m_bool.store(m_lock.IsLocked(), std::memory_order_relaxed); + } + virtual ~ScopedLockBool() throw() + { + m_bool.store(false, std::memory_order_relaxed); + } + void Acquire() + { + m_lock.Acquire(); + m_bool.store(m_lock.IsLocked(), std::memory_order_relaxed); + } + void Release() + { + m_bool.store(false, std::memory_order_relaxed); + m_lock.Release(); + } +}; } - diff --git a/common/include/Utilities/ThreadingDialogs.h b/common/include/Utilities/ThreadingDialogs.h index 064cdbbc31..ce59d24829 100644 --- a/common/include/Utilities/ThreadingDialogs.h +++ b/common/include/Utilities/ThreadingDialogs.h @@ -22,32 +22,31 @@ wxDECLARE_EVENT(pxEvt_ThreadedTaskComplete, wxCommandEvent); namespace Threading { - // -------------------------------------------------------------------------------------- - // WaitForTaskDialog - // -------------------------------------------------------------------------------------- - // This dialog is displayed whenever the main thread is recursively waiting on multiple - // mutexes or semaphores. wxwidgets does not support recursive yielding to pending events - // but it *does* support opening a modal dialog, which disables the interface (preventing - // the user from starting additional actions), and processes messages (allowing the system - // to continue to manage threads and process logging). - // - class WaitForTaskDialog : public wxDialogWithHelpers - { - DECLARE_DYNAMIC_CLASS_NO_COPY(WaitForTaskDialog) +// -------------------------------------------------------------------------------------- +// WaitForTaskDialog +// -------------------------------------------------------------------------------------- +// This dialog is displayed whenever the main thread is recursively waiting on multiple +// mutexes or semaphores. wxwidgets does not support recursive yielding to pending events +// but it *does* support opening a modal dialog, which disables the interface (preventing +// the user from starting additional actions), and processes messages (allowing the system +// to continue to manage threads and process logging). +// +class WaitForTaskDialog : public wxDialogWithHelpers +{ + DECLARE_DYNAMIC_CLASS_NO_COPY(WaitForTaskDialog) - typedef wxDialogWithHelpers _parent; + typedef wxDialogWithHelpers _parent; - protected: - SynchronousActionState m_sync; +protected: + SynchronousActionState m_sync; - public: - WaitForTaskDialog( const wxString& title=wxEmptyString, const wxString& heading=wxEmptyString ); - virtual ~WaitForTaskDialog() throw() {} - virtual int ShowModal(); - - protected: - void OnTaskComplete( wxCommandEvent& evt ); - //void OnTimer( wxTimerEvent& evt ); - }; +public: + WaitForTaskDialog(const wxString &title = wxEmptyString, const wxString &heading = wxEmptyString); + virtual ~WaitForTaskDialog() throw() {} + virtual int ShowModal(); +protected: + void OnTaskComplete(wxCommandEvent &evt); + //void OnTimer( wxTimerEvent& evt ); +}; } diff --git a/common/include/Utilities/TlsVariable.inl b/common/include/Utilities/TlsVariable.inl index 8d7d271051..da592b523b 100644 --- a/common/include/Utilities/TlsVariable.inl +++ b/common/include/Utilities/TlsVariable.inl @@ -18,9 +18,9 @@ #include "Threading.h" #if PCSX2_THREAD_LOCAL -# define DeclareTls(x) __threadlocal x +#define DeclareTls(x) __threadlocal x #else -# define DeclareTls(x) Threading::TlsVariable +#define DeclareTls(x) Threading::TlsVariable #endif namespace Threading @@ -38,152 +38,153 @@ namespace Threading // result in repeated calls to pthread_getspecific. (if the function inlines then it // should actually optimize well enough, but I doubt it does). // -template< typename T > +template class BaseTlsVariable { - DeclareNoncopyableObject(BaseTlsVariable); + DeclareNoncopyableObject(BaseTlsVariable); protected: - pthread_key_t m_thread_key; - bool m_IsDisposed; + pthread_key_t m_thread_key; + bool m_IsDisposed; public: - BaseTlsVariable(); + BaseTlsVariable(); - virtual ~BaseTlsVariable() throw() - { - Dispose(); - } + virtual ~BaseTlsVariable() throw() + { + Dispose(); + } - T* GetPtr() const; - T& GetRef() const { return *GetPtr(); } + T *GetPtr() const; + T &GetRef() const { return *GetPtr(); } - operator T&() const { return GetRef(); } - T* operator->() const { return GetPtr(); } + operator T &() const { return GetRef(); } + T *operator->() const { return GetPtr(); } - void Dispose() - { - if (!m_IsDisposed) - { - m_IsDisposed = true; - KillKey(); - } - } + void Dispose() + { + if (!m_IsDisposed) { + m_IsDisposed = true; + KillKey(); + } + } protected: - void CreateKey(); - void KillKey(); + void CreateKey(); + void KillKey(); - virtual void CreateInstance( T* result ) const - { - new (result) T(); - } + virtual void CreateInstance(T *result) const + { + new (result) T(); + } - static void _aligned_delete_and_free( void* ptr ) - { - if (!ptr) return; - ((T*)ptr)->~T(); - _aligned_free(ptr); - } + static void _aligned_delete_and_free(void *ptr) + { + if (!ptr) + return; + ((T *)ptr)->~T(); + _aligned_free(ptr); + } }; -template< typename T > +template class TlsVariable : public BaseTlsVariable { - DeclareNoncopyableObject(TlsVariable); + DeclareNoncopyableObject(TlsVariable); protected: - T m_initval; + T m_initval; public: - TlsVariable() {} - TlsVariable( const T& initval ) - : m_initval(initval) { } + TlsVariable() {} + TlsVariable(const T &initval) + : m_initval(initval) + { + } - // This is needed; The C++ standard likes making life suck for programmers. - using BaseTlsVariable::GetRef; + // This is needed; The C++ standard likes making life suck for programmers. + using BaseTlsVariable::GetRef; - virtual ~TlsVariable() throw() - { - // disable the parent cleanup. This leaks memory blocks, but its necessary because - // TLS is expected to be persistent until the very end of execution on the main thread. - // Killing the pthread_key at all will lead to the console logger death, etc. - - // DON'T REMOVE this->, the "official"[ly stupid] C++ standard requires it because of its - // insistence that variables be looked up during initial template parsing and not during - // instantiation. - this->m_IsDisposed = true; - } + virtual ~TlsVariable() throw() + { + // disable the parent cleanup. This leaks memory blocks, but its necessary because + // TLS is expected to be persistent until the very end of execution on the main thread. + // Killing the pthread_key at all will lead to the console logger death, etc. - TlsVariable& operator=( const T& src ) - { - GetRef() = src; - return *this; - } + // DON'T REMOVE this->, the "official"[ly stupid] C++ standard requires it because of its + // insistence that variables be looked up during initial template parsing and not during + // instantiation. + this->m_IsDisposed = true; + } - bool operator==( const T& src ) const { return GetRef() == src; } - bool operator!=( const T& src ) const { return GetRef() != src; } - bool operator>( const T& src ) const { return GetRef() > src; } - bool operator<( const T& src ) const { return GetRef() < src; } - bool operator>=( const T& src ) const { return GetRef() >= src; } - bool operator<=( const T& src ) const { return GetRef() <= src; } + TlsVariable &operator=(const T &src) + { + GetRef() = src; + return *this; + } - T operator+( const T& src ) const { return GetRef() + src; } - T operator-( const T& src ) const { return GetRef() - src; } + bool operator==(const T &src) const { return GetRef() == src; } + bool operator!=(const T &src) const { return GetRef() != src; } + bool operator>(const T &src) const { return GetRef() > src; } + bool operator<(const T &src) const { return GetRef() < src; } + bool operator>=(const T &src) const { return GetRef() >= src; } + bool operator<=(const T &src) const { return GetRef() <= src; } + + T operator+(const T &src) const { return GetRef() + src; } + T operator-(const T &src) const { return GetRef() - src; } + + void operator+=(const T &src) { GetRef() += src; } + void operator-=(const T &src) { GetRef() -= src; } - void operator+=( const T& src ) { GetRef() += src; } - void operator-=( const T& src ) { GetRef() -= src; } - protected: - virtual void CreateInstance( T* result ) const - { - new (result) T(m_initval); - } + virtual void CreateInstance(T *result) const + { + new (result) T(m_initval); + } }; }; -template< typename T > +template Threading::BaseTlsVariable::BaseTlsVariable() { - m_IsDisposed = false; - CreateKey(); + m_IsDisposed = false; + CreateKey(); } -template< typename T > +template void Threading::BaseTlsVariable::KillKey() { - if (!m_thread_key) return; + if (!m_thread_key) + return; - // Delete the handle for the current thread (which should always be the main/UI thread!) - // This is needed because pthreads does *not* clean up the dangling objects when you delete - // the key. The TLS for the process main thread will only be deleted when the process - // ends; which is too damn late (it shows up int he leaked memory blocks). + // Delete the handle for the current thread (which should always be the main/UI thread!) + // This is needed because pthreads does *not* clean up the dangling objects when you delete + // the key. The TLS for the process main thread will only be deleted when the process + // ends; which is too damn late (it shows up int he leaked memory blocks). - BaseTlsVariable::_aligned_delete_and_free( pthread_getspecific(m_thread_key) ); + BaseTlsVariable::_aligned_delete_and_free(pthread_getspecific(m_thread_key)); - pthread_key_delete( m_thread_key ); - m_thread_key = 0; + pthread_key_delete(m_thread_key); + m_thread_key = 0; } -template< typename T > -T* Threading::BaseTlsVariable::GetPtr() const +template +T *Threading::BaseTlsVariable::GetPtr() const { - T* result = (T*)pthread_getspecific( m_thread_key ); - if( result == NULL ) - { - pthread_setspecific( m_thread_key, result = (T*)_aligned_malloc(sizeof(T), 16) ); - CreateInstance(result); - if( result == NULL ) - throw Exception::OutOfMemory( L"thread local storage variable instance" ); - } - return result; + T *result = (T *)pthread_getspecific(m_thread_key); + if (result == NULL) { + pthread_setspecific(m_thread_key, result = (T *)_aligned_malloc(sizeof(T), 16)); + CreateInstance(result); + if (result == NULL) + throw Exception::OutOfMemory(L"thread local storage variable instance"); + } + return result; } -template< typename T > +template void Threading::BaseTlsVariable::CreateKey() { - if( 0 != pthread_key_create(&m_thread_key, BaseTlsVariable::_aligned_delete_and_free) ) - { - pxFailRel( "Thread Local Storage Error: key creation failed. This will most likely lead to a rapid application crash." ); - } + if (0 != pthread_key_create(&m_thread_key, BaseTlsVariable::_aligned_delete_and_free)) { + pxFailRel("Thread Local Storage Error: key creation failed. This will most likely lead to a rapid application crash."); + } } diff --git a/common/include/Utilities/TraceLog.h b/common/include/Utilities/TraceLog.h index f7b6f21088..45b9c922e1 100644 --- a/common/include/Utilities/TraceLog.h +++ b/common/include/Utilities/TraceLog.h @@ -29,20 +29,20 @@ // struct TraceLogDescriptor { - // short name, alphanumerics only: used for saving/loading options. - const wxChar* ShortName; + // short name, alphanumerics only: used for saving/loading options. + const wxChar *ShortName; - // Standard UI name for this log source. Used in menus, options dialogs. - const wxChar* Name; + // Standard UI name for this log source. Used in menus, options dialogs. + const wxChar *Name; - // Length description for use as a tooltip or menu item description. - const wxChar* Description; + // Length description for use as a tooltip or menu item description. + const wxChar *Description; - wxString GetShortName() const - { - pxAssumeDev(Name, "Tracelog descriptors require a valid name!"); - return ShortName ? ShortName : Name; - } + wxString GetShortName() const + { + pxAssumeDev(Name, "Tracelog descriptors require a valid name!"); + return ShortName ? ShortName : Name; + } }; // -------------------------------------------------------------------------------------- @@ -62,52 +62,55 @@ struct TraceLogDescriptor // check is done top-level, the parameters' calculations can be skipped. If the IsActive() // check is done internally as part of the Write/Format calls, all parameters have to be // resolved regardless of if the log is actually active. -// +// class BaseTraceLogSource { protected: - const TraceLogDescriptor* m_Descriptor; + const TraceLogDescriptor *m_Descriptor; public: - // Indicates if the user has enabled this specific log. This boolean only represents - // the configured status of this log, and does *NOT* actually mean the log is active - // even when TRUE. Because many tracelogs have master enablers that act on a group - // of logs, logging checks should always use IsActive() instead to determine if a log - // should be processed or not. - bool Enabled; + // Indicates if the user has enabled this specific log. This boolean only represents + // the configured status of this log, and does *NOT* actually mean the log is active + // even when TRUE. Because many tracelogs have master enablers that act on a group + // of logs, logging checks should always use IsActive() instead to determine if a log + // should be processed or not. + bool Enabled; protected: - BaseTraceLogSource() : m_Descriptor(NULL), Enabled(false) {} + BaseTraceLogSource() + : m_Descriptor(NULL) + , Enabled(false) + { + } public: - TraceLog_ImplementBaseAPI(BaseTraceLogSource) + TraceLog_ImplementBaseAPI(BaseTraceLogSource) - BaseTraceLogSource( const TraceLogDescriptor* desc ) - { - pxAssumeDev( desc, "Trace logs must have a valid (non-NULL) descriptor." ); - Enabled = false; - m_Descriptor = desc; - } + BaseTraceLogSource(const TraceLogDescriptor *desc) + { + pxAssumeDev(desc, "Trace logs must have a valid (non-NULL) descriptor."); + Enabled = false; + m_Descriptor = desc; + } - // Provides a categorical identifier, typically in "group.subgroup.subgroup" form. - // (use periods in favor of colons, since they do not require escape characters when - // written to ini/config files). - virtual wxString GetCategory() const { return wxEmptyString; } + // Provides a categorical identifier, typically in "group.subgroup.subgroup" form. + // (use periods in favor of colons, since they do not require escape characters when + // written to ini/config files). + virtual wxString GetCategory() const { return wxEmptyString; } - // This method should be used to determine if a log should be generated or not. - // See the class overview comments for details on how and why this method should - // be used. - virtual bool IsActive() const { return Enabled; } + // This method should be used to determine if a log should be generated or not. + // See the class overview comments for details on how and why this method should + // be used. + virtual bool IsActive() const { return Enabled; } - virtual wxString GetShortName() const { return m_Descriptor->GetShortName(); } - virtual const wxChar* GetName() const { return m_Descriptor->Name; } - virtual const wxChar* GetDescription() const - { - return (m_Descriptor->Description!=NULL) ? pxGetTranslation(m_Descriptor->Description) : wxEmptyString; - } - - virtual bool HasDescription() const { return m_Descriptor->Description != NULL;} + virtual wxString GetShortName() const { return m_Descriptor->GetShortName(); } + virtual const wxChar *GetName() const { return m_Descriptor->Name; } + virtual const wxChar *GetDescription() const + { + return (m_Descriptor->Description != NULL) ? pxGetTranslation(m_Descriptor->Description) : wxEmptyString; + } + virtual bool HasDescription() const { return m_Descriptor->Description != NULL; } }; // -------------------------------------------------------------------------------------- @@ -119,32 +122,32 @@ public: class TextFileTraceLog : public BaseTraceLogSource { public: - TextFileTraceLog( const TraceLogDescriptor* desc ) - : BaseTraceLogSource( desc ) - { - } + TextFileTraceLog(const TraceLogDescriptor *desc) + : BaseTraceLogSource(desc) + { + } - bool Write( const char* fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( fmt, list ); - va_end( list ); + bool Write(const char *fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(fmt, list); + va_end(list); - return false; - } + return false; + } - bool WriteV( const char *fmt, va_list list ) const - { - FastFormatAscii ascii; - ApplyPrefix(ascii); - ascii.WriteV( fmt, list ); - DoWrite( ascii ); - return false; - } + bool WriteV(const char *fmt, va_list list) const + { + FastFormatAscii ascii; + ApplyPrefix(ascii); + ascii.WriteV(fmt, list); + DoWrite(ascii); + return false; + } - virtual void ApplyPrefix( FastFormatAscii& ascii ) const {} - virtual void DoWrite( const char* fmt ) const=0; + virtual void ApplyPrefix(FastFormatAscii &ascii) const {} + virtual void DoWrite(const char *fmt) const = 0; }; // -------------------------------------------------------------------------------------- @@ -156,128 +159,130 @@ public: class ConsoleLogSource : public BaseTraceLogSource { public: - ConsoleColors DefaultColor; + ConsoleColors DefaultColor; protected: - ConsoleLogSource() : DefaultColor(Color_Gray) {} + ConsoleLogSource() + : DefaultColor(Color_Gray) + { + } public: - ConsoleLog_ImplementBaseAPI(ConsoleLogSource) + ConsoleLog_ImplementBaseAPI(ConsoleLogSource) - ConsoleLogSource( const TraceLogDescriptor* desc, ConsoleColors defaultColor = Color_Gray ) - : BaseTraceLogSource(desc) - { - DefaultColor = defaultColor; - } + ConsoleLogSource(const TraceLogDescriptor *desc, ConsoleColors defaultColor = Color_Gray) + : BaseTraceLogSource(desc) + { + DefaultColor = defaultColor; + } - // Writes to the console using the source's default color. Note that the source's default - // color will always be used, thus ConsoleColorScope() will not be effectual unless the - // console's default color is Color_Default. - bool Write( const char* fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( fmt, list ); - va_end( list ); + // Writes to the console using the source's default color. Note that the source's default + // color will always be used, thus ConsoleColorScope() will not be effectual unless the + // console's default color is Color_Default. + bool Write(const char *fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(fmt, list); + va_end(list); - return false; - } + return false; + } - bool Write( const wxChar* fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( fmt, list ); - va_end( list ); + bool Write(const wxChar *fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(fmt, list); + va_end(list); - return false; - } + return false; + } - bool Write( const wxString fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( fmt.wx_str(), list ); - va_end( list ); + bool Write(const wxString fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(fmt.wx_str(), list); + va_end(list); - return false; - } + return false; + } - // Writes to the console using the specified color. This overrides the default color setting - // for this log. - bool Write( ConsoleColors color, const char* fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( color, fmt, list ); - va_end( list ); + // Writes to the console using the specified color. This overrides the default color setting + // for this log. + bool Write(ConsoleColors color, const char *fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(color, fmt, list); + va_end(list); - return false; - } + return false; + } - bool Write( ConsoleColors color, const wxChar* fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( color, fmt, list ); - va_end( list ); + bool Write(ConsoleColors color, const wxChar *fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(color, fmt, list); + va_end(list); - return false; - } + return false; + } - // Writes to the console using bold yellow text -- overrides the log source's default - // color settings. - bool Warn( const wxChar* fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( Color_StrongYellow, fmt, list ); - va_end( list ); + // Writes to the console using bold yellow text -- overrides the log source's default + // color settings. + bool Warn(const wxChar *fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(Color_StrongYellow, fmt, list); + va_end(list); - return false; - } + return false; + } - bool Warn( const wxString fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( Color_StrongYellow, fmt.wx_str(), list ); - va_end( list ); + bool Warn(const wxString fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(Color_StrongYellow, fmt.wx_str(), list); + va_end(list); - return false; - } + return false; + } - // Writes to the console using bold red text -- overrides the log source's default - // color settings. - bool Error( const wxChar* fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( Color_StrongRed, fmt, list ); - va_end( list ); + // Writes to the console using bold red text -- overrides the log source's default + // color settings. + bool Error(const wxChar *fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(Color_StrongRed, fmt, list); + va_end(list); - return false; - } + return false; + } - bool Error( const wxString fmt, ... ) const - { - va_list list; - va_start( list, fmt ); - WriteV( Color_StrongRed, fmt.wx_str(), list ); - va_end( list ); + bool Error(const wxString fmt, ...) const + { + va_list list; + va_start(list, fmt); + WriteV(Color_StrongRed, fmt.wx_str(), list); + va_end(list); - return false; - } + return false; + } - bool WriteV( const char *fmt, va_list list ) const; - bool WriteV( const wxChar *fmt, va_list list ) const; + bool WriteV(const char *fmt, va_list list) const; + bool WriteV(const wxChar *fmt, va_list list) const; - bool WriteV( ConsoleColors color, const char *fmt, va_list list ) const; - bool WriteV( ConsoleColors color, const wxChar *fmt, va_list list ) const; + bool WriteV(ConsoleColors color, const char *fmt, va_list list) const; + bool WriteV(ConsoleColors color, const wxChar *fmt, va_list list) const; - virtual void DoWrite( const wxChar* msg ) const - { - Console.DoWriteLn( msg ); - } + virtual void DoWrite(const wxChar *msg) const + { + Console.DoWriteLn(msg); + } }; - diff --git a/common/include/Utilities/lnx_memzero.h b/common/include/Utilities/lnx_memzero.h index 52ca0abab2..245d622a60 100644 --- a/common/include/Utilities/lnx_memzero.h +++ b/common/include/Utilities/lnx_memzero.h @@ -18,43 +18,43 @@ // This header contains non-optimized implementation of memzero_ptr and memset8, etc -template< u32 data, typename T > -static __fi void memset32( T& obj ) +template +static __fi void memset32(T &obj) { - // this function works on 32-bit aligned lengths of data only. - // If the data length is not a factor of 32 bits, the C++ optimizing compiler will - // probably just generate mysteriously broken code in Release builds. ;) + // this function works on 32-bit aligned lengths of data only. + // If the data length is not a factor of 32 bits, the C++ optimizing compiler will + // probably just generate mysteriously broken code in Release builds. ;) - pxAssume((sizeof(T) & 0x3) == 0); + pxAssume((sizeof(T) & 0x3) == 0); - u32* dest = (u32*)&obj; - for( int i=sizeof(T)>>2; i; --i, ++dest ) - *dest = data; + u32 *dest = (u32 *)&obj; + for (int i = sizeof(T) >> 2; i; --i, ++dest) + *dest = data; } -template< typename T > -static __fi void memzero( T& obj ) +template +static __fi void memzero(T &obj) { - memset( &obj, 0, sizeof( T ) ); + memset(&obj, 0, sizeof(T)); } -template< u8 data, typename T > -static __fi void memset8( T& obj ) +template +static __fi void memset8(T &obj) { - // Aligned sizes use the optimized 32 bit inline memset. Unaligned sizes use memset. - if( (sizeof(T) & 0x3) != 0 ) - memset( &obj, data, sizeof( T ) ); - else { - const u32 data32 = data + (data<<8) + (data<<16) + (data<<24); - memset32( obj ); - } + // Aligned sizes use the optimized 32 bit inline memset. Unaligned sizes use memset. + if ((sizeof(T) & 0x3) != 0) + memset(&obj, data, sizeof(T)); + else { + const u32 data32 = data + (data << 8) + (data << 16) + (data << 24); + memset32(obj); + } } // Code is only called in the init so no need to bother with ASM -template< u8 data, size_t bytes > -static __fi void memset_8( void *dest ) +template +static __fi void memset_8(void *dest) { - memset(dest, data, bytes); + memset(dest, data, bytes); } #endif diff --git a/common/include/Utilities/pxCheckBox.h b/common/include/Utilities/pxCheckBox.h index 537b861e3a..6ba272254a 100644 --- a/common/include/Utilities/pxCheckBox.h +++ b/common/include/Utilities/pxCheckBox.h @@ -29,50 +29,74 @@ class pxCheckBox : public wxPanelWithHelpers { protected: - wxCheckBox* m_checkbox; - pxStaticText* m_subtext; + wxCheckBox *m_checkbox; + pxStaticText *m_subtext; - // padding below the subtext (if there's subtext). If there's no subtext, this value is unused. - int m_subPadding; + // padding below the subtext (if there's subtext). If there's no subtext, this value is unused. + int m_subPadding; + + wxSizerItem *m_sizerItem_subtext; - wxSizerItem* m_sizerItem_subtext; public: - pxCheckBox( wxWindow* parent, const wxString& label, const wxString& subtext=wxEmptyString, int flags = wxCHK_2STATE ); - pxCheckBox( wxWindow* parent, const wxString& label, int flags ); - virtual ~pxCheckBox() throw() {} + pxCheckBox(wxWindow *parent, const wxString &label, const wxString &subtext = wxEmptyString, int flags = wxCHK_2STATE); + pxCheckBox(wxWindow *parent, const wxString &label, int flags); + virtual ~pxCheckBox() throw() {} - bool HasSubText() const { return m_subtext != NULL; } - const pxStaticText* GetSubText() const { return m_subtext; } + bool HasSubText() const { return m_subtext != NULL; } + const pxStaticText *GetSubText() const { return m_subtext; } - pxCheckBox& SetSubPadding( int pad ); - pxCheckBox& SetToolTip( const wxString& tip ); - pxCheckBox& SetValue( bool val ); - pxCheckBox& SetIndeterminate(); - pxCheckBox& SetState( wxCheckBoxState state ); + pxCheckBox &SetSubPadding(int pad); + pxCheckBox &SetToolTip(const wxString &tip); + pxCheckBox &SetValue(bool val); + pxCheckBox &SetIndeterminate(); + pxCheckBox &SetState(wxCheckBoxState state); - wxCheckBoxState GetState() const { pxAssert( m_checkbox != NULL ); return m_checkbox->Get3StateValue(); } - bool GetValue() const { pxAssert( m_checkbox != NULL ); return m_checkbox->GetValue(); } - bool IsChecked() const { pxAssert( m_checkbox != NULL ); return m_checkbox->IsChecked(); } - bool IsIndeterminate() const { pxAssert( m_checkbox != NULL ); return m_checkbox->Get3StateValue() == wxCHK_UNDETERMINED; } - operator wxCheckBox&() { pxAssert( m_checkbox != NULL ); return *m_checkbox; } - operator const wxCheckBox&() const { pxAssert( m_checkbox != NULL ); return *m_checkbox; } + wxCheckBoxState GetState() const + { + pxAssert(m_checkbox != NULL); + return m_checkbox->Get3StateValue(); + } + bool GetValue() const + { + pxAssert(m_checkbox != NULL); + return m_checkbox->GetValue(); + } + bool IsChecked() const + { + pxAssert(m_checkbox != NULL); + return m_checkbox->IsChecked(); + } + bool IsIndeterminate() const + { + pxAssert(m_checkbox != NULL); + return m_checkbox->Get3StateValue() == wxCHK_UNDETERMINED; + } + operator wxCheckBox &() + { + pxAssert(m_checkbox != NULL); + return *m_checkbox; + } + operator const wxCheckBox &() const + { + pxAssert(m_checkbox != NULL); + return *m_checkbox; + } - wxCheckBox* GetWxPtr() { return m_checkbox; } - const wxCheckBox* GetWxPtr() const { return m_checkbox; } + wxCheckBox *GetWxPtr() { return m_checkbox; } + const wxCheckBox *GetWxPtr() const { return m_checkbox; } - //wxWindowID GetId() const { pxAssert( m_checkbox != NULL ); return m_checkbox->GetId(); } + //wxWindowID GetId() const { pxAssert( m_checkbox != NULL ); return m_checkbox->GetId(); } protected: - void Init( const wxString& label, const wxString& subtext, int flags ); - void OnCheckpartCommand( wxCommandEvent& evt ); - void OnSubtextClicked( wxCommandEvent& evt ); + void Init(const wxString &label, const wxString &subtext, int flags); + void OnCheckpartCommand(wxCommandEvent &evt); + void OnSubtextClicked(wxCommandEvent &evt); }; -extern void operator+=( wxSizer& target, pxCheckBox& src ); +extern void operator+=(wxSizer &target, pxCheckBox &src); -template<> -inline void operator+=( wxSizer& target, const pxWindowAndFlags& src ) +template <> +inline void operator+=(wxSizer &target, const pxWindowAndFlags &src) { - target.Add( src.window, src.flags ); + target.Add(src.window, src.flags); } - diff --git a/common/include/Utilities/pxEvents.h b/common/include/Utilities/pxEvents.h index feb17b85af..643c780722 100644 --- a/common/include/Utilities/pxEvents.h +++ b/common/include/Utilities/pxEvents.h @@ -26,36 +26,36 @@ typedef void FnType_Void(); // -------------------------------------------------------------------------------------- class SynchronousActionState { - DeclareNoncopyableObject( SynchronousActionState ); + DeclareNoncopyableObject(SynchronousActionState); protected: - bool m_posted; - Threading::Semaphore m_sema; - ScopedExcept m_exception; + bool m_posted; + Threading::Semaphore m_sema; + ScopedExcept m_exception; public: - sptr return_value; + sptr return_value; - SynchronousActionState() - { - m_posted = false; - return_value = 0; - } + SynchronousActionState() + { + m_posted = false; + return_value = 0; + } - virtual ~SynchronousActionState() throw() {} + virtual ~SynchronousActionState() throw() {} - void SetException( const BaseException& ex ); - void SetException( BaseException* ex ); + void SetException(const BaseException &ex); + void SetException(BaseException *ex); - Threading::Semaphore& GetSemaphore() { return m_sema; } - const Threading::Semaphore& GetSemaphore() const { return m_sema; } + Threading::Semaphore &GetSemaphore() { return m_sema; } + const Threading::Semaphore &GetSemaphore() const { return m_sema; } - void RethrowException() const; - int WaitForResult(); - int WaitForResult_NoExceptions(); - void PostResult( int res ); - void ClearResult(); - void PostResult(); + void RethrowException() const; + int WaitForResult(); + int WaitForResult_NoExceptions(); + void PostResult(int res); + void ClearResult(); + void PostResult(); }; @@ -68,18 +68,20 @@ public: // class pxSimpleEvent : public wxEvent { - DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSimpleEvent) + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSimpleEvent) public: - explicit pxSimpleEvent( int evtid=0 ) - : wxEvent(0, evtid) - { } + explicit pxSimpleEvent(int evtid = 0) + : wxEvent(0, evtid) + { + } - pxSimpleEvent( wxWindowID winId, int evtid ) - : wxEvent(winId, evtid) - { } + pxSimpleEvent(wxWindowID winId, int evtid) + : wxEvent(winId, evtid) + { + } - virtual wxEvent *Clone() const { return new pxSimpleEvent(*this); } + virtual wxEvent *Clone() const { return new pxSimpleEvent(*this); } }; // -------------------------------------------------------------------------------------- @@ -91,41 +93,41 @@ wxDECLARE_EVENT(pxEvt_InvokeAction, pxActionEvent); class pxActionEvent : public wxEvent { - DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxActionEvent) + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxActionEvent) protected: - SynchronousActionState* m_state; + SynchronousActionState *m_state; public: - virtual ~pxActionEvent() throw() { } - virtual pxActionEvent *Clone() const { return new pxActionEvent(*this); } + virtual ~pxActionEvent() throw() {} + virtual pxActionEvent *Clone() const { return new pxActionEvent(*this); } - explicit pxActionEvent( SynchronousActionState* sema=NULL, int msgtype=pxEvt_InvokeAction ); - explicit pxActionEvent( SynchronousActionState& sema, int msgtype=pxEvt_InvokeAction ); - pxActionEvent( const pxActionEvent& src ); + explicit pxActionEvent(SynchronousActionState *sema = NULL, int msgtype = pxEvt_InvokeAction); + explicit pxActionEvent(SynchronousActionState &sema, int msgtype = pxEvt_InvokeAction); + pxActionEvent(const pxActionEvent &src); - Threading::Semaphore* GetSemaphore() const { return m_state ? &m_state->GetSemaphore() : NULL; } + Threading::Semaphore *GetSemaphore() const { return m_state ? &m_state->GetSemaphore() : NULL; } - const SynchronousActionState* GetSyncState() const { return m_state; } - SynchronousActionState* GetSyncState() { return m_state; } + const SynchronousActionState *GetSyncState() const { return m_state; } + SynchronousActionState *GetSyncState() { return m_state; } - void SetSyncState( SynchronousActionState* obj ) { m_state = obj; } - void SetSyncState( SynchronousActionState& obj ) { m_state = &obj; } + void SetSyncState(SynchronousActionState *obj) { m_state = obj; } + void SetSyncState(SynchronousActionState &obj) { m_state = &obj; } - virtual void SetException( BaseException* ex ); - void SetException( const BaseException& ex ); + virtual void SetException(BaseException *ex); + void SetException(const BaseException &ex); + + virtual void _DoInvokeEvent(); - virtual void _DoInvokeEvent(); - protected: - // Extending classes should implement this method to perfoem whatever action it is - // the event is supposed to do. :) Thread affinity is garaunteed to be the Main/UI - // thread, and exceptions will be handled automatically. - // - // Exception note: exceptions are passed back to the thread that posted the event - // to the queue, when possible. If the calling thread is not blocking for a result - // from this event, then the exception will be posted to the Main/UI thread instead. - virtual void InvokeEvent() {} + // Extending classes should implement this method to perfoem whatever action it is + // the event is supposed to do. :) Thread affinity is garaunteed to be the Main/UI + // thread, and exceptions will be handled automatically. + // + // Exception note: exceptions are passed back to the thread that posted the event + // to the queue, when possible. If the calling thread is not blocking for a result + // from this event, then the exception will be posted to the Main/UI thread instead. + virtual void InvokeEvent() {} }; @@ -134,27 +136,27 @@ protected: // -------------------------------------------------------------------------------------- class pxExceptionEvent : public pxActionEvent { - typedef pxActionEvent _parent; + typedef pxActionEvent _parent; protected: - BaseException* m_except; + BaseException *m_except; public: - pxExceptionEvent( BaseException* ex=NULL ) - { - m_except = ex; - } + pxExceptionEvent(BaseException *ex = NULL) + { + m_except = ex; + } - pxExceptionEvent( const BaseException& ex ); + pxExceptionEvent(const BaseException &ex); - virtual ~pxExceptionEvent() throw() - { - } + virtual ~pxExceptionEvent() throw() + { + } - virtual pxExceptionEvent *Clone() const { return new pxExceptionEvent(*this); } + virtual pxExceptionEvent *Clone() const { return new pxExceptionEvent(*this); } protected: - void InvokeEvent(); + void InvokeEvent(); }; // -------------------------------------------------------------------------------------- @@ -163,29 +165,29 @@ protected: class pxSynchronousCommandEvent : public wxCommandEvent { - DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSynchronousCommandEvent) + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSynchronousCommandEvent) protected: - SynchronousActionState* m_sync; - wxEventType m_realEvent; + SynchronousActionState *m_sync; + wxEventType m_realEvent; public: - virtual ~pxSynchronousCommandEvent() throw() { } - virtual pxSynchronousCommandEvent *Clone() const { return new pxSynchronousCommandEvent(*this); } + virtual ~pxSynchronousCommandEvent() throw() {} + virtual pxSynchronousCommandEvent *Clone() const { return new pxSynchronousCommandEvent(*this); } - pxSynchronousCommandEvent(SynchronousActionState* sema=NULL, wxEventType commandType = wxEVT_NULL, int winid = 0); - pxSynchronousCommandEvent(SynchronousActionState& sema, wxEventType commandType = wxEVT_NULL, int winid = 0); + pxSynchronousCommandEvent(SynchronousActionState *sema = NULL, wxEventType commandType = wxEVT_NULL, int winid = 0); + pxSynchronousCommandEvent(SynchronousActionState &sema, wxEventType commandType = wxEVT_NULL, int winid = 0); - pxSynchronousCommandEvent(SynchronousActionState* sema, const wxCommandEvent& evt); - pxSynchronousCommandEvent(SynchronousActionState& sema, const wxCommandEvent& evt); + pxSynchronousCommandEvent(SynchronousActionState *sema, const wxCommandEvent &evt); + pxSynchronousCommandEvent(SynchronousActionState &sema, const wxCommandEvent &evt); - pxSynchronousCommandEvent(const pxSynchronousCommandEvent& src); + pxSynchronousCommandEvent(const pxSynchronousCommandEvent &src); - Threading::Semaphore* GetSemaphore() { return m_sync ? &m_sync->GetSemaphore() : NULL; } - wxEventType GetRealEventType() const { return m_realEvent; } + Threading::Semaphore *GetSemaphore() { return m_sync ? &m_sync->GetSemaphore() : NULL; } + wxEventType GetRealEventType() const { return m_realEvent; } - void SetException( BaseException* ex ); - void SetException( const BaseException& ex ); + void SetException(BaseException *ex); + void SetException(const BaseException &ex); }; wxDECLARE_EVENT(pxEvt_SynchronousCommand, pxSynchronousCommandEvent); @@ -195,23 +197,23 @@ wxDECLARE_EVENT(pxEvt_SynchronousCommand, pxSynchronousCommandEvent); // -------------------------------------------------------------------------------------- class BaseMessageBoxEvent : public pxActionEvent { - typedef pxActionEvent _parent; - DECLARE_DYNAMIC_CLASS_NO_ASSIGN(BaseMessageBoxEvent) + typedef pxActionEvent _parent; + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(BaseMessageBoxEvent) protected: - wxString m_Content; + wxString m_Content; public: - virtual ~BaseMessageBoxEvent() throw() { } - virtual BaseMessageBoxEvent *Clone() const { return new BaseMessageBoxEvent(*this); } + virtual ~BaseMessageBoxEvent() throw() {} + virtual BaseMessageBoxEvent *Clone() const { return new BaseMessageBoxEvent(*this); } - explicit BaseMessageBoxEvent( const wxString& content=wxEmptyString, SynchronousActionState* instdata=NULL ); - BaseMessageBoxEvent( const wxString& content, SynchronousActionState& instdata ); - BaseMessageBoxEvent( const BaseMessageBoxEvent& event ); + explicit BaseMessageBoxEvent(const wxString &content = wxEmptyString, SynchronousActionState *instdata = NULL); + BaseMessageBoxEvent(const wxString &content, SynchronousActionState &instdata); + BaseMessageBoxEvent(const BaseMessageBoxEvent &event); protected: - virtual void InvokeEvent(); - virtual int _DoDialog() const; + virtual void InvokeEvent(); + virtual int _DoDialog() const; }; // -------------------------------------------------------------------------------------- @@ -220,82 +222,134 @@ protected: class MsgButtons { protected: - BITFIELD32() - bool - m_OK :1, - m_Cancel :1, - m_Yes :1, - m_No :1, - m_AllowToAll:1, - m_Apply :1, - m_Abort :1, - m_Retry :1, - m_Ignore :1, - m_Reset :1, - m_Close :1; - BITFIELD_END + BITFIELD32() + bool + m_OK : 1, + m_Cancel : 1, + m_Yes : 1, + m_No : 1, + m_AllowToAll : 1, + m_Apply : 1, + m_Abort : 1, + m_Retry : 1, + m_Ignore : 1, + m_Reset : 1, + m_Close : 1; + BITFIELD_END - wxString m_CustomLabel; - wxString m_CustomLabelId; + wxString m_CustomLabel; + wxString m_CustomLabelId; public: - MsgButtons() { bitset = 0; } + MsgButtons() { bitset = 0; } - MsgButtons& OK() { m_OK = true; return *this; } - MsgButtons& Cancel() { m_Cancel = true; return *this; } - MsgButtons& Apply() { m_Apply = true; return *this; } - MsgButtons& Yes() { m_Yes = true; return *this; } - MsgButtons& No() { m_No = true; return *this; } - MsgButtons& ToAll() { m_AllowToAll = true; return *this; } + MsgButtons &OK() + { + m_OK = true; + return *this; + } + MsgButtons &Cancel() + { + m_Cancel = true; + return *this; + } + MsgButtons &Apply() + { + m_Apply = true; + return *this; + } + MsgButtons &Yes() + { + m_Yes = true; + return *this; + } + MsgButtons &No() + { + m_No = true; + return *this; + } + MsgButtons &ToAll() + { + m_AllowToAll = true; + return *this; + } - MsgButtons& Abort() { m_Abort = true; return *this; } - MsgButtons& Retry() { m_Retry = true; return *this; } - MsgButtons& Ignore() { m_Ignore = true; return *this; } - MsgButtons& Reset() { m_Reset = true; return *this; } - MsgButtons& Close() { m_Close = true; return *this; } + MsgButtons &Abort() + { + m_Abort = true; + return *this; + } + MsgButtons &Retry() + { + m_Retry = true; + return *this; + } + MsgButtons &Ignore() + { + m_Ignore = true; + return *this; + } + MsgButtons &Reset() + { + m_Reset = true; + return *this; + } + MsgButtons &Close() + { + m_Close = true; + return *this; + } - // label - native language label displayed to user - // id - raw ASCII identifier used in the config file (do not translate, hence char*) - MsgButtons& Custom( const wxString& label, const char* id ) - { - m_CustomLabel = label; - m_CustomLabelId = fromUTF8(id); - return *this; - } + // label - native language label displayed to user + // id - raw ASCII identifier used in the config file (do not translate, hence char*) + MsgButtons &Custom(const wxString &label, const char *id) + { + m_CustomLabel = label; + m_CustomLabelId = fromUTF8(id); + return *this; + } - MsgButtons& OKCancel() { m_OK = m_Cancel = true; return *this; } - MsgButtons& YesNo() { m_Yes = m_No = true; return *this; } + MsgButtons &OKCancel() + { + m_OK = m_Cancel = true; + return *this; + } + MsgButtons &YesNo() + { + m_Yes = m_No = true; + return *this; + } - bool HasOK() const { return m_OK; } - bool HasCancel() const { return m_Cancel; } - bool HasApply() const { return m_Apply; } - bool HasYes() const { return m_Yes; } - bool HasNo() const { return m_No; } - bool AllowsToAll() const{ return m_AllowToAll; } + bool HasOK() const { return m_OK; } + bool HasCancel() const { return m_Cancel; } + bool HasApply() const { return m_Apply; } + bool HasYes() const { return m_Yes; } + bool HasNo() const { return m_No; } + bool AllowsToAll() const { return m_AllowToAll; } - bool HasAbort() const { return m_Abort; } - bool HasRetry() const { return m_Retry; } - bool HasIgnore() const { return m_Ignore; } - bool HasReset() const { return m_Reset; } - bool HasClose() const { return m_Close; } + bool HasAbort() const { return m_Abort; } + bool HasRetry() const { return m_Retry; } + bool HasIgnore() const { return m_Ignore; } + bool HasReset() const { return m_Reset; } + bool HasClose() const { return m_Close; } - bool HasCustom() const { return !m_CustomLabel.IsEmpty(); } - const wxString& GetCustomLabel() const { return m_CustomLabel; } - const wxString& GetCustomLabelId() const { return m_CustomLabelId; } + bool HasCustom() const { return !m_CustomLabel.IsEmpty(); } + const wxString &GetCustomLabel() const { return m_CustomLabel; } + const wxString &GetCustomLabelId() const { return m_CustomLabelId; } - bool Allows( wxWindowID id ) const; - void SetBestFocus( wxWindow* dialog ) const; - void SetBestFocus( wxWindow& dialog ) const; + bool Allows(wxWindowID id) const; + void SetBestFocus(wxWindow *dialog) const; + void SetBestFocus(wxWindow &dialog) const; - bool operator ==( const MsgButtons& right ) const - { - return OpEqu( bitset ); - } + bool operator==(const MsgButtons &right) const + { + return OpEqu(bitset); + } - bool operator !=( const MsgButtons& right ) const - { - return !OpEqu( bitset ); - } + bool operator!=(const MsgButtons &right) const + { + return !OpEqu(bitset); + } }; // -------------------------------------------------------------------------------------- @@ -318,24 +372,24 @@ public: // class pxMessageBoxEvent : public BaseMessageBoxEvent { - typedef BaseMessageBoxEvent _parent; - DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxMessageBoxEvent) + typedef BaseMessageBoxEvent _parent; + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxMessageBoxEvent) protected: - wxString m_Title; - MsgButtons m_Buttons; - + wxString m_Title; + MsgButtons m_Buttons; + public: - virtual ~pxMessageBoxEvent() throw() { } - virtual pxMessageBoxEvent *Clone() const { return new pxMessageBoxEvent(*this); } + virtual ~pxMessageBoxEvent() throw() {} + virtual pxMessageBoxEvent *Clone() const { return new pxMessageBoxEvent(*this); } - pxMessageBoxEvent() {} - pxMessageBoxEvent( const wxString& title, const wxString& content, const MsgButtons& buttons, SynchronousActionState& instdata ); - pxMessageBoxEvent( const wxString& title, const wxString& content, const MsgButtons& buttons, SynchronousActionState* instdata=NULL ); - pxMessageBoxEvent( const pxMessageBoxEvent& event ); + pxMessageBoxEvent() {} + pxMessageBoxEvent(const wxString &title, const wxString &content, const MsgButtons &buttons, SynchronousActionState &instdata); + pxMessageBoxEvent(const wxString &title, const wxString &content, const MsgButtons &buttons, SynchronousActionState *instdata = NULL); + pxMessageBoxEvent(const pxMessageBoxEvent &event); protected: - int _DoDialog() const; + int _DoDialog() const; }; // -------------------------------------------------------------------------------------- @@ -343,22 +397,22 @@ protected: // -------------------------------------------------------------------------------------- class pxAssertionEvent : public BaseMessageBoxEvent { - typedef BaseMessageBoxEvent _parent; - DECLARE_DYNAMIC_CLASS_NO_ASSIGN( pxAssertionEvent ) + typedef BaseMessageBoxEvent _parent; + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxAssertionEvent) protected: - wxString m_Stacktrace; + wxString m_Stacktrace; public: - virtual ~pxAssertionEvent() throw() { } - virtual pxAssertionEvent *Clone() const { return new pxAssertionEvent(*this); } + virtual ~pxAssertionEvent() throw() {} + virtual pxAssertionEvent *Clone() const { return new pxAssertionEvent(*this); } - pxAssertionEvent( const wxString& content=wxEmptyString, const wxString& trace=wxEmptyString, SynchronousActionState* instdata=NULL ); - pxAssertionEvent( const wxString& content, const wxString& trace, SynchronousActionState& instdata ); - pxAssertionEvent( const pxAssertionEvent& event ); + pxAssertionEvent(const wxString &content = wxEmptyString, const wxString &trace = wxEmptyString, SynchronousActionState *instdata = NULL); + pxAssertionEvent(const wxString &content, const wxString &trace, SynchronousActionState &instdata); + pxAssertionEvent(const pxAssertionEvent &event); - pxAssertionEvent& SetStacktrace( const wxString& trace ); + pxAssertionEvent &SetStacktrace(const wxString &trace); protected: - int _DoDialog() const; + int _DoDialog() const; }; diff --git a/common/include/Utilities/pxForwardDefs.h b/common/include/Utilities/pxForwardDefs.h index 72904a695c..b1c283f642 100644 --- a/common/include/Utilities/pxForwardDefs.h +++ b/common/include/Utilities/pxForwardDefs.h @@ -40,12 +40,12 @@ extern const wxPoint wxDefaultPosition; namespace Threading { - class Mutex; - class Semaphore; - class pxThread; +class Mutex; +class Semaphore; +class pxThread; } namespace Exception { - class BaseException; +class BaseException; } diff --git a/common/include/Utilities/pxRadioPanel.h b/common/include/Utilities/pxRadioPanel.h index 318502bb3f..8991fad5bb 100644 --- a/common/include/Utilities/pxRadioPanel.h +++ b/common/include/Utilities/pxRadioPanel.h @@ -25,45 +25,45 @@ struct RadioPanelItem { - wxString Label; - wxString SubText; - wxString ToolTip; + wxString Label; + wxString SubText; + wxString ToolTip; - int SomeInt; - void* SomePtr; + int SomeInt; + void *SomePtr; - RadioPanelItem( const wxString& label, const wxString& subtext=wxEmptyString, const wxString& tooltip=wxEmptyString ) - : Label( label ) - , SubText( subtext ) - , ToolTip( tooltip ) - { - SomeInt = 0; - SomePtr = NULL; - } + RadioPanelItem(const wxString &label, const wxString &subtext = wxEmptyString, const wxString &tooltip = wxEmptyString) + : Label(label) + , SubText(subtext) + , ToolTip(tooltip) + { + SomeInt = 0; + SomePtr = NULL; + } - RadioPanelItem& SetToolTip( const wxString& tip ) - { - ToolTip = tip; - return *this; - } + RadioPanelItem &SetToolTip(const wxString &tip) + { + ToolTip = tip; + return *this; + } - RadioPanelItem& SetSubText( const wxString& text ) - { - SubText = text; - return *this; - } - - RadioPanelItem& SetInt( int intval ) - { - SomeInt = intval; - return *this; - } + RadioPanelItem &SetSubText(const wxString &text) + { + SubText = text; + return *this; + } - RadioPanelItem& SetPtr( void* ptrval ) - { - SomePtr = ptrval; - return *this; - } + RadioPanelItem &SetInt(int intval) + { + SomeInt = intval; + return *this; + } + + RadioPanelItem &SetPtr(void *ptrval) + { + SomePtr = ptrval; + return *this; + } }; @@ -71,8 +71,8 @@ struct RadioPanelItem // wrapped and re-wrapped with multiple calls to OnResize(). struct RadioPanelObjects { - wxRadioButton* LabelObj; - pxStaticText* SubTextObj; + wxRadioButton *LabelObj; + pxStaticText *SubTextObj; }; // -------------------------------------------------------------------------------------- @@ -91,86 +91,86 @@ struct RadioPanelObjects class pxRadioPanel : public wxPanelWithHelpers { protected: - typedef std::vector ButtonArray; - typedef SafeArray ButtonObjArray; + typedef std::vector ButtonArray; + typedef SafeArray ButtonObjArray; - ButtonArray m_buttonStrings; - ButtonObjArray m_objects; + ButtonArray m_buttonStrings; + ButtonObjArray m_objects; - bool m_IsRealized; + bool m_IsRealized; - wxSize m_padding; - int m_Indentation; - int m_DefaultIdx; // index of the default option (gets specific color/font treatment) + wxSize m_padding; + int m_Indentation; + int m_DefaultIdx; // index of the default option (gets specific color/font treatment) public: - template< int size > - pxRadioPanel( wxWindow* parent, const RadioPanelItem (&src)[size] ) - : wxPanelWithHelpers( parent, wxVERTICAL ) - { - Init( src, size ); - } + template + pxRadioPanel(wxWindow *parent, const RadioPanelItem (&src)[size]) + : wxPanelWithHelpers(parent, wxVERTICAL) + { + Init(src, size); + } - pxRadioPanel( wxWindow* parent ) - : wxPanelWithHelpers( parent, wxVERTICAL ) - { - Init(); - } + pxRadioPanel(wxWindow *parent) + : wxPanelWithHelpers(parent, wxVERTICAL) + { + Init(); + } - virtual ~pxRadioPanel() throw() {} + virtual ~pxRadioPanel() throw() {} - void Reset(); - void Realize(); + void Reset(); + void Realize(); - pxStaticText* GetSubText( int idx ); - const pxStaticText* GetSubText( int idx ) const; - pxRadioPanel& Append( const RadioPanelItem& entry ); + pxStaticText *GetSubText(int idx); + const pxStaticText *GetSubText(int idx) const; + pxRadioPanel &Append(const RadioPanelItem &entry); - pxRadioPanel& SetToolTip( int idx, const wxString& tip ); - pxRadioPanel& SetSelection( int idx ); - pxRadioPanel& SetDefaultItem( int idx ); - pxRadioPanel& EnableItem( int idx, bool enable=true ); + pxRadioPanel &SetToolTip(int idx, const wxString &tip); + pxRadioPanel &SetSelection(int idx); + pxRadioPanel &SetDefaultItem(int idx); + pxRadioPanel &EnableItem(int idx, bool enable = true); - const RadioPanelItem& Item(int idx) const; - RadioPanelItem& Item(int idx); + const RadioPanelItem &Item(int idx) const; + RadioPanelItem &Item(int idx); - int GetSelection() const; - wxWindowID GetSelectionId() const; - bool IsSelected( int idx ) const; + int GetSelection() const; + wxWindowID GetSelectionId() const; + bool IsSelected(int idx) const; - const RadioPanelItem& SelectedItem() const { return Item(GetSelection()); } - RadioPanelItem& SelectedItem() { return Item(GetSelection()); } + const RadioPanelItem &SelectedItem() const { return Item(GetSelection()); } + RadioPanelItem &SelectedItem() { return Item(GetSelection()); } - wxRadioButton* GetButton( int idx ); - const wxRadioButton* GetButton( int idx ) const; + wxRadioButton *GetButton(int idx); + const wxRadioButton *GetButton(int idx) const; - int GetPaddingVert() const { return m_padding.GetHeight(); } - int GetIndentation() const { return m_Indentation; } + int GetPaddingVert() const { return m_padding.GetHeight(); } + int GetIndentation() const { return m_Indentation; } - pxRadioPanel& SetPaddingHoriz( int newpad ) - { - m_padding.SetHeight( newpad ); - return *this; - } + pxRadioPanel &SetPaddingHoriz(int newpad) + { + m_padding.SetHeight(newpad); + return *this; + } - pxRadioPanel& SetIndentation( int newdent ) - { - m_Indentation = newdent; - return *this; - } + pxRadioPanel &SetIndentation(int newdent) + { + m_Indentation = newdent; + return *this; + } - bool HasSubText( int idx ) const - { - return !m_buttonStrings[idx].SubText.IsEmpty(); - } + bool HasSubText(int idx) const + { + return !m_buttonStrings[idx].SubText.IsEmpty(); + } - pxRadioPanel& Append( const wxString& label, const wxString& subtext=wxEmptyString, const wxString& tooltip=wxEmptyString ) - { - return Append( RadioPanelItem(label, subtext, tooltip) ); - } + pxRadioPanel &Append(const wxString &label, const wxString &subtext = wxEmptyString, const wxString &tooltip = wxEmptyString) + { + return Append(RadioPanelItem(label, subtext, tooltip)); + } protected: - void Init( const RadioPanelItem* srcArray=NULL, int arrsize=0 ); - void _setToolTipImmediate( int idx, const wxString &tip ); - void _RealizeDefaultOption(); + void Init(const RadioPanelItem *srcArray = NULL, int arrsize = 0); + void _setToolTipImmediate(int idx, const wxString &tip); + void _RealizeDefaultOption(); }; diff --git a/common/include/Utilities/pxStaticText.h b/common/include/Utilities/pxStaticText.h index 461a2ab42b..790005ba34 100644 --- a/common/include/Utilities/pxStaticText.h +++ b/common/include/Utilities/pxStaticText.h @@ -33,93 +33,92 @@ // class pxStaticText : public wxControl { - typedef wxControl _parent; + typedef wxControl _parent; protected: - wxString m_label; - wxString m_wrappedLabel; + wxString m_label; + wxString m_wrappedLabel; - wxAlignment m_align; - bool m_autowrap; - int m_wrappedWidth; - int m_heightInLines; + wxAlignment m_align; + bool m_autowrap; + int m_wrappedWidth; + int m_heightInLines; - int m_paddingPix_horiz; - int m_paddingPix_vert; - float m_paddingPct_horiz; - float m_paddingPct_vert; + int m_paddingPix_horiz; + int m_paddingPix_vert; + float m_paddingPct_horiz; + float m_paddingPct_vert; protected: - explicit pxStaticText( wxWindow* parent=NULL ); + explicit pxStaticText(wxWindow *parent = NULL); - // wxWindow overloads! - bool AcceptsFocus() const { return false; } - bool HasTransparentBackground() { return true; } - void DoSetSize(int x, int y, int w, int h, int sizeFlags = wxSIZE_AUTO); + // wxWindow overloads! + bool AcceptsFocus() const { return false; } + bool HasTransparentBackground() { return true; } + void DoSetSize(int x, int y, int w, int h, int sizeFlags = wxSIZE_AUTO); public: - pxStaticText( wxWindow* parent, const wxString& label, wxAlignment align=wxALIGN_CENTRE_HORIZONTAL ); - pxStaticText( wxWindow* parent, int heightInLines, const wxString& label, wxAlignment align=wxALIGN_CENTRE_HORIZONTAL ); - virtual ~pxStaticText() throw() {} + pxStaticText(wxWindow *parent, const wxString &label, wxAlignment align = wxALIGN_CENTRE_HORIZONTAL); + pxStaticText(wxWindow *parent, int heightInLines, const wxString &label, wxAlignment align = wxALIGN_CENTRE_HORIZONTAL); + virtual ~pxStaticText() throw() {} - wxFont GetFontOk() const; - bool Enable( bool enabled=true ); + wxFont GetFontOk() const; + bool Enable(bool enabled = true); - virtual void SetLabel(const wxString& label); - virtual wxString GetLabel() const { return m_label; } + virtual void SetLabel(const wxString &label); + virtual wxString GetLabel() const { return m_label; } - pxStaticText& SetMinWidth( int width ); - pxStaticText& SetMinHeight( int height ); + pxStaticText &SetMinWidth(int width); + pxStaticText &SetMinHeight(int height); - pxStaticText& SetHeight( int lines ); - pxStaticText& Align( wxAlignment align ); - pxStaticText& Bold(); - pxStaticText& WrapAt( int width ); + pxStaticText &SetHeight(int lines); + pxStaticText &Align(wxAlignment align); + pxStaticText &Bold(); + pxStaticText &WrapAt(int width); - pxStaticText& Unwrapped(); + pxStaticText &Unwrapped(); - pxStaticText& PaddingPixH( int pixels ); - pxStaticText& PaddingPixV( int pixels ); + pxStaticText &PaddingPixH(int pixels); + pxStaticText &PaddingPixV(int pixels); - pxStaticText& PaddingPctH( float pct ); - pxStaticText& PaddingPctV( float pct ); - //pxStaticText& DoBestGuessHeight(); + pxStaticText &PaddingPctH(float pct); + pxStaticText &PaddingPctV(float pct); + //pxStaticText& DoBestGuessHeight(); protected: - void SetPaddingDefaults(); - void Init( const wxString& label ); + void SetPaddingDefaults(); + void Init(const wxString &label); - wxSize GetBestWrappedSize( const wxClientDC& dc ) const; - wxSize DoGetBestSize() const; + wxSize GetBestWrappedSize(const wxClientDC &dc) const; + wxSize DoGetBestSize() const; - int calcPaddingWidth( int newWidth ) const; - int calcPaddingHeight( int newHeight ) const; + int calcPaddingWidth(int newWidth) const; + int calcPaddingHeight(int newHeight) const; - void paintEvent(wxPaintEvent& evt); + void paintEvent(wxPaintEvent &evt); - void UpdateWrapping( bool textChanged ); - bool _updateWrapping( bool textChanged ); + void UpdateWrapping(bool textChanged); + bool _updateWrapping(bool textChanged); }; class pxStaticHeading : public pxStaticText { - typedef pxStaticText _parent; + typedef pxStaticText _parent; public: - pxStaticHeading( wxWindow* parent=NULL, const wxString& label=wxEmptyString ); - pxStaticHeading( wxWindow* parent, int heightInLines, const wxString& label=wxEmptyString ); - virtual ~pxStaticHeading() throw() {} + pxStaticHeading(wxWindow *parent = NULL, const wxString &label = wxEmptyString); + pxStaticHeading(wxWindow *parent, int heightInLines, const wxString &label = wxEmptyString); + virtual ~pxStaticHeading() throw() {} protected: - void SetPaddingDefaults(); + void SetPaddingDefaults(); }; -extern void operator+=( wxSizer& target, pxStaticText& src ); +extern void operator+=(wxSizer &target, pxStaticText &src); -template<> -inline void operator+=( wxSizer& target, const pxWindowAndFlags& src ) +template <> +inline void operator+=(wxSizer &target, const pxWindowAndFlags &src) { - target.Add( src.window, src.flags ); + target.Add(src.window, src.flags); } - diff --git a/common/include/Utilities/pxStreams.h b/common/include/Utilities/pxStreams.h index b810c93fc4..0ce284a5ed 100644 --- a/common/include/Utilities/pxStreams.h +++ b/common/include/Utilities/pxStreams.h @@ -23,28 +23,28 @@ // -------------------------------------------------------------------------------------- class pxStreamBase { - DeclareNoncopyableObject(pxStreamBase); + DeclareNoncopyableObject(pxStreamBase); protected: - // Filename of the stream, provided by the creator/caller. This is typically used *only* - // for generating comprehensive error messages when an error occurs (the stream name is - // passed to the exception handlers). - wxString m_filename; + // Filename of the stream, provided by the creator/caller. This is typically used *only* + // for generating comprehensive error messages when an error occurs (the stream name is + // passed to the exception handlers). + wxString m_filename; public: - pxStreamBase(const wxString& filename); - virtual ~pxStreamBase() throw() {} + pxStreamBase(const wxString &filename); + virtual ~pxStreamBase() throw() {} - // Implementing classes should return the base wxStream object (usually either a wxInputStream - // or wxOputStream derivative). - virtual wxStreamBase* GetWxStreamBase() const=0; - virtual void Close()=0; - virtual wxFileOffset Tell() const=0; - virtual wxFileOffset Seek( wxFileOffset ofs, wxSeekMode mode = wxFromStart )=0; + // Implementing classes should return the base wxStream object (usually either a wxInputStream + // or wxOputStream derivative). + virtual wxStreamBase *GetWxStreamBase() const = 0; + virtual void Close() = 0; + virtual wxFileOffset Tell() const = 0; + virtual wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart) = 0; - virtual wxFileOffset Length() const; - bool IsOk() const; - wxString GetStreamName() const { return m_filename; } + virtual wxFileOffset Length() const; + bool IsOk() const; + wxString GetStreamName() const { return m_filename; } }; @@ -53,33 +53,33 @@ public: // -------------------------------------------------------------------------------------- class pxOutputStream : public pxStreamBase { - DeclareNoncopyableObject(pxOutputStream); + DeclareNoncopyableObject(pxOutputStream); protected: - std::unique_ptr m_stream_out; + std::unique_ptr m_stream_out; public: - pxOutputStream(const wxString& filename, std::unique_ptr& output); - pxOutputStream(const wxString& filename, wxOutputStream* output); + pxOutputStream(const wxString &filename, std::unique_ptr &output); + pxOutputStream(const wxString &filename, wxOutputStream *output); - virtual ~pxOutputStream() throw() {} - virtual void Write( const void* data, size_t size ); - - void SetStream( const wxString& filename, std::unique_ptr& stream ); - void SetStream( const wxString& filename, wxOutputStream* stream ); + virtual ~pxOutputStream() throw() {} + virtual void Write(const void *data, size_t size); - void Close() { m_stream_out = nullptr; } + void SetStream(const wxString &filename, std::unique_ptr &stream); + void SetStream(const wxString &filename, wxOutputStream *stream); - virtual wxStreamBase* GetWxStreamBase() const; + void Close() { m_stream_out = nullptr; } - template< typename T > - void Write( const T& data ) - { - Write( &data, sizeof(data) ); - } + virtual wxStreamBase *GetWxStreamBase() const; - wxFileOffset Tell() const; - wxFileOffset Seek( wxFileOffset ofs, wxSeekMode mode = wxFromStart ); + template + void Write(const T &data) + { + Write(&data, sizeof(data)); + } + + wxFileOffset Tell() const; + wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart); }; // -------------------------------------------------------------------------------------- @@ -87,31 +87,31 @@ public: // -------------------------------------------------------------------------------------- class pxInputStream : public pxStreamBase { - DeclareNoncopyableObject(pxInputStream); + DeclareNoncopyableObject(pxInputStream); protected: - std::unique_ptr m_stream_in; + std::unique_ptr m_stream_in; public: - pxInputStream(const wxString& filename, std::unique_ptr& input); - pxInputStream(const wxString& filename, wxInputStream* input); + pxInputStream(const wxString &filename, std::unique_ptr &input); + pxInputStream(const wxString &filename, wxInputStream *input); - virtual ~pxInputStream() throw() {} - virtual void Read( void* dest, size_t size ); - - void SetStream( const wxString& filename, std::unique_ptr& stream ); - void SetStream( const wxString& filename, wxInputStream* stream ); + virtual ~pxInputStream() throw() {} + virtual void Read(void *dest, size_t size); - void Close() { m_stream_in = nullptr; } + void SetStream(const wxString &filename, std::unique_ptr &stream); + void SetStream(const wxString &filename, wxInputStream *stream); - virtual wxStreamBase* GetWxStreamBase() const; + void Close() { m_stream_in = nullptr; } - template< typename T > - void Read( T& dest ) - { - Read( &dest, sizeof(dest) ); - } + virtual wxStreamBase *GetWxStreamBase() const; - wxFileOffset Tell() const; - wxFileOffset Seek( wxFileOffset ofs, wxSeekMode mode = wxFromStart ); + template + void Read(T &dest) + { + Read(&dest, sizeof(dest)); + } + + wxFileOffset Tell() const; + wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart); }; diff --git a/common/include/Utilities/win_memzero.h b/common/include/Utilities/win_memzero.h index 13473b132e..b6fd186afc 100644 --- a/common/include/Utilities/win_memzero.h +++ b/common/include/Utilities/win_memzero.h @@ -16,30 +16,30 @@ #pragma once #ifdef _MSC_VER -# pragma warning(disable:4063) // case '1' is not a valid value for switch() +#pragma warning(disable : 4063) // case '1' is not a valid value for switch() #endif // These functions are meant for memset operations of constant length only. // For dynamic length clears, use the C-compiler provided memset instead. -template< u8 data, size_t bytes > -static __fi void memset_8( void *dest ) +template +static __fi void memset_8(void *dest) { - memset(dest, data, bytes); + memset(dest, data, bytes); } // This method can clear any object-like entity -- which is anything that is not a pointer. // Structures, static arrays, etc. No need to include sizeof() crap, this does it automatically // for you! -template< typename T > -static __fi void memzero( T& object ) +template +static __fi void memzero(T &object) { - memset(&object, 0, sizeof(T)); + memset(&object, 0, sizeof(T)); } // This method clears an object with the given 8 bit value. -template< u8 data, typename T > -static __fi void memset8( T& object ) +template +static __fi void memset8(T &object) { - memset_8( &object ); + memset_8(&object); } diff --git a/common/include/Utilities/wxAppWithHelpers.h b/common/include/Utilities/wxAppWithHelpers.h index 8ba6a08278..dbd39a7a82 100644 --- a/common/include/Utilities/wxAppWithHelpers.h +++ b/common/include/Utilities/wxAppWithHelpers.h @@ -32,10 +32,10 @@ class pxSynchronousCommandEvent; class ConsoleLogSource_App : public ConsoleLogSource { - typedef ConsoleLogSource _parent; + typedef ConsoleLogSource _parent; public: - ConsoleLogSource_App(); + ConsoleLogSource_App(); }; extern ConsoleLogSource_App pxConLog_App; @@ -49,96 +49,97 @@ extern ConsoleLogSource_App pxConLog_App; class ModalButtonPanel : public wxPanelWithHelpers { public: - ModalButtonPanel( wxWindow* window, const MsgButtons& buttons ); - virtual ~ModalButtonPanel() throw() { } + ModalButtonPanel(wxWindow *window, const MsgButtons &buttons); + virtual ~ModalButtonPanel() throw() {} - virtual void AddActionButton( wxWindowID id ); - virtual void AddCustomButton( wxWindowID id, const wxString& label ); + virtual void AddActionButton(wxWindowID id); + virtual void AddCustomButton(wxWindowID id, const wxString &label); - virtual void OnActionButtonClicked( wxCommandEvent& evt ); + virtual void OnActionButtonClicked(wxCommandEvent &evt); }; -typedef std::list< wxEvent* > wxEventList; +typedef std::list wxEventList; // -------------------------------------------------------------------------------------- // wxAppWithHelpers // -------------------------------------------------------------------------------------- class wxAppWithHelpers : public wxApp { - typedef wxApp _parent; - - DECLARE_DYNAMIC_CLASS(wxAppWithHelpers) + typedef wxApp _parent; + + DECLARE_DYNAMIC_CLASS(wxAppWithHelpers) protected: - wxEventList m_IdleEventQueue; - Threading::MutexRecursive m_IdleEventMutex; - wxTimer m_IdleEventTimer; + wxEventList m_IdleEventQueue; + Threading::MutexRecursive m_IdleEventMutex; + wxTimer m_IdleEventTimer; public: - wxAppWithHelpers(); - virtual ~wxAppWithHelpers() {} + wxAppWithHelpers(); + virtual ~wxAppWithHelpers() {} - wxAppTraits* CreateTraits(); + wxAppTraits *CreateTraits(); - void CleanUp(); - - void DeleteObject( BaseDeletableObject& obj ); - void DeleteObject( BaseDeletableObject* obj ) - { - if( obj == NULL ) return; - DeleteObject( *obj ); - } + void CleanUp(); - void DeleteThread( Threading::pxThread& obj ); - void DeleteThread( Threading::pxThread* obj ) - { - if( obj == NULL ) return; - DeleteThread( *obj ); - } + void DeleteObject(BaseDeletableObject &obj); + void DeleteObject(BaseDeletableObject *obj) + { + if (obj == NULL) + return; + DeleteObject(*obj); + } - void PostCommand( void* clientData, int evtType, int intParam=0, long longParam=0, const wxString& stringParam=wxEmptyString ); - void PostCommand( int evtType, int intParam=0, long longParam=0, const wxString& stringParam=wxEmptyString ); - void PostMethod( FnType_Void* method ); - void PostIdleMethod( FnType_Void* method ); - void ProcessMethod( FnType_Void* method ); + void DeleteThread(Threading::pxThread &obj); + void DeleteThread(Threading::pxThread *obj) + { + if (obj == NULL) + return; + DeleteThread(*obj); + } - bool Rpc_TryInvoke( FnType_Void* method ); - bool Rpc_TryInvokeAsync( FnType_Void* method ); + void PostCommand(void *clientData, int evtType, int intParam = 0, long longParam = 0, const wxString &stringParam = wxEmptyString); + void PostCommand(int evtType, int intParam = 0, long longParam = 0, const wxString &stringParam = wxEmptyString); + void PostMethod(FnType_Void *method); + void PostIdleMethod(FnType_Void *method); + void ProcessMethod(FnType_Void *method); - sptr ProcessCommand( void* clientData, int evtType, int intParam=0, long longParam=0, const wxString& stringParam=wxEmptyString ); - sptr ProcessCommand( int evtType, int intParam=0, long longParam=0, const wxString& stringParam=wxEmptyString ); + bool Rpc_TryInvoke(FnType_Void *method); + bool Rpc_TryInvokeAsync(FnType_Void *method); - void ProcessAction( pxActionEvent& evt ); - void PostAction( const pxActionEvent& evt ); + sptr ProcessCommand(void *clientData, int evtType, int intParam = 0, long longParam = 0, const wxString &stringParam = wxEmptyString); + sptr ProcessCommand(int evtType, int intParam = 0, long longParam = 0, const wxString &stringParam = wxEmptyString); - void Ping(); - bool OnInit(); - //int OnExit(); + void ProcessAction(pxActionEvent &evt); + void PostAction(const pxActionEvent &evt); - void AddIdleEvent( const wxEvent& evt ); + void Ping(); + bool OnInit(); + //int OnExit(); - void PostEvent( const wxEvent& evt ); - bool ProcessEvent( wxEvent& evt ); - bool ProcessEvent( wxEvent* evt ); - - bool ProcessEvent( pxActionEvent& evt ); - bool ProcessEvent( pxActionEvent* evt ); + void AddIdleEvent(const wxEvent &evt); + + void PostEvent(const wxEvent &evt); + bool ProcessEvent(wxEvent &evt); + bool ProcessEvent(wxEvent *evt); + + bool ProcessEvent(pxActionEvent &evt); + bool ProcessEvent(pxActionEvent *evt); protected: - void IdleEventDispatcher( const wxChar* action=wxEmptyString ); - - void OnIdleEvent( wxIdleEvent& evt ); - void OnStartIdleEventTimer( wxCommandEvent& evt ); - void OnIdleEventTimeout( wxTimerEvent& evt ); - void OnDeleteObject( wxCommandEvent& evt ); - void OnDeleteThread( wxCommandEvent& evt ); - void OnSynchronousCommand( pxSynchronousCommandEvent& evt ); - void OnInvokeAction( pxActionEvent& evt ); + void IdleEventDispatcher(const wxChar *action = wxEmptyString); + void OnIdleEvent(wxIdleEvent &evt); + void OnStartIdleEventTimer(wxCommandEvent &evt); + void OnIdleEventTimeout(wxTimerEvent &evt); + void OnDeleteObject(wxCommandEvent &evt); + void OnDeleteThread(wxCommandEvent &evt); + void OnSynchronousCommand(pxSynchronousCommandEvent &evt); + void OnInvokeAction(pxActionEvent &evt); }; namespace Msgbox { - extern int ShowModal( BaseMessageBoxEvent& evt ); - extern int ShowModal( const wxString& title, const wxString& content, const MsgButtons& buttons ); +extern int ShowModal(BaseMessageBoxEvent &evt); +extern int ShowModal(const wxString &title, const wxString &content, const MsgButtons &buttons); } diff --git a/common/include/Utilities/wxBaseTools.h b/common/include/Utilities/wxBaseTools.h index b623ea194a..5d65f5b663 100644 --- a/common/include/Utilities/wxBaseTools.h +++ b/common/include/Utilities/wxBaseTools.h @@ -26,11 +26,11 @@ // which require wxCore, see wxGuiTools.h // -------------------------------------------------------------------------------------- -extern void pxExplore( const wxString& path ); -extern void pxExplore( const char *path ); +extern void pxExplore(const wxString &path); +extern void pxExplore(const char *path); -extern void pxLaunch( const wxString& path ); -extern void pxLaunch( const char *path ); +extern void pxLaunch(const wxString &path); +extern void pxLaunch(const char *path); // -------------------------------------------------------------------------------------- // wxDoNotLogInThisScope @@ -44,29 +44,28 @@ extern void pxLaunch( const char *path ); // class wxDoNotLogInThisScope { - DeclareNoncopyableObject(wxDoNotLogInThisScope); + DeclareNoncopyableObject(wxDoNotLogInThisScope); protected: - bool m_prev; + bool m_prev; public: - wxDoNotLogInThisScope() - { - m_prev = wxLog::EnableLogging( false ); - } + wxDoNotLogInThisScope() + { + m_prev = wxLog::EnableLogging(false); + } - virtual ~wxDoNotLogInThisScope() throw() - { - wxLog::EnableLogging( m_prev ); - } + virtual ~wxDoNotLogInThisScope() throw() + { + wxLog::EnableLogging(m_prev); + } }; -extern wxString pxReadLine( wxInputStream& input ); -extern void pxReadLine( wxInputStream& input, wxString& dest ); -extern void pxReadLine( wxInputStream& input, wxString& dest, std::string& intermed ); -extern bool pxReadLine( wxInputStream& input, std::string& dest ); -extern void pxWriteLine( wxOutputStream& output ); -extern void pxWriteLine( wxOutputStream& output, const wxString& text ); -extern void pxWriteMultiline( wxOutputStream& output, const wxString& src ); - +extern wxString pxReadLine(wxInputStream &input); +extern void pxReadLine(wxInputStream &input, wxString &dest); +extern void pxReadLine(wxInputStream &input, wxString &dest, std::string &intermed); +extern bool pxReadLine(wxInputStream &input, std::string &dest); +extern void pxWriteLine(wxOutputStream &output); +extern void pxWriteLine(wxOutputStream &output, const wxString &text); +extern void pxWriteMultiline(wxOutputStream &output, const wxString &src); diff --git a/common/include/Utilities/wxGuiTools.h b/common/include/Utilities/wxGuiTools.h index 4c63ac0957..77bf84ed64 100644 --- a/common/include/Utilities/wxGuiTools.h +++ b/common/include/Utilities/wxGuiTools.h @@ -40,18 +40,18 @@ class wxSpinCtrl; namespace pxSizerFlags { - static const int StdPadding = 4; +static const int StdPadding = 4; - extern wxSizerFlags StdSpace(); - extern wxSizerFlags StdCenter(); - extern wxSizerFlags StdExpand(); - extern wxSizerFlags TopLevelBox(); - extern wxSizerFlags SubGroup(); - extern wxSizerFlags StdButton(); - extern wxSizerFlags Checkbox(); +extern wxSizerFlags StdSpace(); +extern wxSizerFlags StdCenter(); +extern wxSizerFlags StdExpand(); +extern wxSizerFlags TopLevelBox(); +extern wxSizerFlags SubGroup(); +extern wxSizerFlags StdButton(); +extern wxSizerFlags Checkbox(); }; -#define wxSF wxSizerFlags() +#define wxSF wxSizerFlags() // -------------------------------------------------------------------------------------- // pxAlignment / pxStretchType @@ -61,120 +61,118 @@ namespace pxSizerFlags // struct pxAlignmentType { - enum - { - Centre, - Center = Centre, - Middle, - Left, - Right, - Top, - Bottom - }; + enum { + Centre, + Center = Centre, + Middle, + Left, + Right, + Top, + Bottom + }; - int intval; + int intval; - wxSizerFlags Apply( wxSizerFlags flags=wxSizerFlags() ) const; + wxSizerFlags Apply(wxSizerFlags flags = wxSizerFlags()) const; - wxSizerFlags operator& ( const wxSizerFlags& _flgs ) const - { - return Apply( _flgs ); - } + wxSizerFlags operator&(const wxSizerFlags &_flgs) const + { + return Apply(_flgs); + } - wxSizerFlags Expand() const - { - return Apply().Expand(); - } + wxSizerFlags Expand() const + { + return Apply().Expand(); + } - wxSizerFlags Border( int dir, int padding ) const - { - return Apply().Border( dir, padding ); - } + wxSizerFlags Border(int dir, int padding) const + { + return Apply().Border(dir, padding); + } - wxSizerFlags Proportion() const - { - return Apply().Proportion( intval ); - } + wxSizerFlags Proportion() const + { + return Apply().Proportion(intval); + } - operator wxSizerFlags() const - { - return Apply(); - } + operator wxSizerFlags() const + { + return Apply(); + } }; struct pxStretchType { - enum - { - Shrink, - Expand, - Shaped, - ReserveHidden, - FixedMinimum - }; + enum { + Shrink, + Expand, + Shaped, + ReserveHidden, + FixedMinimum + }; - int intval; + int intval; - wxSizerFlags Apply( wxSizerFlags flags=wxSizerFlags() ) const; + wxSizerFlags Apply(wxSizerFlags flags = wxSizerFlags()) const; - wxSizerFlags operator& ( const wxSizerFlags& _flgs ) const - { - return Apply( _flgs ); - } + wxSizerFlags operator&(const wxSizerFlags &_flgs) const + { + return Apply(_flgs); + } - wxSizerFlags Border( int dir, int padding ) const - { - return Apply().Border( dir, padding ); - } + wxSizerFlags Border(int dir, int padding) const + { + return Apply().Border(dir, padding); + } - wxSizerFlags Proportion() const - { - return Apply().Proportion( intval ); - } + wxSizerFlags Proportion() const + { + return Apply().Proportion(intval); + } - operator wxSizerFlags() const - { - return Apply(); - } + operator wxSizerFlags() const + { + return Apply(); + } }; -static __fi wxSizerFlags pxProportion( int prop ) +static __fi wxSizerFlags pxProportion(int prop) { - return wxSizerFlags( prop ); + return wxSizerFlags(prop); } -static __fi wxSizerFlags pxBorder( int dir=wxALL, int pad=pxSizerFlags::StdPadding ) +static __fi wxSizerFlags pxBorder(int dir = wxALL, int pad = pxSizerFlags::StdPadding) { - return wxSizerFlags().Border( dir, pad ); + return wxSizerFlags().Border(dir, pad); } class pxStretchSpacer { public: - int proportion; + int proportion; - pxStretchSpacer( int prop=0 ) - { - proportion = prop; - } + pxStretchSpacer(int prop = 0) + { + proportion = prop; + } }; extern const pxAlignmentType - pxCentre, // Horizontal centered alignment - pxCenter, - pxMiddle, // vertical centered alignment + pxCentre, // Horizontal centered alignment + pxCenter, + pxMiddle, // vertical centered alignment - pxAlignLeft, - pxAlignRight, - pxAlignTop, - pxAlignBottom; + pxAlignLeft, + pxAlignRight, + pxAlignTop, + pxAlignBottom; extern const pxStretchType - pxShrink, - pxExpand, - pxShaped, - pxReserveHidden, - pxFixedMinimum; + pxShrink, + pxExpand, + pxShaped, + pxReserveHidden, + pxFixedMinimum; // -------------------------------------------------------------------------------------- // pxWindowAndFlags @@ -190,28 +188,28 @@ extern const pxStretchType // template, the type of the window would only be known as "wxWindow" when it's added to the // sizer, and would thus fail to invoke the correct operator overload. // -template< typename WinType > +template struct pxWindowAndFlags { - WinType* window; - wxSizerFlags flags; + WinType *window; + wxSizerFlags flags; }; -extern wxSizerFlags operator& ( const wxSizerFlags& _flgs, const wxSizerFlags& _flgs2 ); +extern wxSizerFlags operator&(const wxSizerFlags &_flgs, const wxSizerFlags &_flgs2); -template< typename WinType > -pxWindowAndFlags operator | ( WinType* _win, const wxSizerFlags& _flgs ) +template +pxWindowAndFlags operator|(WinType *_win, const wxSizerFlags &_flgs) { - pxWindowAndFlags result = { _win, _flgs }; - return result; + pxWindowAndFlags result = {_win, _flgs}; + return result; } -template< typename WinType > -pxWindowAndFlags operator | ( WinType& _win, const wxSizerFlags& _flgs ) +template +pxWindowAndFlags operator|(WinType &_win, const wxSizerFlags &_flgs) { - pxWindowAndFlags result = { &_win, _flgs }; - return result; + pxWindowAndFlags result = {&_win, _flgs}; + return result; } // -------------------------------------------------------------------------------------- @@ -226,48 +224,51 @@ pxWindowAndFlags operator | ( WinType& _win, const wxSizerFlags& _flgs // has no sizer set via SetSizer(), an assertion is generated. // -extern void operator+=( wxSizer& target, wxWindow* src ); -extern void operator+=( wxSizer& target, wxSizer* src ); -extern void operator+=( wxSizer& target, wxWindow& src ); -extern void operator+=( wxSizer& target, wxSizer& src ); +extern void operator+=(wxSizer &target, wxWindow *src); +extern void operator+=(wxSizer &target, wxSizer *src); +extern void operator+=(wxSizer &target, wxWindow &src); +extern void operator+=(wxSizer &target, wxSizer &src); -extern void operator+=( wxSizer* target, wxWindow& src ); -extern void operator+=( wxSizer* target, wxSizer& src ); +extern void operator+=(wxSizer *target, wxWindow &src); +extern void operator+=(wxSizer *target, wxSizer &src); -extern void operator+=( wxSizer& target, int spacer ); -extern void operator+=( wxWindow& target, int spacer ); -extern void operator+=( wxSizer& target, const pxStretchSpacer& spacer ); -extern void operator+=( wxWindow& target, const pxStretchSpacer& spacer ); +extern void operator+=(wxSizer &target, int spacer); +extern void operator+=(wxWindow &target, int spacer); +extern void operator+=(wxSizer &target, const pxStretchSpacer &spacer); +extern void operator+=(wxWindow &target, const pxStretchSpacer &spacer); // ---------------------------------------------------------------------------- // Important: This template is needed in order to retain window type information and // invoke the proper overloaded version of += (which is used by pxStaticText and other // classes to perform special actions when added to sizers). -template< typename WinType > -void operator+=( wxWindow& target, WinType* src ) +template +void operator+=(wxWindow &target, WinType *src) { - if( !pxAssert( target.GetSizer() != NULL ) ) return; - *target.GetSizer() += src; + if (!pxAssert(target.GetSizer() != NULL)) + return; + *target.GetSizer() += src; } -template< typename WinType > -void operator+=( wxWindow& target, WinType& src ) +template +void operator+=(wxWindow &target, WinType &src) { - if( !pxAssert( target.GetSizer() != NULL ) ) return; - *target.GetSizer() += src; + if (!pxAssert(target.GetSizer() != NULL)) + return; + *target.GetSizer() += src; } -template< typename WinType > -void operator+=( wxWindow& target, const pxWindowAndFlags& src ) +template +void operator+=(wxWindow &target, const pxWindowAndFlags &src) { - if( !pxAssert( target.GetSizer() != NULL ) ) return; - *target.GetSizer() += src; + if (!pxAssert(target.GetSizer() != NULL)) + return; + *target.GetSizer() += src; } -template< typename WinType > -void operator+=( wxSizer& target, const pxWindowAndFlags& src ) +template +void operator+=(wxSizer &target, const pxWindowAndFlags &src) { - target.Add( src.window, src.flags ); + target.Add(src.window, src.flags); } wxDECLARE_EVENT(pxEvt_OnDialogCreated, wxCommandEvent); @@ -278,211 +279,219 @@ wxDECLARE_EVENT(pxEvt_OnDialogCreated, wxCommandEvent); class pxDialogCreationFlags { public: - wxSize MinimumSize; - wxOrientation BoxSizerOrient; + wxSize MinimumSize; + wxOrientation BoxSizerOrient; - bool isResizable; - bool hasContextHelp; - bool hasCaption; - bool hasMinimizeBox; - bool hasMaximizeBox; - bool hasSystemMenu; - bool hasCloseBox; + bool isResizable; + bool hasContextHelp; + bool hasCaption; + bool hasMinimizeBox; + bool hasMaximizeBox; + bool hasSystemMenu; + bool hasCloseBox; public: - virtual ~pxDialogCreationFlags() throw() {} - - pxDialogCreationFlags() - { - MinimumSize = wxDefaultSize; - BoxSizerOrient = wxVERTICAL; - isResizable = false; - hasContextHelp = false; + virtual ~pxDialogCreationFlags() throw() {} - hasCloseBox = true; - hasSystemMenu = true; - hasMinimizeBox = false; - hasMaximizeBox = false; - hasCaption = true; - } + pxDialogCreationFlags() + { + MinimumSize = wxDefaultSize; + BoxSizerOrient = wxVERTICAL; + isResizable = false; + hasContextHelp = false; - pxDialogCreationFlags& SetSizerOrient( wxOrientation orient ) - { - BoxSizerOrient = orient; - return *this; - } + hasCloseBox = true; + hasSystemMenu = true; + hasMinimizeBox = false; + hasMaximizeBox = false; + hasCaption = true; + } - pxDialogCreationFlags& SetResize( bool enable=true ) - { - isResizable = enable; - return *this; - } + pxDialogCreationFlags &SetSizerOrient(wxOrientation orient) + { + BoxSizerOrient = orient; + return *this; + } - pxDialogCreationFlags& SetMinimize( bool enable=true ) - { - hasMinimizeBox = enable; - return *this; - } + pxDialogCreationFlags &SetResize(bool enable = true) + { + isResizable = enable; + return *this; + } - pxDialogCreationFlags& SetMaximize( bool enable=true ) - { - hasMaximizeBox = enable; - return *this; - } + pxDialogCreationFlags &SetMinimize(bool enable = true) + { + hasMinimizeBox = enable; + return *this; + } - // NOTE: Enabling system menu on dialogs usually doesn't work, and might cause - // other unwanted behavior, such as a missing close button. - pxDialogCreationFlags& SetSystemMenu( bool enable=true ) - { - hasSystemMenu = enable; - return *this; - } + pxDialogCreationFlags &SetMaximize(bool enable = true) + { + hasMaximizeBox = enable; + return *this; + } - pxDialogCreationFlags& SetCaption( bool enable=true ) - { - hasCaption = enable; - return *this; - } + // NOTE: Enabling system menu on dialogs usually doesn't work, and might cause + // other unwanted behavior, such as a missing close button. + pxDialogCreationFlags &SetSystemMenu(bool enable = true) + { + hasSystemMenu = enable; + return *this; + } - pxDialogCreationFlags& SetCloseBox( bool enable=true ) - { - hasCloseBox = enable; - return *this; - } + pxDialogCreationFlags &SetCaption(bool enable = true) + { + hasCaption = enable; + return *this; + } - pxDialogCreationFlags SetContextHelp( bool enabled=true ) - { - hasContextHelp = enabled; - return *this; - } + pxDialogCreationFlags &SetCloseBox(bool enable = true) + { + hasCloseBox = enable; + return *this; + } - pxDialogCreationFlags& SetMinWidth( int width ) - { - if( width > MinimumSize.x ) MinimumSize.SetWidth( width ); - return *this; - } + pxDialogCreationFlags SetContextHelp(bool enabled = true) + { + hasContextHelp = enabled; + return *this; + } - pxDialogCreationFlags& SetMinHeight( int height ) - { - if( height > MinimumSize.y ) MinimumSize.SetHeight( height ); - return *this; - } + pxDialogCreationFlags &SetMinWidth(int width) + { + if (width > MinimumSize.x) + MinimumSize.SetWidth(width); + return *this; + } - pxDialogCreationFlags& SetMinSize( const wxSize& size ) - { - return SetMinWidth(size.x).SetMinHeight(size.y); - } + pxDialogCreationFlags &SetMinHeight(int height) + { + if (height > MinimumSize.y) + MinimumSize.SetHeight(height); + return *this; + } + + pxDialogCreationFlags &SetMinSize(const wxSize &size) + { + return SetMinWidth(size.x).SetMinHeight(size.y); + } - pxDialogCreationFlags Horizontal() const - { - return pxDialogCreationFlags(*this).SetSizerOrient( wxHORIZONTAL ); - } + pxDialogCreationFlags Horizontal() const + { + return pxDialogCreationFlags(*this).SetSizerOrient(wxHORIZONTAL); + } - pxDialogCreationFlags Vertical() const - { - return pxDialogCreationFlags(*this).SetSizerOrient( wxVERTICAL ); - } - - pxDialogCreationFlags NoSizer() const - { - return pxDialogCreationFlags(*this).SetSizerOrient( (wxOrientation)0 ); - } + pxDialogCreationFlags Vertical() const + { + return pxDialogCreationFlags(*this).SetSizerOrient(wxVERTICAL); + } - pxDialogCreationFlags Resize( bool enable=true ) const - { - return pxDialogCreationFlags(*this).SetResize( enable ); - } + pxDialogCreationFlags NoSizer() const + { + return pxDialogCreationFlags(*this).SetSizerOrient((wxOrientation)0); + } - pxDialogCreationFlags Minimize( bool enable=true ) const - { - return pxDialogCreationFlags(*this).SetMinimize( enable ); - } + pxDialogCreationFlags Resize(bool enable = true) const + { + return pxDialogCreationFlags(*this).SetResize(enable); + } - pxDialogCreationFlags Maximize( bool enable=true ) const - { - return pxDialogCreationFlags(*this).SetMaximize( enable ); - } + pxDialogCreationFlags Minimize(bool enable = true) const + { + return pxDialogCreationFlags(*this).SetMinimize(enable); + } - // NOTE: Enabling system menu on dialogs usually doesn't work, and might cause - // other unwanted behavior, such as a missing close button. - pxDialogCreationFlags SystemMenu( bool enable=true ) const - { - return pxDialogCreationFlags(*this).SetSystemMenu( false ); - } + pxDialogCreationFlags Maximize(bool enable = true) const + { + return pxDialogCreationFlags(*this).SetMaximize(enable); + } - pxDialogCreationFlags Caption( bool enable=true ) const - { - return pxDialogCreationFlags(*this).SetCaption( enable ); - } + // NOTE: Enabling system menu on dialogs usually doesn't work, and might cause + // other unwanted behavior, such as a missing close button. + pxDialogCreationFlags SystemMenu(bool enable = true) const + { + return pxDialogCreationFlags(*this).SetSystemMenu(false); + } - pxDialogCreationFlags CloseBox( bool enable=true ) const - { - return pxDialogCreationFlags(*this).SetCloseBox( enable ); - } + pxDialogCreationFlags Caption(bool enable = true) const + { + return pxDialogCreationFlags(*this).SetCaption(enable); + } - pxDialogCreationFlags NoResize() const - { - return pxDialogCreationFlags(*this).SetResize( false ); - } + pxDialogCreationFlags CloseBox(bool enable = true) const + { + return pxDialogCreationFlags(*this).SetCloseBox(enable); + } - pxDialogCreationFlags NoMinimize() const - { - return pxDialogCreationFlags(*this).SetMinimize( false ); - } + pxDialogCreationFlags NoResize() const + { + return pxDialogCreationFlags(*this).SetResize(false); + } - pxDialogCreationFlags NoMaximize() const - { - return pxDialogCreationFlags(*this).SetMaximize( false ); - } + pxDialogCreationFlags NoMinimize() const + { + return pxDialogCreationFlags(*this).SetMinimize(false); + } - pxDialogCreationFlags NoSystemMenu() const - { - return pxDialogCreationFlags(*this).SetSystemMenu( false ); - } + pxDialogCreationFlags NoMaximize() const + { + return pxDialogCreationFlags(*this).SetMaximize(false); + } - pxDialogCreationFlags NoCaption() const - { - return pxDialogCreationFlags(*this).SetCaption( false ); - } + pxDialogCreationFlags NoSystemMenu() const + { + return pxDialogCreationFlags(*this).SetSystemMenu(false); + } - pxDialogCreationFlags NoCloseBox() const - { - return pxDialogCreationFlags(*this).SetCloseBox( false ); - } + pxDialogCreationFlags NoCaption() const + { + return pxDialogCreationFlags(*this).SetCaption(false); + } - pxDialogCreationFlags MinWidth( int width ) const - { - return pxDialogCreationFlags(*this).SetMinWidth( width ); - } + pxDialogCreationFlags NoCloseBox() const + { + return pxDialogCreationFlags(*this).SetCloseBox(false); + } - pxDialogCreationFlags MinHeight( int height ) const - { - return pxDialogCreationFlags(*this).SetMinHeight( height ); - } + pxDialogCreationFlags MinWidth(int width) const + { + return pxDialogCreationFlags(*this).SetMinWidth(width); + } - pxDialogCreationFlags MinSize( const wxSize& size ) const - { - return pxDialogCreationFlags(*this).SetMinSize( size ); - } + pxDialogCreationFlags MinHeight(int height) const + { + return pxDialogCreationFlags(*this).SetMinHeight(height); + } - pxDialogCreationFlags MinSize( int width, int height ) const - { - return pxDialogCreationFlags(*this).SetMinWidth( width ).SetMinHeight( height ); - } - - int GetWxWindowFlags() const - { - int retval = 0; - if( isResizable ) retval |= wxRESIZE_BORDER; - if( hasCaption ) retval |= wxCAPTION; - if( hasMaximizeBox ) retval |= wxMAXIMIZE_BOX; - if( hasMinimizeBox ) retval |= wxMINIMIZE_BOX; - if( hasSystemMenu ) retval |= wxSYSTEM_MENU; - if( hasCloseBox ) retval |= wxCLOSE_BOX; - - return retval; - } + pxDialogCreationFlags MinSize(const wxSize &size) const + { + return pxDialogCreationFlags(*this).SetMinSize(size); + } + + pxDialogCreationFlags MinSize(int width, int height) const + { + return pxDialogCreationFlags(*this).SetMinWidth(width).SetMinHeight(height); + } + + int GetWxWindowFlags() const + { + int retval = 0; + if (isResizable) + retval |= wxRESIZE_BORDER; + if (hasCaption) + retval |= wxCAPTION; + if (hasMaximizeBox) + retval |= wxMAXIMIZE_BOX; + if (hasMinimizeBox) + retval |= wxMINIMIZE_BOX; + if (hasSystemMenu) + retval |= wxSYSTEM_MENU; + if (hasCloseBox) + retval |= wxCLOSE_BOX; + + return retval; + } }; // -------------------------------------------------------------------------------------- @@ -490,50 +499,50 @@ public: // -------------------------------------------------------------------------------------- class wxDialogWithHelpers : public wxDialog { - typedef wxDialog _parent; - DECLARE_DYNAMIC_CLASS_NO_COPY(wxDialogWithHelpers) + typedef wxDialog _parent; + DECLARE_DYNAMIC_CLASS_NO_COPY(wxDialogWithHelpers) protected: - bool m_hasContextHelp; - wxBoxSizer* m_extraButtonSizer; - wxRect m_CreatedRect; + bool m_hasContextHelp; + wxBoxSizer *m_extraButtonSizer; + wxRect m_CreatedRect; public: - wxDialogWithHelpers(); - wxDialogWithHelpers(wxWindow* parent, const wxString& title, const pxDialogCreationFlags& cflags = pxDialogCreationFlags() ); - virtual ~wxDialogWithHelpers() throw(); + wxDialogWithHelpers(); + wxDialogWithHelpers(wxWindow *parent, const wxString &title, const pxDialogCreationFlags &cflags = pxDialogCreationFlags()); + virtual ~wxDialogWithHelpers() throw(); - void Init( const pxDialogCreationFlags& cflags ); - void AddOkCancel( wxSizer& sizer, bool hasApply=false ); - void AddOkCancel( wxSizer* sizer=NULL, bool hasApply=false ); - void RememberPosition(); + void Init(const pxDialogCreationFlags &cflags); + void AddOkCancel(wxSizer &sizer, bool hasApply = false); + void AddOkCancel(wxSizer *sizer = NULL, bool hasApply = false); + void RememberPosition(); - virtual void SmartCenterFit(); - virtual int ShowModal(); - virtual bool Show( bool show=true ); + virtual void SmartCenterFit(); + virtual int ShowModal(); + virtual bool Show(bool show = true); - // Must return the same thing as GetNameStatic; a name ideal for use in uniquely - // identifying dialogs. (this version is the 'instance' version, which is called - // by BaseConfigurationDialog to assign the wxWidgets dialog name, and for saving - // screenshots to disk) - virtual wxString GetDialogName() const; + // Must return the same thing as GetNameStatic; a name ideal for use in uniquely + // identifying dialogs. (this version is the 'instance' version, which is called + // by BaseConfigurationDialog to assign the wxWidgets dialog name, and for saving + // screenshots to disk) + virtual wxString GetDialogName() const; - virtual wxStaticText& Label( const wxString& label ); - virtual pxStaticText& Text( const wxString& label ); - virtual pxStaticText& Heading( const wxString& label ); + virtual wxStaticText &Label(const wxString &label); + virtual pxStaticText &Text(const wxString &label); + virtual pxStaticText &Heading(const wxString &label); - wxDialogWithHelpers& SetMinWidth( int newWidth ); - wxDialogWithHelpers& SetMinHeight( int newHeight ); - - int GetCharHeight() const; + wxDialogWithHelpers &SetMinWidth(int newWidth); + wxDialogWithHelpers &SetMinHeight(int newHeight); + + int GetCharHeight() const; protected: - void OnDialogCreated( wxCommandEvent& evt ); - void OnOkCancel(wxCommandEvent& evt); + void OnDialogCreated(wxCommandEvent &evt); + void OnOkCancel(wxCommandEvent &evt); - bool ShouldPreventAppExit() const { return false; } + bool ShouldPreventAppExit() const { return false; } - void DoAutoCenter(); + void DoAutoCenter(); }; // -------------------------------------------------------------------------------------- @@ -555,24 +564,24 @@ protected: // class wxPanelWithHelpers : public wxPanel { - DECLARE_DYNAMIC_CLASS_NO_COPY(wxPanelWithHelpers) + DECLARE_DYNAMIC_CLASS_NO_COPY(wxPanelWithHelpers) public: - wxPanelWithHelpers( wxWindow* parent, wxOrientation orient, const wxString& staticBoxLabel ); - wxPanelWithHelpers( wxWindow* parent, wxOrientation orient ); - wxPanelWithHelpers( wxWindow* parent, const wxPoint& pos, const wxSize& size=wxDefaultSize ); - explicit wxPanelWithHelpers( wxWindow* parent=NULL ); + wxPanelWithHelpers(wxWindow *parent, wxOrientation orient, const wxString &staticBoxLabel); + wxPanelWithHelpers(wxWindow *parent, wxOrientation orient); + wxPanelWithHelpers(wxWindow *parent, const wxPoint &pos, const wxSize &size = wxDefaultSize); + explicit wxPanelWithHelpers(wxWindow *parent = NULL); - wxPanelWithHelpers* AddFrame( const wxString& label, wxOrientation orient=wxVERTICAL ); + wxPanelWithHelpers *AddFrame(const wxString &label, wxOrientation orient = wxVERTICAL); - wxStaticText& Label( const wxString& label ); - pxStaticText& Text( const wxString& label ); - pxStaticText& Heading( const wxString& label ); + wxStaticText &Label(const wxString &label); + pxStaticText &Text(const wxString &label); + pxStaticText &Heading(const wxString &label); - virtual wxPanelWithHelpers& SetMinWidth( int newWidth ); + virtual wxPanelWithHelpers &SetMinWidth(int newWidth); protected: - void Init(); + void Init(); }; @@ -590,37 +599,37 @@ protected: class pxTextWrapperBase { protected: - bool m_eol; - int m_linecount; - wxString m_indent; + bool m_eol; + int m_linecount; + wxString m_indent; public: - virtual ~pxTextWrapperBase() throw() { } + virtual ~pxTextWrapperBase() throw() {} - pxTextWrapperBase( const wxString& indent=wxEmptyString ) - : m_indent( indent ) - { - m_eol = false; - m_linecount = 0; - } + pxTextWrapperBase(const wxString &indent = wxEmptyString) + : m_indent(indent) + { + m_eol = false; + m_linecount = 0; + } // win is used for getting the font, text is the text to wrap, width is the // max line width or -1 to disable wrapping - pxTextWrapperBase& Wrap( const wxWindow& win, const wxString& text, int widthMax ); + pxTextWrapperBase &Wrap(const wxWindow &win, const wxString &text, int widthMax); - int GetLineCount() const - { - return m_linecount; - } + int GetLineCount() const + { + return m_linecount; + } protected: // line may be empty - virtual void OnOutputLine(const wxString& line) { } + virtual void OnOutputLine(const wxString &line) {} // called at the start of every new line (except the very first one) - virtual void OnNewLine() { } + virtual void OnNewLine() {} - void DoOutputLine(const wxString& line); + void DoOutputLine(const wxString &line); bool IsStartOfNewLine(); }; @@ -632,28 +641,29 @@ protected: // class pxTextWrapper : public pxTextWrapperBase { - typedef pxTextWrapperBase _parent; + typedef pxTextWrapperBase _parent; protected: - wxString m_text; + wxString m_text; public: - pxTextWrapper( const wxString& wrapPrefix=wxEmptyString ) - : pxTextWrapperBase( wrapPrefix ) - { } - - virtual ~pxTextWrapper() throw() { } - - const wxString& GetResult() const + pxTextWrapper(const wxString &wrapPrefix = wxEmptyString) + : pxTextWrapperBase(wrapPrefix) { - return m_text; } - pxTextWrapper& Wrap( const wxWindow& win, const wxString& text, int widthMax ); - pxTextWrapper& Wrap( const wxWindow* win, const wxString& text, int widthMax ); + virtual ~pxTextWrapper() throw() {} + + const wxString &GetResult() const + { + return m_text; + } + + pxTextWrapper &Wrap(const wxWindow &win, const wxString &text, int widthMax); + pxTextWrapper &Wrap(const wxWindow *win, const wxString &text, int widthMax); protected: - void OnOutputLine(const wxString& line); + void OnOutputLine(const wxString &line); void OnNewLine(); }; @@ -663,64 +673,64 @@ protected: class pxWindowTextWriter { protected: - wxDC& m_dc; + wxDC &m_dc; - wxAlignment m_align; - wxPoint m_curpos; - int m_leading; + wxAlignment m_align; + wxPoint m_curpos; + int m_leading; - virtual void _DoWriteLn( const wxChar* msg ); - void _DoWriteLn( const wxString msg ); - void _DoWrite( const wxChar* msg ); + virtual void _DoWriteLn(const wxChar *msg); + void _DoWriteLn(const wxString msg); + void _DoWrite(const wxChar *msg); public: - pxWindowTextWriter( wxDC& dc ); - virtual ~pxWindowTextWriter() throw() { } - - virtual void OnFontChanged(); + pxWindowTextWriter(wxDC &dc); + virtual ~pxWindowTextWriter() throw() {} - pxWindowTextWriter& WriteLn(); - pxWindowTextWriter& FormatLn( const wxChar* fmt, ... ); - pxWindowTextWriter& WriteLn( const wxChar* fmt ); - pxWindowTextWriter& SetFont( const wxFont& font ); - pxWindowTextWriter& Align( const wxAlignment& align ); - pxWindowTextWriter& WriteLn( const wxString fmt ); - - pxWindowTextWriter& SetLeading( int lead ) - { - m_leading = lead; - return *this; - } + virtual void OnFontChanged(); - pxWindowTextWriter& SetWeight( wxFontWeight weight ); - pxWindowTextWriter& SetStyle( wxFontStyle style ); - pxWindowTextWriter& Normal(); + pxWindowTextWriter &WriteLn(); + pxWindowTextWriter &FormatLn(const wxChar *fmt, ...); + pxWindowTextWriter &WriteLn(const wxChar *fmt); + pxWindowTextWriter &SetFont(const wxFont &font); + pxWindowTextWriter &Align(const wxAlignment &align); + pxWindowTextWriter &WriteLn(const wxString fmt); - pxWindowTextWriter& Bold() - { - return SetWeight(wxFONTWEIGHT_BOLD); - } + pxWindowTextWriter &SetLeading(int lead) + { + m_leading = lead; + return *this; + } - pxWindowTextWriter& Italic() - { - return SetStyle(wxFONTSTYLE_ITALIC); - } + pxWindowTextWriter &SetWeight(wxFontWeight weight); + pxWindowTextWriter &SetStyle(wxFontStyle style); + pxWindowTextWriter &Normal(); - pxWindowTextWriter& SetPos( const wxPoint& pos ); - pxWindowTextWriter& MovePos( const wxSize& delta ); + pxWindowTextWriter &Bold() + { + return SetWeight(wxFONTWEIGHT_BOLD); + } - pxWindowTextWriter& SetPos( int xpos, int ypos ) - { - return SetPos( wxPoint(xpos,ypos) ); - } + pxWindowTextWriter &Italic() + { + return SetStyle(wxFONTSTYLE_ITALIC); + } - pxWindowTextWriter& MovePos( int xdelta, int ydelta ) - { - return MovePos( wxSize(xdelta, ydelta) ); - } + pxWindowTextWriter &SetPos(const wxPoint &pos); + pxWindowTextWriter &MovePos(const wxSize &delta); - pxWindowTextWriter& SetY( int ypos ); - pxWindowTextWriter& MoveY( int ydelta ); + pxWindowTextWriter &SetPos(int xpos, int ypos) + { + return SetPos(wxPoint(xpos, ypos)); + } + + pxWindowTextWriter &MovePos(int xdelta, int ydelta) + { + return MovePos(wxSize(xdelta, ydelta)); + } + + pxWindowTextWriter &SetY(int ypos); + pxWindowTextWriter &MoveY(int ydelta); }; // -------------------------------------------------------------------------------------- @@ -731,19 +741,18 @@ public: class MoreStockCursors { protected: - std::unique_ptr m_arrowWait; + std::unique_ptr m_arrowWait; public: - MoreStockCursors() { } - virtual ~MoreStockCursors() throw() { } - const wxCursor& GetArrowWait(); + MoreStockCursors() {} + virtual ~MoreStockCursors() throw() {} + const wxCursor &GetArrowWait(); }; -enum BusyCursorType -{ - Cursor_NotBusy, - Cursor_KindaBusy, - Cursor_ReallyBusy, +enum BusyCursorType { + Cursor_NotBusy, + Cursor_KindaBusy, + Cursor_ReallyBusy, }; extern MoreStockCursors StockCursors; @@ -757,15 +766,15 @@ extern MoreStockCursors StockCursors; class ScopedBusyCursor { protected: - static std::stack m_cursorStack; - static BusyCursorType m_defBusyType; + static std::stack m_cursorStack; + static BusyCursorType m_defBusyType; public: - ScopedBusyCursor( BusyCursorType busytype ); - virtual ~ScopedBusyCursor() throw(); + ScopedBusyCursor(BusyCursorType busytype); + virtual ~ScopedBusyCursor() throw(); - static void SetDefault( BusyCursorType busytype ); - static void SetManualBusyCursor( BusyCursorType busytype ); + static void SetDefault(BusyCursorType busytype); + static void SetManualBusyCursor(BusyCursorType busytype); }; // -------------------------------------------------------------------------------------- @@ -774,24 +783,24 @@ public: // Fits a given text or spinner control to the number of digits requested, since by default // they're usually way over-sized. -extern void pxFitToDigits( wxWindow* win, int digits ); -extern void pxFitToDigits( wxSpinCtrl* win, int digits ); -extern wxTextCtrl* CreateNumericalTextCtrl( wxWindow* parent, int digits, long flags = wxTE_RIGHT ); +extern void pxFitToDigits(wxWindow *win, int digits); +extern void pxFitToDigits(wxSpinCtrl *win, int digits); +extern wxTextCtrl *CreateNumericalTextCtrl(wxWindow *parent, int digits, long flags = wxTE_RIGHT); ////////////////////////////////////////////////////////////////////////////////////////////// -extern bool pxDialogExists( const wxString& name ); -extern bool pxIsValidWindowPosition( const wxWindow& window, const wxPoint& windowPos ); +extern bool pxDialogExists(const wxString &name); +extern bool pxIsValidWindowPosition(const wxWindow &window, const wxPoint &windowPos); extern wxRect wxGetDisplayArea(); extern wxString pxGetAppName(); -extern int pxGetCharHeight( const wxWindow* wind, int rows=1 ); -extern int pxGetCharHeight( const wxWindow& wind, int rows=1 ); +extern int pxGetCharHeight(const wxWindow *wind, int rows = 1); +extern int pxGetCharHeight(const wxWindow &wind, int rows = 1); -extern void pxSetToolTip( wxWindow* wind, const wxString& src ); -extern void pxSetToolTip( wxWindow& wind, const wxString& src ); -extern wxFont pxGetFixedFont( int ptsize = 8, wxFontWeight weight = wxFONTWEIGHT_NORMAL ); +extern void pxSetToolTip(wxWindow *wind, const wxString &src); +extern void pxSetToolTip(wxWindow &wind, const wxString &src); +extern wxFont pxGetFixedFont(int ptsize = 8, wxFontWeight weight = wxFONTWEIGHT_NORMAL); extern pxDialogCreationFlags pxDialogFlags(); diff --git a/common/include/api/CDVDApi.h b/common/include/api/CDVDApi.h index d6d0b4753a..77c305dce6 100644 --- a/common/include/api/CDVDApi.h +++ b/common/include/api/CDVDApi.h @@ -35,101 +35,124 @@ // Basic functions. -EXPORT_C_(s32) CDVDinit(); -EXPORT_C_(s32) CDVDopen(void *pDisplay, const char* pTitleFilename); -EXPORT_C_(void) CDVDclose(); -EXPORT_C_(void) CDVDshutdown(); -EXPORT_C_(s32) CDVDreadTrack(u32 lsn, int mode); +EXPORT_C_(s32) +CDVDinit(); +EXPORT_C_(s32) +CDVDopen(void *pDisplay, const char *pTitleFilename); +EXPORT_C_(void) +CDVDclose(); +EXPORT_C_(void) +CDVDshutdown(); +EXPORT_C_(s32) +CDVDreadTrack(u32 lsn, int mode); // return can be NULL (for async modes) -EXPORT_C_(u8*) CDVDgetBuffer(); +EXPORT_C_(u8 *) +CDVDgetBuffer(); -EXPORT_C_(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq);//read subq from disc (only cds have subq data) -EXPORT_C_(s32) CDVDgetTN(cdvdTN *Buffer); //disk information -EXPORT_C_(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type -EXPORT_C_(s32) CDVDgetTOC(void* toc); //gets ps2 style toc from disc -EXPORT_C_(s32) CDVDgetDiskType(); //CDVD_TYPE_xxxx -EXPORT_C_(s32) CDVDgetTrayStatus(); //CDVD_TRAY_xxxx -EXPORT_C_(s32) CDVDctrlTrayOpen(); //open disc tray -EXPORT_C_(s32) CDVDctrlTrayClose(); //close disc tray +EXPORT_C_(s32) +CDVDreadSubQ(u32 lsn, cdvdSubQ *subq); //read subq from disc (only cds have subq data) +EXPORT_C_(s32) +CDVDgetTN(cdvdTN *Buffer); //disk information +EXPORT_C_(s32) +CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type +EXPORT_C_(s32) +CDVDgetTOC(void *toc); //gets ps2 style toc from disc +EXPORT_C_(s32) +CDVDgetDiskType(); //CDVD_TYPE_xxxx +EXPORT_C_(s32) +CDVDgetTrayStatus(); //CDVD_TRAY_xxxx +EXPORT_C_(s32) +CDVDctrlTrayOpen(); //open disc tray +EXPORT_C_(s32) +CDVDctrlTrayClose(); //close disc tray // Extended functions -EXPORT_C_(void) CDVDkeyEvent(keyEvent *ev); -EXPORT_C_(void) CDVDconfigure(); -EXPORT_C_(s32) CDVDfreeze(u8 mode, freezeData *data); -EXPORT_C_(void) CDVDabout(); -EXPORT_C_(s32) CDVDtest(); -EXPORT_C_(void) CDVDnewDiskCB(void (*callback)()); +EXPORT_C_(void) +CDVDkeyEvent(keyEvent *ev); +EXPORT_C_(void) +CDVDconfigure(); +EXPORT_C_(s32) +CDVDfreeze(u8 mode, freezeData *data); +EXPORT_C_(void) +CDVDabout(); +EXPORT_C_(s32) +CDVDtest(); +EXPORT_C_(void) +CDVDnewDiskCB(void (*callback)()); -typedef struct _cdvdSubQ { - u8 ctrl:4; // control and mode bits - u8 mode:4; // control and mode bits - u8 trackNum; // current track number (1 to 99) - u8 trackIndex; // current index within track (0 to 99) - u8 trackM; // current minute location on the disc (BCD encoded) - u8 trackS; // current sector location on the disc (BCD encoded) - u8 trackF; // current frame location on the disc (BCD encoded) - u8 pad; // unused - u8 discM; // current minute offset from first track (BCD encoded) - u8 discS; // current sector offset from first track (BCD encoded) - u8 discF; // current frame offset from first track (BCD encoded) +typedef struct _cdvdSubQ +{ + u8 ctrl : 4; // control and mode bits + u8 mode : 4; // control and mode bits + u8 trackNum; // current track number (1 to 99) + u8 trackIndex; // current index within track (0 to 99) + u8 trackM; // current minute location on the disc (BCD encoded) + u8 trackS; // current sector location on the disc (BCD encoded) + u8 trackF; // current frame location on the disc (BCD encoded) + u8 pad; // unused + u8 discM; // current minute offset from first track (BCD encoded) + u8 discS; // current sector offset from first track (BCD encoded) + u8 discF; // current frame offset from first track (BCD encoded) } cdvdSubQ; -typedef struct _cdvdTD { // NOT bcd coded - u32 lsn; - u8 type; +typedef struct _cdvdTD +{ // NOT bcd coded + u32 lsn; + u8 type; } cdvdTD; -typedef struct _cdvdTN { - u8 strack; //number of the first track (usually 1) - u8 etrack; //number of the last track +typedef struct _cdvdTN +{ + u8 strack; //number of the first track (usually 1) + u8 etrack; //number of the last track } cdvdTN; // CDVDreadTrack mode values: enum { -CDVD_MODE_2352 0, // full 2352 bytes -CDVD_MODE_2340 1, // skip sync (12) bytes -CDVD_MODE_2328 2, // skip sync+head+sub (24) bytes -CDVD_MODE_2048 3, // skip sync+head+sub (24) bytes -CDVD_MODE_2368 4 // full 2352 bytes + 16 subq + CDVD_MODE_2352 0, // full 2352 bytes + CDVD_MODE_2340 1, // skip sync (12) bytes + CDVD_MODE_2328 2, // skip sync+head+sub (24) bytes + CDVD_MODE_2048 3, // skip sync+head+sub (24) bytes + CDVD_MODE_2368 4 // full 2352 bytes + 16 subq } TrackModes -// CDVDgetDiskType returns: -enum { -CDVD_TYPE_ILLEGAL = 0xff, // Illegal Disc -CDVD_TYPE_DVDV = 0xfe, // DVD Video -CDVD_TYPE_CDDA = 0xfd, // Audio CD -CDVD_TYPE_PS2DVD = 0x14, // PS2 DVD -CDVD_TYPE_PS2CDDA = 0x13, // PS2 CD (with audio) -CDVD_TYPE_PS2CD = 0x12, // PS2 CD -CDVD_TYPE_PSCDDA = 0x11, // PS CD (with audio) -CDVD_TYPE_PSCD = 0x10, // PS CD -CDVD_TYPE_UNKNOWN = 0x05, // Unknown -CDVD_TYPE_DETCTDVDD = 0x04, // Detecting Dvd Dual Sided -CDVD_TYPE_DETCTDVDS = 0x03, // Detecting Dvd Single Sided -CDVD_TYPE_DETCTCD = 0x02, // Detecting Cd -CDVD_TYPE_DETCT = 0x01, // Detecting -CDVD_TYPE_NODISC = 0x00 // No Disc -} DiskType; + // CDVDgetDiskType returns: + enum { + CDVD_TYPE_ILLEGAL = 0xff, // Illegal Disc + CDVD_TYPE_DVDV = 0xfe, // DVD Video + CDVD_TYPE_CDDA = 0xfd, // Audio CD + CDVD_TYPE_PS2DVD = 0x14, // PS2 DVD + CDVD_TYPE_PS2CDDA = 0x13, // PS2 CD (with audio) + CDVD_TYPE_PS2CD = 0x12, // PS2 CD + CDVD_TYPE_PSCDDA = 0x11, // PS CD (with audio) + CDVD_TYPE_PSCD = 0x10, // PS CD + CDVD_TYPE_UNKNOWN = 0x05, // Unknown + CDVD_TYPE_DETCTDVDD = 0x04, // Detecting Dvd Dual Sided + CDVD_TYPE_DETCTDVDS = 0x03, // Detecting Dvd Single Sided + CDVD_TYPE_DETCTCD = 0x02, // Detecting Cd + CDVD_TYPE_DETCT = 0x01, // Detecting + CDVD_TYPE_NODISC = 0x00 // No Disc + } DiskType; // CDVDgetTrayStatus returns: enum { -CDVD_TRAY_CLOSE = 0x00, -CDVD_TRAY_OPEN = 0x01 + CDVD_TRAY_CLOSE = 0x00, + CDVD_TRAY_OPEN = 0x01 } TrayStatus; // cdvdTD.type (track types for cds) enum { -CDVD_AUDIO_TRACK = 0x01, -CDVD_MODE1_TRACK = 0x41, -CDVD_MODE2_TRACK = 0x61 + CDVD_AUDIO_TRACK = 0x01, + CDVD_MODE1_TRACK = 0x41, + CDVD_MODE2_TRACK = 0x61 } CDVDTDType; enum { -CDVD_AUDIO_MASK = 0x00, -CDVD_DATA_MASK = 0x40 -// CDROM_DATA_TRACK 0x04 //do not enable this! (from linux kernel) + CDVD_AUDIO_MASK = 0x00, + CDVD_DATA_MASK = 0x40 + // CDROM_DATA_TRACK 0x04 //do not enable this! (from linux kernel) } CDVD_Masks; #endif // __CDVDAPI_H__ \ No newline at end of file diff --git a/common/include/api/Dev9Api.h b/common/include/api/Dev9Api.h index 849202b4dd..e264adbd46 100644 --- a/common/include/api/Dev9Api.h +++ b/common/include/api/Dev9Api.h @@ -32,37 +32,56 @@ #include "Pcsx2Api.h" typedef void (*DEV9callback)(int cycles); -typedef int (*DEV9handler)(void); +typedef int (*DEV9handler)(void); // Basic functions. // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -EXPORT_C_(s32) DEV9init(); +EXPORT_C_(s32) +DEV9init(); // pDisplay normally is passed a handle to the GS plugins window. -EXPORT_C_(s32) DEV9open(void *pDisplay); -EXPORT_C_(void) DEV9close(); -EXPORT_C_(void) DEV9shutdown(); -EXPORT_C_(u8) DEV9read8(u32 addr); -EXPORT_C_(u16) DEV9read16(u32 addr); -EXPORT_C_(u32) DEV9read32(u32 addr); -EXPORT_C_(void) DEV9write8(u32 addr, u8 value); -EXPORT_C_(void) DEV9write16(u32 addr, u16 value); -EXPORT_C_(void) DEV9write32(u32 addr, u32 value); -EXPORT_C_(void) DEV9readDMA8Mem(u32 *pMem, int size); -EXPORT_C_(void) DEV9writeDMA8Mem(u32 *pMem, int size); +EXPORT_C_(s32) +DEV9open(void *pDisplay); +EXPORT_C_(void) +DEV9close(); +EXPORT_C_(void) +DEV9shutdown(); +EXPORT_C_(u8) +DEV9read8(u32 addr); +EXPORT_C_(u16) +DEV9read16(u32 addr); +EXPORT_C_(u32) +DEV9read32(u32 addr); +EXPORT_C_(void) +DEV9write8(u32 addr, u8 value); +EXPORT_C_(void) +DEV9write16(u32 addr, u16 value); +EXPORT_C_(void) +DEV9write32(u32 addr, u32 value); +EXPORT_C_(void) +DEV9readDMA8Mem(u32 *pMem, int size); +EXPORT_C_(void) +DEV9writeDMA8Mem(u32 *pMem, int size); // cycles = IOP cycles before calling callback, // if callback returns 1 the irq is triggered, else not -EXPORT_C_(void) DEV9irqCallback(DEV9callback callback); -EXPORT_C_(DEV9handler) DEV9irqHandler(void); +EXPORT_C_(void) +DEV9irqCallback(DEV9callback callback); +EXPORT_C_(DEV9handler) +DEV9irqHandler(void); // Extended functions -EXPORT_C_(void) DEV9keyEvent(keyEvent *ev); -EXPORT_C_(s32) DEV9freeze(u8 mode, freezeData *data); -EXPORT_C_(void) DEV9configure(); -EXPORT_C_(void) DEV9about(); -EXPORT_C_(s32) DEV9test(); +EXPORT_C_(void) +DEV9keyEvent(keyEvent *ev); +EXPORT_C_(s32) +DEV9freeze(u8 mode, freezeData *data); +EXPORT_C_(void) +DEV9configure(); +EXPORT_C_(void) +DEV9about(); +EXPORT_C_(s32) +DEV9test(); #endif // __DEV9API_H__ diff --git a/common/include/api/FWApi.h b/common/include/api/FWApi.h index 638686ae96..1f4f56497b 100644 --- a/common/include/api/FWApi.h +++ b/common/include/api/FWApi.h @@ -37,22 +37,34 @@ // NOTE: The read/write functions CANNOT use XMM/MMX regs // If you want to use them, need to save and restore current ones -EXPORT_C_(s32) FWinit(); +EXPORT_C_(s32) +FWinit(); // pDisplay normally is passed a handle to the GS plugins window. -EXPORT_C_(s32) FWopen(void *pDisplay); -EXPORT_C_(void) FWclose(); -EXPORT_C_(void) FWshutdown(); -EXPORT_C_(u32) FWread32(u32 addr); -EXPORT_C_(void) FWwrite32(u32 addr, u32 value); -EXPORT_C_(void) FWirqCallback(void (*callback)()); +EXPORT_C_(s32) +FWopen(void *pDisplay); +EXPORT_C_(void) +FWclose(); +EXPORT_C_(void) +FWshutdown(); +EXPORT_C_(u32) +FWread32(u32 addr); +EXPORT_C_(void) +FWwrite32(u32 addr, u32 value); +EXPORT_C_(void) +FWirqCallback(void (*callback)()); // Extended functions -EXPORT_C_(void) FWkeyEvent(keyEvent *ev); -EXPORT_C_(s32) FWfreeze(u8 mode, freezeData *data); -EXPORT_C_(void) FWconfigure(); -EXPORT_C_(void) FWabout(); -EXPORT_C_(s32) FWtest(); +EXPORT_C_(void) +FWkeyEvent(keyEvent *ev); +EXPORT_C_(s32) +FWfreeze(u8 mode, freezeData *data); +EXPORT_C_(void) +FWconfigure(); +EXPORT_C_(void) +FWabout(); +EXPORT_C_(s32) +FWtest(); #endif #endif // __USBAPI_H__ diff --git a/common/include/api/GSApi.h b/common/include/api/GSApi.h index 79a78bee4a..cc42d0698e 100644 --- a/common/include/api/GSApi.h +++ b/common/include/api/GSApi.h @@ -31,55 +31,86 @@ #include "Pcsx2Api.h" -typedef struct _GSdriverInfo { - char name[8]; - void *common; +typedef struct _GSdriverInfo +{ + char name[8]; + void *common; } GSdriverInfo; // Basic functions. -EXPORT_C_(s32) GSinit(); +EXPORT_C_(s32) +GSinit(); // pDisplay normally is passed a handle to the GS plugins window. -EXPORT_C_(s32) GSopen(void *pDisplay, char *Title, bool multithread); -EXPORT_C_(void) GSclose(); -EXPORT_C_(void) GSshutdown(); -EXPORT_C_(void) GSvsync(int field); -EXPORT_C_(void) GSgifTransfer1(u32 *pMem, u32 addr); -EXPORT_C_(void) GSgifTransfer2(u32 *pMem, u32 size); -EXPORT_C_(void) GSgifTransfer3(u32 *pMem, u32 size); -EXPORT_C_(void) GSgetLastTag(u64* ptag); // returns the last tag processed (64 bits) -EXPORT_C_(void) GSgifSoftReset(u32 mask); -EXPORT_C_(void) GSreadFIFO(u64 *mem); -EXPORT_C_(void) GSreadFIFO2(u64 *mem, int qwc); +EXPORT_C_(s32) +GSopen(void *pDisplay, char *Title, bool multithread); +EXPORT_C_(void) +GSclose(); +EXPORT_C_(void) +GSshutdown(); +EXPORT_C_(void) +GSvsync(int field); +EXPORT_C_(void) +GSgifTransfer1(u32 *pMem, u32 addr); +EXPORT_C_(void) +GSgifTransfer2(u32 *pMem, u32 size); +EXPORT_C_(void) +GSgifTransfer3(u32 *pMem, u32 size); +EXPORT_C_(void) +GSgetLastTag(u64 *ptag); // returns the last tag processed (64 bits) +EXPORT_C_(void) +GSgifSoftReset(u32 mask); +EXPORT_C_(void) +GSreadFIFO(u64 *mem); +EXPORT_C_(void) +GSreadFIFO2(u64 *mem, int qwc); // Extended functions // GSkeyEvent gets called when there is a keyEvent from the PAD plugin -EXPORT_C_(void) GSkeyEvent(keyEvent *ev); -EXPORT_C_(void) GSchangeSaveState(s32 state, const char* filename); -EXPORT_C_(void) GSmakeSnapshot(char *path); -EXPORT_C_(void) GSmakeSnapshot2(char *pathname, int* snapdone, int savejpg); -EXPORT_C_(void) GSirqCallback(void (*callback)()); -EXPORT_C_(void) CALLBACK GSprintf(s32 timeout, char *fmt, ...); -EXPORT_C_(void) GSsetBaseMem(void*); -EXPORT_C_(void) GSsetGameCRC(s32 crc, s32 gameoptions); +EXPORT_C_(void) +GSkeyEvent(keyEvent *ev); +EXPORT_C_(void) +GSchangeSaveState(s32 state, const char *filename); +EXPORT_C_(void) +GSmakeSnapshot(char *path); +EXPORT_C_(void) +GSmakeSnapshot2(char *pathname, int *snapdone, int savejpg); +EXPORT_C_(void) +GSirqCallback(void (*callback)()); +EXPORT_C_(void) +CALLBACK GSprintf(s32 timeout, char *fmt, ...); +EXPORT_C_(void) +GSsetBaseMem(void *); +EXPORT_C_(void) +GSsetGameCRC(s32 crc, s32 gameoptions); // controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done -EXPORT_C_(void) GSsetFrameSkip(int frameskip); +EXPORT_C_(void) +GSsetFrameSkip(int frameskip); // if start is true, starts recording spu2 data, else stops // returns true if successful // for now, pData is not used -EXPORT_C_(bool) GSsetupRecording(bool start); +EXPORT_C_(bool) +GSsetupRecording(bool start); -EXPORT_C_(void) GSreset(); -EXPORT_C_(void) GSwriteCSR(u32 value); -EXPORT_C_(void ) GSgetDriverInfo(GSdriverInfo *info); +EXPORT_C_(void) +GSreset(); +EXPORT_C_(void) +GSwriteCSR(u32 value); +EXPORT_C_(void) +GSgetDriverInfo(GSdriverInfo *info); #ifdef _WIN32 -EXPORT_C_(s32) CALLBACK GSsetWindowInfo(winInfo *info); +EXPORT_C_(s32) +CALLBACK GSsetWindowInfo(winInfo *info); #endif -EXPORT_C_(s32) GSfreeze(u8 mode, freezeData *data); -EXPORT_C_(void) GSconfigure(); -EXPORT_C_(void) GSabout(); -EXPORT_C_(s32) GStest(); +EXPORT_C_(s32) +GSfreeze(u8 mode, freezeData *data); +EXPORT_C_(void) +GSconfigure(); +EXPORT_C_(void) +GSabout(); +EXPORT_C_(s32) +GStest(); #endif // __GSAPI_H__ \ No newline at end of file diff --git a/common/include/api/PadApi.h b/common/include/api/PadApi.h index 06f0e11782..0b0e286315 100644 --- a/common/include/api/PadApi.h +++ b/common/include/api/PadApi.h @@ -35,19 +35,27 @@ /* So obsolete that everyone uses it. */ // Basic functions. -EXPORT_C_(s32) PADinit(u32 flags); +EXPORT_C_(s32) +PADinit(u32 flags); // pDisplay normally is passed a handle to the GS plugins window. -EXPORT_C_(s32) PADopen(void *pDisplay); -EXPORT_C_(void) PADclose(); -EXPORT_C_(void) PADshutdown(); +EXPORT_C_(s32) +PADopen(void *pDisplay); +EXPORT_C_(void) +PADclose(); +EXPORT_C_(void) +PADshutdown(); // PADkeyEvent is called every vsync (return NULL if no event) -EXPORT_C_(keyEvent*) PADkeyEvent(); -EXPORT_C_(u8) PADstartPoll(u8 pad); -EXPORT_C_(u8) PADpoll(u8 value); +EXPORT_C_(keyEvent *) +PADkeyEvent(); +EXPORT_C_(u8) +PADstartPoll(u8 pad); +EXPORT_C_(u8) +PADpoll(u8 value); // returns: 1 if supported pad1 // 2 if supported pad2 // 3 if both are supported -EXPORT_C_(u8) PADquery(); +EXPORT_C_(u8) +PADquery(); // call to give a hint to the PAD plugin to query for the keyboard state. A // good plugin will query the OS for keyboard state ONLY in this function. @@ -56,25 +64,33 @@ EXPORT_C_(u8) PADquery(); // the window (and input). Note that PADupdate can be called from a different // thread than the other functions, so mutex or other multithreading primitives // have to be added to maintain data integrity. -EXPORT_C_(void) PADupdate(u8 pad); +EXPORT_C_(void) +PADupdate(u8 pad); // Extended functions -EXPORT_C_(void) PADgsDriverInfo(GSdriverInfo *info); -EXPORT_C_(s32) PADfreeze(u8 mode, freezeData *data); +EXPORT_C_(void) +PADgsDriverInfo(GSdriverInfo *info); +EXPORT_C_(s32) +PADfreeze(u8 mode, freezeData *data); // Returns 1 if the pad plugin wants a multitap on the specified port. // 0 otherwise. -EXPORT_C_(s32) PADqueryMtap(u8 port); +EXPORT_C_(s32) +PADqueryMtap(u8 port); // Sets the active pad slot for the specified port. // Both numbers are 1-based indices. Should return 0 if there's no // pad on the specified slot. Even if PADqueryMtap(port) returns 0, // should handle this properly for slot != 1, so emulator can allow // Multitap to be enabled/disabled elsewhere. -EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot); +EXPORT_C_(s32) +PADsetSlot(u8 port, u8 slot); -EXPORT_C_(void) PADconfigure(); -EXPORT_C_(void) PADabout(); -EXPORT_C_(s32) PADtest(); +EXPORT_C_(void) +PADconfigure(); +EXPORT_C_(void) +PADabout(); +EXPORT_C_(s32) +PADtest(); #endif // __PADAPI_H__ \ No newline at end of file diff --git a/common/include/api/SIOApi.h b/common/include/api/SIOApi.h index a08fd1532a..b74ca069b7 100644 --- a/common/include/api/SIOApi.h +++ b/common/include/api/SIOApi.h @@ -38,49 +38,61 @@ // MTAP SIO plugins should ignore slot values on startPoll, as should RMs (probably). // Port isn't strictly necessary, but doesn't hurt. -typedef int (CALLBACK * SIOchangeSlotCB)(int port, int slot); +typedef int(CALLBACK *SIOchangeSlotCB)(int port, int slot); // Basic functions. // Types is an or-ed combination of SioTypes to initialize. It'd probably be simplest // just to make each SIO plugin support only one type, for simplicity. // SIOchangeSlotCB should *only* be called by MTAP plugins. -EXPORT_C_(s32) SIOinit(int types, SIOchangeSlotCB f); +EXPORT_C_(s32) +SIOinit(int types, SIOchangeSlotCB f); // Single plugin can only be PAD, MTAP, RM, or MC. Only load one plugin of each type, // but not both a PAD and MTAP. Simplifies plugin selection and interface, as well // as API. // pDisplay normally is passed a handle to the GS plugins window. -EXPORT_C_(s32) SIOopen(void *pDisplay); -EXPORT_C_(void) SIOclose(); -EXPORT_C_(void) SIOshutdown(); +EXPORT_C_(s32) +SIOopen(void *pDisplay); +EXPORT_C_(void) +SIOclose(); +EXPORT_C_(void) +SIOshutdown(); // Returns 0 if device doesn't exist. Means old pad plugins can just say nothing // connected to other slots, and SIOpoll won't be called on those slots, ideally. -EXPORT_C_(s32) SIOstartPoll(u8 deviceType, u32 port, u32 slot, u8 *returnValue); +EXPORT_C_(s32) +SIOstartPoll(u8 deviceType, u32 port, u32 slot, u8 *returnValue); // Returns 0 on the last output byte. -EXPORT_C_(s32) SIOpoll(u8 value, u8 *returnValue); +EXPORT_C_(s32) +SIOpoll(u8 value, u8 *returnValue); // returns: SIO_TYPE_{PAD,MTAP,RM,MC} -EXPORT_C_(u32) SIOquery(); +EXPORT_C_(u32) +SIOquery(); // extended funcs -EXPORT_C_(void) SIOconfigure(); -EXPORT_C_(keyEvent*) CALLBACK SIOkeyEvent(); +EXPORT_C_(void) +SIOconfigure(); +EXPORT_C_(keyEvent *) +CALLBACK SIOkeyEvent(); // Save one type at a time. If a plugin supports all 4 types, // should expect 4 calls. Increases savestate compatibility. -EXPORT_C_(s32) SIOfreeze(u8 mode, freezeData *data, int type); -EXPORT_C_(void) SIOabout(); -EXPORT_C_(s32) SIOtest(); +EXPORT_C_(s32) +SIOfreeze(u8 mode, freezeData *data, int type); +EXPORT_C_(void) +SIOabout(); +EXPORT_C_(s32) +SIOtest(); enum { -SIO_TYPE_PAD = 0x00000001, -SIO_TYPE_MTAP = 0x00000004, -SIO_TYPE_RM = 0x00000040, -SIO_TYPE_MC = 0x00000100 + SIO_TYPE_PAD = 0x00000001, + SIO_TYPE_MTAP = 0x00000004, + SIO_TYPE_RM = 0x00000040, + SIO_TYPE_MC = 0x00000100 } SioTypes; #endif // __SIOAPI_H__ \ No newline at end of file diff --git a/common/include/api/Spu2Api.h b/common/include/api/Spu2Api.h index af29e7abfe..47175e39ce 100644 --- a/common/include/api/Spu2Api.h +++ b/common/include/api/Spu2Api.h @@ -31,47 +31,74 @@ #include "Pcsx2Api.h" -EXPORT_C_(s32) SPU2init(); +EXPORT_C_(s32) +SPU2init(); // pDisplay normally is passed a handle to the GS plugins window. -EXPORT_C_(s32) SPU2open(void *pDisplay); -EXPORT_C_(void) SPU2close(); -EXPORT_C_(void) SPU2shutdown(); -EXPORT_C_(void) SPU2write(u32 mem, u16 value); -EXPORT_C_(u16) SPU2read(u32 mem); +EXPORT_C_(s32) +SPU2open(void *pDisplay); +EXPORT_C_(void) +SPU2close(); +EXPORT_C_(void) +SPU2shutdown(); +EXPORT_C_(void) +SPU2write(u32 mem, u16 value); +EXPORT_C_(u16) +SPU2read(u32 mem); // The following calls are depreciated. -EXPORT_C_(void) SPU2readDMA4Mem(u16 *pMem, u32 size); -EXPORT_C_(void) SPU2readDMA7Mem(u16 *pMem, u32 size); -EXPORT_C_(void) SPU2writeDMA4Mem(u16 *pMem, u32 size); -EXPORT_C_(void) SPU2writeDMA7Mem(u16 *pMem, u32 size); -EXPORT_C_(void) SPU2interruptDMA4(); -EXPORT_C_(void) SPU2interruptDMA7(); +EXPORT_C_(void) +SPU2readDMA4Mem(u16 *pMem, u32 size); +EXPORT_C_(void) +SPU2readDMA7Mem(u16 *pMem, u32 size); +EXPORT_C_(void) +SPU2writeDMA4Mem(u16 *pMem, u32 size); +EXPORT_C_(void) +SPU2writeDMA7Mem(u16 *pMem, u32 size); +EXPORT_C_(void) +SPU2interruptDMA4(); +EXPORT_C_(void) +SPU2interruptDMA7(); // These calls replace the calls above. -EXPORT_C_(void) SPU2readDMAMem(u16 *pMem, u32 size, u8 core); -EXPORT_C_(void) SPU2writeDMAMem(u16 *pMem, u32 size, u8 core); -EXPORT_C_(void) SPU2interruptDMA(u8 core); +EXPORT_C_(void) +SPU2readDMAMem(u16 *pMem, u32 size, u8 core); +EXPORT_C_(void) +SPU2writeDMAMem(u16 *pMem, u32 size, u8 core); +EXPORT_C_(void) +SPU2interruptDMA(u8 core); // all addresses passed by dma will be pointers to the array starting at baseaddr // This function is necessary to successfully save and reload the spu2 state -EXPORT_C_(void) SPU2setDMABaseAddr(uptr baseaddr); +EXPORT_C_(void) +SPU2setDMABaseAddr(uptr baseaddr); -EXPORT_C_(u32) SPU2ReadMemAddr(u8 core); -EXPORT_C_(void) SPU2WriteMemAddr(u8 core,u32 value); -EXPORT_C_(void) SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)()); +EXPORT_C_(u32) +SPU2ReadMemAddr(u8 core); +EXPORT_C_(void) +SPU2WriteMemAddr(u8 core, u32 value); +EXPORT_C_(void) +SPU2irqCallback(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)()); // extended funcs // if start is true, starts recording spu2 data, else stops // returns true if successful -EXPORT_C_(bool) SPU2setupRecording(bool start); +EXPORT_C_(bool) +SPU2setupRecording(bool start); -EXPORT_C_(void) SPU2keyEvent(keyEvent *ev); -EXPORT_C_(void) SPU2setClockPtr(u32* ptr); -EXPORT_C_(void) SPU2async(u32 cycles); -EXPORT_C_(s32) SPU2freeze(u8 mode, freezeData *data); -EXPORT_C_(void) SPU2configure(); -EXPORT_C_(void) SPU2about(); -EXPORT_C_(s32) SPU2test(); +EXPORT_C_(void) +SPU2keyEvent(keyEvent *ev); +EXPORT_C_(void) +SPU2setClockPtr(u32 *ptr); +EXPORT_C_(void) +SPU2async(u32 cycles); +EXPORT_C_(s32) +SPU2freeze(u8 mode, freezeData *data); +EXPORT_C_(void) +SPU2configure(); +EXPORT_C_(void) +SPU2about(); +EXPORT_C_(s32) +SPU2test(); #endif diff --git a/common/include/api/USBApi.h b/common/include/api/USBApi.h index 629acb90c4..27e75b436c 100644 --- a/common/include/api/USBApi.h +++ b/common/include/api/USBApi.h @@ -32,34 +32,53 @@ #include "Pcsx2Api.h" typedef void (*USBcallback)(int cycles); -typedef int (*USBhandler)(void); +typedef int (*USBhandler)(void); // Basic functions. -EXPORT_C_(s32) USBinit(); +EXPORT_C_(s32) +USBinit(); // pDisplay normally is passed a handle to the GS plugins window. -EXPORT_C_(s32) USBopen(void *pDisplay); -EXPORT_C_(void) USBclose(); -EXPORT_C_(void) USBshutdown(); -EXPORT_C_(u8) USBread8(u32 addr); -EXPORT_C_(u16) USBread16(u32 addr); -EXPORT_C_(u32) USBread32(u32 addr); -EXPORT_C_(void) USBwrite8(u32 addr, u8 value); -EXPORT_C_(void) USBwrite16(u32 addr, u16 value); -EXPORT_C_(void) USBwrite32(u32 addr, u32 value); -EXPORT_C_(void) USBasync(u32 cycles); +EXPORT_C_(s32) +USBopen(void *pDisplay); +EXPORT_C_(void) +USBclose(); +EXPORT_C_(void) +USBshutdown(); +EXPORT_C_(u8) +USBread8(u32 addr); +EXPORT_C_(u16) +USBread16(u32 addr); +EXPORT_C_(u32) +USBread32(u32 addr); +EXPORT_C_(void) +USBwrite8(u32 addr, u8 value); +EXPORT_C_(void) +USBwrite16(u32 addr, u16 value); +EXPORT_C_(void) +USBwrite32(u32 addr, u32 value); +EXPORT_C_(void) +USBasync(u32 cycles); // cycles = IOP cycles before calling callback, // if callback returns 1 the irq is triggered, else not -EXPORT_C_(void) USBirqCallback(USBcallback callback); -EXPORT_C_(USBhandler) USBirqHandler(void); -EXPORT_C_(void) USBsetRAM(void *mem); +EXPORT_C_(void) +USBirqCallback(USBcallback callback); +EXPORT_C_(USBhandler) +USBirqHandler(void); +EXPORT_C_(void) +USBsetRAM(void *mem); // Extended functions -EXPORT_C_(void) USBkeyEvent(keyEvent *ev); -EXPORT_C_(s32) USBfreeze(u8 mode, freezeData *data); -EXPORT_C_(void) USBconfigure(); -EXPORT_C_(void) USBabout(); -EXPORT_C_(s32) USBtest(); +EXPORT_C_(void) +USBkeyEvent(keyEvent *ev); +EXPORT_C_(s32) +USBfreeze(u8 mode, freezeData *data); +EXPORT_C_(void) +USBconfigure(); +EXPORT_C_(void) +USBabout(); +EXPORT_C_(s32) +USBtest(); #endif // __USBAPI_H__ diff --git a/common/include/x86emitter/implement/bmi.h b/common/include/x86emitter/implement/bmi.h index 52e576b751..6a8e777a6b 100644 --- a/common/include/x86emitter/implement/bmi.h +++ b/common/include/x86emitter/implement/bmi.h @@ -17,21 +17,22 @@ // Implement BMI1/BMI2 instruction set -namespace x86Emitter { +namespace x86Emitter +{ - struct xImplBMI_RVM - { - u8 Prefix; - u8 MbPrefix; - u8 Opcode; +struct xImplBMI_RVM +{ + u8 Prefix; + u8 MbPrefix; + u8 Opcode; - // RVM - // MULX Unsigned multiply without affecting flags, and arbitrary destination registers - // PDEP Parallel bits deposit - // PEXT Parallel bits extract - // ANDN Logical and not ~x & y - void operator()( const xRegisterInt& to, const xRegisterInt& from1, const xRegisterInt& from2) const; - void operator()( const xRegisterInt& to, const xRegisterInt& from1, const xIndirectVoid& from2) const; + // RVM + // MULX Unsigned multiply without affecting flags, and arbitrary destination registers + // PDEP Parallel bits deposit + // PEXT Parallel bits extract + // ANDN Logical and not ~x & y + void operator()(const xRegisterInt &to, const xRegisterInt &from1, const xRegisterInt &from2) const; + void operator()(const xRegisterInt &to, const xRegisterInt &from1, const xIndirectVoid &from2) const; #if 0 // RMV @@ -56,6 +57,5 @@ namespace x86Emitter { void operator()( const xRegisterInt& to, const xRegisterInt& from, u8 imm) const; void operator()( const xRegisterInt& to, const xIndirectVoid& from, u8 imm) const; #endif - }; - +}; } diff --git a/common/include/x86emitter/implement/dwshift.h b/common/include/x86emitter/implement/dwshift.h index edba5703a0..c2eee26656 100644 --- a/common/include/x86emitter/implement/dwshift.h +++ b/common/include/x86emitter/implement/dwshift.h @@ -15,7 +15,8 @@ #pragma once -namespace x86Emitter { +namespace x86Emitter +{ // Implementations here cover SHLD and SHRD. @@ -30,14 +31,14 @@ namespace x86Emitter { // struct xImpl_DwordShift { - u16 OpcodeBase; + u16 OpcodeBase; - void operator()( const xRegister16or32or64& to, const xRegister16or32or64& from, const xRegisterCL& clreg ) const; + void operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from, const xRegisterCL &clreg) const; - void operator()( const xRegister16or32or64& to, const xRegister16or32or64& from, u8 shiftcnt ) const; + void operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from, u8 shiftcnt) const; - void operator()( const xIndirectVoid& dest,const xRegister16or32or64& from, const xRegisterCL& clreg ) const; - void operator()( const xIndirectVoid& dest,const xRegister16or32or64& from, u8 shiftcnt ) const; + void operator()(const xIndirectVoid &dest, const xRegister16or32or64 &from, const xRegisterCL &clreg) const; + void operator()(const xIndirectVoid &dest, const xRegister16or32or64 &from, u8 shiftcnt) const; }; -} // End namespace x86Emitter +} // End namespace x86Emitter diff --git a/common/include/x86emitter/implement/group1.h b/common/include/x86emitter/implement/group1.h index 9703acb60f..1981e133f3 100644 --- a/common/include/x86emitter/implement/group1.h +++ b/common/include/x86emitter/implement/group1.h @@ -15,35 +15,35 @@ #pragma once -namespace x86Emitter { - -enum G1Type +namespace x86Emitter { - G1Type_ADD=0, - G1Type_OR, - G1Type_ADC, - G1Type_SBB, - G1Type_AND, - G1Type_SUB, - G1Type_XOR, - G1Type_CMP + +enum G1Type { + G1Type_ADD = 0, + G1Type_OR, + G1Type_ADC, + G1Type_SBB, + G1Type_AND, + G1Type_SUB, + G1Type_XOR, + G1Type_CMP }; -extern void _g1_EmitOp( G1Type InstType, const xRegisterInt& to, const xRegisterInt& from ); +extern void _g1_EmitOp(G1Type InstType, const xRegisterInt &to, const xRegisterInt &from); // -------------------------------------------------------------------------------------- // xImpl_Group1 // -------------------------------------------------------------------------------------- struct xImpl_Group1 { - G1Type InstType; + G1Type InstType; - void operator()( const xRegisterInt& to, const xRegisterInt& from ) const; + void operator()(const xRegisterInt &to, const xRegisterInt &from) const; - void operator()( const xIndirectVoid& to, const xRegisterInt& from ) const; - void operator()( const xRegisterInt& to, const xIndirectVoid& from ) const; - void operator()( const xRegisterInt& to, int imm ) const; - void operator()( const xIndirect64orLess& to, int imm ) const; + void operator()(const xIndirectVoid &to, const xRegisterInt &from) const; + void operator()(const xRegisterInt &to, const xIndirectVoid &from) const; + void operator()(const xRegisterInt &to, int imm) const; + void operator()(const xIndirect64orLess &to, int imm) const; #if 0 // ------------------------------------------------------------------------ @@ -87,18 +87,18 @@ struct xImpl_Group1 // struct xImpl_G1Logic { - G1Type InstType; + G1Type InstType; - void operator()( const xRegisterInt& to, const xRegisterInt& from ) const; + void operator()(const xRegisterInt &to, const xRegisterInt &from) const; - void operator()( const xIndirectVoid& to, const xRegisterInt& from ) const; - void operator()( const xRegisterInt& to, const xIndirectVoid& from ) const; - void operator()( const xRegisterInt& to, int imm ) const; + void operator()(const xIndirectVoid &to, const xRegisterInt &from) const; + void operator()(const xRegisterInt &to, const xIndirectVoid &from) const; + void operator()(const xRegisterInt &to, int imm) const; - void operator()( const xIndirect64orLess& to, int imm ) const; + void operator()(const xIndirect64orLess &to, int imm) const; - xImplSimd_DestRegSSE PS; // packed single precision - xImplSimd_DestRegSSE PD; // packed double precision + xImplSimd_DestRegSSE PS; // packed single precision + xImplSimd_DestRegSSE PD; // packed double precision }; // ------------------------------------------------------------------------ @@ -106,38 +106,37 @@ struct xImpl_G1Logic // struct xImpl_G1Arith { - G1Type InstType; + G1Type InstType; - void operator()( const xRegisterInt& to, const xRegisterInt& from ) const; + void operator()(const xRegisterInt &to, const xRegisterInt &from) const; - void operator()( const xIndirectVoid& to, const xRegisterInt& from ) const; - void operator()( const xRegisterInt& to, const xIndirectVoid& from ) const; - void operator()( const xRegisterInt& to, int imm ) const; + void operator()(const xIndirectVoid &to, const xRegisterInt &from) const; + void operator()(const xRegisterInt &to, const xIndirectVoid &from) const; + void operator()(const xRegisterInt &to, int imm) const; - void operator()( const xIndirect64orLess& to, int imm ) const; + void operator()(const xIndirect64orLess &to, int imm) const; - xImplSimd_DestRegSSE PS; // packed single precision - xImplSimd_DestRegSSE PD; // packed double precision - xImplSimd_DestRegSSE SS; // scalar single precision - xImplSimd_DestRegSSE SD; // scalar double precision + xImplSimd_DestRegSSE PS; // packed single precision + xImplSimd_DestRegSSE PD; // packed double precision + xImplSimd_DestRegSSE SS; // scalar single precision + xImplSimd_DestRegSSE SD; // scalar double precision }; // ------------------------------------------------------------------------ struct xImpl_G1Compare { - void operator()( const xRegisterInt& to, const xRegisterInt& from ) const; + void operator()(const xRegisterInt &to, const xRegisterInt &from) const; - void operator()( const xIndirectVoid& to, const xRegisterInt& from ) const; - void operator()( const xRegisterInt& to, const xIndirectVoid& from ) const; - void operator()( const xRegisterInt& to, int imm ) const; + void operator()(const xIndirectVoid &to, const xRegisterInt &from) const; + void operator()(const xRegisterInt &to, const xIndirectVoid &from) const; + void operator()(const xRegisterInt &to, int imm) const; - void operator()( const xIndirect64orLess& to, int imm ) const; + void operator()(const xIndirect64orLess &to, int imm) const; - xImplSimd_DestSSE_CmpImm PS; - xImplSimd_DestSSE_CmpImm PD; - xImplSimd_DestSSE_CmpImm SS; - xImplSimd_DestSSE_CmpImm SD; + xImplSimd_DestSSE_CmpImm PS; + xImplSimd_DestSSE_CmpImm PD; + xImplSimd_DestSSE_CmpImm SS; + xImplSimd_DestSSE_CmpImm SD; }; -} // End namespace x86Emitter - +} // End namespace x86Emitter diff --git a/common/include/x86emitter/implement/group2.h b/common/include/x86emitter/implement/group2.h index f0dc936812..ae42e12afa 100644 --- a/common/include/x86emitter/implement/group2.h +++ b/common/include/x86emitter/implement/group2.h @@ -15,18 +15,18 @@ #pragma once -namespace x86Emitter { - -enum G2Type +namespace x86Emitter { - G2Type_ROL=0, - G2Type_ROR, - G2Type_RCL, - G2Type_RCR, - G2Type_SHL, - G2Type_SHR, - G2Type_Unused, - G2Type_SAR + +enum G2Type { + G2Type_ROL = 0, + G2Type_ROR, + G2Type_RCL, + G2Type_RCR, + G2Type_SHL, + G2Type_SHR, + G2Type_Unused, + G2Type_SAR }; // -------------------------------------------------------------------------------------- @@ -38,12 +38,12 @@ enum G2Type // struct xImpl_Group2 { - G2Type InstType; + G2Type InstType; - void operator()( const xRegisterInt& to, const xRegisterCL& from ) const; - void operator()( const xIndirect64orLess& to, const xRegisterCL& from ) const; - void operator()( const xRegisterInt& to, u8 imm ) const; - void operator()( const xIndirect64orLess& to, u8 imm ) const; + void operator()(const xRegisterInt &to, const xRegisterCL &from) const; + void operator()(const xIndirect64orLess &to, const xRegisterCL &from) const; + void operator()(const xRegisterInt &to, u8 imm) const; + void operator()(const xIndirect64orLess &to, u8 imm) const; #if 0 // ------------------------------------------------------------------------ diff --git a/common/include/x86emitter/implement/group3.h b/common/include/x86emitter/implement/group3.h index 1c26cb0313..69eeafed31 100644 --- a/common/include/x86emitter/implement/group3.h +++ b/common/include/x86emitter/implement/group3.h @@ -15,16 +15,16 @@ #pragma once -namespace x86Emitter { - -enum G3Type +namespace x86Emitter { - G3Type_NOT = 2, - G3Type_NEG = 3, - G3Type_MUL = 4, - G3Type_iMUL = 5, // partial implementation, iMul has additional forms in ix86.cpp - G3Type_DIV = 6, - G3Type_iDIV = 7 + +enum G3Type { + G3Type_NOT = 2, + G3Type_NEG = 3, + G3Type_MUL = 4, + G3Type_iMUL = 5, // partial implementation, iMul has additional forms in ix86.cpp + G3Type_DIV = 6, + G3Type_iDIV = 7 }; // -------------------------------------------------------------------------------------- @@ -32,10 +32,10 @@ enum G3Type // -------------------------------------------------------------------------------------- struct xImpl_Group3 { - G3Type InstType; + G3Type InstType; - void operator()( const xRegisterInt& from ) const; - void operator()( const xIndirect64orLess& from ) const; + void operator()(const xRegisterInt &from) const; + void operator()(const xIndirect64orLess &from) const; #if 0 template< typename T > @@ -53,16 +53,16 @@ struct xImpl_Group3 // struct xImpl_MulDivBase { - G3Type InstType; - u16 OpcodeSSE; + G3Type InstType; + u16 OpcodeSSE; - void operator()( const xRegisterInt& from ) const; - void operator()( const xIndirect64orLess& from ) const; + void operator()(const xRegisterInt &from) const; + void operator()(const xIndirect64orLess &from) const; - const xImplSimd_DestRegSSE PS; - const xImplSimd_DestRegSSE PD; - const xImplSimd_DestRegSSE SS; - const xImplSimd_DestRegSSE SD; + const xImplSimd_DestRegSSE PS; + const xImplSimd_DestRegSSE PD; + const xImplSimd_DestRegSSE SS; + const xImplSimd_DestRegSSE SD; }; // -------------------------------------------------------------------------------------- @@ -70,13 +70,13 @@ struct xImpl_MulDivBase // -------------------------------------------------------------------------------------- struct xImpl_iDiv { - void operator()( const xRegisterInt& from ) const; - void operator()( const xIndirect64orLess& from ) const; + void operator()(const xRegisterInt &from) const; + void operator()(const xIndirect64orLess &from) const; - const xImplSimd_DestRegSSE PS; - const xImplSimd_DestRegSSE PD; - const xImplSimd_DestRegSSE SS; - const xImplSimd_DestRegSSE SD; + const xImplSimd_DestRegSSE PS; + const xImplSimd_DestRegSSE PD; + const xImplSimd_DestRegSSE SS; + const xImplSimd_DestRegSSE SD; }; // -------------------------------------------------------------------------------------- @@ -85,25 +85,24 @@ struct xImpl_iDiv // struct xImpl_iMul { - void operator()( const xRegisterInt& from ) const; - void operator()( const xIndirect64orLess& from ) const; + void operator()(const xRegisterInt &from) const; + void operator()(const xIndirect64orLess &from) const; - // The following iMul-specific forms are valid for 16 and 32 bit register operands only! + // The following iMul-specific forms are valid for 16 and 32 bit register operands only! - void operator()( const xRegister32& to, const xRegister32& from ) const; - void operator()( const xRegister32& to, const xIndirectVoid& src ) const; - void operator()( const xRegister16& to, const xRegister16& from ) const; - void operator()( const xRegister16& to, const xIndirectVoid& src ) const; + void operator()(const xRegister32 &to, const xRegister32 &from) const; + void operator()(const xRegister32 &to, const xIndirectVoid &src) const; + void operator()(const xRegister16 &to, const xRegister16 &from) const; + void operator()(const xRegister16 &to, const xIndirectVoid &src) const; - void operator()( const xRegister32& to, const xRegister32& from, s32 imm ) const; - void operator()( const xRegister32& to, const xIndirectVoid& from, s32 imm ) const; - void operator()( const xRegister16& to, const xRegister16& from, s16 imm ) const; - void operator()( const xRegister16& to, const xIndirectVoid& from, s16 imm ) const; + void operator()(const xRegister32 &to, const xRegister32 &from, s32 imm) const; + void operator()(const xRegister32 &to, const xIndirectVoid &from, s32 imm) const; + void operator()(const xRegister16 &to, const xRegister16 &from, s16 imm) const; + void operator()(const xRegister16 &to, const xIndirectVoid &from, s16 imm) const; - const xImplSimd_DestRegSSE PS; - const xImplSimd_DestRegSSE PD; - const xImplSimd_DestRegSSE SS; - const xImplSimd_DestRegSSE SD; + const xImplSimd_DestRegSSE PS; + const xImplSimd_DestRegSSE PD; + const xImplSimd_DestRegSSE SS; + const xImplSimd_DestRegSSE SD; }; - } diff --git a/common/include/x86emitter/implement/helpers.h b/common/include/x86emitter/implement/helpers.h index c0560cf958..f9a58984f4 100644 --- a/common/include/x86emitter/implement/helpers.h +++ b/common/include/x86emitter/implement/helpers.h @@ -15,7 +15,8 @@ #pragma once -namespace x86Emitter { +namespace x86Emitter +{ // helpermess is currently broken >_< @@ -88,4 +89,4 @@ void _DoI_helpermess( const xImpl& helpme, const xDirectOrIndirect& to, const } #endif -} // End namespace x86Emitter +} // End namespace x86Emitter diff --git a/common/include/x86emitter/implement/incdec.h b/common/include/x86emitter/implement/incdec.h index 2dd0e9f91b..2a01a2d345 100644 --- a/common/include/x86emitter/implement/incdec.h +++ b/common/include/x86emitter/implement/incdec.h @@ -18,17 +18,18 @@ // Implementations found here: Increment and Decrement Instructions! // (They're soooo lonely... but I dunno where else to stick this class!) -namespace x86Emitter { +namespace x86Emitter +{ // -------------------------------------------------------------------------------------- // xImpl_IncDec // -------------------------------------------------------------------------------------- struct xImpl_IncDec { - bool isDec; + bool isDec; - void operator()( const xRegisterInt& to ) const; - void operator()( const xIndirect64orLess& to ) const; + void operator()(const xRegisterInt &to) const; + void operator()(const xIndirect64orLess &to) const; }; -} // End namespace x86Emitter +} // End namespace x86Emitter diff --git a/common/include/x86emitter/implement/jmpcall.h b/common/include/x86emitter/implement/jmpcall.h index 285398274f..11191070ab 100644 --- a/common/include/x86emitter/implement/jmpcall.h +++ b/common/include/x86emitter/implement/jmpcall.h @@ -17,171 +17,170 @@ // Implementations found here: CALL and JMP! (unconditional only) -namespace x86Emitter { +namespace x86Emitter +{ -extern void xJccKnownTarget( JccComparisonType comparison, const void* target, bool slideForward ); +extern void xJccKnownTarget(JccComparisonType comparison, const void *target, bool slideForward); // ------------------------------------------------------------------------ struct xImpl_JmpCall { - bool isJmp; + bool isJmp; - void operator()( const xRegisterInt& absreg ) const; - void operator()( const xIndirect64orLess& src ) const; + void operator()(const xRegisterInt &absreg) const; + void operator()(const xIndirect64orLess &src) const; - // Special form for calling functions. This form automatically resolves the - // correct displacement based on the size of the instruction being generated. - void operator()( void* func ) const - { - if( isJmp ) - xJccKnownTarget( Jcc_Unconditional, (void*)(uptr)func, false ); // double cast to/from (uptr) needed to appease GCC - else - { - // calls are relative to the instruction after this one, and length is - // always 5 bytes (16 bit calls are bad mojo, so no bother to do special logic). + // Special form for calling functions. This form automatically resolves the + // correct displacement based on the size of the instruction being generated. + void operator()(void *func) const + { + if (isJmp) + xJccKnownTarget(Jcc_Unconditional, (void *)(uptr)func, false); // double cast to/from (uptr) needed to appease GCC + else { + // calls are relative to the instruction after this one, and length is + // always 5 bytes (16 bit calls are bad mojo, so no bother to do special logic). - sptr dest = (sptr)func - ((sptr)xGetPtr() + 5); - xWrite8( 0xe8 ); - xWrite32( dest ); - } - } + sptr dest = (sptr)func - ((sptr)xGetPtr() + 5); + xWrite8(0xe8); + xWrite32(dest); + } + } }; // yes it is awful. Due to template code is in a header with a nice circular dep. -extern const xImpl_Mov xMOV; -extern const xImpl_JmpCall xCALL; +extern const xImpl_Mov xMOV; +extern const xImpl_JmpCall xCALL; struct xImpl_FastCall { - // FIXME: current 64 bits is mostly a copy/past potentially it would require to push/pop - // some registers. But I think it is enough to handle the first call. +// FIXME: current 64 bits is mostly a copy/past potentially it would require to push/pop +// some registers. But I think it is enough to handle the first call. - // Type unsafety is nice +// Type unsafety is nice #ifdef __x86_64__ #define XFASTCALL \ - xCALL(f); + xCALL(f); #define XFASTCALL1 \ - xMOV(rdi, a1); \ - xCALL(f); + xMOV(rdi, a1); \ + xCALL(f); #define XFASTCALL2 \ - xMOV(rdi, a1); \ - xMOV(rsi, a2); \ - xCALL(f); + xMOV(rdi, a1); \ + xMOV(rsi, a2); \ + xCALL(f); #else #define XFASTCALL \ - xCALL(f); + xCALL(f); #define XFASTCALL1 \ - xMOV(ecx, a1); \ - xCALL(f); + xMOV(ecx, a1); \ + xCALL(f); #define XFASTCALL2 \ - xMOV(ecx, a1); \ - xMOV(edx, a2); \ - xCALL(f); + xMOV(ecx, a1); \ + xMOV(edx, a2); \ + xCALL(f); #endif - void operator()( void* f, const xRegisterLong& a1 = xEmptyReg, const xRegisterLong& a2 = xEmptyReg) const - { + void operator()(void *f, const xRegisterLong &a1 = xEmptyReg, const xRegisterLong &a2 = xEmptyReg) const + { #ifdef __x86_64__ - if (a1.IsEmpty()) { - XFASTCALL; - } else if (a2.IsEmpty()) { - XFASTCALL1; - } else { - XFASTCALL2; - } + if (a1.IsEmpty()) { + XFASTCALL; + } else if (a2.IsEmpty()) { + XFASTCALL1; + } else { + XFASTCALL2; + } #else - if (a1.IsEmpty()) { - XFASTCALL; - } else if (a2.IsEmpty()) { - XFASTCALL1; - } else { - XFASTCALL2; - } + if (a1.IsEmpty()) { + XFASTCALL; + } else if (a2.IsEmpty()) { + XFASTCALL1; + } else { + XFASTCALL2; + } #endif - } + } - template< typename T > __fi - void operator()( T* func, u32 a1, const xRegisterLong& a2) const - { - void* f = (void*)func; + template + __fi void operator()(T *func, u32 a1, const xRegisterLong &a2) const + { + void *f = (void *)func; #ifdef __x86_64__ - XFASTCALL2; + XFASTCALL2; #else - XFASTCALL2; + XFASTCALL2; #endif - } + } - template< typename T > __fi - void operator()( T* func, const xIndirectVoid& a1) const - { - void* f = (void*)func; + template + __fi void operator()(T *func, const xIndirectVoid &a1) const + { + void *f = (void *)func; #ifdef __x86_64__ - XFASTCALL1; + XFASTCALL1; #else - XFASTCALL1; + XFASTCALL1; #endif - } + } - template< typename T > __fi - void operator()( T* func, u32 a1, u32 a2) const - { - void* f = (void*)func; + template + __fi void operator()(T *func, u32 a1, u32 a2) const + { + void *f = (void *)func; #ifdef __x86_64__ - XFASTCALL2; + XFASTCALL2; #else - XFASTCALL2; + XFASTCALL2; #endif - } + } - template< typename T > __fi - void operator()( T* func, u32 a1) const - { - void* f = (void*)func; + template + __fi void operator()(T *func, u32 a1) const + { + void *f = (void *)func; #ifdef __x86_64__ - XFASTCALL1; + XFASTCALL1; #else - XFASTCALL1; + XFASTCALL1; #endif - } + } - void operator()(const xIndirect32& f, const xRegisterLong& a1 = xEmptyReg, const xRegisterLong& a2 = xEmptyReg) const - { + void operator()(const xIndirect32 &f, const xRegisterLong &a1 = xEmptyReg, const xRegisterLong &a2 = xEmptyReg) const + { #ifdef __x86_64__ - if (a1.IsEmpty()) { - XFASTCALL; - } else if (a2.IsEmpty()) { - XFASTCALL1; - } else { - XFASTCALL2; - } + if (a1.IsEmpty()) { + XFASTCALL; + } else if (a2.IsEmpty()) { + XFASTCALL1; + } else { + XFASTCALL2; + } #else - if (a1.IsEmpty()) { - XFASTCALL; - } else if (a2.IsEmpty()) { - XFASTCALL1; - } else { - XFASTCALL2; - } + if (a1.IsEmpty()) { + XFASTCALL; + } else if (a2.IsEmpty()) { + XFASTCALL1; + } else { + XFASTCALL2; + } #endif - } + } #undef XFASTCALL #undef XFASTCALL1 #undef XFASTCALL2 }; -} // End namespace x86Emitter - +} // End namespace x86Emitter diff --git a/common/include/x86emitter/implement/movs.h b/common/include/x86emitter/implement/movs.h index e389c086b9..d159a0ad90 100644 --- a/common/include/x86emitter/implement/movs.h +++ b/common/include/x86emitter/implement/movs.h @@ -18,7 +18,8 @@ // Header: ix86_impl_movs.h -- covers mov, cmov, movsx/movzx, and SETcc (which shares // with cmov many similarities). -namespace x86Emitter { +namespace x86Emitter +{ // -------------------------------------------------------------------------------------- // MovImplAll @@ -27,13 +28,13 @@ namespace x86Emitter { // struct xImpl_Mov { - xImpl_Mov() {} // Satisfy GCC's whims. + xImpl_Mov() {} // Satisfy GCC's whims. - void operator()( const xRegisterInt& to, const xRegisterInt& from ) const; - void operator()( const xIndirectVoid& dest, const xRegisterInt& from ) const; - void operator()( const xRegisterInt& to, const xIndirectVoid& src ) const; - void operator()( const xIndirect64orLess& dest, int imm ) const; - void operator()( const xRegisterInt& to, int imm, bool preserve_flags=false ) const; + void operator()(const xRegisterInt &to, const xRegisterInt &from) const; + void operator()(const xIndirectVoid &dest, const xRegisterInt &from) const; + void operator()(const xRegisterInt &to, const xIndirectVoid &src) const; + void operator()(const xIndirect64orLess &dest, int imm) const; + void operator()(const xRegisterInt &to, int imm, bool preserve_flags = false) const; #if 0 template< typename T > __noinline void operator()( const ModSibBase& to, const xImmReg& immOrReg ) const @@ -84,22 +85,22 @@ struct xImpl_Mov struct xImpl_CMov { - JccComparisonType ccType; - void operator()( const xRegister16or32or64& to, const xRegister16or32or64& from ) const; - void operator()( const xRegister16or32or64& to, const xIndirectVoid& sibsrc ) const; + JccComparisonType ccType; + void operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from) const; + void operator()(const xRegister16or32or64 &to, const xIndirectVoid &sibsrc) const; - //void operator()( const xDirectOrIndirect32& to, const xDirectOrIndirect32& from ); - //void operator()( const xDirectOrIndirect16& to, const xDirectOrIndirect16& from ) const; + //void operator()( const xDirectOrIndirect32& to, const xDirectOrIndirect32& from ); + //void operator()( const xDirectOrIndirect16& to, const xDirectOrIndirect16& from ) const; }; struct xImpl_Set { - JccComparisonType ccType; + JccComparisonType ccType; - void operator()( const xRegister8& to ) const; - void operator()( const xIndirect8& dest ) const; + void operator()(const xRegister8 &to) const; + void operator()(const xIndirect8 &dest) const; - //void operator()( const xDirectOrIndirect8& dest ) const; + //void operator()( const xDirectOrIndirect8& dest ) const; }; @@ -110,16 +111,16 @@ struct xImpl_Set // struct xImpl_MovExtend { - bool SignExtend; + bool SignExtend; - void operator()( const xRegister16or32or64& to, const xRegister8& from ) const; - void operator()( const xRegister16or32or64& to, const xIndirect8& sibsrc ) const; - void operator()( const xRegister32or64& to, const xRegister16& from ) const; - void operator()( const xRegister32or64& to, const xIndirect16& sibsrc ) const; + void operator()(const xRegister16or32or64 &to, const xRegister8 &from) const; + void operator()(const xRegister16or32or64 &to, const xIndirect8 &sibsrc) const; + void operator()(const xRegister32or64 &to, const xRegister16 &from) const; + void operator()(const xRegister32or64 &to, const xIndirect16 &sibsrc) const; - //void operator()( const xRegister32& to, const xDirectOrIndirect16& src ) const; - //void operator()( const xRegister16or32& to, const xDirectOrIndirect8& src ) const; - //void operator()( const xRegister16& to, const xDirectOrIndirect8& src ) const; + //void operator()( const xRegister32& to, const xDirectOrIndirect16& src ) const; + //void operator()( const xRegister16or32& to, const xDirectOrIndirect8& src ) const; + //void operator()( const xRegister16& to, const xDirectOrIndirect8& src ) const; }; -} // End namespace x86Emitter +} // End namespace x86Emitter diff --git a/common/include/x86emitter/implement/simd_arithmetic.h b/common/include/x86emitter/implement/simd_arithmetic.h index fb9f44d8d2..6de68d1f20 100644 --- a/common/include/x86emitter/implement/simd_arithmetic.h +++ b/common/include/x86emitter/implement/simd_arithmetic.h @@ -15,22 +15,23 @@ #pragma once -namespace x86Emitter { +namespace x86Emitter +{ // -------------------------------------------------------------------------------------- // _SimdShiftHelper // -------------------------------------------------------------------------------------- struct _SimdShiftHelper { - u8 Prefix; - u16 Opcode; - u16 OpcodeImm; - u8 Modcode; + u8 Prefix; + u16 Opcode; + u16 OpcodeImm; + u8 Modcode; - void operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const; + void operator()(const xRegisterSSE &to, const xRegisterSSE &from) const; + void operator()(const xRegisterSSE &to, const xIndirectVoid &from) const; - void operator()( const xRegisterSSE& to, u8 imm8 ) const; + void operator()(const xRegisterSSE &to, u8 imm8) const; }; // -------------------------------------------------------------------------------------- @@ -41,70 +42,70 @@ struct _SimdShiftHelper // struct xImplSimd_ShiftWithoutQ { - const _SimdShiftHelper W; - const _SimdShiftHelper D; + const _SimdShiftHelper W; + const _SimdShiftHelper D; }; // Implements PSRL and PSLL // struct xImplSimd_Shift { - const _SimdShiftHelper W; - const _SimdShiftHelper D; - const _SimdShiftHelper Q; + const _SimdShiftHelper W; + const _SimdShiftHelper D; + const _SimdShiftHelper Q; - void DQ( const xRegisterSSE& to, u8 imm8 ) const; + void DQ(const xRegisterSSE &to, u8 imm8) const; }; ////////////////////////////////////////////////////////////////////////////////////////// // struct xImplSimd_AddSub { - const xImplSimd_DestRegEither B; - const xImplSimd_DestRegEither W; - const xImplSimd_DestRegEither D; - const xImplSimd_DestRegEither Q; + const xImplSimd_DestRegEither B; + const xImplSimd_DestRegEither W; + const xImplSimd_DestRegEither D; + const xImplSimd_DestRegEither Q; - // Add/Sub packed signed byte [8bit] integers from src into dest, and saturate the results. - const xImplSimd_DestRegEither SB; + // Add/Sub packed signed byte [8bit] integers from src into dest, and saturate the results. + const xImplSimd_DestRegEither SB; - // Add/Sub packed signed word [16bit] integers from src into dest, and saturate the results. - const xImplSimd_DestRegEither SW; + // Add/Sub packed signed word [16bit] integers from src into dest, and saturate the results. + const xImplSimd_DestRegEither SW; - // Add/Sub packed unsigned byte [8bit] integers from src into dest, and saturate the results. - const xImplSimd_DestRegEither USB; + // Add/Sub packed unsigned byte [8bit] integers from src into dest, and saturate the results. + const xImplSimd_DestRegEither USB; - // Add/Sub packed unsigned word [16bit] integers from src into dest, and saturate the results. - const xImplSimd_DestRegEither USW; + // Add/Sub packed unsigned word [16bit] integers from src into dest, and saturate the results. + const xImplSimd_DestRegEither USW; }; ////////////////////////////////////////////////////////////////////////////////////////// // struct xImplSimd_PMul { - const xImplSimd_DestRegEither LW; - const xImplSimd_DestRegEither HW; - const xImplSimd_DestRegEither HUW; - const xImplSimd_DestRegEither UDQ; + const xImplSimd_DestRegEither LW; + const xImplSimd_DestRegEither HW; + const xImplSimd_DestRegEither HUW; + const xImplSimd_DestRegEither UDQ; - // [SSE-3] PMULHRSW multiplies vertically each signed 16-bit integer from dest with the - // corresponding signed 16-bit integer of source, producing intermediate signed 32-bit - // integers. Each intermediate 32-bit integer is truncated to the 18 most significant - // bits. Rounding is always performed by adding 1 to the least significant bit of the - // 18-bit intermediate result. The final result is obtained by selecting the 16 bits - // immediately to the right of the most significant bit of each 18-bit intermediate - // result and packed to the destination operand. - // - // Both operands can be MMX or XMM registers. Source can be register or memory. - // - const xImplSimd_DestRegEither HRSW; + // [SSE-3] PMULHRSW multiplies vertically each signed 16-bit integer from dest with the + // corresponding signed 16-bit integer of source, producing intermediate signed 32-bit + // integers. Each intermediate 32-bit integer is truncated to the 18 most significant + // bits. Rounding is always performed by adding 1 to the least significant bit of the + // 18-bit intermediate result. The final result is obtained by selecting the 16 bits + // immediately to the right of the most significant bit of each 18-bit intermediate + // result and packed to the destination operand. + // + // Both operands can be MMX or XMM registers. Source can be register or memory. + // + const xImplSimd_DestRegEither HRSW; - // [SSE-4.1] Multiply the packed dword signed integers in dest with src, and store - // the low 32 bits of each product in xmm1. - const xImplSimd_DestRegSSE LD; + // [SSE-4.1] Multiply the packed dword signed integers in dest with src, and store + // the low 32 bits of each product in xmm1. + const xImplSimd_DestRegSSE LD; - // [SSE-4.1] Multiply the packed signed dword integers in dest with src. - const xImplSimd_DestRegSSE DQ; + // [SSE-4.1] Multiply the packed signed dword integers in dest with src. + const xImplSimd_DestRegSSE DQ; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -112,8 +113,8 @@ struct xImplSimd_PMul // struct xImplSimd_rSqrt { - const xImplSimd_DestRegSSE PS; - const xImplSimd_DestRegSSE SS; + const xImplSimd_DestRegSSE PS; + const xImplSimd_DestRegSSE SS; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -121,17 +122,17 @@ struct xImplSimd_rSqrt // struct xImplSimd_Sqrt { - const xImplSimd_DestRegSSE PS; - const xImplSimd_DestRegSSE SS; - const xImplSimd_DestRegSSE SD; + const xImplSimd_DestRegSSE PS; + const xImplSimd_DestRegSSE SS; + const xImplSimd_DestRegSSE SD; }; ////////////////////////////////////////////////////////////////////////////////////////// // struct xImplSimd_AndNot { - const xImplSimd_DestRegSSE PS; - const xImplSimd_DestRegSSE PD; + const xImplSimd_DestRegSSE PS; + const xImplSimd_DestRegSSE PD; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -139,17 +140,17 @@ struct xImplSimd_AndNot // struct xImplSimd_PAbsolute { - // [sSSE-3] Computes the absolute value of bytes in the src, and stores the result - // in dest, as UNSIGNED. - const xImplSimd_DestRegEither B; + // [sSSE-3] Computes the absolute value of bytes in the src, and stores the result + // in dest, as UNSIGNED. + const xImplSimd_DestRegEither B; - // [sSSE-3] Computes the absolute value of word in the src, and stores the result - // in dest, as UNSIGNED. - const xImplSimd_DestRegEither W; + // [sSSE-3] Computes the absolute value of word in the src, and stores the result + // in dest, as UNSIGNED. + const xImplSimd_DestRegEither W; - // [sSSE-3] Computes the absolute value of doublewords in the src, and stores the - // result in dest, as UNSIGNED. - const xImplSimd_DestRegEither D; + // [sSSE-3] Computes the absolute value of doublewords in the src, and stores the + // result in dest, as UNSIGNED. + const xImplSimd_DestRegEither D; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -158,27 +159,26 @@ struct xImplSimd_PAbsolute // struct xImplSimd_PSign { - // [sSSE-3] negates each byte element of dest if the signed integer value of the - // corresponding data element in src is less than zero. If the signed integer value - // of a data element in src is positive, the corresponding data element in dest is - // unchanged. If a data element in src is zero, the corresponding data element in - // dest is set to zero. - const xImplSimd_DestRegEither B; + // [sSSE-3] negates each byte element of dest if the signed integer value of the + // corresponding data element in src is less than zero. If the signed integer value + // of a data element in src is positive, the corresponding data element in dest is + // unchanged. If a data element in src is zero, the corresponding data element in + // dest is set to zero. + const xImplSimd_DestRegEither B; - // [sSSE-3] negates each word element of dest if the signed integer value of the - // corresponding data element in src is less than zero. If the signed integer value - // of a data element in src is positive, the corresponding data element in dest is - // unchanged. If a data element in src is zero, the corresponding data element in - // dest is set to zero. - const xImplSimd_DestRegEither W; - - // [sSSE-3] negates each doubleword element of dest if the signed integer value - // of the corresponding data element in src is less than zero. If the signed integer - // value of a data element in src is positive, the corresponding data element in dest - // is unchanged. If a data element in src is zero, the corresponding data element in - // dest is set to zero. - const xImplSimd_DestRegEither D; + // [sSSE-3] negates each word element of dest if the signed integer value of the + // corresponding data element in src is less than zero. If the signed integer value + // of a data element in src is positive, the corresponding data element in dest is + // unchanged. If a data element in src is zero, the corresponding data element in + // dest is set to zero. + const xImplSimd_DestRegEither W; + // [sSSE-3] negates each doubleword element of dest if the signed integer value + // of the corresponding data element in src is less than zero. If the signed integer + // value of a data element in src is positive, the corresponding data element in dest + // is unchanged. If a data element in src is zero, the corresponding data element in + // dest is set to zero. + const xImplSimd_DestRegEither D; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -186,31 +186,31 @@ struct xImplSimd_PSign // struct xImplSimd_PMultAdd { - // Multiplies the individual signed words of dest by the corresponding signed words - // of src, producing temporary signed, doubleword results. The adjacent doubleword - // results are then summed and stored in the destination operand. - // - // DEST[31:0] = ( DEST[15:0] * SRC[15:0]) + (DEST[31:16] * SRC[31:16] ); - // DEST[63:32] = ( DEST[47:32] * SRC[47:32]) + (DEST[63:48] * SRC[63:48] ); - // [.. repeat in the case of XMM src/dest operands ..] - // - const xImplSimd_DestRegEither WD; + // Multiplies the individual signed words of dest by the corresponding signed words + // of src, producing temporary signed, doubleword results. The adjacent doubleword + // results are then summed and stored in the destination operand. + // + // DEST[31:0] = ( DEST[15:0] * SRC[15:0]) + (DEST[31:16] * SRC[31:16] ); + // DEST[63:32] = ( DEST[47:32] * SRC[47:32]) + (DEST[63:48] * SRC[63:48] ); + // [.. repeat in the case of XMM src/dest operands ..] + // + const xImplSimd_DestRegEither WD; - // [sSSE-3] multiplies vertically each unsigned byte of dest with the corresponding - // signed byte of src, producing intermediate signed 16-bit integers. Each adjacent - // pair of signed words is added and the saturated result is packed to dest. - // For example, the lowest-order bytes (bits 7-0) in src and dest are multiplied - // and the intermediate signed word result is added with the corresponding - // intermediate result from the 2nd lowest-order bytes (bits 15-8) of the operands; - // the sign-saturated result is stored in the lowest word of dest (bits 15-0). - // The same operation is performed on the other pairs of adjacent bytes. - // - // In Coder Speak: - // DEST[15-0] = SaturateToSignedWord( SRC[15-8] * DEST[15-8] + SRC[7-0] * DEST[7-0] ); - // DEST[31-16] = SaturateToSignedWord( SRC[31-24] * DEST[31-24] + SRC[23-16] * DEST[23-16] ); - // [.. repeat for each 16 bits up to 64 (mmx) or 128 (xmm) ..] - // - const xImplSimd_DestRegEither UBSW; + // [sSSE-3] multiplies vertically each unsigned byte of dest with the corresponding + // signed byte of src, producing intermediate signed 16-bit integers. Each adjacent + // pair of signed words is added and the saturated result is packed to dest. + // For example, the lowest-order bytes (bits 7-0) in src and dest are multiplied + // and the intermediate signed word result is added with the corresponding + // intermediate result from the 2nd lowest-order bytes (bits 15-8) of the operands; + // the sign-saturated result is stored in the lowest word of dest (bits 15-0). + // The same operation is performed on the other pairs of adjacent bytes. + // + // In Coder Speak: + // DEST[15-0] = SaturateToSignedWord( SRC[15-8] * DEST[15-8] + SRC[7-0] * DEST[7-0] ); + // DEST[31-16] = SaturateToSignedWord( SRC[31-24] * DEST[31-24] + SRC[23-16] * DEST[23-16] ); + // [.. repeat for each 16 bits up to 64 (mmx) or 128 (xmm) ..] + // + const xImplSimd_DestRegEither UBSW; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -218,21 +218,21 @@ struct xImplSimd_PMultAdd // struct xImplSimd_HorizAdd { - // [SSE-3] Horizontal Add of Packed Data. A three step process: - // * Adds the single-precision floating-point values in the first and second dwords of - // dest and stores the result in the first dword of dest. - // * Adds single-precision floating-point values in the third and fourth dword of dest - // stores the result in the second dword of dest. - // * Adds single-precision floating-point values in the first and second dword of *src* - // and stores the result in the third dword of dest. - const xImplSimd_DestRegSSE PS; + // [SSE-3] Horizontal Add of Packed Data. A three step process: + // * Adds the single-precision floating-point values in the first and second dwords of + // dest and stores the result in the first dword of dest. + // * Adds single-precision floating-point values in the third and fourth dword of dest + // stores the result in the second dword of dest. + // * Adds single-precision floating-point values in the first and second dword of *src* + // and stores the result in the third dword of dest. + const xImplSimd_DestRegSSE PS; - // [SSE-3] Horizontal Add of Packed Data. A two step process: - // * Adds the double-precision floating-point values in the high and low quadwords of - // dest and stores the result in the low quadword of dest. - // * Adds the double-precision floating-point values in the high and low quadwords of - // *src* stores the result in the high quadword of dest. - const xImplSimd_DestRegSSE PD; + // [SSE-3] Horizontal Add of Packed Data. A two step process: + // * Adds the double-precision floating-point values in the high and low quadwords of + // dest and stores the result in the low quadword of dest. + // * Adds the double-precision floating-point values in the high and low quadwords of + // *src* stores the result in the high quadword of dest. + const xImplSimd_DestRegSSE PD; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -240,23 +240,23 @@ struct xImplSimd_HorizAdd // struct xImplSimd_DotProduct { - // [SSE-4.1] Conditionally multiplies the packed single precision floating-point - // values in dest with the packed single-precision floats in src depending on a - // mask extracted from the high 4 bits of the immediate byte. If a condition mask - // bit in Imm8[7:4] is zero, the corresponding multiplication is replaced by a value - // of 0.0. The four resulting single-precision values are summed into an inter- - // mediate result. - // - // The intermediate result is conditionally broadcasted to the destination using a - // broadcast mask specified by bits [3:0] of the immediate byte. If a broadcast - // mask bit is 1, the intermediate result is copied to the corresponding dword - // element in dest. If a broadcast mask bit is zero, the corresponding element in - // the destination is set to zero. - // - xImplSimd_DestRegImmSSE PS; + // [SSE-4.1] Conditionally multiplies the packed single precision floating-point + // values in dest with the packed single-precision floats in src depending on a + // mask extracted from the high 4 bits of the immediate byte. If a condition mask + // bit in Imm8[7:4] is zero, the corresponding multiplication is replaced by a value + // of 0.0. The four resulting single-precision values are summed into an inter- + // mediate result. + // + // The intermediate result is conditionally broadcasted to the destination using a + // broadcast mask specified by bits [3:0] of the immediate byte. If a broadcast + // mask bit is 1, the intermediate result is copied to the corresponding dword + // element in dest. If a broadcast mask bit is zero, the corresponding element in + // the destination is set to zero. + // + xImplSimd_DestRegImmSSE PS; - // [SSE-4.1] - xImplSimd_DestRegImmSSE PD; + // [SSE-4.1] + xImplSimd_DestRegImmSSE PD; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -264,54 +264,53 @@ struct xImplSimd_DotProduct // (SSE4.1 only!) struct xImplSimd_Round { - // [SSE-4.1] Rounds the 4 packed single-precision src values and stores them in dest. - // - // Imm8 specifies control fields for the rounding operation: - // Bit 3 - processor behavior for a precision exception (0: normal, 1: inexact) - // Bit 2 - If enabled, use MXCSR.RC, else use RC specified in bits 1:0 of this Imm8. - // Bits 1:0 - Specifies a rounding mode for this instruction only. - // - // Rounding Mode Reference: - // 0 - Nearest, 1 - Negative Infinity, 2 - Positive infinity, 3 - Truncate. - // - const xImplSimd_DestRegImmSSE PS; + // [SSE-4.1] Rounds the 4 packed single-precision src values and stores them in dest. + // + // Imm8 specifies control fields for the rounding operation: + // Bit 3 - processor behavior for a precision exception (0: normal, 1: inexact) + // Bit 2 - If enabled, use MXCSR.RC, else use RC specified in bits 1:0 of this Imm8. + // Bits 1:0 - Specifies a rounding mode for this instruction only. + // + // Rounding Mode Reference: + // 0 - Nearest, 1 - Negative Infinity, 2 - Positive infinity, 3 - Truncate. + // + const xImplSimd_DestRegImmSSE PS; - // [SSE-4.1] Rounds the 2 packed double-precision src values and stores them in dest. - // - // Imm8 specifies control fields for the rounding operation: - // Bit 3 - processor behavior for a precision exception (0: normal, 1: inexact) - // Bit 2 - If enabled, use MXCSR.RC, else use RC specified in bits 1:0 of this Imm8. - // Bits 1:0 - Specifies a rounding mode for this instruction only. - // - // Rounding Mode Reference: - // 0 - Nearest, 1 - Negative Infinity, 2 - Positive infinity, 3 - Truncate. - // - const xImplSimd_DestRegImmSSE PD; + // [SSE-4.1] Rounds the 2 packed double-precision src values and stores them in dest. + // + // Imm8 specifies control fields for the rounding operation: + // Bit 3 - processor behavior for a precision exception (0: normal, 1: inexact) + // Bit 2 - If enabled, use MXCSR.RC, else use RC specified in bits 1:0 of this Imm8. + // Bits 1:0 - Specifies a rounding mode for this instruction only. + // + // Rounding Mode Reference: + // 0 - Nearest, 1 - Negative Infinity, 2 - Positive infinity, 3 - Truncate. + // + const xImplSimd_DestRegImmSSE PD; - // [SSE-4.1] Rounds the single-precision src value and stores in dest. - // - // Imm8 specifies control fields for the rounding operation: - // Bit 3 - processor behavior for a precision exception (0: normal, 1: inexact) - // Bit 2 - If enabled, use MXCSR.RC, else use RC specified in bits 1:0 of this Imm8. - // Bits 1:0 - Specifies a rounding mode for this instruction only. - // - // Rounding Mode Reference: - // 0 - Nearest, 1 - Negative Infinity, 2 - Positive infinity, 3 - Truncate. - // - const xImplSimd_DestRegImmSSE SS; + // [SSE-4.1] Rounds the single-precision src value and stores in dest. + // + // Imm8 specifies control fields for the rounding operation: + // Bit 3 - processor behavior for a precision exception (0: normal, 1: inexact) + // Bit 2 - If enabled, use MXCSR.RC, else use RC specified in bits 1:0 of this Imm8. + // Bits 1:0 - Specifies a rounding mode for this instruction only. + // + // Rounding Mode Reference: + // 0 - Nearest, 1 - Negative Infinity, 2 - Positive infinity, 3 - Truncate. + // + const xImplSimd_DestRegImmSSE SS; - // [SSE-4.1] Rounds the double-precision src value and stores in dest. - // - // Imm8 specifies control fields for the rounding operation: - // Bit 3 - processor behavior for a precision exception (0: normal, 1: inexact) - // Bit 2 - If enabled, use MXCSR.RC, else use RC specified in bits 1:0 of this Imm8. - // Bits 1:0 - Specifies a rounding mode for this instruction only. - // - // Rounding Mode Reference: - // 0 - Nearest, 1 - Negative Infinity, 2 - Positive infinity, 3 - Truncate. - // - const xImplSimd_DestRegImmSSE SD; + // [SSE-4.1] Rounds the double-precision src value and stores in dest. + // + // Imm8 specifies control fields for the rounding operation: + // Bit 3 - processor behavior for a precision exception (0: normal, 1: inexact) + // Bit 2 - If enabled, use MXCSR.RC, else use RC specified in bits 1:0 of this Imm8. + // Bits 1:0 - Specifies a rounding mode for this instruction only. + // + // Rounding Mode Reference: + // 0 - Nearest, 1 - Negative Infinity, 2 - Positive infinity, 3 - Truncate. + // + const xImplSimd_DestRegImmSSE SD; }; -} // End namespace x86Emitter - +} // End namespace x86Emitter diff --git a/common/include/x86emitter/implement/simd_comparisons.h b/common/include/x86emitter/implement/simd_comparisons.h index d8ffd4eb7c..6bf815f9b1 100644 --- a/common/include/x86emitter/implement/simd_comparisons.h +++ b/common/include/x86emitter/implement/simd_comparisons.h @@ -15,33 +15,34 @@ #pragma once -namespace x86Emitter { +namespace x86Emitter +{ struct xImplSimd_MinMax { - const xImplSimd_DestRegSSE PS; // packed single precision - const xImplSimd_DestRegSSE PD; // packed double precision - const xImplSimd_DestRegSSE SS; // scalar single precision - const xImplSimd_DestRegSSE SD; // scalar double precision + const xImplSimd_DestRegSSE PS; // packed single precision + const xImplSimd_DestRegSSE PD; // packed double precision + const xImplSimd_DestRegSSE SS; // scalar single precision + const xImplSimd_DestRegSSE SD; // scalar double precision }; ////////////////////////////////////////////////////////////////////////////////////////// // struct xImplSimd_Compare { - SSE2_ComparisonType CType; + SSE2_ComparisonType CType; - void PS( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void PS( const xRegisterSSE& to, const xIndirectVoid& from ) const; + void PS(const xRegisterSSE &to, const xRegisterSSE &from) const; + void PS(const xRegisterSSE &to, const xIndirectVoid &from) const; - void PD( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void PD( const xRegisterSSE& to, const xIndirectVoid& from ) const; + void PD(const xRegisterSSE &to, const xRegisterSSE &from) const; + void PD(const xRegisterSSE &to, const xIndirectVoid &from) const; - void SS( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void SS( const xRegisterSSE& to, const xIndirectVoid& from ) const; + void SS(const xRegisterSSE &to, const xRegisterSSE &from) const; + void SS(const xRegisterSSE &to, const xIndirectVoid &from) const; - void SD( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void SD( const xRegisterSSE& to, const xIndirectVoid& from ) const; + void SD(const xRegisterSSE &to, const xRegisterSSE &from) const; + void SD(const xRegisterSSE &to, const xIndirectVoid &from) const; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -49,8 +50,8 @@ struct xImplSimd_Compare // struct xImplSimd_COMI { - const xImplSimd_DestRegSSE SS; - const xImplSimd_DestRegSSE SD; + const xImplSimd_DestRegSSE SS; + const xImplSimd_DestRegSSE SD; }; @@ -59,65 +60,64 @@ struct xImplSimd_COMI struct xImplSimd_PCompare { public: - // Compare packed bytes for equality. - // If a data element in dest is equal to the corresponding date element src, the - // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. - const xImplSimd_DestRegEither EQB; + // Compare packed bytes for equality. + // If a data element in dest is equal to the corresponding date element src, the + // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. + const xImplSimd_DestRegEither EQB; - // Compare packed words for equality. - // If a data element in dest is equal to the corresponding date element src, the - // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. - const xImplSimd_DestRegEither EQW; + // Compare packed words for equality. + // If a data element in dest is equal to the corresponding date element src, the + // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. + const xImplSimd_DestRegEither EQW; - // Compare packed doublewords [32-bits] for equality. - // If a data element in dest is equal to the corresponding date element src, the - // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. - const xImplSimd_DestRegEither EQD; + // Compare packed doublewords [32-bits] for equality. + // If a data element in dest is equal to the corresponding date element src, the + // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. + const xImplSimd_DestRegEither EQD; - // Compare packed signed bytes for greater than. - // If a data element in dest is greater than the corresponding date element src, the - // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. - const xImplSimd_DestRegEither GTB; + // Compare packed signed bytes for greater than. + // If a data element in dest is greater than the corresponding date element src, the + // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. + const xImplSimd_DestRegEither GTB; - // Compare packed signed words for greater than. - // If a data element in dest is greater than the corresponding date element src, the - // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. - const xImplSimd_DestRegEither GTW; + // Compare packed signed words for greater than. + // If a data element in dest is greater than the corresponding date element src, the + // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. + const xImplSimd_DestRegEither GTW; - // Compare packed signed doublewords [32-bits] for greater than. - // If a data element in dest is greater than the corresponding date element src, the - // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. - const xImplSimd_DestRegEither GTD; + // Compare packed signed doublewords [32-bits] for greater than. + // If a data element in dest is greater than the corresponding date element src, the + // corresponding data element in dest is set to all 1s; otherwise, it is set to all 0s. + const xImplSimd_DestRegEither GTD; }; ////////////////////////////////////////////////////////////////////////////////////////// // struct xImplSimd_PMinMax { - // Compare packed unsigned byte integers in dest to src and store packed min/max - // values in dest. - const xImplSimd_DestRegEither UB; + // Compare packed unsigned byte integers in dest to src and store packed min/max + // values in dest. + const xImplSimd_DestRegEither UB; - // Compare packed signed word integers in dest to src and store packed min/max - // values in dest. - const xImplSimd_DestRegEither SW; + // Compare packed signed word integers in dest to src and store packed min/max + // values in dest. + const xImplSimd_DestRegEither SW; - // [SSE-4.1] Compare packed signed byte integers in dest to src and store - // packed min/max values in dest. (SSE operands only) - const xImplSimd_DestRegSSE SB; + // [SSE-4.1] Compare packed signed byte integers in dest to src and store + // packed min/max values in dest. (SSE operands only) + const xImplSimd_DestRegSSE SB; - // [SSE-4.1] Compare packed signed doubleword integers in dest to src and store - // packed min/max values in dest. (SSE operands only) - const xImplSimd_DestRegSSE SD; + // [SSE-4.1] Compare packed signed doubleword integers in dest to src and store + // packed min/max values in dest. (SSE operands only) + const xImplSimd_DestRegSSE SD; - // [SSE-4.1] Compare packed unsigned word integers in dest to src and store - // packed min/max values in dest. (SSE operands only) - const xImplSimd_DestRegSSE UW; + // [SSE-4.1] Compare packed unsigned word integers in dest to src and store + // packed min/max values in dest. (SSE operands only) + const xImplSimd_DestRegSSE UW; - // [SSE-4.1] Compare packed unsigned doubleword integers in dest to src and store - // packed min/max values in dest. (SSE operands only) - const xImplSimd_DestRegSSE UD; + // [SSE-4.1] Compare packed unsigned doubleword integers in dest to src and store + // packed min/max values in dest. (SSE operands only) + const xImplSimd_DestRegSSE UD; }; -} // end namespace x86Emitter - +} // end namespace x86Emitter diff --git a/common/include/x86emitter/implement/simd_helpers.h b/common/include/x86emitter/implement/simd_helpers.h index 606a500076..43719f2366 100644 --- a/common/include/x86emitter/implement/simd_helpers.h +++ b/common/include/x86emitter/implement/simd_helpers.h @@ -15,7 +15,8 @@ #pragma once -namespace x86Emitter { +namespace x86Emitter +{ // ===================================================================================================== // xImpl_SIMD Types (template free!) @@ -27,11 +28,11 @@ namespace x86Emitter { // struct xImplSimd_DestRegSSE { - u8 Prefix; - u16 Opcode; + u8 Prefix; + u16 Opcode; - void operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const; + void operator()(const xRegisterSSE &to, const xRegisterSSE &from) const; + void operator()(const xRegisterSSE &to, const xIndirectVoid &from) const; }; // ------------------------------------------------------------------------ @@ -40,20 +41,20 @@ struct xImplSimd_DestRegSSE // struct xImplSimd_DestRegImmSSE { - u8 Prefix; - u16 Opcode; + u8 Prefix; + u16 Opcode; - void operator()( const xRegisterSSE& to, const xRegisterSSE& from, u8 imm ) const; - void operator()( const xRegisterSSE& to, const xIndirectVoid& from, u8 imm ) const; + void operator()(const xRegisterSSE &to, const xRegisterSSE &from, u8 imm) const; + void operator()(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm) const; }; struct xImplSimd_DestSSE_CmpImm { - u8 Prefix; - u16 Opcode; + u8 Prefix; + u16 Opcode; - void operator()( const xRegisterSSE& to, const xRegisterSSE& from, SSE2_ComparisonType imm ) const; - void operator()( const xRegisterSSE& to, const xIndirectVoid& from, SSE2_ComparisonType imm ) const; + void operator()(const xRegisterSSE &to, const xRegisterSSE &from, SSE2_ComparisonType imm) const; + void operator()(const xRegisterSSE &to, const xIndirectVoid &from, SSE2_ComparisonType imm) const; }; // ------------------------------------------------------------------------ @@ -62,12 +63,11 @@ struct xImplSimd_DestSSE_CmpImm // struct xImplSimd_DestRegEither { - u8 Prefix; - u16 Opcode; + u8 Prefix; + u16 Opcode; - void operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const; + void operator()(const xRegisterSSE &to, const xRegisterSSE &from) const; + void operator()(const xRegisterSSE &to, const xIndirectVoid &from) const; }; -} // end namespace x86Emitter - +} // end namespace x86Emitter diff --git a/common/include/x86emitter/implement/simd_moremovs.h b/common/include/x86emitter/implement/simd_moremovs.h index 40c6392246..72798a15e0 100644 --- a/common/include/x86emitter/implement/simd_moremovs.h +++ b/common/include/x86emitter/implement/simd_moremovs.h @@ -15,7 +15,8 @@ #pragma once -namespace x86Emitter { +namespace x86Emitter +{ // -------------------------------------------------------------------------------------- // xImplSimd_MovHL @@ -25,13 +26,13 @@ namespace x86Emitter { // struct xImplSimd_MovHL { - u16 Opcode; + u16 Opcode; - void PS( const xRegisterSSE& to, const xIndirectVoid& from ) const; - void PS( const xIndirectVoid& to, const xRegisterSSE& from ) const; + void PS(const xRegisterSSE &to, const xIndirectVoid &from) const; + void PS(const xIndirectVoid &to, const xRegisterSSE &from) const; - void PD( const xRegisterSSE& to, const xIndirectVoid& from ) const; - void PD( const xIndirectVoid& to, const xRegisterSSE& from ) const; + void PD(const xRegisterSSE &to, const xIndirectVoid &from) const; + void PD(const xIndirectVoid &to, const xRegisterSSE &from) const; }; // -------------------------------------------------------------------------------------- @@ -42,10 +43,10 @@ struct xImplSimd_MovHL // struct xImplSimd_MovHL_RtoR { - u16 Opcode; + u16 Opcode; - void PS( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void PD( const xRegisterSSE& to, const xRegisterSSE& from ) const; + void PS(const xRegisterSSE &to, const xRegisterSSE &from) const; + void PD(const xRegisterSSE &to, const xRegisterSSE &from) const; }; // -------------------------------------------------------------------------------------- @@ -59,12 +60,12 @@ struct xImplSimd_MovHL_RtoR // struct xImplSimd_MoveSSE { - u8 Prefix; - bool isAligned; + u8 Prefix; + bool isAligned; - void operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const; - void operator()( const xIndirectVoid& to, const xRegisterSSE& from ) const; + void operator()(const xRegisterSSE &to, const xRegisterSSE &from) const; + void operator()(const xRegisterSSE &to, const xIndirectVoid &from) const; + void operator()(const xIndirectVoid &to, const xRegisterSSE &from) const; }; // -------------------------------------------------------------------------------------- @@ -78,12 +79,12 @@ struct xImplSimd_MoveSSE struct xImplSimd_MoveDQ { - u8 Prefix; - bool isAligned; + u8 Prefix; + bool isAligned; - void operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const; - void operator()( const xIndirectVoid& to, const xRegisterSSE& from ) const; + void operator()(const xRegisterSSE &to, const xRegisterSSE &from) const; + void operator()(const xRegisterSSE &to, const xIndirectVoid &from) const; + void operator()(const xIndirectVoid &to, const xRegisterSSE &from) const; }; // -------------------------------------------------------------------------------------- @@ -93,41 +94,41 @@ struct xImplSimd_MoveDQ // struct xImplSimd_Blend { - // [SSE-4.1] Conditionally copies dword values from src to dest, depending on the - // mask bits in the immediate operand (bits [3:0]). Each mask bit corresponds to a - // dword element in a 128-bit operand. - // - // If a mask bit is 1, then the corresponding dword in the source operand is copied - // to dest, else the dword element in dest is left unchanged. - // - xImplSimd_DestRegImmSSE PS; + // [SSE-4.1] Conditionally copies dword values from src to dest, depending on the + // mask bits in the immediate operand (bits [3:0]). Each mask bit corresponds to a + // dword element in a 128-bit operand. + // + // If a mask bit is 1, then the corresponding dword in the source operand is copied + // to dest, else the dword element in dest is left unchanged. + // + xImplSimd_DestRegImmSSE PS; - // [SSE-4.1] Conditionally copies quadword values from src to dest, depending on the - // mask bits in the immediate operand (bits [1:0]). Each mask bit corresponds to a - // quadword element in a 128-bit operand. - // - // If a mask bit is 1, then the corresponding dword in the source operand is copied - // to dest, else the dword element in dest is left unchanged. - // - xImplSimd_DestRegImmSSE PD; + // [SSE-4.1] Conditionally copies quadword values from src to dest, depending on the + // mask bits in the immediate operand (bits [1:0]). Each mask bit corresponds to a + // quadword element in a 128-bit operand. + // + // If a mask bit is 1, then the corresponding dword in the source operand is copied + // to dest, else the dword element in dest is left unchanged. + // + xImplSimd_DestRegImmSSE PD; - // [SSE-4.1] Conditionally copies dword values from src to dest, depending on the - // mask (bits [3:0]) in XMM0 (yes, the fixed register). Each mask bit corresponds - // to a dword element in the 128-bit operand. - // - // If a mask bit is 1, then the corresponding dword in the source operand is copied - // to dest, else the dword element in dest is left unchanged. - // - xImplSimd_DestRegSSE VPS; + // [SSE-4.1] Conditionally copies dword values from src to dest, depending on the + // mask (bits [3:0]) in XMM0 (yes, the fixed register). Each mask bit corresponds + // to a dword element in the 128-bit operand. + // + // If a mask bit is 1, then the corresponding dword in the source operand is copied + // to dest, else the dword element in dest is left unchanged. + // + xImplSimd_DestRegSSE VPS; - // [SSE-4.1] Conditionally copies quadword values from src to dest, depending on the - // mask (bits [1:0]) in XMM0 (yes, the fixed register). Each mask bit corresponds - // to a quadword element in the 128-bit operand. - // - // If a mask bit is 1, then the corresponding dword in the source operand is copied - // to dest, else the dword element in dest is left unchanged. - // - xImplSimd_DestRegSSE VPD; + // [SSE-4.1] Conditionally copies quadword values from src to dest, depending on the + // mask (bits [1:0]) in XMM0 (yes, the fixed register). Each mask bit corresponds + // to a quadword element in the 128-bit operand. + // + // If a mask bit is 1, then the corresponding dword in the source operand is copied + // to dest, else the dword element in dest is left unchanged. + // + xImplSimd_DestRegSSE VPD; }; // -------------------------------------------------------------------------------------- @@ -137,38 +138,36 @@ struct xImplSimd_Blend // struct xImplSimd_PMove { - u16 OpcodeBase; + u16 OpcodeBase; - // [SSE-4.1] Zero/Sign-extend the low byte values in src into word integers - // and store them in dest. - void BW( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void BW( const xRegisterSSE& to, const xIndirect64& from ) const; + // [SSE-4.1] Zero/Sign-extend the low byte values in src into word integers + // and store them in dest. + void BW(const xRegisterSSE &to, const xRegisterSSE &from) const; + void BW(const xRegisterSSE &to, const xIndirect64 &from) const; - // [SSE-4.1] Zero/Sign-extend the low byte values in src into dword integers - // and store them in dest. - void BD( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void BD( const xRegisterSSE& to, const xIndirect32& from ) const; + // [SSE-4.1] Zero/Sign-extend the low byte values in src into dword integers + // and store them in dest. + void BD(const xRegisterSSE &to, const xRegisterSSE &from) const; + void BD(const xRegisterSSE &to, const xIndirect32 &from) const; - // [SSE-4.1] Zero/Sign-extend the low byte values in src into qword integers - // and store them in dest. - void BQ( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void BQ( const xRegisterSSE& to, const xIndirect16& from ) const; + // [SSE-4.1] Zero/Sign-extend the low byte values in src into qword integers + // and store them in dest. + void BQ(const xRegisterSSE &to, const xRegisterSSE &from) const; + void BQ(const xRegisterSSE &to, const xIndirect16 &from) const; - // [SSE-4.1] Zero/Sign-extend the low word values in src into dword integers - // and store them in dest. - void WD( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void WD( const xRegisterSSE& to, const xIndirect64& from ) const; + // [SSE-4.1] Zero/Sign-extend the low word values in src into dword integers + // and store them in dest. + void WD(const xRegisterSSE &to, const xRegisterSSE &from) const; + void WD(const xRegisterSSE &to, const xIndirect64 &from) const; - // [SSE-4.1] Zero/Sign-extend the low word values in src into qword integers - // and store them in dest. - void WQ( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void WQ( const xRegisterSSE& to, const xIndirect32& from ) const; + // [SSE-4.1] Zero/Sign-extend the low word values in src into qword integers + // and store them in dest. + void WQ(const xRegisterSSE &to, const xRegisterSSE &from) const; + void WQ(const xRegisterSSE &to, const xIndirect32 &from) const; - // [SSE-4.1] Zero/Sign-extend the low dword values in src into qword integers - // and store them in dest. - void DQ( const xRegisterSSE& to, const xRegisterSSE& from ) const; - void DQ( const xRegisterSSE& to, const xIndirect64& from ) const; + // [SSE-4.1] Zero/Sign-extend the low dword values in src into qword integers + // and store them in dest. + void DQ(const xRegisterSSE &to, const xRegisterSSE &from) const; + void DQ(const xRegisterSSE &to, const xIndirect64 &from) const; }; - } - diff --git a/common/include/x86emitter/implement/simd_shufflepack.h b/common/include/x86emitter/implement/simd_shufflepack.h index 47b884ab2c..5d5f0634f1 100644 --- a/common/include/x86emitter/implement/simd_shufflepack.h +++ b/common/include/x86emitter/implement/simd_shufflepack.h @@ -15,20 +15,21 @@ #pragma once -namespace x86Emitter { +namespace x86Emitter +{ // -------------------------------------------------------------------------------------- // xImplSimd_Shuffle // -------------------------------------------------------------------------------------- struct xImplSimd_Shuffle { - inline void _selector_assertion_check( u8 selector ) const; + inline void _selector_assertion_check(u8 selector) const; - void PS( const xRegisterSSE& to, const xRegisterSSE& from, u8 selector ) const; - void PS( const xRegisterSSE& to, const xIndirectVoid& from, u8 selector ) const; + void PS(const xRegisterSSE &to, const xRegisterSSE &from, u8 selector) const; + void PS(const xRegisterSSE &to, const xIndirectVoid &from, u8 selector) const; - void PD( const xRegisterSSE& to, const xRegisterSSE& from, u8 selector ) const; - void PD( const xRegisterSSE& to, const xIndirectVoid& from, u8 selector ) const; + void PD(const xRegisterSSE &to, const xRegisterSSE &from, u8 selector) const; + void PD(const xRegisterSSE &to, const xIndirectVoid &from, u8 selector) const; }; // -------------------------------------------------------------------------------------- @@ -36,33 +37,33 @@ struct xImplSimd_Shuffle // -------------------------------------------------------------------------------------- struct xImplSimd_PShuffle { - // Copies doublewords from src and inserts them into dest at dword locations selected - // with the order operand (8 bit immediate). - const xImplSimd_DestRegImmSSE D; + // Copies doublewords from src and inserts them into dest at dword locations selected + // with the order operand (8 bit immediate). + const xImplSimd_DestRegImmSSE D; - // Copies words from the low quadword of src and inserts them into the low quadword - // of dest at word locations selected with the order operand (8 bit immediate). - // The high quadword of src is copied to the high quadword of dest. - const xImplSimd_DestRegImmSSE LW; + // Copies words from the low quadword of src and inserts them into the low quadword + // of dest at word locations selected with the order operand (8 bit immediate). + // The high quadword of src is copied to the high quadword of dest. + const xImplSimd_DestRegImmSSE LW; - // Copies words from the high quadword of src and inserts them into the high quadword - // of dest at word locations selected with the order operand (8 bit immediate). - // The low quadword of src is copied to the low quadword of dest. - const xImplSimd_DestRegImmSSE HW; + // Copies words from the high quadword of src and inserts them into the high quadword + // of dest at word locations selected with the order operand (8 bit immediate). + // The low quadword of src is copied to the low quadword of dest. + const xImplSimd_DestRegImmSSE HW; - // [sSSE-3] Performs in-place shuffles of bytes in dest according to the shuffle - // control mask in src. If the most significant bit (bit[7]) of each byte of the - // shuffle control mask is set, then constant zero is written in the result byte. - // Each byte in the shuffle control mask forms an index to permute the corresponding - // byte in dest. The value of each index is the least significant 4 bits (128-bit - // operation) or 3 bits (64-bit operation) of the shuffle control byte. - // - const xImplSimd_DestRegEither B; + // [sSSE-3] Performs in-place shuffles of bytes in dest according to the shuffle + // control mask in src. If the most significant bit (bit[7]) of each byte of the + // shuffle control mask is set, then constant zero is written in the result byte. + // Each byte in the shuffle control mask forms an index to permute the corresponding + // byte in dest. The value of each index is the least significant 4 bits (128-bit + // operation) or 3 bits (64-bit operation) of the shuffle control byte. + // + const xImplSimd_DestRegEither B; - // below is my test bed for a new system, free of subclasses. Was supposed to improve intellisense - // but it doesn't (makes it worse). Will try again in MSVC 2010. --air +// below is my test bed for a new system, free of subclasses. Was supposed to improve intellisense +// but it doesn't (makes it worse). Will try again in MSVC 2010. --air - #if 0 +#if 0 // Copies words from src and inserts them into dest at word locations selected with // the order operand (8 bit immediate). @@ -92,7 +93,7 @@ struct xImplSimd_PShuffle // void B( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( 0x66, 0x0038 ); } void B( const xRegisterSSE& to, const xIndirectVoid& from ) const { OpWriteSSE( 0x66, 0x0038 ); } - #endif +#endif }; // -------------------------------------------------------------------------------------- @@ -100,23 +101,23 @@ struct xImplSimd_PShuffle // -------------------------------------------------------------------------------------- struct SimdImpl_PUnpack { - // Unpack and interleave low-order bytes from src and dest into dest. - const xImplSimd_DestRegEither LBW; - // Unpack and interleave low-order words from src and dest into dest. - const xImplSimd_DestRegEither LWD; - // Unpack and interleave low-order doublewords from src and dest into dest. - const xImplSimd_DestRegEither LDQ; - // Unpack and interleave low-order quadwords from src and dest into dest. - const xImplSimd_DestRegSSE LQDQ; + // Unpack and interleave low-order bytes from src and dest into dest. + const xImplSimd_DestRegEither LBW; + // Unpack and interleave low-order words from src and dest into dest. + const xImplSimd_DestRegEither LWD; + // Unpack and interleave low-order doublewords from src and dest into dest. + const xImplSimd_DestRegEither LDQ; + // Unpack and interleave low-order quadwords from src and dest into dest. + const xImplSimd_DestRegSSE LQDQ; - // Unpack and interleave high-order bytes from src and dest into dest. - const xImplSimd_DestRegEither HBW; - // Unpack and interleave high-order words from src and dest into dest. - const xImplSimd_DestRegEither HWD; - // Unpack and interleave high-order doublewords from src and dest into dest. - const xImplSimd_DestRegEither HDQ; - // Unpack and interleave high-order quadwords from src and dest into dest. - const xImplSimd_DestRegSSE HQDQ; + // Unpack and interleave high-order bytes from src and dest into dest. + const xImplSimd_DestRegEither HBW; + // Unpack and interleave high-order words from src and dest into dest. + const xImplSimd_DestRegEither HWD; + // Unpack and interleave high-order doublewords from src and dest into dest. + const xImplSimd_DestRegEither HDQ; + // Unpack and interleave high-order quadwords from src and dest into dest. + const xImplSimd_DestRegSSE HQDQ; }; // -------------------------------------------------------------------------------------- @@ -126,21 +127,21 @@ struct SimdImpl_PUnpack // struct SimdImpl_Pack { - // Converts packed signed word integers from src and dest into packed signed - // byte integers in dest, using signed saturation. - const xImplSimd_DestRegEither SSWB; + // Converts packed signed word integers from src and dest into packed signed + // byte integers in dest, using signed saturation. + const xImplSimd_DestRegEither SSWB; - // Converts packed signed dword integers from src and dest into packed signed - // word integers in dest, using signed saturation. - const xImplSimd_DestRegEither SSDW; + // Converts packed signed dword integers from src and dest into packed signed + // word integers in dest, using signed saturation. + const xImplSimd_DestRegEither SSDW; - // Converts packed unsigned word integers from src and dest into packed unsigned - // byte integers in dest, using unsigned saturation. - const xImplSimd_DestRegEither USWB; + // Converts packed unsigned word integers from src and dest into packed unsigned + // byte integers in dest, using unsigned saturation. + const xImplSimd_DestRegEither USWB; - // [SSE-4.1] Converts packed unsigned dword integers from src and dest into packed - // unsigned word integers in dest, using signed saturation. - const xImplSimd_DestRegSSE USDW; + // [SSE-4.1] Converts packed unsigned dword integers from src and dest into packed + // unsigned word integers in dest, using signed saturation. + const xImplSimd_DestRegSSE USDW; }; // -------------------------------------------------------------------------------------- @@ -148,50 +149,50 @@ struct SimdImpl_Pack // -------------------------------------------------------------------------------------- struct xImplSimd_Unpack { - // Unpacks the high doubleword [single-precision] values from src and dest into - // dest, such that the result of dest looks like this: - // dest[0] <- dest[2] - // dest[1] <- src[2] - // dest[2] <- dest[3] - // dest[3] <- src[3] - // - const xImplSimd_DestRegSSE HPS; + // Unpacks the high doubleword [single-precision] values from src and dest into + // dest, such that the result of dest looks like this: + // dest[0] <- dest[2] + // dest[1] <- src[2] + // dest[2] <- dest[3] + // dest[3] <- src[3] + // + const xImplSimd_DestRegSSE HPS; - // Unpacks the high quadword [double-precision] values from src and dest into - // dest, such that the result of dest looks like this: - // dest.lo <- dest.hi - // dest.hi <- src.hi - // - const xImplSimd_DestRegSSE HPD; + // Unpacks the high quadword [double-precision] values from src and dest into + // dest, such that the result of dest looks like this: + // dest.lo <- dest.hi + // dest.hi <- src.hi + // + const xImplSimd_DestRegSSE HPD; - // Unpacks the low doubleword [single-precision] values from src and dest into - // dest, such that the result of dest looks like this: - // dest[3] <- src[1] - // dest[2] <- dest[1] - // dest[1] <- src[0] - // dest[0] <- dest[0] - // - const xImplSimd_DestRegSSE LPS; + // Unpacks the low doubleword [single-precision] values from src and dest into + // dest, such that the result of dest looks like this: + // dest[3] <- src[1] + // dest[2] <- dest[1] + // dest[1] <- src[0] + // dest[0] <- dest[0] + // + const xImplSimd_DestRegSSE LPS; - // Unpacks the low quadword [double-precision] values from src and dest into - // dest, effectively moving the low portion of src into the upper portion of dest. - // The result of dest is loaded as such: - // dest.hi <- src.lo - // dest.lo <- dest.lo [remains unchanged!] - // - const xImplSimd_DestRegSSE LPD; + // Unpacks the low quadword [double-precision] values from src and dest into + // dest, effectively moving the low portion of src into the upper portion of dest. + // The result of dest is loaded as such: + // dest.hi <- src.lo + // dest.lo <- dest.lo [remains unchanged!] + // + const xImplSimd_DestRegSSE LPD; }; struct xImplSimd_InsertExtractHelper { - u16 Opcode; + u16 Opcode; - // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) - void operator()( const xRegisterSSE& to, const xRegister32& from, u8 imm8 ) const; + // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) + void operator()(const xRegisterSSE &to, const xRegister32 &from, u8 imm8) const; - // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) - void operator()( const xRegisterSSE& to, const xIndirectVoid& from, u8 imm8 ) const; + // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) + void operator()(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm8) const; }; // -------------------------------------------------------------------------------------- @@ -201,14 +202,14 @@ struct xImplSimd_InsertExtractHelper // struct xImplSimd_PInsert { - void W( const xRegisterSSE& to, const xRegister32& from, u8 imm8 ) const; - void W( const xRegisterSSE& to, const xIndirectVoid& from, u8 imm8 ) const; + void W(const xRegisterSSE &to, const xRegister32 &from, u8 imm8) const; + void W(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm8) const; - // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) - xImplSimd_InsertExtractHelper B; + // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) + xImplSimd_InsertExtractHelper B; - // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) - xImplSimd_InsertExtractHelper D; + // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) + xImplSimd_InsertExtractHelper D; }; @@ -219,23 +220,22 @@ struct xImplSimd_PInsert // struct SimdImpl_PExtract { - // Copies the word element specified by imm8 from src to dest. The upper bits - // of dest are zero-extended (cleared). This can be used to extract any single packed - // word value from src into an x86 32 bit register. - // - // [SSE-4.1] Note: Indirect memory forms of this instruction are an SSE-4.1 extension! - // - void W( const xRegister32& to, const xRegisterSSE& from, u8 imm8 ) const; - void W( const xIndirectVoid& dest, const xRegisterSSE& from, u8 imm8 ) const; + // Copies the word element specified by imm8 from src to dest. The upper bits + // of dest are zero-extended (cleared). This can be used to extract any single packed + // word value from src into an x86 32 bit register. + // + // [SSE-4.1] Note: Indirect memory forms of this instruction are an SSE-4.1 extension! + // + void W(const xRegister32 &to, const xRegisterSSE &from, u8 imm8) const; + void W(const xIndirectVoid &dest, const xRegisterSSE &from, u8 imm8) const; - // [SSE-4.1] Copies the byte element specified by imm8 from src to dest. The upper bits - // of dest are zero-extended (cleared). This can be used to extract any single packed - // byte value from src into an x86 32 bit register. - const xImplSimd_InsertExtractHelper B; + // [SSE-4.1] Copies the byte element specified by imm8 from src to dest. The upper bits + // of dest are zero-extended (cleared). This can be used to extract any single packed + // byte value from src into an x86 32 bit register. + const xImplSimd_InsertExtractHelper B; - // [SSE-4.1] Copies the dword element specified by imm8 from src to dest. This can be - // used to extract any single packed dword value from src into an x86 32 bit register. - const xImplSimd_InsertExtractHelper D; + // [SSE-4.1] Copies the dword element specified by imm8 from src to dest. This can be + // used to extract any single packed dword value from src into an x86 32 bit register. + const xImplSimd_InsertExtractHelper D; }; - } diff --git a/common/include/x86emitter/implement/simd_templated_helpers.h b/common/include/x86emitter/implement/simd_templated_helpers.h index c2e7d5a371..d7dcf6cfe4 100644 --- a/common/include/x86emitter/implement/simd_templated_helpers.h +++ b/common/include/x86emitter/implement/simd_templated_helpers.h @@ -22,17 +22,17 @@ // For implementing SSE-only logic operations that have xmmreg,xmmreg/rm forms only, // like ANDPS/ANDPD // -template< u8 Prefix, u16 Opcode > +template class SimdImpl_DestRegSSE { public: - __forceinline void operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const { xOpWrite0F( Prefix, Opcode, to, from ); } - __forceinline void operator()( const xRegisterSSE& to, const ModSibBase& from ) const - { - bool isReallyAligned = ((from.Displacement & 0x0f) == 0) && from.Index.IsEmpty() && from.Base.IsEmpty(); - pxAssertDev( isReallyAligned, "Alignment check failed on SSE indirect load." ); - xOpWrite0F( Prefix, Opcode, to, from ); - } + __forceinline void operator()(const xRegisterSSE &to, const xRegisterSSE &from) const { xOpWrite0F(Prefix, Opcode, to, from); } + __forceinline void operator()(const xRegisterSSE &to, const ModSibBase &from) const + { + bool isReallyAligned = ((from.Displacement & 0x0f) == 0) && from.Index.IsEmpty() && from.Base.IsEmpty(); + pxAssertDev(isReallyAligned, "Alignment check failed on SSE indirect load."); + xOpWrite0F(Prefix, Opcode, to, from); + } - SimdImpl_DestRegSSE() {} //GCWho? + SimdImpl_DestRegSSE() {} //GCWho? }; diff --git a/common/include/x86emitter/implement/test.h b/common/include/x86emitter/implement/test.h index 6eee1f1fc0..4d14ff1eda 100644 --- a/common/include/x86emitter/implement/test.h +++ b/common/include/x86emitter/implement/test.h @@ -17,7 +17,8 @@ // Implementations found here: TEST + BTS/BT/BTC/BTR + BSF/BSR! (for lack of better location) -namespace x86Emitter { +namespace x86Emitter +{ // -------------------------------------------------------------------------------------- // xImpl_Test @@ -25,17 +26,16 @@ namespace x86Emitter { // struct xImpl_Test { - void operator()( const xRegisterInt& to, const xRegisterInt& from ) const; - void operator()( const xIndirect64orLess& dest, int imm ) const; - void operator()( const xRegisterInt& to, int imm ) const; + void operator()(const xRegisterInt &to, const xRegisterInt &from) const; + void operator()(const xIndirect64orLess &dest, int imm) const; + void operator()(const xRegisterInt &to, int imm) const; }; -enum G8Type -{ - G8Type_BT = 4, - G8Type_BTS, - G8Type_BTR, - G8Type_BTC, +enum G8Type { + G8Type_BT = 4, + G8Type_BTS, + G8Type_BTR, + G8Type_BTC, }; // -------------------------------------------------------------------------------------- @@ -45,11 +45,11 @@ enum G8Type // struct xImpl_BitScan { - // 0xbc [fwd] / 0xbd [rev] - u16 Opcode; + // 0xbc [fwd] / 0xbd [rev] + u16 Opcode; - void operator()( const xRegister16or32or64& to, const xRegister16or32or64& from ) const; - void operator()( const xRegister16or32or64& to, const xIndirectVoid& sibsrc ) const; + void operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from) const; + void operator()(const xRegister16or32or64 &to, const xIndirectVoid &sibsrc) const; }; // -------------------------------------------------------------------------------------- @@ -59,17 +59,16 @@ struct xImpl_BitScan // struct xImpl_Group8 { - G8Type InstType; + G8Type InstType; - void operator()( const xRegister16or32or64& bitbase, const xRegister16or32or64& bitoffset ) const; - void operator()( const xRegister16or32or64& bitbase, u8 bitoffset ) const; + void operator()(const xRegister16or32or64 &bitbase, const xRegister16or32or64 &bitoffset) const; + void operator()(const xRegister16or32or64 &bitbase, u8 bitoffset) const; - void operator()( const xIndirectVoid& bitbase, const xRegister16or32or64& bitoffset ) const; + void operator()(const xIndirectVoid &bitbase, const xRegister16or32or64 &bitoffset) const; - void operator()( const xIndirect64& bitbase, u8 bitoffset ) const; - void operator()( const xIndirect32& bitbase, u8 bitoffset ) const; - void operator()( const xIndirect16& bitbase, u8 bitoffset ) const; + void operator()(const xIndirect64 &bitbase, u8 bitoffset) const; + void operator()(const xIndirect32 &bitbase, u8 bitoffset) const; + void operator()(const xIndirect16 &bitbase, u8 bitoffset) const; }; -} // End namespace x86Emitter - +} // End namespace x86Emitter diff --git a/common/include/x86emitter/implement/xchg.h b/common/include/x86emitter/implement/xchg.h index 4a555d6885..74ad36c5b3 100644 --- a/common/include/x86emitter/implement/xchg.h +++ b/common/include/x86emitter/implement/xchg.h @@ -18,7 +18,8 @@ // This header file is intended to be the future home of xchg, cmpxchg, xadd, and // other threading-related exchange instructions. -namespace x86Emitter { +namespace x86Emitter +{ -} // End namespace x86Emitter +} // End namespace x86Emitter diff --git a/common/include/x86emitter/instructions.h b/common/include/x86emitter/instructions.h index 9bd62693d9..0212c73d92 100644 --- a/common/include/x86emitter/instructions.h +++ b/common/include/x86emitter/instructions.h @@ -32,472 +32,551 @@ namespace x86Emitter { - extern void xStoreReg( const xRegisterSSE& src ); - extern void xRestoreReg( const xRegisterSSE& dest ); +extern void xStoreReg(const xRegisterSSE &src); +extern void xRestoreReg(const xRegisterSSE &dest); - // ------------------------------------------------------------------------ - // Group 1 Instruction Class +// ------------------------------------------------------------------------ +// Group 1 Instruction Class - extern const xImpl_Group1 xADC; - extern const xImpl_Group1 xSBB; +extern const xImpl_Group1 xADC; +extern const xImpl_Group1 xSBB; - extern const xImpl_G1Logic xAND; - extern const xImpl_G1Logic xOR; - extern const xImpl_G1Logic xXOR; +extern const xImpl_G1Logic xAND; +extern const xImpl_G1Logic xOR; +extern const xImpl_G1Logic xXOR; - extern const xImpl_G1Arith xADD; - extern const xImpl_G1Arith xSUB; - extern const xImpl_G1Compare xCMP; +extern const xImpl_G1Arith xADD; +extern const xImpl_G1Arith xSUB; +extern const xImpl_G1Compare xCMP; - // ------------------------------------------------------------------------ - // Group 2 Instruction Class - // - // Optimization Note: For Imm forms, we ignore the instruction if the shift count is - // zero. This is a safe optimization since any zero-value shift does not affect any - // flags. +// ------------------------------------------------------------------------ +// Group 2 Instruction Class +// +// Optimization Note: For Imm forms, we ignore the instruction if the shift count is +// zero. This is a safe optimization since any zero-value shift does not affect any +// flags. - extern const xImpl_Mov xMOV; - extern const xImpl_Test xTEST; +extern const xImpl_Mov xMOV; +extern const xImpl_Test xTEST; - extern const xImpl_Group2 xROL, xROR, - xRCL, xRCR, - xSHL, xSHR, - xSAR; +extern const xImpl_Group2 xROL, xROR, + xRCL, xRCR, + xSHL, xSHR, + xSAR; - // ------------------------------------------------------------------------ - // Group 3 Instruction Class +// ------------------------------------------------------------------------ +// Group 3 Instruction Class - extern const xImpl_Group3 xNOT, xNEG; - extern const xImpl_Group3 xUMUL, xUDIV; - extern const xImpl_iDiv xDIV; - extern const xImpl_iMul xMUL; +extern const xImpl_Group3 xNOT, xNEG; +extern const xImpl_Group3 xUMUL, xUDIV; +extern const xImpl_iDiv xDIV; +extern const xImpl_iMul xMUL; - extern const xImpl_IncDec xINC, xDEC; +extern const xImpl_IncDec xINC, xDEC; - extern const xImpl_MovExtend xMOVZX, xMOVSX; +extern const xImpl_MovExtend xMOVZX, xMOVSX; - extern const xImpl_DwordShift xSHLD, xSHRD; +extern const xImpl_DwordShift xSHLD, xSHRD; - extern const xImpl_Group8 xBT; - extern const xImpl_Group8 xBTR; - extern const xImpl_Group8 xBTS; - extern const xImpl_Group8 xBTC; +extern const xImpl_Group8 xBT; +extern const xImpl_Group8 xBTR; +extern const xImpl_Group8 xBTS; +extern const xImpl_Group8 xBTC; - extern const xImpl_BitScan xBSF, xBSR; +extern const xImpl_BitScan xBSF, xBSR; - extern const xImpl_JmpCall xJMP; +extern const xImpl_JmpCall xJMP; #ifdef __x86_64__ - // 32 bits Call won't be compatible in 64 bits (different ABI) - // Just a reminder to port the code - [[deprecated]] extern const xImpl_JmpCall xCALL; +// 32 bits Call won't be compatible in 64 bits (different ABI) +// Just a reminder to port the code +[[deprecated]] extern const xImpl_JmpCall xCALL; #else - extern const xImpl_JmpCall xCALL; +extern const xImpl_JmpCall xCALL; #endif - extern const xImpl_FastCall xFastCall; - - // ------------------------------------------------------------------------ - extern const xImpl_CMov - xCMOVA, xCMOVAE, - xCMOVB, xCMOVBE, - xCMOVG, xCMOVGE, - xCMOVL, xCMOVLE, - - xCMOVZ, xCMOVE, - xCMOVNZ, xCMOVNE, - xCMOVO, xCMOVNO, - xCMOVC, xCMOVNC, - - xCMOVS, xCMOVNS, - xCMOVPE, xCMOVPO; - - // ------------------------------------------------------------------------ - extern const xImpl_Set - xSETA, xSETAE, - xSETB, xSETBE, - xSETG, xSETGE, - xSETL, xSETLE, - - xSETZ, xSETE, - xSETNZ, xSETNE, - xSETO, xSETNO, - xSETC, xSETNC, - - xSETS, xSETNS, - xSETPE, xSETPO; - - // ------------------------------------------------------------------------ - // BMI extra instruction requires BMI1/BMI2 - extern const xImplBMI_RVM xMULX, xPDEP, xPEXT, xANDN_S; // Warning xANDN is already used by SSE - - ////////////////////////////////////////////////////////////////////////////////////////// - // Miscellaneous Instructions - // These are all defined inline or in ix86.cpp. - // - - extern void xBSWAP( const xRegister32or64& to ); - - // ----- Lea Instructions (Load Effective Address) ----- - // Note: alternate (void*) forms of these instructions are not provided since those - // forms are functionally equivalent to Mov reg,imm, and thus better written as MOVs - // instead. - - extern void xLEA( xRegister64 to, const xIndirectVoid& src, bool preserve_flags=false ); - extern void xLEA( xRegister32 to, const xIndirectVoid& src, bool preserve_flags=false ); - extern void xLEA( xRegister16 to, const xIndirectVoid& src, bool preserve_flags=false ); - - // ----- Push / Pop Instructions ----- - // Note: pushad/popad implementations are intentionally left out. The instructions are - // invalid in x64, and are super slow on x32. Use multiple Push/Pop instructions instead. - - extern void xPOP( const xIndirectVoid& from ); - extern void xPUSH( const xIndirectVoid& from ); - - extern void xPOP( xRegister32or64 from ); - - extern void xPUSH( u32 imm ); - extern void xPUSH( xRegister32or64 from ); - - // pushes the EFLAGS register onto the stack - extern void xPUSHFD(); - // pops the EFLAGS register from the stack - extern void xPOPFD(); - - // ----- Miscellaneous Instructions ----- - // Various Instructions with no parameter and no special encoding logic. - - extern void xLEAVE(); - extern void xRET(); - extern void xCBW(); - extern void xCWD(); - extern void xCDQ(); - extern void xCWDE(); - - extern void xLAHF(); - extern void xSAHF(); - - extern void xSTC(); - extern void xCLC(); - - // NOP 1-byte - extern void xNOP(); - - extern void xINT( u8 imm ); - extern void xINTO(); - - ////////////////////////////////////////////////////////////////////////////////////////// - // Helper object to handle the various functions ABI - class xScopedStackFrame - { - bool m_base_frame; - bool m_save_base_pointer; - int m_offset; - - public: - xScopedStackFrame(bool base_frame, bool save_base_pointer = false, int offset = 0); - ~xScopedStackFrame(); - }; - - ////////////////////////////////////////////////////////////////////////////////////////// - // JMP / Jcc Instructions! - - extern void xJcc( JccComparisonType comparison, const void* target ); - extern s8* xJcc8( JccComparisonType comparison=Jcc_Unconditional, s8 displacement=0 ); - extern s32* xJcc32( JccComparisonType comparison=Jcc_Unconditional, s32 displacement=0 ); - - // ------------------------------------------------------------------------ - // Conditional jumps to fixed targets. - // Jumps accept any pointer as a valid target (function or data), and will generate either - // 8 or 32 bit displacement versions of the jump, depending on relative displacement of - // the target (efficient!) - // - - template< typename T > __fi void xJE( T* func ) { xJcc( Jcc_Equal, (void*)(uptr)func ); } - template< typename T > __fi void xJZ( T* func ) { xJcc( Jcc_Zero, (void*)(uptr)func ); } - template< typename T > __fi void xJNE( T* func ) { xJcc( Jcc_NotEqual, (void*)(uptr)func ); } - template< typename T > __fi void xJNZ( T* func ) { xJcc( Jcc_NotZero, (void*)(uptr)func ); } - - template< typename T > __fi void xJO( T* func ) { xJcc( Jcc_Overflow, (void*)(uptr)func ); } - template< typename T > __fi void xJNO( T* func ) { xJcc( Jcc_NotOverflow, (void*)(uptr)func ); } - template< typename T > __fi void xJC( T* func ) { xJcc( Jcc_Carry, (void*)(uptr)func ); } - template< typename T > __fi void xJNC( T* func ) { xJcc( Jcc_NotCarry, (void*)(uptr)func ); } - template< typename T > __fi void xJS( T* func ) { xJcc( Jcc_Signed, (void*)(uptr)func ); } - template< typename T > __fi void xJNS( T* func ) { xJcc( Jcc_Unsigned, (void*)(uptr)func ); } - - template< typename T > __fi void xJPE( T* func ) { xJcc( Jcc_ParityEven, (void*)(uptr)func ); } - template< typename T > __fi void xJPO( T* func ) { xJcc( Jcc_ParityOdd, (void*)(uptr)func ); } - - template< typename T > __fi void xJL( T* func ) { xJcc( Jcc_Less, (void*)(uptr)func ); } - template< typename T > __fi void xJLE( T* func ) { xJcc( Jcc_LessOrEqual, (void*)(uptr)func ); } - template< typename T > __fi void xJG( T* func ) { xJcc( Jcc_Greater, (void*)(uptr)func ); } - template< typename T > __fi void xJGE( T* func ) { xJcc( Jcc_GreaterOrEqual, (void*)(uptr)func ); } - - template< typename T > __fi void xJB( T* func ) { xJcc( Jcc_Below, (void*)(uptr)func ); } - template< typename T > __fi void xJBE( T* func ) { xJcc( Jcc_BelowOrEqual, (void*)(uptr)func ); } - template< typename T > __fi void xJA( T* func ) { xJcc( Jcc_Above, (void*)(uptr)func ); } - template< typename T > __fi void xJAE( T* func ) { xJcc( Jcc_AboveOrEqual, (void*)(uptr)func ); } - - // ------------------------------------------------------------------------ - // Forward Jump Helpers (act as labels!) - -#define DEFINE_FORWARD_JUMP( label, cond ) \ - template< typename OperandType > \ - class xForward##label : public xForwardJump \ - { \ - public: \ - xForward##label() : xForwardJump( cond ) {} \ - }; - - // ------------------------------------------------------------------------ - // Note: typedefs below are defined individually in order to appease Intellisense - // resolution. Including them into the class definition macro above breaks it. - - typedef xForwardJump xForwardJump8; - typedef xForwardJump xForwardJump32; - - DEFINE_FORWARD_JUMP( JA, Jcc_Above ); - DEFINE_FORWARD_JUMP( JB, Jcc_Below ); - DEFINE_FORWARD_JUMP( JAE, Jcc_AboveOrEqual ); - DEFINE_FORWARD_JUMP( JBE, Jcc_BelowOrEqual ); - - typedef xForwardJA xForwardJA8; - typedef xForwardJA xForwardJA32; - typedef xForwardJB xForwardJB8; - typedef xForwardJB xForwardJB32; - typedef xForwardJAE xForwardJAE8; - typedef xForwardJAE xForwardJAE32; - typedef xForwardJBE xForwardJBE8; - typedef xForwardJBE xForwardJBE32; - - DEFINE_FORWARD_JUMP( JG, Jcc_Greater ); - DEFINE_FORWARD_JUMP( JL, Jcc_Less ); - DEFINE_FORWARD_JUMP( JGE, Jcc_GreaterOrEqual ); - DEFINE_FORWARD_JUMP( JLE, Jcc_LessOrEqual ); - - typedef xForwardJG xForwardJG8; - typedef xForwardJG xForwardJG32; - typedef xForwardJL xForwardJL8; - typedef xForwardJL xForwardJL32; - typedef xForwardJGE xForwardJGE8; - typedef xForwardJGE xForwardJGE32; - typedef xForwardJLE xForwardJLE8; - typedef xForwardJLE xForwardJLE32; - - DEFINE_FORWARD_JUMP( JZ, Jcc_Zero ); - DEFINE_FORWARD_JUMP( JE, Jcc_Equal ); - DEFINE_FORWARD_JUMP( JNZ, Jcc_NotZero ); - DEFINE_FORWARD_JUMP( JNE, Jcc_NotEqual ); - - typedef xForwardJZ xForwardJZ8; - typedef xForwardJZ xForwardJZ32; - typedef xForwardJE xForwardJE8; - typedef xForwardJE xForwardJE32; - typedef xForwardJNZ xForwardJNZ8; - typedef xForwardJNZ xForwardJNZ32; - typedef xForwardJNE xForwardJNE8; - typedef xForwardJNE xForwardJNE32; - - DEFINE_FORWARD_JUMP( JS, Jcc_Signed ); - DEFINE_FORWARD_JUMP( JNS, Jcc_Unsigned ); - - typedef xForwardJS xForwardJS8; - typedef xForwardJS xForwardJS32; - typedef xForwardJNS xForwardJNS8; - typedef xForwardJNS xForwardJNS32; - - DEFINE_FORWARD_JUMP( JO, Jcc_Overflow ); - DEFINE_FORWARD_JUMP( JNO, Jcc_NotOverflow ); - - typedef xForwardJO xForwardJO8; - typedef xForwardJO xForwardJO32; - typedef xForwardJNO xForwardJNO8; - typedef xForwardJNO xForwardJNO32; - - DEFINE_FORWARD_JUMP( JC, Jcc_Carry ); - DEFINE_FORWARD_JUMP( JNC, Jcc_NotCarry ); - - typedef xForwardJC xForwardJC8; - typedef xForwardJC xForwardJC32; - typedef xForwardJNC xForwardJNC8; - typedef xForwardJNC xForwardJNC32; - - DEFINE_FORWARD_JUMP( JPE, Jcc_ParityEven ); - DEFINE_FORWARD_JUMP( JPO, Jcc_ParityOdd ); - - typedef xForwardJPE xForwardJPE8; - typedef xForwardJPE xForwardJPE32; - typedef xForwardJPO xForwardJPO8; - typedef xForwardJPO xForwardJPO32; - - // ------------------------------------------------------------------------ - - extern void xEMMS(); - extern void xSTMXCSR( const xIndirect32& dest ); - extern void xLDMXCSR( const xIndirect32& src ); - extern void xFXSAVE( const xIndirectVoid& dest ); - extern void xFXRSTOR( const xIndirectVoid& src ); - - extern void xMOVDZX( const xRegisterSSE& to, const xRegister32or64& from ); - extern void xMOVDZX( const xRegisterSSE& to, const xIndirectVoid& src ); - - extern void xMOVD( const xRegister32or64& to, const xRegisterSSE& from ); - extern void xMOVD( const xIndirectVoid& dest, const xRegisterSSE& from ); - - extern void xMOVQ( const xIndirectVoid& dest, const xRegisterSSE& from ); - - extern void xMOVQZX( const xRegisterSSE& to, const xIndirectVoid& src ); - extern void xMOVQZX( const xRegisterSSE& to, const xRegisterSSE& from ); - - extern void xMOVSS( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xMOVSS( const xIndirectVoid& to, const xRegisterSSE& from ); - extern void xMOVSD( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xMOVSD( const xIndirectVoid& to, const xRegisterSSE& from ); - - extern void xMOVSSZX( const xRegisterSSE& to, const xIndirectVoid& from ); - extern void xMOVSDZX( const xRegisterSSE& to, const xIndirectVoid& from ); - - extern void xMOVNTDQA( const xRegisterSSE& to, const xIndirectVoid& from ); - extern void xMOVNTDQA( const xIndirectVoid& to, const xRegisterSSE& from ); - - extern void xMOVNTPD( const xIndirectVoid& to, const xRegisterSSE& from ); - extern void xMOVNTPS( const xIndirectVoid& to, const xRegisterSSE& from ); - - extern void xMOVMSKPS( const xRegister32or64& to, const xRegisterSSE& from ); - extern void xMOVMSKPD( const xRegister32or64& to, const xRegisterSSE& from ); - - extern void xMASKMOV( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xPMOVMSKB( const xRegister32or64& to, const xRegisterSSE& from ); - extern void xPALIGNR( const xRegisterSSE& to, const xRegisterSSE& from, u8 imm8 ); - - // ------------------------------------------------------------------------ - - extern const xImplSimd_MoveSSE xMOVAPS; - extern const xImplSimd_MoveSSE xMOVUPS; - extern const xImplSimd_MoveSSE xMOVAPD; - extern const xImplSimd_MoveSSE xMOVUPD; - -#ifdef ALWAYS_USE_MOVAPS - extern const xImplSimd_MoveSSE xMOVDQA; - extern const xImplSimd_MoveSSE xMOVDQU; -#else - extern const xImplSimd_MoveDQ xMOVDQA; - extern const xImplSimd_MoveDQ xMOVDQU; -#endif - - extern const xImplSimd_MovHL xMOVH; - extern const xImplSimd_MovHL xMOVL; - extern const xImplSimd_MovHL_RtoR xMOVLH; - extern const xImplSimd_MovHL_RtoR xMOVHL; - - extern const xImplSimd_Blend xBLEND; - extern const xImplSimd_PMove xPMOVSX; - extern const xImplSimd_PMove xPMOVZX; - - extern const xImplSimd_DestRegSSE xMOVSLDUP; - extern const xImplSimd_DestRegSSE xMOVSHDUP; - - extern void xINSERTPS( const xRegisterSSE& to, const xRegisterSSE& from, u8 imm8 ); - extern void xINSERTPS( const xRegisterSSE& to, const xIndirect32& from, u8 imm8 ); - - extern void xEXTRACTPS( const xRegister32or64& to, const xRegisterSSE& from, u8 imm8 ); - extern void xEXTRACTPS( const xIndirect32& dest, const xRegisterSSE& from, u8 imm8 ); - - // ------------------------------------------------------------------------ - - extern const xImplSimd_DestRegEither xPAND; - extern const xImplSimd_DestRegEither xPANDN; - extern const xImplSimd_DestRegEither xPOR; - extern const xImplSimd_DestRegEither xPXOR; - - extern const xImplSimd_Shuffle xSHUF; - - // ------------------------------------------------------------------------ - - extern const xImplSimd_DestRegSSE xPTEST; - - extern const xImplSimd_MinMax xMIN; - extern const xImplSimd_MinMax xMAX; - - extern const xImplSimd_Compare xCMPEQ, xCMPLT, - xCMPLE, xCMPUNORD, - xCMPNE, xCMPNLT, - xCMPNLE,xCMPORD; - - extern const xImplSimd_COMI xCOMI; - extern const xImplSimd_COMI xUCOMI; - - extern const xImplSimd_PCompare xPCMP; - extern const xImplSimd_PMinMax xPMIN; - extern const xImplSimd_PMinMax xPMAX; - - // ------------------------------------------------------------------------ - // - // - extern void xCVTDQ2PD( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTDQ2PD( const xRegisterSSE& to, const xIndirect64& from ); - extern void xCVTDQ2PS( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTDQ2PS( const xRegisterSSE& to, const xIndirect128& from ); - - extern void xCVTPD2DQ( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTPD2DQ( const xRegisterSSE& to, const xIndirect128& from ); - extern void xCVTPD2PS( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTPD2PS( const xRegisterSSE& to, const xIndirect128& from ); - - extern void xCVTPI2PD( const xRegisterSSE& to, const xIndirect64& from ); - extern void xCVTPI2PS( const xRegisterSSE& to, const xIndirect64& from ); - - extern void xCVTPS2DQ( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTPS2DQ( const xRegisterSSE& to, const xIndirect128& from ); - extern void xCVTPS2PD( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTPS2PD( const xRegisterSSE& to, const xIndirect64& from ); - - extern void xCVTSD2SI( const xRegister32or64& to, const xRegisterSSE& from ); - extern void xCVTSD2SI( const xRegister32or64& to, const xIndirect64& from ); - extern void xCVTSD2SS( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTSD2SS( const xRegisterSSE& to, const xIndirect64& from ); - extern void xCVTSI2SS( const xRegisterSSE& to, const xRegister32or64& from ); - extern void xCVTSI2SS( const xRegisterSSE& to, const xIndirect32& from ); - - extern void xCVTSS2SD( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTSS2SD( const xRegisterSSE& to, const xIndirect32& from ); - extern void xCVTSS2SI( const xRegister32or64& to, const xRegisterSSE& from ); - extern void xCVTSS2SI( const xRegister32or64& to, const xIndirect32& from ); - - extern void xCVTTPD2DQ( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTTPD2DQ( const xRegisterSSE& to, const xIndirect128& from ); - extern void xCVTTPS2DQ( const xRegisterSSE& to, const xRegisterSSE& from ); - extern void xCVTTPS2DQ( const xRegisterSSE& to, const xIndirect128& from ); - - extern void xCVTTSD2SI( const xRegister32or64& to, const xRegisterSSE& from ); - extern void xCVTTSD2SI( const xRegister32or64& to, const xIndirect64& from ); - extern void xCVTTSS2SI( const xRegister32or64& to, const xRegisterSSE& from ); - extern void xCVTTSS2SI( const xRegister32or64& to, const xIndirect32& from ); - - // ------------------------------------------------------------------------ - - extern const xImplSimd_AndNot xANDN; - extern const xImplSimd_rSqrt xRCP; - extern const xImplSimd_rSqrt xRSQRT; - extern const xImplSimd_Sqrt xSQRT; - - extern const xImplSimd_Shift xPSLL; - extern const xImplSimd_Shift xPSRL; - extern const xImplSimd_ShiftWithoutQ xPSRA; - extern const xImplSimd_AddSub xPADD; - extern const xImplSimd_AddSub xPSUB; - extern const xImplSimd_PMul xPMUL; - extern const xImplSimd_PAbsolute xPABS; - extern const xImplSimd_PSign xPSIGN; - extern const xImplSimd_PMultAdd xPMADD; - extern const xImplSimd_HorizAdd xHADD; - extern const xImplSimd_DotProduct xDP; - extern const xImplSimd_Round xROUND; - - extern const xImplSimd_PShuffle xPSHUF; - extern const SimdImpl_PUnpack xPUNPCK; - extern const xImplSimd_Unpack xUNPCK; - extern const SimdImpl_Pack xPACK; - extern const xImplSimd_PInsert xPINSR; - extern const SimdImpl_PExtract xPEXTR; +extern const xImpl_FastCall xFastCall; +// ------------------------------------------------------------------------ +extern const xImpl_CMov xCMOVA, xCMOVAE, + xCMOVB, xCMOVBE, + xCMOVG, xCMOVGE, + xCMOVL, xCMOVLE, + + xCMOVZ, xCMOVE, + xCMOVNZ, xCMOVNE, + xCMOVO, xCMOVNO, + xCMOVC, xCMOVNC, + + xCMOVS, xCMOVNS, + xCMOVPE, xCMOVPO; + +// ------------------------------------------------------------------------ +extern const xImpl_Set xSETA, xSETAE, + xSETB, xSETBE, + xSETG, xSETGE, + xSETL, xSETLE, + + xSETZ, xSETE, + xSETNZ, xSETNE, + xSETO, xSETNO, + xSETC, xSETNC, + + xSETS, xSETNS, + xSETPE, xSETPO; + +// ------------------------------------------------------------------------ +// BMI extra instruction requires BMI1/BMI2 +extern const xImplBMI_RVM xMULX, xPDEP, xPEXT, xANDN_S; // Warning xANDN is already used by SSE + +////////////////////////////////////////////////////////////////////////////////////////// +// Miscellaneous Instructions +// These are all defined inline or in ix86.cpp. +// + +extern void xBSWAP(const xRegister32or64 &to); + +// ----- Lea Instructions (Load Effective Address) ----- +// Note: alternate (void*) forms of these instructions are not provided since those +// forms are functionally equivalent to Mov reg,imm, and thus better written as MOVs +// instead. + +extern void xLEA(xRegister64 to, const xIndirectVoid &src, bool preserve_flags = false); +extern void xLEA(xRegister32 to, const xIndirectVoid &src, bool preserve_flags = false); +extern void xLEA(xRegister16 to, const xIndirectVoid &src, bool preserve_flags = false); + +// ----- Push / Pop Instructions ----- +// Note: pushad/popad implementations are intentionally left out. The instructions are +// invalid in x64, and are super slow on x32. Use multiple Push/Pop instructions instead. + +extern void xPOP(const xIndirectVoid &from); +extern void xPUSH(const xIndirectVoid &from); + +extern void xPOP(xRegister32or64 from); + +extern void xPUSH(u32 imm); +extern void xPUSH(xRegister32or64 from); + +// pushes the EFLAGS register onto the stack +extern void xPUSHFD(); +// pops the EFLAGS register from the stack +extern void xPOPFD(); + +// ----- Miscellaneous Instructions ----- +// Various Instructions with no parameter and no special encoding logic. + +extern void xLEAVE(); +extern void xRET(); +extern void xCBW(); +extern void xCWD(); +extern void xCDQ(); +extern void xCWDE(); + +extern void xLAHF(); +extern void xSAHF(); + +extern void xSTC(); +extern void xCLC(); + +// NOP 1-byte +extern void xNOP(); + +extern void xINT(u8 imm); +extern void xINTO(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Helper object to handle the various functions ABI +class xScopedStackFrame +{ + bool m_base_frame; + bool m_save_base_pointer; + int m_offset; + +public: + xScopedStackFrame(bool base_frame, bool save_base_pointer = false, int offset = 0); + ~xScopedStackFrame(); +}; + +////////////////////////////////////////////////////////////////////////////////////////// +// JMP / Jcc Instructions! + +extern void xJcc(JccComparisonType comparison, const void *target); +extern s8 *xJcc8(JccComparisonType comparison = Jcc_Unconditional, s8 displacement = 0); +extern s32 *xJcc32(JccComparisonType comparison = Jcc_Unconditional, s32 displacement = 0); + +// ------------------------------------------------------------------------ +// Conditional jumps to fixed targets. +// Jumps accept any pointer as a valid target (function or data), and will generate either +// 8 or 32 bit displacement versions of the jump, depending on relative displacement of +// the target (efficient!) +// + +template +__fi void xJE(T *func) +{ + xJcc(Jcc_Equal, (void *)(uptr)func); +} +template +__fi void xJZ(T *func) +{ + xJcc(Jcc_Zero, (void *)(uptr)func); +} +template +__fi void xJNE(T *func) +{ + xJcc(Jcc_NotEqual, (void *)(uptr)func); +} +template +__fi void xJNZ(T *func) +{ + xJcc(Jcc_NotZero, (void *)(uptr)func); } +template +__fi void xJO(T *func) +{ + xJcc(Jcc_Overflow, (void *)(uptr)func); +} +template +__fi void xJNO(T *func) +{ + xJcc(Jcc_NotOverflow, (void *)(uptr)func); +} +template +__fi void xJC(T *func) +{ + xJcc(Jcc_Carry, (void *)(uptr)func); +} +template +__fi void xJNC(T *func) +{ + xJcc(Jcc_NotCarry, (void *)(uptr)func); +} +template +__fi void xJS(T *func) +{ + xJcc(Jcc_Signed, (void *)(uptr)func); +} +template +__fi void xJNS(T *func) +{ + xJcc(Jcc_Unsigned, (void *)(uptr)func); +} + +template +__fi void xJPE(T *func) +{ + xJcc(Jcc_ParityEven, (void *)(uptr)func); +} +template +__fi void xJPO(T *func) +{ + xJcc(Jcc_ParityOdd, (void *)(uptr)func); +} + +template +__fi void xJL(T *func) +{ + xJcc(Jcc_Less, (void *)(uptr)func); +} +template +__fi void xJLE(T *func) +{ + xJcc(Jcc_LessOrEqual, (void *)(uptr)func); +} +template +__fi void xJG(T *func) +{ + xJcc(Jcc_Greater, (void *)(uptr)func); +} +template +__fi void xJGE(T *func) +{ + xJcc(Jcc_GreaterOrEqual, (void *)(uptr)func); +} + +template +__fi void xJB(T *func) +{ + xJcc(Jcc_Below, (void *)(uptr)func); +} +template +__fi void xJBE(T *func) +{ + xJcc(Jcc_BelowOrEqual, (void *)(uptr)func); +} +template +__fi void xJA(T *func) +{ + xJcc(Jcc_Above, (void *)(uptr)func); +} +template +__fi void xJAE(T *func) +{ + xJcc(Jcc_AboveOrEqual, (void *)(uptr)func); +} + +// ------------------------------------------------------------------------ +// Forward Jump Helpers (act as labels!) + +#define DEFINE_FORWARD_JUMP(label, cond) \ + template \ + class xForward##label : public xForwardJump \ + { \ + public: \ + xForward##label() \ + : xForwardJump(cond) \ + { \ + } \ + }; + +// ------------------------------------------------------------------------ +// Note: typedefs below are defined individually in order to appease Intellisense +// resolution. Including them into the class definition macro above breaks it. + +typedef xForwardJump xForwardJump8; +typedef xForwardJump xForwardJump32; + +DEFINE_FORWARD_JUMP(JA, Jcc_Above); +DEFINE_FORWARD_JUMP(JB, Jcc_Below); +DEFINE_FORWARD_JUMP(JAE, Jcc_AboveOrEqual); +DEFINE_FORWARD_JUMP(JBE, Jcc_BelowOrEqual); + +typedef xForwardJA xForwardJA8; +typedef xForwardJA xForwardJA32; +typedef xForwardJB xForwardJB8; +typedef xForwardJB xForwardJB32; +typedef xForwardJAE xForwardJAE8; +typedef xForwardJAE xForwardJAE32; +typedef xForwardJBE xForwardJBE8; +typedef xForwardJBE xForwardJBE32; + +DEFINE_FORWARD_JUMP(JG, Jcc_Greater); +DEFINE_FORWARD_JUMP(JL, Jcc_Less); +DEFINE_FORWARD_JUMP(JGE, Jcc_GreaterOrEqual); +DEFINE_FORWARD_JUMP(JLE, Jcc_LessOrEqual); + +typedef xForwardJG xForwardJG8; +typedef xForwardJG xForwardJG32; +typedef xForwardJL xForwardJL8; +typedef xForwardJL xForwardJL32; +typedef xForwardJGE xForwardJGE8; +typedef xForwardJGE xForwardJGE32; +typedef xForwardJLE xForwardJLE8; +typedef xForwardJLE xForwardJLE32; + +DEFINE_FORWARD_JUMP(JZ, Jcc_Zero); +DEFINE_FORWARD_JUMP(JE, Jcc_Equal); +DEFINE_FORWARD_JUMP(JNZ, Jcc_NotZero); +DEFINE_FORWARD_JUMP(JNE, Jcc_NotEqual); + +typedef xForwardJZ xForwardJZ8; +typedef xForwardJZ xForwardJZ32; +typedef xForwardJE xForwardJE8; +typedef xForwardJE xForwardJE32; +typedef xForwardJNZ xForwardJNZ8; +typedef xForwardJNZ xForwardJNZ32; +typedef xForwardJNE xForwardJNE8; +typedef xForwardJNE xForwardJNE32; + +DEFINE_FORWARD_JUMP(JS, Jcc_Signed); +DEFINE_FORWARD_JUMP(JNS, Jcc_Unsigned); + +typedef xForwardJS xForwardJS8; +typedef xForwardJS xForwardJS32; +typedef xForwardJNS xForwardJNS8; +typedef xForwardJNS xForwardJNS32; + +DEFINE_FORWARD_JUMP(JO, Jcc_Overflow); +DEFINE_FORWARD_JUMP(JNO, Jcc_NotOverflow); + +typedef xForwardJO xForwardJO8; +typedef xForwardJO xForwardJO32; +typedef xForwardJNO xForwardJNO8; +typedef xForwardJNO xForwardJNO32; + +DEFINE_FORWARD_JUMP(JC, Jcc_Carry); +DEFINE_FORWARD_JUMP(JNC, Jcc_NotCarry); + +typedef xForwardJC xForwardJC8; +typedef xForwardJC xForwardJC32; +typedef xForwardJNC xForwardJNC8; +typedef xForwardJNC xForwardJNC32; + +DEFINE_FORWARD_JUMP(JPE, Jcc_ParityEven); +DEFINE_FORWARD_JUMP(JPO, Jcc_ParityOdd); + +typedef xForwardJPE xForwardJPE8; +typedef xForwardJPE xForwardJPE32; +typedef xForwardJPO xForwardJPO8; +typedef xForwardJPO xForwardJPO32; + +// ------------------------------------------------------------------------ + +extern void xEMMS(); +extern void xSTMXCSR(const xIndirect32 &dest); +extern void xLDMXCSR(const xIndirect32 &src); +extern void xFXSAVE(const xIndirectVoid &dest); +extern void xFXRSTOR(const xIndirectVoid &src); + +extern void xMOVDZX(const xRegisterSSE &to, const xRegister32or64 &from); +extern void xMOVDZX(const xRegisterSSE &to, const xIndirectVoid &src); + +extern void xMOVD(const xRegister32or64 &to, const xRegisterSSE &from); +extern void xMOVD(const xIndirectVoid &dest, const xRegisterSSE &from); + +extern void xMOVQ(const xIndirectVoid &dest, const xRegisterSSE &from); + +extern void xMOVQZX(const xRegisterSSE &to, const xIndirectVoid &src); +extern void xMOVQZX(const xRegisterSSE &to, const xRegisterSSE &from); + +extern void xMOVSS(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xMOVSS(const xIndirectVoid &to, const xRegisterSSE &from); +extern void xMOVSD(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xMOVSD(const xIndirectVoid &to, const xRegisterSSE &from); + +extern void xMOVSSZX(const xRegisterSSE &to, const xIndirectVoid &from); +extern void xMOVSDZX(const xRegisterSSE &to, const xIndirectVoid &from); + +extern void xMOVNTDQA(const xRegisterSSE &to, const xIndirectVoid &from); +extern void xMOVNTDQA(const xIndirectVoid &to, const xRegisterSSE &from); + +extern void xMOVNTPD(const xIndirectVoid &to, const xRegisterSSE &from); +extern void xMOVNTPS(const xIndirectVoid &to, const xRegisterSSE &from); + +extern void xMOVMSKPS(const xRegister32or64 &to, const xRegisterSSE &from); +extern void xMOVMSKPD(const xRegister32or64 &to, const xRegisterSSE &from); + +extern void xMASKMOV(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xPMOVMSKB(const xRegister32or64 &to, const xRegisterSSE &from); +extern void xPALIGNR(const xRegisterSSE &to, const xRegisterSSE &from, u8 imm8); + +// ------------------------------------------------------------------------ + +extern const xImplSimd_MoveSSE xMOVAPS; +extern const xImplSimd_MoveSSE xMOVUPS; +extern const xImplSimd_MoveSSE xMOVAPD; +extern const xImplSimd_MoveSSE xMOVUPD; + +#ifdef ALWAYS_USE_MOVAPS +extern const xImplSimd_MoveSSE xMOVDQA; +extern const xImplSimd_MoveSSE xMOVDQU; +#else +extern const xImplSimd_MoveDQ xMOVDQA; +extern const xImplSimd_MoveDQ xMOVDQU; +#endif + +extern const xImplSimd_MovHL xMOVH; +extern const xImplSimd_MovHL xMOVL; +extern const xImplSimd_MovHL_RtoR xMOVLH; +extern const xImplSimd_MovHL_RtoR xMOVHL; + +extern const xImplSimd_Blend xBLEND; +extern const xImplSimd_PMove xPMOVSX; +extern const xImplSimd_PMove xPMOVZX; + +extern const xImplSimd_DestRegSSE xMOVSLDUP; +extern const xImplSimd_DestRegSSE xMOVSHDUP; + +extern void xINSERTPS(const xRegisterSSE &to, const xRegisterSSE &from, u8 imm8); +extern void xINSERTPS(const xRegisterSSE &to, const xIndirect32 &from, u8 imm8); + +extern void xEXTRACTPS(const xRegister32or64 &to, const xRegisterSSE &from, u8 imm8); +extern void xEXTRACTPS(const xIndirect32 &dest, const xRegisterSSE &from, u8 imm8); + +// ------------------------------------------------------------------------ + +extern const xImplSimd_DestRegEither xPAND; +extern const xImplSimd_DestRegEither xPANDN; +extern const xImplSimd_DestRegEither xPOR; +extern const xImplSimd_DestRegEither xPXOR; + +extern const xImplSimd_Shuffle xSHUF; + +// ------------------------------------------------------------------------ + +extern const xImplSimd_DestRegSSE xPTEST; + +extern const xImplSimd_MinMax xMIN; +extern const xImplSimd_MinMax xMAX; + +extern const xImplSimd_Compare xCMPEQ, xCMPLT, + xCMPLE, xCMPUNORD, + xCMPNE, xCMPNLT, + xCMPNLE, xCMPORD; + +extern const xImplSimd_COMI xCOMI; +extern const xImplSimd_COMI xUCOMI; + +extern const xImplSimd_PCompare xPCMP; +extern const xImplSimd_PMinMax xPMIN; +extern const xImplSimd_PMinMax xPMAX; + +// ------------------------------------------------------------------------ +// +// +extern void xCVTDQ2PD(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTDQ2PD(const xRegisterSSE &to, const xIndirect64 &from); +extern void xCVTDQ2PS(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTDQ2PS(const xRegisterSSE &to, const xIndirect128 &from); + +extern void xCVTPD2DQ(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTPD2DQ(const xRegisterSSE &to, const xIndirect128 &from); +extern void xCVTPD2PS(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTPD2PS(const xRegisterSSE &to, const xIndirect128 &from); + +extern void xCVTPI2PD(const xRegisterSSE &to, const xIndirect64 &from); +extern void xCVTPI2PS(const xRegisterSSE &to, const xIndirect64 &from); + +extern void xCVTPS2DQ(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTPS2DQ(const xRegisterSSE &to, const xIndirect128 &from); +extern void xCVTPS2PD(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTPS2PD(const xRegisterSSE &to, const xIndirect64 &from); + +extern void xCVTSD2SI(const xRegister32or64 &to, const xRegisterSSE &from); +extern void xCVTSD2SI(const xRegister32or64 &to, const xIndirect64 &from); +extern void xCVTSD2SS(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTSD2SS(const xRegisterSSE &to, const xIndirect64 &from); +extern void xCVTSI2SS(const xRegisterSSE &to, const xRegister32or64 &from); +extern void xCVTSI2SS(const xRegisterSSE &to, const xIndirect32 &from); + +extern void xCVTSS2SD(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTSS2SD(const xRegisterSSE &to, const xIndirect32 &from); +extern void xCVTSS2SI(const xRegister32or64 &to, const xRegisterSSE &from); +extern void xCVTSS2SI(const xRegister32or64 &to, const xIndirect32 &from); + +extern void xCVTTPD2DQ(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTTPD2DQ(const xRegisterSSE &to, const xIndirect128 &from); +extern void xCVTTPS2DQ(const xRegisterSSE &to, const xRegisterSSE &from); +extern void xCVTTPS2DQ(const xRegisterSSE &to, const xIndirect128 &from); + +extern void xCVTTSD2SI(const xRegister32or64 &to, const xRegisterSSE &from); +extern void xCVTTSD2SI(const xRegister32or64 &to, const xIndirect64 &from); +extern void xCVTTSS2SI(const xRegister32or64 &to, const xRegisterSSE &from); +extern void xCVTTSS2SI(const xRegister32or64 &to, const xIndirect32 &from); + +// ------------------------------------------------------------------------ + +extern const xImplSimd_AndNot xANDN; +extern const xImplSimd_rSqrt xRCP; +extern const xImplSimd_rSqrt xRSQRT; +extern const xImplSimd_Sqrt xSQRT; + +extern const xImplSimd_Shift xPSLL; +extern const xImplSimd_Shift xPSRL; +extern const xImplSimd_ShiftWithoutQ xPSRA; +extern const xImplSimd_AddSub xPADD; +extern const xImplSimd_AddSub xPSUB; +extern const xImplSimd_PMul xPMUL; +extern const xImplSimd_PAbsolute xPABS; +extern const xImplSimd_PSign xPSIGN; +extern const xImplSimd_PMultAdd xPMADD; +extern const xImplSimd_HorizAdd xHADD; +extern const xImplSimd_DotProduct xDP; +extern const xImplSimd_Round xROUND; + +extern const xImplSimd_PShuffle xPSHUF; +extern const SimdImpl_PUnpack xPUNPCK; +extern const xImplSimd_Unpack xUNPCK; +extern const SimdImpl_Pack xPACK; +extern const xImplSimd_PInsert xPINSR; +extern const SimdImpl_PExtract xPEXTR; +} diff --git a/common/include/x86emitter/internal.h b/common/include/x86emitter/internal.h index f24d660f27..997711d403 100644 --- a/common/include/x86emitter/internal.h +++ b/common/include/x86emitter/internal.h @@ -19,156 +19,164 @@ #include "instructions.h" -namespace x86Emitter { +namespace x86Emitter +{ -#define OpWriteSSE( pre, op ) xOpWrite0F( pre, op, to, from ) +#define OpWriteSSE(pre, op) xOpWrite0F(pre, op, to, from) - extern void SimdPrefix( u8 prefix, u16 opcode ); - extern void EmitSibMagic( uint regfield, const void* address ); - extern void EmitSibMagic( uint regfield, const xIndirectVoid& info ); - extern void EmitSibMagic( uint reg1, const xRegisterBase& reg2 ); - extern void EmitSibMagic( const xRegisterBase& reg1, const xRegisterBase& reg2 ); - extern void EmitSibMagic( const xRegisterBase& reg1, const void* src ); - extern void EmitSibMagic( const xRegisterBase& reg1, const xIndirectVoid& sib ); +extern void SimdPrefix(u8 prefix, u16 opcode); +extern void EmitSibMagic(uint regfield, const void *address); +extern void EmitSibMagic(uint regfield, const xIndirectVoid &info); +extern void EmitSibMagic(uint reg1, const xRegisterBase ®2); +extern void EmitSibMagic(const xRegisterBase ®1, const xRegisterBase ®2); +extern void EmitSibMagic(const xRegisterBase ®1, const void *src); +extern void EmitSibMagic(const xRegisterBase ®1, const xIndirectVoid &sib); - extern void EmitRex( uint regfield, const void* address ); - extern void EmitRex( uint regfield, const xIndirectVoid& info ); - extern void EmitRex( uint reg1, const xRegisterBase& reg2 ); - extern void EmitRex( const xRegisterBase& reg1, const xRegisterBase& reg2 ); - extern void EmitRex( const xRegisterBase& reg1, const void* src ); - extern void EmitRex( const xRegisterBase& reg1, const xIndirectVoid& sib ); +extern void EmitRex(uint regfield, const void *address); +extern void EmitRex(uint regfield, const xIndirectVoid &info); +extern void EmitRex(uint reg1, const xRegisterBase ®2); +extern void EmitRex(const xRegisterBase ®1, const xRegisterBase ®2); +extern void EmitRex(const xRegisterBase ®1, const void *src); +extern void EmitRex(const xRegisterBase ®1, const xIndirectVoid &sib); - extern void _xMovRtoR( const xRegisterInt& to, const xRegisterInt& from ); - - template< typename T > inline - void xWrite( T val ) - { - *(T*)x86Ptr = val; - x86Ptr += sizeof(T); - } - - template< typename T1, typename T2 > __emitinline - void xOpWrite( u8 prefix, u8 opcode, const T1& param1, const T2& param2 ) - { - if( prefix != 0 ) xWrite8( prefix ); - EmitRex( param1, param2 ); - - xWrite8( opcode ); - - EmitSibMagic( param1, param2 ); - } - - template< typename T1, typename T2 > __emitinline - void xOpAccWrite( u8 prefix, u8 opcode, const T1& param1, const T2& param2 ) - { - if( prefix != 0 ) xWrite8( prefix ); - EmitRex( param1, param2 ); - - xWrite8( opcode ); - } - - - ////////////////////////////////////////////////////////////////////////////////////////// - // emitter helpers for xmm instruction with prefixes, most of which are using - // the basic opcode format (items inside braces denote optional or conditional - // emission): - // - // [Prefix] / 0x0f / [OpcodePrefix] / Opcode / ModRM+[SibSB] - // - // Prefixes are typically 0x66, 0xf2, or 0xf3. OpcodePrefixes are either 0x38 or - // 0x3a [and other value will result in assertion failue]. - // - template< typename T1, typename T2 > __emitinline - void xOpWrite0F( u8 prefix, u16 opcode, const T1& param1, const T2& param2 ) - { - if( prefix != 0 ) xWrite8( prefix ); - EmitRex( param1, param2 ); - - SimdPrefix( 0, opcode ); - - EmitSibMagic( param1, param2 ); - } - - template< typename T1, typename T2 > __emitinline - void xOpWrite0F( u8 prefix, u16 opcode, const T1& param1, const T2& param2, u8 imm8 ) - { - xOpWrite0F( prefix, opcode, param1, param2 ); - xWrite8( imm8 ); - } - - template< typename T1, typename T2 > __emitinline - void xOpWrite0F( u16 opcode, const T1& param1, const T2& param2 ) { xOpWrite0F( 0, opcode, param1, param2 ); } - - template< typename T1, typename T2 > __emitinline - void xOpWrite0F( u16 opcode, const T1& param1, const T2& param2, u8 imm8 ) { xOpWrite0F( 0, opcode, param1, param2, imm8 ); } - - // VEX 2 Bytes Prefix - template< typename T1, typename T2, typename T3 > __emitinline - void xOpWriteC5( u8 prefix, u8 opcode, const T1& param1, const T2& param2, const T3& param3 ) - { - pxAssert( prefix == 0 || prefix == 0x66 || prefix == 0xF3 || prefix == 0xF2 ); - - const xRegisterInt& reg = param1.IsReg() ? param1 : param2; - -#ifdef __x86_64__ - u8 nR = reg.IsExtended() ? 0x00 : 0x80; -#else - u8 nR = 0x80; -#endif - u8 L = reg.IsWideSIMD() ? 4 : 0; - - u8 nv = (~param2.GetId() & 0xF) << 3; - - u8 p = - prefix == 0xF2 ? 3 : - prefix == 0xF3 ? 2 : - prefix == 0x66 ? 1 : 0; - - xWrite8( 0xC5 ); - xWrite8( nR | nv | L | p ); - xWrite8( opcode ); - EmitSibMagic( param1, param3 ); - } - - // VEX 3 Bytes Prefix - template< typename T1, typename T2, typename T3 > __emitinline - void xOpWriteC4( u8 prefix, u8 mb_prefix, u8 opcode, const T1& param1, const T2& param2, const T3& param3, int w = -1 ) - { - pxAssert( prefix == 0 || prefix == 0x66 || prefix == 0xF3 || prefix == 0xF2 ); - pxAssert( mb_prefix == 0x0F || mb_prefix == 0x38 || mb_prefix == 0x3A ); - - const xRegisterInt& reg = param1.IsReg() ? param1 : param2; - -#ifdef __x86_64__ - u8 nR = reg.IsExtended() ? 0x00 : 0x80; - u8 nB = param3.IsExtended() ? 0x00 : 0x20; - u8 nX = 0x40; // likely unused so hardwired to disabled -#else - u8 nR = 0x80; - u8 nB = 0x20; - u8 nX = 0x40; -#endif - u8 L = reg.IsWideSIMD() ? 4 : 0; - u8 W = (w == -1) ? (reg.GetOperandSize() == 8 ? 0x80 : 0) : // autodetect the size - 0x80 * w; // take directly the W value - - u8 nv = (~param2.GetId() & 0xF) << 3; - - u8 p = - prefix == 0xF2 ? 3 : - prefix == 0xF3 ? 2 : - prefix == 0x66 ? 1 : 0; - - u8 m = - mb_prefix == 0x3A ? 3 : - mb_prefix == 0x38 ? 2 : 1; - - xWrite8( 0xC4 ); - xWrite8( nR | nX | nB | m ); - xWrite8( W | nv | L | p ); - xWrite8( opcode ); - EmitSibMagic( param1, param3 ); - } +extern void _xMovRtoR(const xRegisterInt &to, const xRegisterInt &from); +template +inline void xWrite(T val) +{ + *(T *)x86Ptr = val; + x86Ptr += sizeof(T); } +template +__emitinline void xOpWrite(u8 prefix, u8 opcode, const T1 ¶m1, const T2 ¶m2) +{ + if (prefix != 0) + xWrite8(prefix); + EmitRex(param1, param2); + + xWrite8(opcode); + + EmitSibMagic(param1, param2); +} + +template +__emitinline void xOpAccWrite(u8 prefix, u8 opcode, const T1 ¶m1, const T2 ¶m2) +{ + if (prefix != 0) + xWrite8(prefix); + EmitRex(param1, param2); + + xWrite8(opcode); +} + + +////////////////////////////////////////////////////////////////////////////////////////// +// emitter helpers for xmm instruction with prefixes, most of which are using +// the basic opcode format (items inside braces denote optional or conditional +// emission): +// +// [Prefix] / 0x0f / [OpcodePrefix] / Opcode / ModRM+[SibSB] +// +// Prefixes are typically 0x66, 0xf2, or 0xf3. OpcodePrefixes are either 0x38 or +// 0x3a [and other value will result in assertion failue]. +// +template +__emitinline void xOpWrite0F(u8 prefix, u16 opcode, const T1 ¶m1, const T2 ¶m2) +{ + if (prefix != 0) + xWrite8(prefix); + EmitRex(param1, param2); + + SimdPrefix(0, opcode); + + EmitSibMagic(param1, param2); +} + +template +__emitinline void xOpWrite0F(u8 prefix, u16 opcode, const T1 ¶m1, const T2 ¶m2, u8 imm8) +{ + xOpWrite0F(prefix, opcode, param1, param2); + xWrite8(imm8); +} + +template +__emitinline void xOpWrite0F(u16 opcode, const T1 ¶m1, const T2 ¶m2) +{ + xOpWrite0F(0, opcode, param1, param2); +} + +template +__emitinline void xOpWrite0F(u16 opcode, const T1 ¶m1, const T2 ¶m2, u8 imm8) +{ + xOpWrite0F(0, opcode, param1, param2, imm8); +} + +// VEX 2 Bytes Prefix +template +__emitinline void xOpWriteC5(u8 prefix, u8 opcode, const T1 ¶m1, const T2 ¶m2, const T3 ¶m3) +{ + pxAssert(prefix == 0 || prefix == 0x66 || prefix == 0xF3 || prefix == 0xF2); + + const xRegisterInt ® = param1.IsReg() ? param1 : param2; + +#ifdef __x86_64__ + u8 nR = reg.IsExtended() ? 0x00 : 0x80; +#else + u8 nR = 0x80; +#endif + u8 L = reg.IsWideSIMD() ? 4 : 0; + + u8 nv = (~param2.GetId() & 0xF) << 3; + + u8 p = + prefix == 0xF2 ? 3 : + prefix == 0xF3 ? 2 : + prefix == 0x66 ? 1 : 0; + + xWrite8(0xC5); + xWrite8(nR | nv | L | p); + xWrite8(opcode); + EmitSibMagic(param1, param3); +} + +// VEX 3 Bytes Prefix +template +__emitinline void xOpWriteC4(u8 prefix, u8 mb_prefix, u8 opcode, const T1 ¶m1, const T2 ¶m2, const T3 ¶m3, int w = -1) +{ + pxAssert(prefix == 0 || prefix == 0x66 || prefix == 0xF3 || prefix == 0xF2); + pxAssert(mb_prefix == 0x0F || mb_prefix == 0x38 || mb_prefix == 0x3A); + + const xRegisterInt ® = param1.IsReg() ? param1 : param2; + +#ifdef __x86_64__ + u8 nR = reg.IsExtended() ? 0x00 : 0x80; + u8 nB = param3.IsExtended() ? 0x00 : 0x20; + u8 nX = 0x40; // likely unused so hardwired to disabled +#else + u8 nR = 0x80; + u8 nB = 0x20; + u8 nX = 0x40; +#endif + u8 L = reg.IsWideSIMD() ? 4 : 0; + u8 W = (w == -1) ? (reg.GetOperandSize() == 8 ? 0x80 : 0) : // autodetect the size + 0x80 * w; // take directly the W value + + u8 nv = (~param2.GetId() & 0xF) << 3; + + u8 p = + prefix == 0xF2 ? 3 : + prefix == 0xF3 ? 2 : + prefix == 0x66 ? 1 : 0; + + u8 m = + mb_prefix == 0x3A ? 3 : + mb_prefix == 0x38 ? 2 : 1; + + xWrite8(0xC4); + xWrite8(nR | nX | nB | m); + xWrite8(W | nv | L | p); + xWrite8(opcode); + EmitSibMagic(param1, param3); +} +} diff --git a/common/include/x86emitter/legacy_instructions.h b/common/include/x86emitter/legacy_instructions.h index 2769f6d192..602e5137b8 100644 --- a/common/include/x86emitter/legacy_instructions.h +++ b/common/include/x86emitter/legacy_instructions.h @@ -25,15 +25,15 @@ //------------------------------------------------------------------ // legacy jump/align functions //------------------------------------------------------------------ -ATTR_DEP extern void x86SetPtr( u8 *ptr ); -ATTR_DEP extern void x86SetJ8( u8 *j8 ); -ATTR_DEP extern void x86SetJ8A( u8 *j8 ); -ATTR_DEP extern void x86SetJ16( u16 *j16 ); -ATTR_DEP extern void x86SetJ16A( u16 *j16 ); -ATTR_DEP extern void x86SetJ32( u32 *j32 ); -ATTR_DEP extern void x86SetJ32A( u32 *j32 ); -ATTR_DEP extern void x86Align( int bytes ); -ATTR_DEP extern void x86AlignExecutable( int align ); +ATTR_DEP extern void x86SetPtr(u8 *ptr); +ATTR_DEP extern void x86SetJ8(u8 *j8); +ATTR_DEP extern void x86SetJ8A(u8 *j8); +ATTR_DEP extern void x86SetJ16(u16 *j16); +ATTR_DEP extern void x86SetJ16A(u16 *j16); +ATTR_DEP extern void x86SetJ32(u32 *j32); +ATTR_DEP extern void x86SetJ32A(u32 *j32); +ATTR_DEP extern void x86Align(int bytes); +ATTR_DEP extern void x86AlignExecutable(int align); //------------------------------------------------------------------ //////////////////////////////////// @@ -41,55 +41,55 @@ ATTR_DEP extern void x86AlignExecutable( int align ); //////////////////////////////////// // jmp rel8 -ATTR_DEP extern u8* JMP8( u8 to ); +ATTR_DEP extern u8 *JMP8(u8 to); // jmp rel32 -ATTR_DEP extern u32* JMP32( uptr to ); +ATTR_DEP extern u32 *JMP32(uptr to); // jp rel8 -ATTR_DEP extern u8* JP8( u8 to ); +ATTR_DEP extern u8 *JP8(u8 to); // jnp rel8 -ATTR_DEP extern u8* JNP8( u8 to ); +ATTR_DEP extern u8 *JNP8(u8 to); // je rel8 -ATTR_DEP extern u8* JE8( u8 to ); +ATTR_DEP extern u8 *JE8(u8 to); // jz rel8 -ATTR_DEP extern u8* JZ8( u8 to ); +ATTR_DEP extern u8 *JZ8(u8 to); // jg rel8 -ATTR_DEP extern u8* JG8( u8 to ); +ATTR_DEP extern u8 *JG8(u8 to); // jge rel8 -ATTR_DEP extern u8* JGE8( u8 to ); +ATTR_DEP extern u8 *JGE8(u8 to); // js rel8 -ATTR_DEP extern u8* JS8( u8 to ); +ATTR_DEP extern u8 *JS8(u8 to); // jns rel8 -ATTR_DEP extern u8* JNS8( u8 to ); +ATTR_DEP extern u8 *JNS8(u8 to); // jl rel8 -ATTR_DEP extern u8* JL8( u8 to ); +ATTR_DEP extern u8 *JL8(u8 to); // ja rel8 -ATTR_DEP extern u8* JA8( u8 to ); +ATTR_DEP extern u8 *JA8(u8 to); // jae rel8 -ATTR_DEP extern u8* JAE8( u8 to ); +ATTR_DEP extern u8 *JAE8(u8 to); // jb rel8 -ATTR_DEP extern u8* JB8( u8 to ); +ATTR_DEP extern u8 *JB8(u8 to); // jbe rel8 -ATTR_DEP extern u8* JBE8( u8 to ); +ATTR_DEP extern u8 *JBE8(u8 to); // jle rel8 -ATTR_DEP extern u8* JLE8( u8 to ); +ATTR_DEP extern u8 *JLE8(u8 to); // jne rel8 -ATTR_DEP extern u8* JNE8( u8 to ); +ATTR_DEP extern u8 *JNE8(u8 to); // jnz rel8 -ATTR_DEP extern u8* JNZ8( u8 to ); +ATTR_DEP extern u8 *JNZ8(u8 to); // jng rel8 -ATTR_DEP extern u8* JNG8( u8 to ); +ATTR_DEP extern u8 *JNG8(u8 to); // jnge rel8 -ATTR_DEP extern u8* JNGE8( u8 to ); +ATTR_DEP extern u8 *JNGE8(u8 to); // jnl rel8 -ATTR_DEP extern u8* JNL8( u8 to ); +ATTR_DEP extern u8 *JNL8(u8 to); // jnle rel8 -ATTR_DEP extern u8* JNLE8( u8 to ); +ATTR_DEP extern u8 *JNLE8(u8 to); // jo rel8 -ATTR_DEP extern u8* JO8( u8 to ); +ATTR_DEP extern u8 *JO8(u8 to); // jno rel8 -ATTR_DEP extern u8* JNO8( u8 to ); +ATTR_DEP extern u8 *JNO8(u8 to); /* // jb rel16 @@ -103,51 +103,51 @@ ATTR_DEP extern u16* JZ16( u16 to ); */ // jns rel32 -ATTR_DEP extern u32* JNS32( u32 to ); +ATTR_DEP extern u32 *JNS32(u32 to); // js rel32 -ATTR_DEP extern u32* JS32( u32 to ); +ATTR_DEP extern u32 *JS32(u32 to); // jb rel32 -ATTR_DEP extern u32* JB32( u32 to ); +ATTR_DEP extern u32 *JB32(u32 to); // je rel32 -ATTR_DEP extern u32* JE32( u32 to ); +ATTR_DEP extern u32 *JE32(u32 to); // jz rel32 -ATTR_DEP extern u32* JZ32( u32 to ); +ATTR_DEP extern u32 *JZ32(u32 to); // jg rel32 -ATTR_DEP extern u32* JG32( u32 to ); +ATTR_DEP extern u32 *JG32(u32 to); // jge rel32 -ATTR_DEP extern u32* JGE32( u32 to ); +ATTR_DEP extern u32 *JGE32(u32 to); // jl rel32 -ATTR_DEP extern u32* JL32( u32 to ); +ATTR_DEP extern u32 *JL32(u32 to); // jle rel32 -ATTR_DEP extern u32* JLE32( u32 to ); +ATTR_DEP extern u32 *JLE32(u32 to); // jae rel32 -ATTR_DEP extern u32* JAE32( u32 to ); +ATTR_DEP extern u32 *JAE32(u32 to); // jne rel32 -ATTR_DEP extern u32* JNE32( u32 to ); +ATTR_DEP extern u32 *JNE32(u32 to); // jnz rel32 -ATTR_DEP extern u32* JNZ32( u32 to ); +ATTR_DEP extern u32 *JNZ32(u32 to); // jng rel32 -ATTR_DEP extern u32* JNG32( u32 to ); +ATTR_DEP extern u32 *JNG32(u32 to); // jnge rel32 -ATTR_DEP extern u32* JNGE32( u32 to ); +ATTR_DEP extern u32 *JNGE32(u32 to); // jnl rel32 -ATTR_DEP extern u32* JNL32( u32 to ); +ATTR_DEP extern u32 *JNL32(u32 to); // jnle rel32 -ATTR_DEP extern u32* JNLE32( u32 to ); +ATTR_DEP extern u32 *JNLE32(u32 to); // jo rel32 -ATTR_DEP extern u32* JO32( u32 to ); +ATTR_DEP extern u32 *JO32(u32 to); // jno rel32 -ATTR_DEP extern u32* JNO32( u32 to ); +ATTR_DEP extern u32 *JNO32(u32 to); // js rel32 -ATTR_DEP extern u32* JS32( u32 to ); +ATTR_DEP extern u32 *JS32(u32 to); //****************** // FPU instructions //****************** // fld m32 to fpu reg stack -ATTR_DEP extern void FLD32( u32 from ); +ATTR_DEP extern void FLD32(u32 from); // fld st(i) ATTR_DEP extern void FLD(int st); // fld1 (push +1.0f on the stack) @@ -155,7 +155,7 @@ ATTR_DEP extern void FLD1(); // fld1 (push log_2 e on the stack) ATTR_DEP extern void FLDL2E(); // fstp m32 from fpu reg stack -ATTR_DEP extern void FSTP32( u32 to ); +ATTR_DEP extern void FSTP32(u32 to); // fstp st(i) ATTR_DEP extern void FSTP(int st); @@ -166,32 +166,32 @@ ATTR_DEP extern void F2XM1(); ATTR_DEP extern void FSCALE(); // fadd ST(0) to fpu reg stack ST(src) -ATTR_DEP extern void FADD320toR( x86IntRegType src ); +ATTR_DEP extern void FADD320toR(x86IntRegType src); // fsub ST(src) to fpu reg stack ST(0) -ATTR_DEP extern void FSUB32Rto0( x86IntRegType src ); +ATTR_DEP extern void FSUB32Rto0(x86IntRegType src); // fmul m32 to fpu reg stack -ATTR_DEP extern void FMUL32( u32 from ); +ATTR_DEP extern void FMUL32(u32 from); // fdiv m32 to fpu reg stack -ATTR_DEP extern void FDIV32( u32 from ); +ATTR_DEP extern void FDIV32(u32 from); // ftan fpu reg stack -ATTR_DEP extern void FPATAN( void ); +ATTR_DEP extern void FPATAN(void); // fsin fpu reg stack -ATTR_DEP extern void FSIN( void ); +ATTR_DEP extern void FSIN(void); //********************* // SSE instructions * //********************* -ATTR_DEP extern void SSE_MAXSS_XMM_to_XMM( x86SSERegType to, x86SSERegType from ); -ATTR_DEP extern void SSE_MINSS_XMM_to_XMM( x86SSERegType to, x86SSERegType from ); -ATTR_DEP extern void SSE_ADDSS_XMM_to_XMM( x86SSERegType to, x86SSERegType from ); -ATTR_DEP extern void SSE_SUBSS_XMM_to_XMM( x86SSERegType to, x86SSERegType from ); +ATTR_DEP extern void SSE_MAXSS_XMM_to_XMM(x86SSERegType to, x86SSERegType from); +ATTR_DEP extern void SSE_MINSS_XMM_to_XMM(x86SSERegType to, x86SSERegType from); +ATTR_DEP extern void SSE_ADDSS_XMM_to_XMM(x86SSERegType to, x86SSERegType from); +ATTR_DEP extern void SSE_SUBSS_XMM_to_XMM(x86SSERegType to, x86SSERegType from); //********************* // SSE 2 Instructions* //********************* -ATTR_DEP extern void SSE2_MAXSD_XMM_to_XMM( x86SSERegType to, x86SSERegType from ); -ATTR_DEP extern void SSE2_MINSD_XMM_to_XMM( x86SSERegType to, x86SSERegType from ); -ATTR_DEP extern void SSE2_ADDSD_XMM_to_XMM( x86SSERegType to, x86SSERegType from ); -ATTR_DEP extern void SSE2_SUBSD_XMM_to_XMM( x86SSERegType to, x86SSERegType from ); +ATTR_DEP extern void SSE2_MAXSD_XMM_to_XMM(x86SSERegType to, x86SSERegType from); +ATTR_DEP extern void SSE2_MINSD_XMM_to_XMM(x86SSERegType to, x86SSERegType from); +ATTR_DEP extern void SSE2_ADDSD_XMM_to_XMM(x86SSERegType to, x86SSERegType from); +ATTR_DEP extern void SSE2_SUBSD_XMM_to_XMM(x86SSERegType to, x86SSERegType from); diff --git a/common/include/x86emitter/legacy_internal.h b/common/include/x86emitter/legacy_internal.h index a881520920..53f647a1ab 100644 --- a/common/include/x86emitter/legacy_internal.h +++ b/common/include/x86emitter/legacy_internal.h @@ -31,11 +31,10 @@ using x86Emitter::xWrite64; #include "legacy_types.h" #include "legacy_instructions.h" -#define MEMADDR(addr, oplen) (addr) - -extern void ModRM( uint mod, uint reg, uint rm ); -extern void SibSB( uint ss, uint index, uint base ); -extern void SET8R( int cc, int to ); -extern u8* J8Rel( int cc, int to ); -extern u32* J32Rel( int cc, u32 to ); +#define MEMADDR(addr, oplen) (addr) +extern void ModRM(uint mod, uint reg, uint rm); +extern void SibSB(uint ss, uint index, uint base); +extern void SET8R(int cc, int to); +extern u8 *J8Rel(int cc, int to); +extern u32 *J32Rel(int cc, u32 to); diff --git a/common/include/x86emitter/legacy_types.h b/common/include/x86emitter/legacy_types.h index 6761d2af8f..b79c99498f 100644 --- a/common/include/x86emitter/legacy_types.h +++ b/common/include/x86emitter/legacy_types.h @@ -17,7 +17,7 @@ //#define SIB 4 // maps to ESP //#define SIBDISP 5 // maps to EBP -#define DISP32 5 // maps to EBP +#define DISP32 5 // maps to EBP // general types typedef int x86IntRegType; diff --git a/common/include/x86emitter/tools.h b/common/include/x86emitter/tools.h index 5105f2276e..58541f81ba 100644 --- a/common/include/x86emitter/tools.h +++ b/common/include/x86emitter/tools.h @@ -17,11 +17,10 @@ #include "x86emitter.h" -enum x86VendorType -{ - x86Vendor_Intel = 0, - x86Vendor_AMD = 1, - x86Vendor_Unknown = 2 +enum x86VendorType { + x86Vendor_Intel = 0, + x86Vendor_AMD = 1, + x86Vendor_Unknown = 2 }; // -------------------------------------------------------------------------------------- @@ -30,110 +29,111 @@ enum x86VendorType class x86capabilities { public: - bool isIdentified; + bool isIdentified; public: - x86VendorType VendorID; + x86VendorType VendorID; - uint FamilyID; // Processor Family - uint Model; // Processor Model - uint TypeID; // Processor Type - uint StepID; // Stepping ID + uint FamilyID; // Processor Family + uint Model; // Processor Model + uint TypeID; // Processor Type + uint StepID; // Stepping ID - u32 Flags; // Feature Flags - u32 Flags2; // More Feature Flags - u32 EFlags; // Extended Feature Flags - u32 EFlags2; // Extended Feature Flags pg2 - u32 SEFlag; // Structured Extended Feature Flags Enumeration + u32 Flags; // Feature Flags + u32 Flags2; // More Feature Flags + u32 EFlags; // Extended Feature Flags + u32 EFlags2; // Extended Feature Flags pg2 + u32 SEFlag; // Structured Extended Feature Flags Enumeration - char VendorName[16]; // Vendor/Creator ID - char FamilyName[50]; // the original cpu name + char VendorName[16]; // Vendor/Creator ID + char FamilyName[50]; // the original cpu name - // ---------------------------------------------------------------------------- - // x86 CPU Capabilities Section (all boolean flags!) - // ---------------------------------------------------------------------------- + // ---------------------------------------------------------------------------- + // x86 CPU Capabilities Section (all boolean flags!) + // ---------------------------------------------------------------------------- - union { - struct { - u32 hasFloatingPointUnit :1; - u32 hasVirtual8086ModeEnhancements :1; - u32 hasDebuggingExtensions :1; - u32 hasPageSizeExtensions :1; - u32 hasTimeStampCounter :1; - u32 hasModelSpecificRegisters :1; - u32 hasPhysicalAddressExtension :1; - u32 hasCOMPXCHG8BInstruction :1; - u32 hasAdvancedProgrammableInterruptController :1; - u32 hasSEPFastSystemCall :1; - u32 hasMemoryTypeRangeRegisters :1; - u32 hasPTEGlobalFlag :1; - u32 hasMachineCheckArchitecture :1; - u32 hasConditionalMoveAndCompareInstructions :1; - u32 hasFGPageAttributeTable :1; - u32 has36bitPageSizeExtension :1; - u32 hasProcessorSerialNumber :1; - u32 hasCFLUSHInstruction :1; - u32 hasDebugStore :1; - u32 hasACPIThermalMonitorAndClockControl :1; - u32 hasFastStreamingSIMDExtensionsSaveRestore :1; - u32 hasStreamingSIMDExtensions :1; - u32 hasStreamingSIMD2Extensions :1; - u32 hasSelfSnoop :1; + union + { + struct + { + u32 hasFloatingPointUnit : 1; + u32 hasVirtual8086ModeEnhancements : 1; + u32 hasDebuggingExtensions : 1; + u32 hasPageSizeExtensions : 1; + u32 hasTimeStampCounter : 1; + u32 hasModelSpecificRegisters : 1; + u32 hasPhysicalAddressExtension : 1; + u32 hasCOMPXCHG8BInstruction : 1; + u32 hasAdvancedProgrammableInterruptController : 1; + u32 hasSEPFastSystemCall : 1; + u32 hasMemoryTypeRangeRegisters : 1; + u32 hasPTEGlobalFlag : 1; + u32 hasMachineCheckArchitecture : 1; + u32 hasConditionalMoveAndCompareInstructions : 1; + u32 hasFGPageAttributeTable : 1; + u32 has36bitPageSizeExtension : 1; + u32 hasProcessorSerialNumber : 1; + u32 hasCFLUSHInstruction : 1; + u32 hasDebugStore : 1; + u32 hasACPIThermalMonitorAndClockControl : 1; + u32 hasFastStreamingSIMDExtensionsSaveRestore : 1; + u32 hasStreamingSIMDExtensions : 1; + u32 hasStreamingSIMD2Extensions : 1; + u32 hasSelfSnoop : 1; - // is TRUE for both multi-core and Hyperthreaded CPUs. - u32 hasMultiThreading :1; + // is TRUE for both multi-core and Hyperthreaded CPUs. + u32 hasMultiThreading : 1; - u32 hasThermalMonitor :1; - u32 hasIntel64BitArchitecture :1; - u32 hasStreamingSIMD3Extensions :1; - u32 hasSupplementalStreamingSIMD3Extensions :1; - u32 hasStreamingSIMD4Extensions :1; - u32 hasStreamingSIMD4Extensions2 :1; - u32 hasAVX :1; - u32 hasAVX2 :1; - u32 hasBMI1 :1; - u32 hasBMI2 :1; - u32 hasFMA :1; + u32 hasThermalMonitor : 1; + u32 hasIntel64BitArchitecture : 1; + u32 hasStreamingSIMD3Extensions : 1; + u32 hasSupplementalStreamingSIMD3Extensions : 1; + u32 hasStreamingSIMD4Extensions : 1; + u32 hasStreamingSIMD4Extensions2 : 1; + u32 hasAVX : 1; + u32 hasAVX2 : 1; + u32 hasBMI1 : 1; + u32 hasBMI2 : 1; + u32 hasFMA : 1; - // AMD-specific CPU Features - u32 hasAMD64BitArchitecture :1; - u32 hasStreamingSIMD4ExtensionsA :1; - }; + // AMD-specific CPU Features + u32 hasAMD64BitArchitecture : 1; + u32 hasStreamingSIMD4ExtensionsA : 1; + }; - u64 AllCapabilities; - }; + u64 AllCapabilities; + }; - // Core Counts! - u32 PhysicalCores; - u32 LogicalCores; + // Core Counts! + u32 PhysicalCores; + u32 LogicalCores; public: - x86capabilities(); + x86capabilities(); - void Identify(); - void CountCores(); - wxString GetTypeName() const; + void Identify(); + void CountCores(); + wxString GetTypeName() const; - u32 CalculateMHz() const; + u32 CalculateMHz() const; - void SIMD_EstablishMXCSRmask(); + void SIMD_EstablishMXCSRmask(); protected: - s64 _CPUSpeedHz( u64 time ) const; - void CountLogicalCores(); + s64 _CPUSpeedHz(u64 time) const; + void CountLogicalCores(); }; -enum SSE_RoundMode -{ - SSE_RoundMode_FIRST = 0, - SSEround_Nearest = 0, - SSEround_NegInf, - SSEround_PosInf, - SSEround_Chop, - SSE_RoundMode_COUNT +enum SSE_RoundMode { + SSE_RoundMode_FIRST = 0, + SSEround_Nearest = 0, + SSEround_NegInf, + SSEround_PosInf, + SSEround_Chop, + SSE_RoundMode_COUNT }; -ImplementEnumOperators( SSE_RoundMode ); +ImplementEnumOperators(SSE_RoundMode); // -------------------------------------------------------------------------------------- // SSE_MXCSR - Control/Status Register (bitfield) @@ -147,56 +147,55 @@ ImplementEnumOperators( SSE_RoundMode ); // union SSE_MXCSR { - u32 bitmask; - struct - { - u32 - InvalidOpFlag :1, - DenormalFlag :1, - DivideByZeroFlag :1, - OverflowFlag :1, - UnderflowFlag :1, - PrecisionFlag :1, + u32 bitmask; + struct + { + u32 + InvalidOpFlag : 1, + DenormalFlag : 1, + DivideByZeroFlag : 1, + OverflowFlag : 1, + UnderflowFlag : 1, + PrecisionFlag : 1, - // This bit is supported only on SSE2 or better CPUs. Setting it to 1 on - // SSE1 cpus will result in an invalid instruction exception when executing - // LDMXSCR. - DenormalsAreZero :1, + // This bit is supported only on SSE2 or better CPUs. Setting it to 1 on + // SSE1 cpus will result in an invalid instruction exception when executing + // LDMXSCR. + DenormalsAreZero : 1, - InvalidOpMask :1, - DenormalMask :1, - DivideByZeroMask :1, - OverflowMask :1, - UnderflowMask :1, - PrecisionMask :1, + InvalidOpMask : 1, + DenormalMask : 1, + DivideByZeroMask : 1, + OverflowMask : 1, + UnderflowMask : 1, + PrecisionMask : 1, - RoundingControl :2, - FlushToZero :1; - }; + RoundingControl : 2, + FlushToZero : 1; + }; - SSE_RoundMode GetRoundMode() const; - SSE_MXCSR& SetRoundMode( SSE_RoundMode mode ); - SSE_MXCSR& ClearExceptionFlags(); - SSE_MXCSR& EnableExceptions(); - SSE_MXCSR& DisableExceptions(); + SSE_RoundMode GetRoundMode() const; + SSE_MXCSR &SetRoundMode(SSE_RoundMode mode); + SSE_MXCSR &ClearExceptionFlags(); + SSE_MXCSR &EnableExceptions(); + SSE_MXCSR &DisableExceptions(); - SSE_MXCSR& ApplyReserveMask(); + SSE_MXCSR &ApplyReserveMask(); - bool operator ==( const SSE_MXCSR& right ) const - { - return bitmask == right.bitmask; - } + bool operator==(const SSE_MXCSR &right) const + { + return bitmask == right.bitmask; + } - bool operator !=( const SSE_MXCSR& right ) const - { - return bitmask != right.bitmask; - } + bool operator!=(const SSE_MXCSR &right) const + { + return bitmask != right.bitmask; + } - operator x86Emitter::xIndirect32() const; + operator x86Emitter::xIndirect32() const; }; -extern SSE_MXCSR MXCSR_Mask; +extern SSE_MXCSR MXCSR_Mask; extern __aligned16 x86capabilities x86caps; - diff --git a/common/include/x86emitter/x86_intrin.h b/common/include/x86emitter/x86_intrin.h index f3f8bcb823..8c3e52d3c3 100644 --- a/common/include/x86emitter/x86_intrin.h +++ b/common/include/x86emitter/x86_intrin.h @@ -32,26 +32,30 @@ // CPU information support #if defined(_WIN32) -#define cpuid __cpuid +#define cpuid __cpuid #define cpuidex __cpuidex #else #include -static __inline__ __attribute__((always_inline)) void cpuidex(int CPUInfo[], const int InfoType, const int count) { - __cpuid_count(InfoType, count, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); +static __inline__ __attribute__((always_inline)) void cpuidex(int CPUInfo[], const int InfoType, const int count) +{ + __cpuid_count(InfoType, count, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); } -static __inline__ __attribute__((always_inline)) void cpuid(int CPUInfo[], const int InfoType) { - __cpuid(InfoType, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); +static __inline__ __attribute__((always_inline)) void cpuid(int CPUInfo[], const int InfoType) +{ + __cpuid(InfoType, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); } static __inline__ __attribute__((always_inline)) unsigned long long _xgetbv(unsigned int index) { - unsigned int eax, edx; - __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); - return ((unsigned long long)edx << 32) | eax; + unsigned int eax, edx; + __asm__ __volatile__("xgetbv" + : "=a"(eax), "=d"(edx) + : "c"(index)); + return ((unsigned long long)edx << 32) | eax; } #endif @@ -61,16 +65,16 @@ static __inline__ __attribute__((always_inline)) unsigned long long _xgetbv(unsi // Seriously what is so complicated to provided this bunch of intrinsics in clangs. static unsigned int _rotr(unsigned int x, int s) { - return (x >> s) | (x << (32 - s)); + return (x >> s) | (x << (32 - s)); } static unsigned int _rotl(unsigned int x, int s) { - return (x << s) | (x >> (32 - s)); + return (x << s) | (x >> (32 - s)); } #endif // Not correctly defined in GCC4.8 and below ! (dunno for VS) #ifndef _MM_MK_INSERTPS_NDX -#define _MM_MK_INSERTPS_NDX(srcField, dstField, zeroMask) (((srcField)<<6) | ((dstField)<<4) | (zeroMask)) +#define _MM_MK_INSERTPS_NDX(srcField, dstField, zeroMask) (((srcField) << 6) | ((dstField) << 4) | (zeroMask)) #endif diff --git a/common/include/x86emitter/x86types.h b/common/include/x86emitter/x86types.h index cc6c8ffe68..d8e715e21a 100644 --- a/common/include/x86emitter/x86types.h +++ b/common/include/x86emitter/x86types.h @@ -24,11 +24,10 @@ static const uint iREGCNT_XMM = 8; static const uint iREGCNT_GPR = 8; #endif -enum XMMSSEType -{ - XMMT_INT = 0, // integer (sse2 only) - XMMT_FPS = 1, // floating point - //XMMT_FPD = 3, // double +enum XMMSSEType { + XMMT_INT = 0, // integer (sse2 only) + XMMT_FPS = 1, // floating point + //XMMT_FPD = 3, // double }; // -------------------------------------------------------------------------------------- @@ -42,46 +41,50 @@ enum XMMSSEType #include "Utilities/Threading.h" #ifndef x86EMIT_MULTITHREADED -# if PCSX2_THREAD_LOCAL -# define x86EMIT_MULTITHREADED 1 -# else - // No TLS support? Force-clear the MT flag: -# pragma message("x86emitter: TLS not available, multithreaded emitter disabled.") -# undef x86EMIT_MULTITHREADED -# define x86EMIT_MULTITHREADED 0 -# endif +#if PCSX2_THREAD_LOCAL +#define x86EMIT_MULTITHREADED 1 +#else +// No TLS support? Force-clear the MT flag: +#pragma message("x86emitter: TLS not available, multithreaded emitter disabled.") +#undef x86EMIT_MULTITHREADED +#define x86EMIT_MULTITHREADED 0 +#endif #endif #ifndef __tls_emit -# if x86EMIT_MULTITHREADED -# define __tls_emit __threadlocal -# else - // Using TlsVariable is sub-optimal and could result in huge executables, so we - // force-disable TLS entirely, and disallow running multithreaded recompilation - // components within PCSX2 manually. -# define __tls_emit -# endif +#if x86EMIT_MULTITHREADED +#define __tls_emit __threadlocal +#else +// Using TlsVariable is sub-optimal and could result in huge executables, so we +// force-disable TLS entirely, and disallow running multithreaded recompilation +// components within PCSX2 manually. +#define __tls_emit +#endif #endif -extern __tls_emit u8* x86Ptr; -extern __tls_emit XMMSSEType g_xmmtypes[iREGCNT_XMM]; +extern __tls_emit u8 *x86Ptr; +extern __tls_emit XMMSSEType g_xmmtypes[iREGCNT_XMM]; namespace x86Emitter { -extern void xWrite8( u8 val ); -extern void xWrite16( u16 val ); -extern void xWrite32( u32 val ); -extern void xWrite64( u64 val ); +extern void xWrite8(u8 val); +extern void xWrite16(u16 val); +extern void xWrite32(u32 val); +extern void xWrite64(u64 val); -extern const char* xGetRegName( int regid, int operandSize ); +extern const char *xGetRegName(int regid, int operandSize); //------------------------------------------------------------------ // templated version of is_s8 is required, so that u16's get correct sign extension treatment. -template< typename T > -static __fi bool is_s8( T imm ) { return (s8)imm == (s32)imm; } +template +static __fi bool is_s8(T imm) +{ + return (s8)imm == (s32)imm; +} -template< typename T > void xWrite( T val ); +template +void xWrite(T val); // -------------------------------------------------------------------------------------- // ALWAYS_USE_MOVAPS [define] / AlwaysUseMovaps [const] @@ -95,9 +98,9 @@ template< typename T > void xWrite( T val ); #define ALWAYS_USE_MOVAPS #ifdef ALWAYS_USE_MOVAPS - static const bool AlwaysUseMovaps = true; +static const bool AlwaysUseMovaps = true; #else - static const bool AlwaysUseMovaps = false; +static const bool AlwaysUseMovaps = false; #endif // -------------------------------------------------------------------------------------- @@ -118,295 +121,348 @@ template< typename T > void xWrite( T val ); // can't trace into single-line functions anyway. // #ifdef PCSX2_DEVBUILD -# define __emitinline +#define __emitinline #else -# define __emitinline __fi +#define __emitinline __fi #endif - // ModRM 'mod' field enumeration. Provided mostly for reference: - enum ModRm_ModField - { - Mod_NoDisp = 0, // effective address operation with no displacement, in the form of [reg] (or uses special Disp32-only encoding in the case of [ebp] form) - Mod_Disp8, // effective address operation with 8 bit displacement, in the form of [reg+disp8] - Mod_Disp32, // effective address operation with 32 bit displacement, in the form of [reg+disp32], - Mod_Direct, // direct reg/reg operation - }; +// ModRM 'mod' field enumeration. Provided mostly for reference: +enum ModRm_ModField { + Mod_NoDisp = 0, // effective address operation with no displacement, in the form of [reg] (or uses special Disp32-only encoding in the case of [ebp] form) + Mod_Disp8, // effective address operation with 8 bit displacement, in the form of [reg+disp8] + Mod_Disp32, // effective address operation with 32 bit displacement, in the form of [reg+disp32], + Mod_Direct, // direct reg/reg operation +}; - // ---------------------------------------------------------------------------- - // JccComparisonType - enumerated possibilities for inspired code branching! - // - enum JccComparisonType - { - Jcc_Unknown = -2, - Jcc_Unconditional = -1, - Jcc_Overflow = 0x0, - Jcc_NotOverflow = 0x1, - Jcc_Below = 0x2, - Jcc_Carry = 0x2, - Jcc_AboveOrEqual = 0x3, - Jcc_NotCarry = 0x3, - Jcc_Zero = 0x4, - Jcc_Equal = 0x4, - Jcc_NotZero = 0x5, - Jcc_NotEqual = 0x5, - Jcc_BelowOrEqual = 0x6, - Jcc_Above = 0x7, - Jcc_Signed = 0x8, - Jcc_Unsigned = 0x9, - Jcc_ParityEven = 0xa, - Jcc_ParityOdd = 0xb, - Jcc_Less = 0xc, - Jcc_GreaterOrEqual = 0xd, - Jcc_LessOrEqual = 0xe, - Jcc_Greater = 0xf, - }; +// ---------------------------------------------------------------------------- +// JccComparisonType - enumerated possibilities for inspired code branching! +// +enum JccComparisonType { + Jcc_Unknown = -2, + Jcc_Unconditional = -1, + Jcc_Overflow = 0x0, + Jcc_NotOverflow = 0x1, + Jcc_Below = 0x2, + Jcc_Carry = 0x2, + Jcc_AboveOrEqual = 0x3, + Jcc_NotCarry = 0x3, + Jcc_Zero = 0x4, + Jcc_Equal = 0x4, + Jcc_NotZero = 0x5, + Jcc_NotEqual = 0x5, + Jcc_BelowOrEqual = 0x6, + Jcc_Above = 0x7, + Jcc_Signed = 0x8, + Jcc_Unsigned = 0x9, + Jcc_ParityEven = 0xa, + Jcc_ParityOdd = 0xb, + Jcc_Less = 0xc, + Jcc_GreaterOrEqual = 0xd, + Jcc_LessOrEqual = 0xe, + Jcc_Greater = 0xf, +}; - // Not supported yet: - //E3 cb JECXZ rel8 Jump short if ECX register is 0. +// Not supported yet: +//E3 cb JECXZ rel8 Jump short if ECX register is 0. - // ---------------------------------------------------------------------------- - // SSE2_ComparisonType - enumerated possibilities for SIMD data comparison! - // - enum SSE2_ComparisonType - { - SSE2_Equal = 0, - SSE2_Less, - SSE2_LessOrEqual, - SSE2_Unordered, - SSE2_NotEqual, - SSE2_NotLess, - SSE2_NotLessOrEqual, - SSE2_Ordered - }; +// ---------------------------------------------------------------------------- +// SSE2_ComparisonType - enumerated possibilities for SIMD data comparison! +// +enum SSE2_ComparisonType { + SSE2_Equal = 0, + SSE2_Less, + SSE2_LessOrEqual, + SSE2_Unordered, + SSE2_NotEqual, + SSE2_NotLess, + SSE2_NotLessOrEqual, + SSE2_Ordered +}; - static const int ModRm_UseSib = 4; // same index value as ESP (used in RM field) - static const int ModRm_UseDisp32 = 5; // same index value as EBP (used in Mod field) +static const int ModRm_UseSib = 4; // same index value as ESP (used in RM field) +static const int ModRm_UseDisp32 = 5; // same index value as EBP (used in Mod field) - extern void xSetPtr( void* ptr ); - extern void xAlignPtr( uint bytes ); - extern void xAdvancePtr( uint bytes ); - extern void xAlignCallTarget(); +extern void xSetPtr(void *ptr); +extern void xAlignPtr(uint bytes); +extern void xAdvancePtr(uint bytes); +extern void xAlignCallTarget(); - extern u8* xGetPtr(); - extern u8* xGetAlignedCallTarget(); +extern u8 *xGetPtr(); +extern u8 *xGetAlignedCallTarget(); - extern JccComparisonType xInvertCond( JccComparisonType src ); +extern JccComparisonType xInvertCond(JccComparisonType src); - class xAddressVoid; +class xAddressVoid; - // -------------------------------------------------------------------------------------- - // OperandSizedObject - // -------------------------------------------------------------------------------------- - class OperandSizedObject - { - public: - virtual uint GetOperandSize() const=0; +// -------------------------------------------------------------------------------------- +// OperandSizedObject +// -------------------------------------------------------------------------------------- +class OperandSizedObject +{ +public: + virtual uint GetOperandSize() const = 0; - bool Is8BitOp() const { return GetOperandSize() == 1; } - u8 GetPrefix16() const { return GetOperandSize() == 2 ? 0x66 : 0; } - void prefix16() const { if( GetOperandSize() == 2 ) xWrite8( 0x66 ); } + bool Is8BitOp() const { return GetOperandSize() == 1; } + u8 GetPrefix16() const { return GetOperandSize() == 2 ? 0x66 : 0; } + void prefix16() const + { + if (GetOperandSize() == 2) + xWrite8(0x66); + } - void xWriteImm( int imm ) const - { - switch( GetOperandSize() ) - { - case 1: xWrite8( imm ); break; - case 2: xWrite16( imm ); break; - case 4: xWrite32( imm ); break; - case 8: xWrite64( imm ); break; + void xWriteImm(int imm) const + { + switch (GetOperandSize()) { + case 1: + xWrite8(imm); + break; + case 2: + xWrite16(imm); + break; + case 4: + xWrite32(imm); + break; + case 8: + xWrite64(imm); + break; - jNO_DEFAULT - } - } - }; + jNO_DEFAULT + } + } +}; - // Represents an unused or "empty" register assignment. If encountered by the emitter, this - // will be ignored (in some cases it is disallowed and generates an assertion) - static const int xRegId_Empty = -1; +// Represents an unused or "empty" register assignment. If encountered by the emitter, this +// will be ignored (in some cases it is disallowed and generates an assertion) +static const int xRegId_Empty = -1; - // Represents an invalid or uninitialized register. If this is encountered by the emitter it - // will generate an assertion. - static const int xRegId_Invalid = -2; +// Represents an invalid or uninitialized register. If this is encountered by the emitter it +// will generate an assertion. +static const int xRegId_Invalid = -2; - // -------------------------------------------------------------------------------------- - // xRegisterBase - type-unsafe x86 register representation. - // -------------------------------------------------------------------------------------- - // Unless doing some fundamental stuff, use the friendly xRegister32/16/8 and xRegisterSSE - // instead, which are built using this class and provide strict register type safety when - // passed into emitter instructions. - // - class xRegisterBase : public OperandSizedObject - { - public: - int Id; +// -------------------------------------------------------------------------------------- +// xRegisterBase - type-unsafe x86 register representation. +// -------------------------------------------------------------------------------------- +// Unless doing some fundamental stuff, use the friendly xRegister32/16/8 and xRegisterSSE +// instead, which are built using this class and provide strict register type safety when +// passed into emitter instructions. +// +class xRegisterBase : public OperandSizedObject +{ +public: + int Id; - xRegisterBase() - { - Id = xRegId_Invalid; - } + xRegisterBase() + { + Id = xRegId_Invalid; + } - explicit xRegisterBase( int regId ) - { - Id = regId; - // Note: to avoid tons of ifdef, the 32 bits build will instantiate - // all 16x64 bits registers. - pxAssert( (Id >= xRegId_Empty) && (Id < 16) ); - } + explicit xRegisterBase(int regId) + { + Id = regId; + // Note: to avoid tons of ifdef, the 32 bits build will instantiate + // all 16x64 bits registers. + pxAssert((Id >= xRegId_Empty) && (Id < 16)); + } - bool IsEmpty() const { return Id < 0 ; } - bool IsInvalid() const { return Id == xRegId_Invalid; } - bool IsExtended() const { return Id > 7; } // Register 8-15 need an extra bit to be selected - bool IsMem() const { return false; } - bool IsReg() const { return true; } + bool IsEmpty() const { return Id < 0; } + bool IsInvalid() const { return Id == xRegId_Invalid; } + bool IsExtended() const { return Id > 7; } // Register 8-15 need an extra bit to be selected + bool IsMem() const { return false; } + bool IsReg() const { return true; } - // Returns true if the register is a valid accumulator: Eax, Ax, Al, XMM0. - bool IsAccumulator() const { return Id == 0; } + // Returns true if the register is a valid accumulator: Eax, Ax, Al, XMM0. + bool IsAccumulator() const { return Id == 0; } - // IsSIMD: returns true if the register is a valid XMM register. - bool IsSIMD() const { return GetOperandSize() == 16; } + // IsSIMD: returns true if the register is a valid XMM register. + bool IsSIMD() const { return GetOperandSize() == 16; } - // IsWide: return true if the register is 64 bits (requires a wide op on the rex prefix) +// IsWide: return true if the register is 64 bits (requires a wide op on the rex prefix) #ifdef __x86_64__ - bool IsWide() const { return GetOperandSize() == 8; } + bool IsWide() const + { + return GetOperandSize() == 8; + } #else - bool IsWide() const { return false; } // no 64 bits GPR + bool IsWide() const + { + return false; + } // no 64 bits GPR #endif - // return true if the register is a valid YMM register - bool IsWideSIMD() const { return GetOperandSize() == 32; } + // return true if the register is a valid YMM register + bool IsWideSIMD() const { return GetOperandSize() == 32; } - bool operator==( const xRegisterBase& src ) const { return (Id == src.Id); } - bool operator!=( const xRegisterBase& src ) const { return (Id != src.Id); } + bool operator==(const xRegisterBase &src) const { return (Id == src.Id); } + bool operator!=(const xRegisterBase &src) const { return (Id != src.Id); } - // Diagnostics -- returns a string representation of this register. Return string - // is a valid non-null string for any Id, valid or invalid. No assertions are generated. - const char* GetName(); - int GetId() const { return Id; } - }; + // Diagnostics -- returns a string representation of this register. Return string + // is a valid non-null string for any Id, valid or invalid. No assertions are generated. + const char *GetName(); + int GetId() const { return Id; } +}; - class xRegisterInt : public xRegisterBase - { - typedef xRegisterBase _parent; +class xRegisterInt : public xRegisterBase +{ + typedef xRegisterBase _parent; - public: - xRegisterInt() {} - explicit xRegisterInt( const xRegisterBase& src ) : _parent( src ) {} - explicit xRegisterInt( int regId ) : _parent( regId ) { } +public: + xRegisterInt() {} + explicit xRegisterInt(const xRegisterBase &src) + : _parent(src) + { + } + explicit xRegisterInt(int regId) + : _parent(regId) + { + } - bool operator==( const xRegisterInt& src ) const { return Id == src.Id && (GetOperandSize() == src.GetOperandSize()); } - bool operator!=( const xRegisterInt& src ) const { return !operator==(src); } - }; + bool operator==(const xRegisterInt &src) const { return Id == src.Id && (GetOperandSize() == src.GetOperandSize()); } + bool operator!=(const xRegisterInt &src) const { return !operator==(src); } +}; - // -------------------------------------------------------------------------------------- - // xRegister8/16/32/64 - Represents a basic 8/16/32/64 bit GPR on the x86 - // -------------------------------------------------------------------------------------- - class xRegister8 : public xRegisterInt - { - typedef xRegisterInt _parent; +// -------------------------------------------------------------------------------------- +// xRegister8/16/32/64 - Represents a basic 8/16/32/64 bit GPR on the x86 +// -------------------------------------------------------------------------------------- +class xRegister8 : public xRegisterInt +{ + typedef xRegisterInt _parent; - public: - xRegister8(): _parent() {} - explicit xRegister8( int regId ) : _parent( regId ) {} +public: + xRegister8() + : _parent() + { + } + explicit xRegister8(int regId) + : _parent(regId) + { + } - virtual uint GetOperandSize() const { return 1; } + virtual uint GetOperandSize() const { return 1; } - bool operator==( const xRegister8& src ) const { return Id == src.Id; } - bool operator!=( const xRegister8& src ) const { return Id != src.Id; } - }; + bool operator==(const xRegister8 &src) const { return Id == src.Id; } + bool operator!=(const xRegister8 &src) const { return Id != src.Id; } +}; - class xRegister16 : public xRegisterInt - { - typedef xRegisterInt _parent; +class xRegister16 : public xRegisterInt +{ + typedef xRegisterInt _parent; - public: - xRegister16(): _parent() {} - explicit xRegister16( int regId ) : _parent( regId ) {} +public: + xRegister16() + : _parent() + { + } + explicit xRegister16(int regId) + : _parent(regId) + { + } - virtual uint GetOperandSize() const { return 2; } + virtual uint GetOperandSize() const { return 2; } - bool operator==( const xRegister16& src ) const { return this->Id == src.Id; } - bool operator!=( const xRegister16& src ) const { return this->Id != src.Id; } - }; + bool operator==(const xRegister16 &src) const { return this->Id == src.Id; } + bool operator!=(const xRegister16 &src) const { return this->Id != src.Id; } +}; - class xRegister32 : public xRegisterInt - { - typedef xRegisterInt _parent; +class xRegister32 : public xRegisterInt +{ + typedef xRegisterInt _parent; - public: - xRegister32(): _parent() {} - explicit xRegister32( int regId ) : _parent( regId ) {} +public: + xRegister32() + : _parent() + { + } + explicit xRegister32(int regId) + : _parent(regId) + { + } - virtual uint GetOperandSize() const { return 4; } + virtual uint GetOperandSize() const { return 4; } - bool operator==( const xRegister32& src ) const { return this->Id == src.Id; } - bool operator!=( const xRegister32& src ) const { return this->Id != src.Id; } - }; + bool operator==(const xRegister32 &src) const { return this->Id == src.Id; } + bool operator!=(const xRegister32 &src) const { return this->Id != src.Id; } +}; - class xRegister64 : public xRegisterInt - { - typedef xRegisterInt _parent; +class xRegister64 : public xRegisterInt +{ + typedef xRegisterInt _parent; - public: - xRegister64(): _parent() {} - explicit xRegister64( int regId ) : _parent( regId ) {} +public: + xRegister64() + : _parent() + { + } + explicit xRegister64(int regId) + : _parent(regId) + { + } - virtual uint GetOperandSize() const { return 8; } + virtual uint GetOperandSize() const { return 8; } - bool operator==( const xRegister64& src ) const { return this->Id == src.Id; } - bool operator!=( const xRegister64& src ) const { return this->Id != src.Id; } - }; + bool operator==(const xRegister64 &src) const { return this->Id == src.Id; } + bool operator!=(const xRegister64 &src) const { return this->Id != src.Id; } +}; - // -------------------------------------------------------------------------------------- - // xRegisterSSE - Represents either a 64 bit or 128 bit SIMD register - // -------------------------------------------------------------------------------------- - // This register type is provided to allow legal syntax for instructions that accept - // an XMM register as a parameter, but do not allow for a GPR. +// -------------------------------------------------------------------------------------- +// xRegisterSSE - Represents either a 64 bit or 128 bit SIMD register +// -------------------------------------------------------------------------------------- +// This register type is provided to allow legal syntax for instructions that accept +// an XMM register as a parameter, but do not allow for a GPR. - class xRegisterSSE : public xRegisterBase - { - typedef xRegisterBase _parent; +class xRegisterSSE : public xRegisterBase +{ + typedef xRegisterBase _parent; - public: - xRegisterSSE(): _parent() {} - explicit xRegisterSSE( int regId ) : _parent( regId ) {} +public: + xRegisterSSE() + : _parent() + { + } + explicit xRegisterSSE(int regId) + : _parent(regId) + { + } - virtual uint GetOperandSize() const { return 16; } + virtual uint GetOperandSize() const { return 16; } - bool operator==( const xRegisterSSE& src ) const { return this->Id == src.Id; } - bool operator!=( const xRegisterSSE& src ) const { return this->Id != src.Id; } + bool operator==(const xRegisterSSE &src) const { return this->Id == src.Id; } + bool operator!=(const xRegisterSSE &src) const { return this->Id != src.Id; } - xRegisterSSE& operator++() - { - ++Id; - Id &= (iREGCNT_XMM - 1); - return *this; - } + xRegisterSSE &operator++() + { + ++Id; + Id &= (iREGCNT_XMM - 1); + return *this; + } - xRegisterSSE& operator--() - { - --Id; - Id &= (iREGCNT_XMM - 1); - return *this; - } + xRegisterSSE &operator--() + { + --Id; + Id &= (iREGCNT_XMM - 1); + return *this; + } - static const inline xRegisterSSE& GetInstance(uint id); - }; + static const inline xRegisterSSE &GetInstance(uint id); +}; - class xRegisterCL : public xRegister8 - { - public: - xRegisterCL(): xRegister8( 1 ) {} - }; +class xRegisterCL : public xRegister8 +{ +public: + xRegisterCL() + : xRegister8(1) + { + } +}; - // -------------------------------------------------------------------------------------- - // xAddressReg - // -------------------------------------------------------------------------------------- - // Use 32/64 bit registers as our index registers (for ModSib-style memory address calculations). - // This type is implicitly exchangeable with xRegister32/64. - // - // Only xAddressReg provides operators for constructing xAddressInfo types. These operators - // could have been added to xRegister32/64 directly instead, however I think this design makes - // more sense and allows the programmer a little more type protection if needed. - // +// -------------------------------------------------------------------------------------- +// xAddressReg +// -------------------------------------------------------------------------------------- +// Use 32/64 bit registers as our index registers (for ModSib-style memory address calculations). +// This type is implicitly exchangeable with xRegister32/64. +// +// Only xAddressReg provides operators for constructing xAddressInfo types. These operators +// could have been added to xRegister32/64 directly instead, however I think this design makes +// more sense and allows the programmer a little more type protection if needed. +// #ifdef __x86_64__ #define xRegisterLong xRegister64 @@ -414,462 +470,543 @@ template< typename T > void xWrite( T val ); #define xRegisterLong xRegister32 #endif - class xAddressReg : public xRegisterLong - { - public: - xAddressReg(): xRegisterLong() {} - xAddressReg( const xAddressReg& src ) : xRegisterLong( src.Id ) {} - xAddressReg( const xRegister32& src ) : xRegisterLong( src.Id ) {} - xAddressReg( const xRegister64& src ) : xRegisterLong( src.Id ) {} - explicit xAddressReg( int regId ) : xRegisterLong( regId ) {} +class xAddressReg : public xRegisterLong +{ +public: + xAddressReg() + : xRegisterLong() + { + } + xAddressReg(const xAddressReg &src) + : xRegisterLong(src.Id) + { + } + xAddressReg(const xRegister32 &src) + : xRegisterLong(src.Id) + { + } + xAddressReg(const xRegister64 &src) + : xRegisterLong(src.Id) + { + } + explicit xAddressReg(int regId) + : xRegisterLong(regId) + { + } - // Returns true if the register is the stack pointer: ESP. - bool IsStackPointer() const { return Id == 4; } + // Returns true if the register is the stack pointer: ESP. + bool IsStackPointer() const { return Id == 4; } - xAddressVoid operator+( const xAddressReg& right ) const; - xAddressVoid operator+( s32 right ) const; - xAddressVoid operator+( const void* right ) const; - xAddressVoid operator-( s32 right ) const; - xAddressVoid operator-( const void* right ) const; - xAddressVoid operator*( int factor ) const; - xAddressVoid operator<<( u32 shift ) const; + xAddressVoid operator+(const xAddressReg &right) const; + xAddressVoid operator+(s32 right) const; + xAddressVoid operator+(const void *right) const; + xAddressVoid operator-(s32 right) const; + xAddressVoid operator-(const void *right) const; + xAddressVoid operator*(int factor) const; + xAddressVoid operator<<(u32 shift) const; +}; - }; +// -------------------------------------------------------------------------------------- +// xRegisterEmpty +// -------------------------------------------------------------------------------------- +struct xRegisterEmpty +{ + operator xRegister8() const + { + return xRegister8(xRegId_Empty); + } - // -------------------------------------------------------------------------------------- - // xRegisterEmpty - // -------------------------------------------------------------------------------------- - struct xRegisterEmpty - { - operator xRegister8() const - { - return xRegister8( xRegId_Empty ); - } + operator xRegister16() const + { + return xRegister16(xRegId_Empty); + } - operator xRegister16() const - { - return xRegister16( xRegId_Empty ); - } + operator xRegisterSSE() const + { + return xRegisterSSE(xRegId_Empty); + } - operator xRegisterSSE() const - { - return xRegisterSSE( xRegId_Empty ); - } + operator xAddressReg() const + { + return xAddressReg(xRegId_Empty); + } +}; - operator xAddressReg() const - { - return xAddressReg( xRegId_Empty ); - } - }; +// FIXME This one is likely useless and superseeded by the future xRegister16or32or64 +class xRegister16or32 +{ +protected: + const xRegisterInt &m_convtype; - // FIXME This one is likely useless and superseeded by the future xRegister16or32or64 - class xRegister16or32 - { - protected: - const xRegisterInt& m_convtype; +public: + xRegister16or32(const xRegister32 &src) + : m_convtype(src) + { + } + xRegister16or32(const xRegister16 &src) + : m_convtype(src) + { + } - public: - xRegister16or32( const xRegister32& src ) : m_convtype( src ) {} - xRegister16or32( const xRegister16& src ) : m_convtype( src ) {} + operator const xRegisterBase &() const { return m_convtype; } - operator const xRegisterBase&() const { return m_convtype; } + const xRegisterInt *operator->() const + { + return &m_convtype; + } +}; - const xRegisterInt* operator->() const - { - return &m_convtype; - } - }; +class xRegister16or32or64 +{ +protected: + const xRegisterInt &m_convtype; - class xRegister16or32or64 - { - protected: - const xRegisterInt& m_convtype; +public: + xRegister16or32or64(const xRegister64 &src) + : m_convtype(src) + { + } + xRegister16or32or64(const xRegister32 &src) + : m_convtype(src) + { + } + xRegister16or32or64(const xRegister16 &src) + : m_convtype(src) + { + } - public: - xRegister16or32or64( const xRegister64& src ) : m_convtype( src ) {} - xRegister16or32or64( const xRegister32& src ) : m_convtype( src ) {} - xRegister16or32or64( const xRegister16& src ) : m_convtype( src ) {} + operator const xRegisterBase &() const { return m_convtype; } - operator const xRegisterBase&() const { return m_convtype; } + const xRegisterInt *operator->() const + { + return &m_convtype; + } +}; - const xRegisterInt* operator->() const - { - return &m_convtype; - } - }; +class xRegister32or64 +{ +protected: + const xRegisterInt &m_convtype; - class xRegister32or64 - { - protected: - const xRegisterInt& m_convtype; +public: + xRegister32or64(const xRegister64 &src) + : m_convtype(src) + { + } + xRegister32or64(const xRegister32 &src) + : m_convtype(src) + { + } - public: - xRegister32or64( const xRegister64& src ) : m_convtype( src ) {} - xRegister32or64( const xRegister32& src ) : m_convtype( src ) {} + operator const xRegisterBase &() const { return m_convtype; } - operator const xRegisterBase&() const { return m_convtype; } + const xRegisterInt *operator->() const + { + return &m_convtype; + } +}; - const xRegisterInt* operator->() const - { - return &m_convtype; - } - }; +extern const xRegisterEmpty xEmptyReg; - extern const xRegisterEmpty xEmptyReg; +// clang-format off - extern const xRegisterSSE - xmm0, xmm1, xmm2, xmm3, - xmm4, xmm5, xmm6, xmm7, - xmm8, xmm9, xmm10, xmm11, - xmm12, xmm13, xmm14, xmm15; +extern const xRegisterSSE + xmm0, xmm1, xmm2, xmm3, + xmm4, xmm5, xmm6, xmm7, + xmm8, xmm9, xmm10, xmm11, + xmm12, xmm13, xmm14, xmm15; - extern const xAddressReg - rax, rbx, rcx, rdx, - rsi, rdi, rbp, rsp, - r8, r9, r10, r11, - r12, r13, r14, r15; +extern const xAddressReg + rax, rbx, rcx, rdx, + rsi, rdi, rbp, rsp, + r8, r9, r10, r11, + r12, r13, r14, r15; - extern const xAddressReg - eax, ebx, ecx, edx, - esi, edi, ebp, esp; +extern const xAddressReg + eax, ebx, ecx, edx, + esi, edi, ebp, esp; - extern const xRegister16 - ax, bx, cx, dx, - si, di, bp, sp; +extern const xRegister16 + ax, bx, cx, dx, + si, di, bp, sp; - extern const xRegister8 - al, dl, bl, - ah, ch, dh, bh; +extern const xRegister8 + al, dl, bl, + ah, ch, dh, bh; - extern const xRegisterCL cl; // I'm special! +// clang-format on - const xRegisterSSE& xRegisterSSE::GetInstance(uint id) - { - static const xRegisterSSE *const m_tbl_xmmRegs[] = - { - &xmm0, &xmm1, &xmm2, &xmm3, - &xmm4, &xmm5, &xmm6, &xmm7, - &xmm8, &xmm9, &xmm10, &xmm11, - &xmm12, &xmm13, &xmm14, &xmm15 - }; +extern const xRegisterCL cl; // I'm special! - pxAssert(id < iREGCNT_XMM); - return *m_tbl_xmmRegs[id]; - } +const xRegisterSSE &xRegisterSSE::GetInstance(uint id) +{ + static const xRegisterSSE *const m_tbl_xmmRegs[] = + { + &xmm0, &xmm1, &xmm2, &xmm3, + &xmm4, &xmm5, &xmm6, &xmm7, + &xmm8, &xmm9, &xmm10, &xmm11, + &xmm12, &xmm13, &xmm14, &xmm15}; - // -------------------------------------------------------------------------------------- - // xAddressVoid - // -------------------------------------------------------------------------------------- - class xAddressVoid - { - public: - xAddressReg Base; // base register (no scale) - xAddressReg Index; // index reg gets multiplied by the scale - int Factor; // scale applied to the index register, in factor form (not a shift!) - s32 Displacement; // address displacement // 4B max even on 64 bits + pxAssert(id < iREGCNT_XMM); + return *m_tbl_xmmRegs[id]; +} - public: - xAddressVoid( const xAddressReg& base, const xAddressReg& index, int factor=1, s32 displacement=0 ); +// -------------------------------------------------------------------------------------- +// xAddressVoid +// -------------------------------------------------------------------------------------- +class xAddressVoid +{ +public: + xAddressReg Base; // base register (no scale) + xAddressReg Index; // index reg gets multiplied by the scale + int Factor; // scale applied to the index register, in factor form (not a shift!) + s32 Displacement; // address displacement // 4B max even on 64 bits - xAddressVoid( const xAddressReg& index, int displacement=0 ); - explicit xAddressVoid( const void* displacement ); - explicit xAddressVoid( s32 displacement=0 ); +public: + xAddressVoid(const xAddressReg &base, const xAddressReg &index, int factor = 1, s32 displacement = 0); - public: - bool IsByteSizeDisp() const { return is_s8( Displacement ); } + xAddressVoid(const xAddressReg &index, int displacement = 0); + explicit xAddressVoid(const void *displacement); + explicit xAddressVoid(s32 displacement = 0); - xAddressVoid& Add( s32 imm ) - { - Displacement += imm; - return *this; - } +public: + bool IsByteSizeDisp() const { return is_s8(Displacement); } - xAddressVoid& Add( const xAddressReg& src ); - xAddressVoid& Add( const xAddressVoid& src ); + xAddressVoid &Add(s32 imm) + { + Displacement += imm; + return *this; + } - __fi xAddressVoid operator+( const xAddressReg& right ) const { return xAddressVoid( *this ).Add( right ); } - __fi xAddressVoid operator+( const xAddressVoid& right ) const { return xAddressVoid( *this ).Add( right ); } - __fi xAddressVoid operator+( s32 imm ) const { return xAddressVoid( *this ).Add( imm ); } - __fi xAddressVoid operator-( s32 imm ) const { return xAddressVoid( *this ).Add( -imm ); } - __fi xAddressVoid operator+( const void* addr ) const { return xAddressVoid( *this ).Add( (uptr)addr ); } + xAddressVoid &Add(const xAddressReg &src); + xAddressVoid &Add(const xAddressVoid &src); - __fi void operator+=( const xAddressReg& right ) { Add( right ); } - __fi void operator+=( s32 imm ) { Add( imm ); } - __fi void operator-=( s32 imm ) { Add( -imm ); } - }; + __fi xAddressVoid operator+(const xAddressReg &right) const { return xAddressVoid(*this).Add(right); } + __fi xAddressVoid operator+(const xAddressVoid &right) const { return xAddressVoid(*this).Add(right); } + __fi xAddressVoid operator+(s32 imm) const { return xAddressVoid(*this).Add(imm); } + __fi xAddressVoid operator-(s32 imm) const { return xAddressVoid(*this).Add(-imm); } + __fi xAddressVoid operator+(const void *addr) const { return xAddressVoid(*this).Add((uptr)addr); } - // -------------------------------------------------------------------------------------- - // xAddressInfo - // -------------------------------------------------------------------------------------- - template< typename BaseType > - class xAddressInfo : public xAddressVoid - { - typedef xAddressVoid _parent; + __fi void operator+=(const xAddressReg &right) { Add(right); } + __fi void operator+=(s32 imm) { Add(imm); } + __fi void operator-=(s32 imm) { Add(-imm); } +}; - public: - xAddressInfo( const xAddressReg& base, const xAddressReg& index, int factor=1, s32 displacement=0 ) - : _parent( base, index, factor, displacement ) {} +// -------------------------------------------------------------------------------------- +// xAddressInfo +// -------------------------------------------------------------------------------------- +template +class xAddressInfo : public xAddressVoid +{ + typedef xAddressVoid _parent; - /*xAddressInfo( const xAddressVoid& src ) +public: + xAddressInfo(const xAddressReg &base, const xAddressReg &index, int factor = 1, s32 displacement = 0) + : _parent(base, index, factor, displacement) + { + } + + /*xAddressInfo( const xAddressVoid& src ) : _parent( src ) {}*/ - explicit xAddressInfo( const xAddressReg& index, int displacement=0 ) - : _parent( index, displacement ) {} + explicit xAddressInfo(const xAddressReg &index, int displacement = 0) + : _parent(index, displacement) + { + } - explicit xAddressInfo( s32 displacement=0 ) - : _parent( displacement ) {} + explicit xAddressInfo(s32 displacement = 0) + : _parent(displacement) + { + } - static xAddressInfo FromIndexReg( const xAddressReg& index, int scale=0, s32 displacement=0 ); + static xAddressInfo FromIndexReg(const xAddressReg &index, int scale = 0, s32 displacement = 0); - public: - using _parent::operator+=; - using _parent::operator-=; +public: + using _parent::operator+=; + using _parent::operator-=; - bool IsByteSizeDisp() const { return is_s8( Displacement ); } + bool IsByteSizeDisp() const { return is_s8(Displacement); } - xAddressInfo& Add( s32 imm ) - { - Displacement += imm; - return *this; - } + xAddressInfo &Add(s32 imm) + { + Displacement += imm; + return *this; + } - xAddressInfo& Add( const xAddressReg& src ) { _parent::Add(src); return *this; } - xAddressInfo& Add( const xAddressInfo& src ) { _parent::Add(src); return *this; } + xAddressInfo &Add(const xAddressReg &src) + { + _parent::Add(src); + return *this; + } + xAddressInfo &Add(const xAddressInfo &src) + { + _parent::Add(src); + return *this; + } - __fi xAddressInfo operator+( const xAddressReg& right ) const { return xAddressInfo( *this ).Add( right ); } - __fi xAddressInfo operator+( const xAddressInfo& right ) const { return xAddressInfo( *this ).Add( right ); } - __fi xAddressInfo operator+( s32 imm ) const { return xAddressInfo( *this ).Add( imm ); } - __fi xAddressInfo operator-( s32 imm ) const { return xAddressInfo( *this ).Add( -imm ); } - __fi xAddressInfo operator+( const void* addr ) const { return xAddressInfo( *this ).Add( (uptr)addr ); } + __fi xAddressInfo operator+(const xAddressReg &right) const { return xAddressInfo(*this).Add(right); } + __fi xAddressInfo operator+(const xAddressInfo &right) const { return xAddressInfo(*this).Add(right); } + __fi xAddressInfo operator+(s32 imm) const { return xAddressInfo(*this).Add(imm); } + __fi xAddressInfo operator-(s32 imm) const { return xAddressInfo(*this).Add(-imm); } + __fi xAddressInfo operator+(const void *addr) const { return xAddressInfo(*this).Add((uptr)addr); } - __fi void operator+=( const xAddressInfo& right ) { Add( right ); } - }; + __fi void operator+=(const xAddressInfo &right) { Add(right); } +}; - typedef xAddressInfo xAddress128; - typedef xAddressInfo xAddress64; - typedef xAddressInfo xAddress32; - typedef xAddressInfo xAddress16; - typedef xAddressInfo xAddress8; +typedef xAddressInfo xAddress128; +typedef xAddressInfo xAddress64; +typedef xAddressInfo xAddress32; +typedef xAddressInfo xAddress16; +typedef xAddressInfo xAddress8; - static __fi xAddressVoid operator+( const void* addr, const xAddressVoid& right ) - { - return right + addr; - } +static __fi xAddressVoid operator+(const void *addr, const xAddressVoid &right) +{ + return right + addr; +} - static __fi xAddressVoid operator+( s32 addr, const xAddressVoid& right ) - { - return right + addr; - } +static __fi xAddressVoid operator+(s32 addr, const xAddressVoid &right) +{ + return right + addr; +} - template< typename OperandType > - static __fi xAddressInfo operator+( const void* addr, const xAddressInfo& right ) - { - //return xAddressInfo( (sptr)addr ).Add( reg ); - return right + addr; - } +template +static __fi xAddressInfo operator+(const void *addr, const xAddressInfo &right) +{ + //return xAddressInfo( (sptr)addr ).Add( reg ); + return right + addr; +} - template< typename OperandType > - static __fi xAddressInfo operator+( s32 addr, const xAddressInfo& right ) - { - return right + addr; - } +template +static __fi xAddressInfo operator+(s32 addr, const xAddressInfo &right) +{ + return right + addr; +} - // -------------------------------------------------------------------------------------- - // xImmReg< typename xRegType > - // -------------------------------------------------------------------------------------- - // Used to represent an immediate value which can also be optimized to a register. Note - // that the immediate value represented by this structure is *always* legal. The register - // assignment is an optional optimization which can be implemented in cases where an - // immediate is used enough times to merit allocating it to a register. - // - // Note: not all instructions support this operand type (yet). You can always implement it - // manually by checking the status of IsReg() and generating the xOP conditionally. - // - template< typename xRegType > - class xImmReg - { - xRegType m_reg; - int m_imm; +// -------------------------------------------------------------------------------------- +// xImmReg< typename xRegType > +// -------------------------------------------------------------------------------------- +// Used to represent an immediate value which can also be optimized to a register. Note +// that the immediate value represented by this structure is *always* legal. The register +// assignment is an optional optimization which can be implemented in cases where an +// immediate is used enough times to merit allocating it to a register. +// +// Note: not all instructions support this operand type (yet). You can always implement it +// manually by checking the status of IsReg() and generating the xOP conditionally. +// +template +class xImmReg +{ + xRegType m_reg; + int m_imm; - public: - xImmReg() : m_reg() - { - m_imm = 0; - } +public: + xImmReg() + : m_reg() + { + m_imm = 0; + } - xImmReg( int imm, const xRegType& reg = xEmptyReg ) - { - m_reg = reg; - m_imm = imm; - } + xImmReg(int imm, const xRegType ® = xEmptyReg) + { + m_reg = reg; + m_imm = imm; + } - const xRegType& GetReg() const { return m_reg; } - int GetImm() const { return m_imm; } - bool IsReg() const { return !m_reg.IsEmpty(); } - }; + const xRegType &GetReg() const { return m_reg; } + int GetImm() const { return m_imm; } + bool IsReg() const { return !m_reg.IsEmpty(); } +}; - // -------------------------------------------------------------------------------------- - // xIndirectVoid - Internal low-level representation of the ModRM/SIB information. - // -------------------------------------------------------------------------------------- - // This class serves two purposes: It houses 'reduced' ModRM/SIB info only, which means - // that the Base, Index, Scale, and Displacement values are all in the correct arrange- - // ments, and it serves as a type-safe layer between the xRegister's operators (which - // generate xAddressInfo types) and the emitter's ModSib instruction forms. Without this, - // the xRegister would pass as a ModSib type implicitly, and that would cause ambiguity - // on a number of instructions. - // - // End users should always use xAddressInfo instead. - // - class xIndirectVoid : public OperandSizedObject - { - public: - xAddressReg Base; // base register (no scale) - xAddressReg Index; // index reg gets multiplied by the scale - uint Scale; // scale applied to the index register, in scale/shift form - s32 Displacement; // offset applied to the Base/Index registers. - // Displacement is 8/32 bits even on x86_64 +// -------------------------------------------------------------------------------------- +// xIndirectVoid - Internal low-level representation of the ModRM/SIB information. +// -------------------------------------------------------------------------------------- +// This class serves two purposes: It houses 'reduced' ModRM/SIB info only, which means +// that the Base, Index, Scale, and Displacement values are all in the correct arrange- +// ments, and it serves as a type-safe layer between the xRegister's operators (which +// generate xAddressInfo types) and the emitter's ModSib instruction forms. Without this, +// the xRegister would pass as a ModSib type implicitly, and that would cause ambiguity +// on a number of instructions. +// +// End users should always use xAddressInfo instead. +// +class xIndirectVoid : public OperandSizedObject +{ +public: + xAddressReg Base; // base register (no scale) + xAddressReg Index; // index reg gets multiplied by the scale + uint Scale; // scale applied to the index register, in scale/shift form + s32 Displacement; // offset applied to the Base/Index registers. + // Displacement is 8/32 bits even on x86_64 - public: - explicit xIndirectVoid( s32 disp ); - explicit xIndirectVoid( const xAddressVoid& src ); - xIndirectVoid( xAddressReg base, xAddressReg index, int scale=0, s32 displacement=0 ); +public: + explicit xIndirectVoid(s32 disp); + explicit xIndirectVoid(const xAddressVoid &src); + xIndirectVoid(xAddressReg base, xAddressReg index, int scale = 0, s32 displacement = 0); - virtual uint GetOperandSize() const; - xIndirectVoid& Add( s32 imm ); + virtual uint GetOperandSize() const; + xIndirectVoid &Add(s32 imm); - bool IsByteSizeDisp() const { return is_s8( Displacement ); } - bool IsMem() const { return true; } - bool IsReg() const { return false; } - bool IsExtended() const { return false; } // Non sense but ease template + bool IsByteSizeDisp() const { return is_s8(Displacement); } + bool IsMem() const { return true; } + bool IsReg() const { return false; } + bool IsExtended() const { return false; } // Non sense but ease template - operator xAddressVoid() - { - return xAddressVoid( Base, Index, Scale, Displacement ); - } + operator xAddressVoid() + { + return xAddressVoid(Base, Index, Scale, Displacement); + } - __fi xIndirectVoid operator+( const s32 imm ) const { return xIndirectVoid( *this ).Add( imm ); } - __fi xIndirectVoid operator-( const s32 imm ) const { return xIndirectVoid( *this ).Add( -imm ); } + __fi xIndirectVoid operator+(const s32 imm) const { return xIndirectVoid(*this).Add(imm); } + __fi xIndirectVoid operator-(const s32 imm) const { return xIndirectVoid(*this).Add(-imm); } - protected: - void Reduce(); - }; +protected: + void Reduce(); +}; - template< typename OperandType > - class xIndirect : public xIndirectVoid - { - typedef xIndirectVoid _parent; +template +class xIndirect : public xIndirectVoid +{ + typedef xIndirectVoid _parent; - public: - explicit xIndirect( s32 disp ) : _parent( disp ) {} - explicit xIndirect( const xAddressInfo& src ) : _parent( src ) {} - xIndirect( xAddressReg base, xAddressReg index, int scale=0, s32 displacement=0 ) - : _parent( base, index, scale, displacement ) {} +public: + explicit xIndirect(s32 disp) + : _parent(disp) + { + } + explicit xIndirect(const xAddressInfo &src) + : _parent(src) + { + } + xIndirect(xAddressReg base, xAddressReg index, int scale = 0, s32 displacement = 0) + : _parent(base, index, scale, displacement) + { + } - virtual uint GetOperandSize() const { return sizeof(OperandType); } + virtual uint GetOperandSize() const { return sizeof(OperandType); } - xIndirect& Add( s32 imm ) - { - Displacement += imm; - return *this; - } + xIndirect &Add(s32 imm) + { + Displacement += imm; + return *this; + } - __fi xIndirect operator+( const s32 imm ) const { return xIndirect( *this ).Add( imm ); } - __fi xIndirect operator-( const s32 imm ) const { return xIndirect( *this ).Add( -imm ); } + __fi xIndirect operator+(const s32 imm) const { return xIndirect(*this).Add(imm); } + __fi xIndirect operator-(const s32 imm) const { return xIndirect(*this).Add(-imm); } - bool operator==( const xIndirect& src ) const - { - return - ( Base == src.Base ) && ( Index == src.Index ) && - ( Scale == src.Scale ) && ( Displacement == src.Displacement ); - } + bool operator==(const xIndirect &src) const + { + return (Base == src.Base) && (Index == src.Index) && + (Scale == src.Scale) && (Displacement == src.Displacement); + } - bool operator!=( const xIndirect& src ) const - { - return !operator==( src ); - } + bool operator!=(const xIndirect &src) const + { + return !operator==(src); + } - protected: - void Reduce(); - }; +protected: + void Reduce(); +}; - typedef xIndirect xIndirect128; - typedef xIndirect xIndirect64; - typedef xIndirect xIndirect32; - typedef xIndirect xIndirect16; - typedef xIndirect xIndirect8; +typedef xIndirect xIndirect128; +typedef xIndirect xIndirect64; +typedef xIndirect xIndirect32; +typedef xIndirect xIndirect16; +typedef xIndirect xIndirect8; - // -------------------------------------------------------------------------------------- - // xIndirect64orLess - base class 64, 32, 16, and 8 bit operand types - // -------------------------------------------------------------------------------------- - class xIndirect64orLess : public xIndirectVoid - { - typedef xIndirectVoid _parent; +// -------------------------------------------------------------------------------------- +// xIndirect64orLess - base class 64, 32, 16, and 8 bit operand types +// -------------------------------------------------------------------------------------- +class xIndirect64orLess : public xIndirectVoid +{ + typedef xIndirectVoid _parent; - protected: - uint m_OpSize; +protected: + uint m_OpSize; - public: - xIndirect64orLess( const xIndirect8& src ) : _parent( src ) { m_OpSize = src.GetOperandSize(); } - xIndirect64orLess( const xIndirect16& src ) : _parent( src ) { m_OpSize = src.GetOperandSize(); } - xIndirect64orLess( const xIndirect32& src ) : _parent( src ) { m_OpSize = src.GetOperandSize(); } - xIndirect64orLess( const xIndirect64& src ) : _parent( src ) { m_OpSize = src.GetOperandSize(); } +public: + xIndirect64orLess(const xIndirect8 &src) + : _parent(src) + { + m_OpSize = src.GetOperandSize(); + } + xIndirect64orLess(const xIndirect16 &src) + : _parent(src) + { + m_OpSize = src.GetOperandSize(); + } + xIndirect64orLess(const xIndirect32 &src) + : _parent(src) + { + m_OpSize = src.GetOperandSize(); + } + xIndirect64orLess(const xIndirect64 &src) + : _parent(src) + { + m_OpSize = src.GetOperandSize(); + } - uint GetOperandSize() const { return m_OpSize; } + uint GetOperandSize() const { return m_OpSize; } - protected: - //xIndirect64orLess( const xAddressVoid& src ) : _parent( src ) {} +protected: + //xIndirect64orLess( const xAddressVoid& src ) : _parent( src ) {} - explicit xIndirect64orLess( s32 disp ) : _parent( disp ) {} - xIndirect64orLess( xAddressReg base, xAddressReg index, int scale=0, s32 displacement=0 ) : - _parent( base, index, scale, displacement ) {} - }; + explicit xIndirect64orLess(s32 disp) + : _parent(disp) + { + } + xIndirect64orLess(xAddressReg base, xAddressReg index, int scale = 0, s32 displacement = 0) + : _parent(base, index, scale, displacement) + { + } +}; - // -------------------------------------------------------------------------------------- - // xAddressIndexer - // -------------------------------------------------------------------------------------- - // This is a type-translation "interface class" which provisions our ptr[] syntax. - // xAddressReg types go in, and xIndirectVoid derived types come out. - // - template< typename xModSibType > - class xAddressIndexer - { - public: - // passthrough instruction, allows ModSib to pass silently through ptr translation - // without doing anything and without compiler error. - const xModSibType& operator[]( const xModSibType& src ) const { return src; } +// -------------------------------------------------------------------------------------- +// xAddressIndexer +// -------------------------------------------------------------------------------------- +// This is a type-translation "interface class" which provisions our ptr[] syntax. +// xAddressReg types go in, and xIndirectVoid derived types come out. +// +template +class xAddressIndexer +{ +public: + // passthrough instruction, allows ModSib to pass silently through ptr translation + // without doing anything and without compiler error. + const xModSibType &operator[](const xModSibType &src) const { return src; } - xModSibType operator[]( const xAddressReg& src ) const - { - return xModSibType( src, xEmptyReg ); - } + xModSibType operator[](const xAddressReg &src) const + { + return xModSibType(src, xEmptyReg); + } - xModSibType operator[]( const xAddressVoid& src ) const - { - return xModSibType( src.Base, src.Index, src.Factor, src.Displacement ); - } + xModSibType operator[](const xAddressVoid &src) const + { + return xModSibType(src.Base, src.Index, src.Factor, src.Displacement); + } - xModSibType operator[]( const void* src ) const - { - return xModSibType( (uptr)src ); - } - }; + xModSibType operator[](const void *src) const + { + return xModSibType((uptr)src); + } +}; - // ptr[] - use this form for instructions which can resolve the address operand size from - // the other register operand sizes. - extern const xAddressIndexer ptr; - extern const xAddressIndexer ptr128; - extern const xAddressIndexer ptr64; - extern const xAddressIndexer ptr32; - extern const xAddressIndexer ptr16; - extern const xAddressIndexer ptr8; +// ptr[] - use this form for instructions which can resolve the address operand size from +// the other register operand sizes. +extern const xAddressIndexer ptr; +extern const xAddressIndexer ptr128; +extern const xAddressIndexer ptr64; +extern const xAddressIndexer ptr32; +extern const xAddressIndexer ptr16; +extern const xAddressIndexer ptr8; - // -------------------------------------------------------------------------------------- - // xDirectOrIndirect - // -------------------------------------------------------------------------------------- - // This utility class can represent either a direct (register) or indirect (memory address) - // source or destination operand. When supplied to an emitted instruction, the direct form - // is favored *if* it is not Empty (xEmptyReg). Otherwise the indirect form is used. - // +// -------------------------------------------------------------------------------------- +// xDirectOrIndirect +// -------------------------------------------------------------------------------------- +// This utility class can represent either a direct (register) or indirect (memory address) +// source or destination operand. When supplied to an emitted instruction, the direct form +// is favored *if* it is not Empty (xEmptyReg). Otherwise the indirect form is used. +// #if 0 template< typename xRegType, typename xSibType > class xDirectOrIndirect @@ -914,120 +1051,123 @@ template< typename T > void xWrite( T val ); typedef xDirectOrIndirect xDirectOrIndirect128; #endif - // -------------------------------------------------------------------------------------- - // xSmartJump - // -------------------------------------------------------------------------------------- - // This class provides an interface for generating forward-based j8's or j32's "smartly" - // as per the measured displacement distance. If the displacement is a valid s8, then - // a j8 is inserted, else a j32. - // - // Note: This class is inherently unsafe, and so it's recommended to use xForwardJump8/32 - // whenever it is known that the jump destination is (or is not) short. Only use - // xSmartJump in cases where it's unknown what jump encoding will be ideal. - // - // Important: Use this tool with caution! xSmartJump cannot be used in cases where jump - // targets overlap, since the writeback of the second target will alter the position of - // the first target (which breaks the relative addressing). To assist in avoiding such - // errors, xSmartJump works based on C++ block scope, where the destruction of the - // xSmartJump object (invoked by a '}') signals the target of the jump. Example: - // - // { - // iCMP( EAX, ECX ); - // xSmartJump jumpTo( Jcc_Above ); - // [... conditional code ...] - // } // smartjump targets this spot. - // - // No code inside the scope can attempt to jump outside the scoped block (unless the jump - // uses an immediate addressing method, such as Register or Mod/RM forms of JMP/CALL). - // Multiple SmartJumps can be safely nested inside scopes, as long as they are properly - // scoped themselves. - // - // Performance Analysis: j8's use 4 less byes per opcode, and thus can provide minor - // speed benefits in the form of L1/L2 cache clutter, on any CPU. They're also notably - // faster on P4's, and mildly faster on AMDs. (Core2's and i7's don't care) - // - class xSmartJump - { - DeclareNoncopyableObject(xSmartJump); +// -------------------------------------------------------------------------------------- +// xSmartJump +// -------------------------------------------------------------------------------------- +// This class provides an interface for generating forward-based j8's or j32's "smartly" +// as per the measured displacement distance. If the displacement is a valid s8, then +// a j8 is inserted, else a j32. +// +// Note: This class is inherently unsafe, and so it's recommended to use xForwardJump8/32 +// whenever it is known that the jump destination is (or is not) short. Only use +// xSmartJump in cases where it's unknown what jump encoding will be ideal. +// +// Important: Use this tool with caution! xSmartJump cannot be used in cases where jump +// targets overlap, since the writeback of the second target will alter the position of +// the first target (which breaks the relative addressing). To assist in avoiding such +// errors, xSmartJump works based on C++ block scope, where the destruction of the +// xSmartJump object (invoked by a '}') signals the target of the jump. Example: +// +// { +// iCMP( EAX, ECX ); +// xSmartJump jumpTo( Jcc_Above ); +// [... conditional code ...] +// } // smartjump targets this spot. +// +// No code inside the scope can attempt to jump outside the scoped block (unless the jump +// uses an immediate addressing method, such as Register or Mod/RM forms of JMP/CALL). +// Multiple SmartJumps can be safely nested inside scopes, as long as they are properly +// scoped themselves. +// +// Performance Analysis: j8's use 4 less byes per opcode, and thus can provide minor +// speed benefits in the form of L1/L2 cache clutter, on any CPU. They're also notably +// faster on P4's, and mildly faster on AMDs. (Core2's and i7's don't care) +// +class xSmartJump +{ + DeclareNoncopyableObject(xSmartJump); - protected: - u8* m_baseptr; // base address of the instruction (passed to the instruction emitter) - JccComparisonType m_cc; // comparison type of the instruction +protected: + u8 *m_baseptr; // base address of the instruction (passed to the instruction emitter) + JccComparisonType m_cc; // comparison type of the instruction - public: - int GetMaxInstructionSize() const - { - pxAssert( m_cc != Jcc_Unknown ); - return ( m_cc == Jcc_Unconditional ) ? 5 : 6; - } +public: + int GetMaxInstructionSize() const + { + pxAssert(m_cc != Jcc_Unknown); + return (m_cc == Jcc_Unconditional) ? 5 : 6; + } - JccComparisonType GetCondition() const { return m_cc; } - virtual ~xSmartJump(); + JccComparisonType GetCondition() const { return m_cc; } + virtual ~xSmartJump(); - // ------------------------------------------------------------------------ - // ccType - Comparison type to be written back to the jump instruction position. - // - xSmartJump( JccComparisonType ccType ) - { - pxAssert( ccType != Jcc_Unknown ); - m_baseptr = xGetPtr(); - m_cc = ccType; - xAdvancePtr( GetMaxInstructionSize() ); - } + // ------------------------------------------------------------------------ + // ccType - Comparison type to be written back to the jump instruction position. + // + xSmartJump(JccComparisonType ccType) + { + pxAssert(ccType != Jcc_Unknown); + m_baseptr = xGetPtr(); + m_cc = ccType; + xAdvancePtr(GetMaxInstructionSize()); + } - protected: - void SetTarget(); - }; +protected: + void SetTarget(); +}; - // -------------------------------------------------------------------------------------- - // xForwardJump - // -------------------------------------------------------------------------------------- - // Primary use of this class is through the various xForwardJA8/xForwardJLE32/etc. helpers - // defined later in this header. :) - // +// -------------------------------------------------------------------------------------- +// xForwardJump +// -------------------------------------------------------------------------------------- +// Primary use of this class is through the various xForwardJA8/xForwardJLE32/etc. helpers +// defined later in this header. :) +// - class xForwardJumpBase - { - public: - // pointer to base of the instruction *Following* the jump. The jump address will be - // relative to this address. - s8* BasePtr; +class xForwardJumpBase +{ +public: + // pointer to base of the instruction *Following* the jump. The jump address will be + // relative to this address. + s8 *BasePtr; - public: - xForwardJumpBase( uint opsize, JccComparisonType cctype ); +public: + xForwardJumpBase(uint opsize, JccComparisonType cctype); - protected: - void _setTarget( uint opsize ) const; - }; +protected: + void _setTarget(uint opsize) const; +}; - template< typename OperandType > - class xForwardJump : public xForwardJumpBase - { - public: - static const uint OperandSize = sizeof( OperandType ); +template +class xForwardJump : public xForwardJumpBase +{ +public: + static const uint OperandSize = sizeof(OperandType); - // The jump instruction is emitted at the point of object construction. The conditional - // type must be valid (Jcc_Unknown generates an assertion). - xForwardJump( JccComparisonType cctype = Jcc_Unconditional ) : xForwardJumpBase( OperandSize, cctype ) { } + // The jump instruction is emitted at the point of object construction. The conditional + // type must be valid (Jcc_Unknown generates an assertion). + xForwardJump(JccComparisonType cctype = Jcc_Unconditional) + : xForwardJumpBase(OperandSize, cctype) + { + } - // Sets the jump target by writing back the current x86Ptr to the jump instruction. - // This method can be called multiple times, re-writing the jump instruction's target - // in each case. (the the last call is the one that takes effect). - void SetTarget() const - { - _setTarget( OperandSize ); - } - }; + // Sets the jump target by writing back the current x86Ptr to the jump instruction. + // This method can be called multiple times, re-writing the jump instruction's target + // in each case. (the the last call is the one that takes effect). + void SetTarget() const + { + _setTarget(OperandSize); + } +}; - static __fi xAddressVoid operator+( const void* addr, const xAddressReg& reg ) - { - return reg + (sptr)addr; - } +static __fi xAddressVoid operator+(const void *addr, const xAddressReg ®) +{ + return reg + (sptr)addr; +} - static __fi xAddressVoid operator+( s32 addr, const xAddressReg& reg ) - { - return reg + (sptr)addr; - } +static __fi xAddressVoid operator+(s32 addr, const xAddressReg ®) +{ + return reg + (sptr)addr; +} } #include "implement/helpers.h" @@ -1041,8 +1181,8 @@ template< typename T > void xWrite( T val ); #include "implement/group1.h" #include "implement/group2.h" #include "implement/group3.h" -#include "implement/movs.h" // cmov and movsx/zx -#include "implement/dwshift.h" // doubleword shifts! +#include "implement/movs.h" // cmov and movsx/zx +#include "implement/dwshift.h" // doubleword shifts! #include "implement/incdec.h" #include "implement/test.h" #include "implement/jmpcall.h" diff --git a/common/src/Utilities/AlignedMalloc.cpp b/common/src/Utilities/AlignedMalloc.cpp index bed63b2d02..fac931b7ab 100644 --- a/common/src/Utilities/AlignedMalloc.cpp +++ b/common/src/Utilities/AlignedMalloc.cpp @@ -18,32 +18,32 @@ #include "PrecompiledHeader.h" -void* __fastcall _aligned_malloc(size_t size, size_t align) +void *__fastcall _aligned_malloc(size_t size, size_t align) { - pxAssert( align < 0x10000 ); + pxAssert(align < 0x10000); #if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9 - return aligned_alloc(align, size); + return aligned_alloc(align, size); #else - void *result = 0; - posix_memalign(&result, align, size); - return result; + void *result = 0; + posix_memalign(&result, align, size); + return result; #endif } -void* __fastcall pcsx2_aligned_realloc(void* handle, size_t new_size, size_t align, size_t old_size) +void *__fastcall pcsx2_aligned_realloc(void *handle, size_t new_size, size_t align, size_t old_size) { - pxAssert( align < 0x10000 ); + pxAssert(align < 0x10000); - void* newbuf = _aligned_malloc(new_size, align); + void *newbuf = _aligned_malloc(new_size, align); - if (newbuf != NULL && handle != NULL) { - memcpy(newbuf, handle, std::min(old_size, new_size)); - _aligned_free(handle); - } - return newbuf; + if (newbuf != NULL && handle != NULL) { + memcpy(newbuf, handle, std::min(old_size, new_size)); + _aligned_free(handle); + } + return newbuf; } -__fi void _aligned_free(void* pmem) +__fi void _aligned_free(void *pmem) { - free(pmem); + free(pmem); } diff --git a/common/src/Utilities/CheckedStaticBox.cpp b/common/src/Utilities/CheckedStaticBox.cpp index ee26175904..388bf1327e 100644 --- a/common/src/Utilities/CheckedStaticBox.cpp +++ b/common/src/Utilities/CheckedStaticBox.cpp @@ -16,62 +16,61 @@ #include "PrecompiledHeader.h" #include "CheckedStaticBox.h" -CheckedStaticBox::CheckedStaticBox( wxWindow* parent, int orientation, const wxString& title ) - : wxPanelWithHelpers( parent, wxVERTICAL ) - , ThisSizer( *new wxStaticBoxSizer( orientation, this ) ) - , ThisToggle( *new wxCheckBox( this, wxID_ANY, title, wxPoint( 8, 0 ) ) ) +CheckedStaticBox::CheckedStaticBox(wxWindow *parent, int orientation, const wxString &title) + : wxPanelWithHelpers(parent, wxVERTICAL) + , ThisSizer(*new wxStaticBoxSizer(orientation, this)) + , ThisToggle(*new wxCheckBox(this, wxID_ANY, title, wxPoint(8, 0))) { - *this += ThisToggle; - *this += ThisSizer | pxExpand; + *this += ThisToggle; + *this += ThisSizer | pxExpand; - // Ensure that the right-side of the static group box isn't too cozy: - SetMinWidth( ThisToggle.GetSize().GetWidth() + 32 ); + // Ensure that the right-side of the static group box isn't too cozy: + SetMinWidth(ThisToggle.GetSize().GetWidth() + 32); - Bind(wxEVT_CHECKBOX, &CheckedStaticBox::MainToggle_Click, this, ThisToggle.GetId()); + Bind(wxEVT_CHECKBOX, &CheckedStaticBox::MainToggle_Click, this, ThisToggle.GetId()); } // Event handler for click events for the main checkbox (default behavior: enables/disables all child controls) // This function can be overridden to implement custom handling of check enable/disable behavior. -void CheckedStaticBox::MainToggle_Click( wxCommandEvent& evt ) +void CheckedStaticBox::MainToggle_Click(wxCommandEvent &evt) { - SetValue( evt.IsChecked() ); + SetValue(evt.IsChecked()); } // Sets the main checkbox status, and enables/disables all child controls // bound to the StaticBox accordingly. -void CheckedStaticBox::SetValue( bool val ) +void CheckedStaticBox::SetValue(bool val) { - wxWindowList& list = GetChildren(); + wxWindowList &list = GetChildren(); - for( wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter) - { - wxWindow *current = *iter; - if( current != &ThisToggle ) - current->Enable( val ); - } - ThisToggle.SetValue( val ); + for (wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter) { + wxWindow *current = *iter; + if (current != &ThisToggle) + current->Enable(val); + } + ThisToggle.SetValue(val); } bool CheckedStaticBox::GetValue() const { - return ThisToggle.GetValue(); + return ThisToggle.GetValue(); } // This override is here so to only enable the children if both the main toggle and // the enable request are true. If not, disable them! -bool CheckedStaticBox::Enable( bool enable ) +bool CheckedStaticBox::Enable(bool enable) { - if (!_parent::Enable(enable)) return false; + if (!_parent::Enable(enable)) + return false; - bool val = enable && ThisToggle.GetValue(); - wxWindowList& list = GetChildren(); + bool val = enable && ThisToggle.GetValue(); + wxWindowList &list = GetChildren(); - for( wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter) - { - wxWindow *current = *iter; - if( current != &ThisToggle ) - current->Enable( val ); - } + for (wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter) { + wxWindow *current = *iter; + if (current != &ThisToggle) + current->Enable(val); + } - return true; + return true; } diff --git a/common/src/Utilities/Console.cpp b/common/src/Utilities/Console.cpp index 50ea203737..1c7f57410a 100644 --- a/common/src/Utilities/Console.cpp +++ b/common/src/Utilities/Console.cpp @@ -18,22 +18,22 @@ #include "TraceLog.h" #include "TlsVariable.inl" -#include "RedtapeWindows.h" // nneded for OutputDebugString +#include "RedtapeWindows.h" // nneded for OutputDebugString using namespace Threading; // thread-local console indentation setting. -static DeclareTls(int) conlog_Indent( 0 ); +static DeclareTls(int) conlog_Indent(0); // thread-local console color storage. -static DeclareTls(ConsoleColors) conlog_Color( DefaultConsoleColor ); +static DeclareTls(ConsoleColors) conlog_Color(DefaultConsoleColor); #ifdef __POSIX__ static FILE *stdout_fp = stdout; void Console_SetStdout(FILE *fp) { - stdout_fp = fp; + stdout_fp = fp; } #endif @@ -44,33 +44,33 @@ void Console_SetStdout(FILE *fp) // Important! Only Assert and Null console loggers are allowed during C++ startup init (when // the program or DLL first loads). Other log targets rely on the static buffer and a // threaded mutex lock, which are only valid after C++ initialization has finished. -void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp ) +void Console_SetActiveHandler(const IConsoleWriter &writer, FILE *flushfp) { - pxAssertDev( - (writer.WriteRaw != NULL) && (writer.DoWriteLn != NULL) && - (writer.Newline != NULL) && (writer.SetTitle != NULL) && - (writer.DoSetColor != NULL), - "Invalid IConsoleWriter object! All function pointer interfaces must be implemented." - ); + pxAssertDev( + (writer.WriteRaw != NULL) && (writer.DoWriteLn != NULL) && + (writer.Newline != NULL) && (writer.SetTitle != NULL) && + (writer.DoSetColor != NULL), + "Invalid IConsoleWriter object! All function pointer interfaces must be implemented."); - Console = writer; - DevConWriter = writer; + Console = writer; + DevConWriter = writer; #ifdef PCSX2_DEBUG - DbgCon = writer; + DbgCon = writer; #endif } // Writes text to the Visual Studio Output window (Microsoft Windows only). // On all other platforms this pipes to Stdout instead. -void MSW_OutputDebugString( const wxString& text ) +void MSW_OutputDebugString(const wxString &text) { #if defined(__WXMSW__) && !defined(__WXMICROWIN__) - static bool hasDebugger = wxIsDebuggerRunning(); - if( hasDebugger ) OutputDebugString( text ); + static bool hasDebugger = wxIsDebuggerRunning(); + if (hasDebugger) + OutputDebugString(text); #else - fputs(text.utf8_str(), stdout_fp); - fflush(stdout_fp); + fputs(text.utf8_str(), stdout_fp); + fflush(stdout_fp); #endif } @@ -79,23 +79,23 @@ void MSW_OutputDebugString( const wxString& text ) // ConsoleNull // -------------------------------------------------------------------------------------- -static void __concall ConsoleNull_SetTitle( const wxString& title ) {} -static void __concall ConsoleNull_DoSetColor( ConsoleColors color ) {} +static void __concall ConsoleNull_SetTitle(const wxString &title) {} +static void __concall ConsoleNull_DoSetColor(ConsoleColors color) {} static void __concall ConsoleNull_Newline() {} -static void __concall ConsoleNull_DoWrite( const wxString& fmt ) {} -static void __concall ConsoleNull_DoWriteLn( const wxString& fmt ) {} +static void __concall ConsoleNull_DoWrite(const wxString &fmt) {} +static void __concall ConsoleNull_DoWriteLn(const wxString &fmt) {} const IConsoleWriter ConsoleWriter_Null = -{ - ConsoleNull_DoWrite, - ConsoleNull_DoWriteLn, - ConsoleNull_DoSetColor, + { + ConsoleNull_DoWrite, + ConsoleNull_DoWriteLn, + ConsoleNull_DoSetColor, - ConsoleNull_DoWrite, - ConsoleNull_Newline, - ConsoleNull_SetTitle, + ConsoleNull_DoWrite, + ConsoleNull_Newline, + ConsoleNull_SetTitle, - 0, // instance-level indentation (should always be 0) + 0, // instance-level indentation (should always be 0) }; // -------------------------------------------------------------------------------------- @@ -103,118 +103,133 @@ const IConsoleWriter ConsoleWriter_Null = // -------------------------------------------------------------------------------------- #if defined(__unix__) -static __fi const char* GetLinuxConsoleColor(ConsoleColors color) +static __fi const char *GetLinuxConsoleColor(ConsoleColors color) { - switch(color) - { + switch (color) { case Color_Black: - case Color_StrongBlack: return "\033[30m\033[1m"; + case Color_StrongBlack: + return "\033[30m\033[1m"; - case Color_Red: return "\033[31m"; - case Color_StrongRed: return "\033[31m\033[1m"; + case Color_Red: + return "\033[31m"; + case Color_StrongRed: + return "\033[31m\033[1m"; - case Color_Green: return "\033[32m"; - case Color_StrongGreen: return "\033[32m\033[1m"; + case Color_Green: + return "\033[32m"; + case Color_StrongGreen: + return "\033[32m\033[1m"; - case Color_Yellow: return "\033[33m"; - case Color_StrongYellow: return "\033[33m\033[1m"; + case Color_Yellow: + return "\033[33m"; + case Color_StrongYellow: + return "\033[33m\033[1m"; - case Color_Blue: return "\033[34m"; - case Color_StrongBlue: return "\033[34m\033[1m"; + case Color_Blue: + return "\033[34m"; + case Color_StrongBlue: + return "\033[34m\033[1m"; // No orange, so use magenta. case Color_Orange: - case Color_Magenta: return "\033[35m"; + case Color_Magenta: + return "\033[35m"; case Color_StrongOrange: - case Color_StrongMagenta: return "\033[35m\033[1m"; + case Color_StrongMagenta: + return "\033[35m\033[1m"; - case Color_Cyan: return "\033[36m"; - case Color_StrongCyan: return "\033[36m\033[1m"; + case Color_Cyan: + return "\033[36m"; + case Color_StrongCyan: + return "\033[36m\033[1m"; // Use 'white' instead of grey. case Color_Gray: - case Color_White: return "\033[37m"; + case Color_White: + return "\033[37m"; case Color_StrongGray: - case Color_StrongWhite: return "\033[37m\033[1m"; + case Color_StrongWhite: + return "\033[37m\033[1m"; // On some other value being passed, clear any formatting. case Color_Default: - default: return "\033[0m"; + default: + return "\033[0m"; } } #endif // One possible default write action at startup and shutdown is to use the stdout. -static void __concall ConsoleStdout_DoWrite( const wxString& fmt ) +static void __concall ConsoleStdout_DoWrite(const wxString &fmt) { - MSW_OutputDebugString( fmt ); + MSW_OutputDebugString(fmt); } // Default write action at startup and shutdown is to use the stdout. -static void __concall ConsoleStdout_DoWriteLn( const wxString& fmt ) +static void __concall ConsoleStdout_DoWriteLn(const wxString &fmt) { - MSW_OutputDebugString( fmt + L"\n" ); + MSW_OutputDebugString(fmt + L"\n"); } static void __concall ConsoleStdout_Newline() { - MSW_OutputDebugString( L"\n" ); + MSW_OutputDebugString(L"\n"); } -static void __concall ConsoleStdout_DoSetColor( ConsoleColors color ) +static void __concall ConsoleStdout_DoSetColor(ConsoleColors color) { #if defined(__unix__) - fprintf(stdout_fp, "\033[0m%s", GetLinuxConsoleColor(color)); - fflush(stdout_fp); + fprintf(stdout_fp, "\033[0m%s", GetLinuxConsoleColor(color)); + fflush(stdout_fp); #endif } -static void __concall ConsoleStdout_SetTitle( const wxString& title ) +static void __concall ConsoleStdout_SetTitle(const wxString &title) { #if defined(__unix__) - fputs("\033]0;", stdout_fp); - fputs(title.utf8_str(), stdout_fp); - fputs("\007", stdout_fp); + fputs("\033]0;", stdout_fp); + fputs(title.utf8_str(), stdout_fp); + fputs("\007", stdout_fp); #endif } const IConsoleWriter ConsoleWriter_Stdout = -{ - ConsoleStdout_DoWrite, // Writes without newlines go to buffer to avoid error log spam. - ConsoleStdout_DoWriteLn, - ConsoleStdout_DoSetColor, + { + ConsoleStdout_DoWrite, // Writes without newlines go to buffer to avoid error log spam. + ConsoleStdout_DoWriteLn, + ConsoleStdout_DoSetColor, - ConsoleNull_DoWrite, // writes from re-piped stdout are ignored here, lest we create infinite loop hell >_< - ConsoleStdout_Newline, - ConsoleStdout_SetTitle, - 0, // instance-level indentation (should always be 0) + ConsoleNull_DoWrite, // writes from re-piped stdout are ignored here, lest we create infinite loop hell >_< + ConsoleStdout_Newline, + ConsoleStdout_SetTitle, + 0, // instance-level indentation (should always be 0) }; // -------------------------------------------------------------------------------------- // ConsoleAssert // -------------------------------------------------------------------------------------- -static void __concall ConsoleAssert_DoWrite( const wxString& fmt ) +static void __concall ConsoleAssert_DoWrite(const wxString &fmt) { - pxFail( L"Console class has not been initialized; Message written:\n\t" + fmt ); + pxFail(L"Console class has not been initialized; Message written:\n\t" + fmt); } -static void __concall ConsoleAssert_DoWriteLn( const wxString& fmt ) +static void __concall ConsoleAssert_DoWriteLn(const wxString &fmt) { - pxFail( L"Console class has not been initialized; Message written:\n\t" + fmt ); + pxFail(L"Console class has not been initialized; Message written:\n\t" + fmt); } const IConsoleWriter ConsoleWriter_Assert = -{ - ConsoleAssert_DoWrite, - ConsoleAssert_DoWriteLn, - ConsoleNull_DoSetColor, + { + ConsoleAssert_DoWrite, + ConsoleAssert_DoWriteLn, + ConsoleNull_DoSetColor, - ConsoleNull_DoWrite, - ConsoleNull_Newline, - ConsoleNull_SetTitle, + ConsoleNull_DoWrite, + ConsoleNull_Newline, + ConsoleNull_SetTitle, - 0, // instance-level indentation (should always be 0) + 0, // instance-level indentation (should always be 0) }; // ===================================================================================================== @@ -227,214 +242,216 @@ const IConsoleWriter ConsoleWriter_Assert = // glob_indent - this parameter is used to specify a global indentation setting. It is used by // WriteLn function, but defaults to 0 for Warning and Error calls. Local indentation always // applies to all writes. -wxString IConsoleWriter::_addIndentation( const wxString& src, int glob_indent=0 ) const +wxString IConsoleWriter::_addIndentation(const wxString &src, int glob_indent = 0) const { - const int indent = glob_indent + _imm_indentation; - if( indent == 0 ) return src; + const int indent = glob_indent + _imm_indentation; + if (indent == 0) + return src; - wxString result( src ); - const wxString indentStr( L'\t', indent ); - result.Replace( L"\n", L"\n" + indentStr ); - return indentStr + result; + wxString result(src); + const wxString indentStr(L'\t', indent); + result.Replace(L"\n", L"\n" + indentStr); + return indentStr + result; } // Sets the indentation to be applied to all WriteLn's. The indentation is added to the // primary write, and to any newlines specified within the write. Note that this applies // to calls to WriteLn *only* -- calls to Write bypass the indentation parser. -const IConsoleWriter& IConsoleWriter::SetIndent( int tabcount ) const +const IConsoleWriter &IConsoleWriter::SetIndent(int tabcount) const { - conlog_Indent += tabcount; - pxAssert( conlog_Indent >= 0 ); - return *this; + conlog_Indent += tabcount; + pxAssert(conlog_Indent >= 0); + return *this; } -IConsoleWriter IConsoleWriter::Indent( int tabcount ) const +IConsoleWriter IConsoleWriter::Indent(int tabcount) const { - IConsoleWriter retval = *this; - retval._imm_indentation = tabcount; - return retval; + IConsoleWriter retval = *this; + retval._imm_indentation = tabcount; + return retval; } // Changes the active console color. // This color will be unset by calls to colored text methods // such as ErrorMsg and Notice. -const IConsoleWriter& IConsoleWriter::SetColor( ConsoleColors color ) const +const IConsoleWriter &IConsoleWriter::SetColor(ConsoleColors color) const { - // Ignore current color requests since, well, the current color is already set. ;) - if( color == Color_Current ) return *this; + // Ignore current color requests since, well, the current color is already set. ;) + if (color == Color_Current) + return *this; - pxAssertMsg( (color > Color_Current) && (color < ConsoleColors_Count), "Invalid ConsoleColor specified." ); + pxAssertMsg((color > Color_Current) && (color < ConsoleColors_Count), "Invalid ConsoleColor specified."); - if( conlog_Color != color ) - DoSetColor( conlog_Color = color ); + if (conlog_Color != color) + DoSetColor(conlog_Color = color); - return *this; + return *this; } ConsoleColors IConsoleWriter::GetColor() const { - return conlog_Color; + return conlog_Color; } // Restores the console color to default (usually black, or low-intensity white if the console uses a black background) -const IConsoleWriter& IConsoleWriter::ClearColor() const +const IConsoleWriter &IConsoleWriter::ClearColor() const { - if( conlog_Color != DefaultConsoleColor ) - DoSetColor( conlog_Color = DefaultConsoleColor ); + if (conlog_Color != DefaultConsoleColor) + DoSetColor(conlog_Color = DefaultConsoleColor); - return *this; + return *this; } // -------------------------------------------------------------------------------------- // ASCII/UTF8 (char*) // -------------------------------------------------------------------------------------- -bool IConsoleWriter::FormatV( const char* fmt, va_list args ) const +bool IConsoleWriter::FormatV(const char *fmt, va_list args) const { - DoWriteLn( _addIndentation( pxsFmtV(fmt,args), conlog_Indent ) ); - return false; + DoWriteLn(_addIndentation(pxsFmtV(fmt, args), conlog_Indent)); + return false; } -bool IConsoleWriter::WriteLn( const char* fmt, ... ) const +bool IConsoleWriter::WriteLn(const char *fmt, ...) const { - va_list args; - va_start(args,fmt); - FormatV(fmt, args); - va_end(args); + va_list args; + va_start(args, fmt); + FormatV(fmt, args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::WriteLn( ConsoleColors color, const char* fmt, ... ) const +bool IConsoleWriter::WriteLn(ConsoleColors color, const char *fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( color ); - FormatV(fmt, args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(color); + FormatV(fmt, args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::Error( const char* fmt, ... ) const +bool IConsoleWriter::Error(const char *fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( Color_StrongRed ); - FormatV(fmt, args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(Color_StrongRed); + FormatV(fmt, args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::Warning( const char* fmt, ... ) const +bool IConsoleWriter::Warning(const char *fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( Color_StrongOrange ); - FormatV(fmt, args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(Color_StrongOrange); + FormatV(fmt, args); + va_end(args); - return false; + return false; } // -------------------------------------------------------------------------------------- // Write Variants - Unicode/UTF16 style // -------------------------------------------------------------------------------------- -bool IConsoleWriter::FormatV( const wxChar* fmt, va_list args ) const +bool IConsoleWriter::FormatV(const wxChar *fmt, va_list args) const { - DoWriteLn( _addIndentation( pxsFmtV( fmt, args ), conlog_Indent ) ); - return false; + DoWriteLn(_addIndentation(pxsFmtV(fmt, args), conlog_Indent)); + return false; } -bool IConsoleWriter::WriteLn( const wxChar* fmt, ... ) const +bool IConsoleWriter::WriteLn(const wxChar *fmt, ...) const { - va_list args; - va_start(args,fmt); - FormatV(fmt,args); - va_end(args); + va_list args; + va_start(args, fmt); + FormatV(fmt, args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const +bool IConsoleWriter::WriteLn(ConsoleColors color, const wxChar *fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( color ); - FormatV(fmt,args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(color); + FormatV(fmt, args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::Error( const wxChar* fmt, ... ) const +bool IConsoleWriter::Error(const wxChar *fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( Color_StrongRed ); - FormatV(fmt,args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(Color_StrongRed); + FormatV(fmt, args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::Warning( const wxChar* fmt, ... ) const +bool IConsoleWriter::Warning(const wxChar *fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( Color_StrongOrange ); - FormatV(fmt,args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(Color_StrongOrange); + FormatV(fmt, args); + va_end(args); - return false; + return false; } // -------------------------------------------------------------------------------------- // Write Variants - Unknown style // -------------------------------------------------------------------------------------- -bool IConsoleWriter::WriteLn( const wxString fmt, ... ) const +bool IConsoleWriter::WriteLn(const wxString fmt, ...) const { - va_list args; - va_start(args,fmt); - FormatV(fmt.wx_str(),args); - va_end(args); + va_list args; + va_start(args, fmt); + FormatV(fmt.wx_str(), args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::WriteLn( ConsoleColors color, const wxString fmt, ... ) const +bool IConsoleWriter::WriteLn(ConsoleColors color, const wxString fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( color ); - FormatV(fmt.wx_str(),args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(color); + FormatV(fmt.wx_str(), args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::Error( const wxString fmt, ... ) const +bool IConsoleWriter::Error(const wxString fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( Color_StrongRed ); - FormatV(fmt.wx_str(),args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(Color_StrongRed); + FormatV(fmt.wx_str(), args); + va_end(args); - return false; + return false; } -bool IConsoleWriter::Warning( const wxString fmt, ... ) const +bool IConsoleWriter::Warning(const wxString fmt, ...) const { - va_list args; - va_start(args,fmt); - ConsoleColorScope cs( Color_StrongOrange ); - FormatV(fmt.wx_str(),args); - va_end(args); + va_list args; + va_start(args, fmt); + ConsoleColorScope cs(Color_StrongOrange); + FormatV(fmt.wx_str(), args); + va_end(args); - return false; + return false; } @@ -442,73 +459,72 @@ bool IConsoleWriter::Warning( const wxString fmt, ... ) const // ConsoleColorScope / ConsoleIndentScope // -------------------------------------------------------------------------------------- -ConsoleColorScope::ConsoleColorScope( ConsoleColors newcolor ) +ConsoleColorScope::ConsoleColorScope(ConsoleColors newcolor) { - m_IsScoped = false; - m_newcolor = newcolor; - EnterScope(); + m_IsScoped = false; + m_newcolor = newcolor; + EnterScope(); } ConsoleColorScope::~ConsoleColorScope() throw() { - LeaveScope(); + LeaveScope(); } void ConsoleColorScope::EnterScope() { - if (!m_IsScoped) - { - m_old_color = Console.GetColor(); - Console.SetColor( m_newcolor ); - m_IsScoped = true; - } + if (!m_IsScoped) { + m_old_color = Console.GetColor(); + Console.SetColor(m_newcolor); + m_IsScoped = true; + } } void ConsoleColorScope::LeaveScope() { - m_IsScoped = m_IsScoped && (Console.SetColor( m_old_color ), false); + m_IsScoped = m_IsScoped && (Console.SetColor(m_old_color), false); } -ConsoleIndentScope::ConsoleIndentScope( int tabs ) +ConsoleIndentScope::ConsoleIndentScope(int tabs) { - m_IsScoped = false; - m_amount = tabs; - EnterScope(); + m_IsScoped = false; + m_amount = tabs; + EnterScope(); } ConsoleIndentScope::~ConsoleIndentScope() throw() { - try { - LeaveScope(); - } - DESTRUCTOR_CATCHALL + try { + LeaveScope(); + } + DESTRUCTOR_CATCHALL } void ConsoleIndentScope::EnterScope() { - m_IsScoped = m_IsScoped || (Console.SetIndent( m_amount ),true); + m_IsScoped = m_IsScoped || (Console.SetIndent(m_amount), true); } void ConsoleIndentScope::LeaveScope() { - m_IsScoped = m_IsScoped && (Console.SetIndent( -m_amount ),false); + m_IsScoped = m_IsScoped && (Console.SetIndent(-m_amount), false); } -ConsoleAttrScope::ConsoleAttrScope( ConsoleColors newcolor, int indent ) +ConsoleAttrScope::ConsoleAttrScope(ConsoleColors newcolor, int indent) { - m_old_color = Console.GetColor(); - Console.SetIndent( m_tabsize = indent ); - Console.SetColor( newcolor ); + m_old_color = Console.GetColor(); + Console.SetIndent(m_tabsize = indent); + Console.SetColor(newcolor); } ConsoleAttrScope::~ConsoleAttrScope() throw() { - try { - Console.SetColor( m_old_color ); - Console.SetIndent( -m_tabsize ); - } - DESTRUCTOR_CATCHALL + try { + Console.SetColor(m_old_color); + Console.SetIndent(-m_tabsize); + } + DESTRUCTOR_CATCHALL } @@ -520,18 +536,18 @@ ConsoleAttrScope::~ConsoleAttrScope() throw() // platform specific code). Under windows Stdout will attempt to write to the IDE Debug // console, if one is available (such as running pcsx2 via MSVC). If not available, then // the log message will pretty much be lost into the ether. -// -#define _DefaultWriter_ ConsoleWriter_Stdout +// +#define _DefaultWriter_ ConsoleWriter_Stdout -IConsoleWriter Console = _DefaultWriter_; -IConsoleWriter DevConWriter = _DefaultWriter_; -bool DevConWriterEnabled = false; +IConsoleWriter Console = _DefaultWriter_; +IConsoleWriter DevConWriter = _DefaultWriter_; +bool DevConWriterEnabled = false; #ifdef PCSX2_DEBUG -IConsoleWriter DbgConWriter = _DefaultWriter_; +IConsoleWriter DbgConWriter = _DefaultWriter_; #endif -NullConsoleWriter NullCon = {}; +NullConsoleWriter NullCon = {}; // -------------------------------------------------------------------------------------- // ConsoleLogSource (implementations) @@ -539,31 +555,31 @@ NullConsoleWriter NullCon = {}; // Writes to the console using the specified color. This overrides the default color setting // for this log. -bool ConsoleLogSource::WriteV( ConsoleColors color, const char *fmt, va_list list ) const +bool ConsoleLogSource::WriteV(ConsoleColors color, const char *fmt, va_list list) const { - ConsoleColorScope cs(color); - DoWrite( pxsFmtV(fmt,list).c_str() ); - return false; + ConsoleColorScope cs(color); + DoWrite(pxsFmtV(fmt, list).c_str()); + return false; } -bool ConsoleLogSource::WriteV( ConsoleColors color, const wxChar *fmt, va_list list ) const +bool ConsoleLogSource::WriteV(ConsoleColors color, const wxChar *fmt, va_list list) const { - ConsoleColorScope cs(color); - DoWrite( pxsFmtV(fmt,list).c_str() ); - return false; + ConsoleColorScope cs(color); + DoWrite(pxsFmtV(fmt, list).c_str()); + return false; } // Writes to the console using the source's default color. Note that the source's default // color will always be used, thus ConsoleColorScope() will not be effectual unless the // console's default color is Color_Default. -bool ConsoleLogSource::WriteV( const char *fmt, va_list list ) const +bool ConsoleLogSource::WriteV(const char *fmt, va_list list) const { - WriteV( DefaultColor, fmt, list ); - return false; + WriteV(DefaultColor, fmt, list); + return false; } -bool ConsoleLogSource::WriteV( const wxChar *fmt, va_list list ) const +bool ConsoleLogSource::WriteV(const wxChar *fmt, va_list list) const { - WriteV( DefaultColor, fmt, list ); - return false; + WriteV(DefaultColor, fmt, list); + return false; } diff --git a/common/src/Utilities/Darwin/DarwinMisc.cpp b/common/src/Utilities/Darwin/DarwinMisc.cpp index a8624ece0e..4087a1364d 100644 --- a/common/src/Utilities/Darwin/DarwinMisc.cpp +++ b/common/src/Utilities/Darwin/DarwinMisc.cpp @@ -24,7 +24,7 @@ #include #define NELEM(x) \ - ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) + ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) // Darwin (OSX) is a bit different from Linux when requesting properties of // the OS because of its BSD/Mach heritage. Helpfully, most of this code @@ -38,23 +38,23 @@ // failure (not supported by the operating system). u64 GetPhysicalMemory() { - static u64 mem = 0; + static u64 mem = 0; - // fetch the total memory only once, as its an expensive system call and - // doesn't change during the course of the program. Thread-safety is - // ensured by atomic operations with full-barriers (usually compiled - // down to XCHG on x86). - if (__atomic_load_n(&mem, __ATOMIC_SEQ_CST) == 0) { - u64 getmem = 0; - size_t len = sizeof(getmem); - int mib[] = { CTL_HW, HW_MEMSIZE }; - if (sysctl(mib, NELEM(mib), &getmem, &len, NULL, 0) < 0) { - perror("sysctl:"); - } - __atomic_store_n(&mem, getmem, __ATOMIC_SEQ_CST); - } + // fetch the total memory only once, as its an expensive system call and + // doesn't change during the course of the program. Thread-safety is + // ensured by atomic operations with full-barriers (usually compiled + // down to XCHG on x86). + if (__atomic_load_n(&mem, __ATOMIC_SEQ_CST) == 0) { + u64 getmem = 0; + size_t len = sizeof(getmem); + int mib[] = {CTL_HW, HW_MEMSIZE}; + if (sysctl(mib, NELEM(mib), &getmem, &len, NULL, 0) < 0) { + perror("sysctl:"); + } + __atomic_store_n(&mem, getmem, __ATOMIC_SEQ_CST); + } - return mem; + return mem; } void InitCPUTicks() @@ -71,26 +71,26 @@ void InitCPUTicks() // GetTickFrequency() to maintain good precision. u64 GetTickFrequency() { - static u64 freq = 0; + static u64 freq = 0; - // by the time denom is not 0, the structure will have been fully - // updated and no more atomic accesses are necessary. - if (__atomic_load_n(&freq, __ATOMIC_SEQ_CST) == 0) { - mach_timebase_info_data_t info; + // by the time denom is not 0, the structure will have been fully + // updated and no more atomic accesses are necessary. + if (__atomic_load_n(&freq, __ATOMIC_SEQ_CST) == 0) { + mach_timebase_info_data_t info; - // mach_timebase_info() is a syscall, very slow, that's why we take - // pains to only do it once. On x86(-64), the result is guaranteed - // to be info.denom == info.numer == 1 (i.e.: the frequency is 1e9, - // which means GetCPUTicks is just nanoseconds). - if (mach_timebase_info(&info) != KERN_SUCCESS) { - abort(); - } + // mach_timebase_info() is a syscall, very slow, that's why we take + // pains to only do it once. On x86(-64), the result is guaranteed + // to be info.denom == info.numer == 1 (i.e.: the frequency is 1e9, + // which means GetCPUTicks is just nanoseconds). + if (mach_timebase_info(&info) != KERN_SUCCESS) { + abort(); + } - // store the calculated value atomically - __atomic_store_n(&freq, (u64) 1e9 * (u64) info.denom / (u64) info.numer, __ATOMIC_SEQ_CST); - } + // store the calculated value atomically + __atomic_store_n(&freq, (u64)1e9 * (u64)info.denom / (u64)info.numer, __ATOMIC_SEQ_CST); + } - return freq; + return freq; } // return the number of "ticks" since some arbitrary, fixed time in the @@ -99,52 +99,52 @@ u64 GetTickFrequency() // nanoseconds. u64 GetCPUTicks() { - return mach_absolute_time(); + return mach_absolute_time(); } wxString GetOSVersionString() { - wxString version; - static int initialized = 0; + wxString version; + static int initialized = 0; - // fetch the OS description only once (thread-safely) - if (__atomic_load_n(&initialized, __ATOMIC_SEQ_CST) == 0) { - char type[32] = {0}; - char release[32] = {0}; - char arch[32] = {0}; + // fetch the OS description only once (thread-safely) + if (__atomic_load_n(&initialized, __ATOMIC_SEQ_CST) == 0) { + char type[32] = {0}; + char release[32] = {0}; + char arch[32] = {0}; -#define SYSCTL_GET(var, base, name) \ - do { \ - int mib[] = { base, name }; \ - size_t len = sizeof(var); \ - sysctl(mib, NELEM(mib), NULL, &len, NULL, 0); \ - sysctl(mib, NELEM(mib), var, &len, NULL, 0); \ - } while (0) +#define SYSCTL_GET(var, base, name) \ + do { \ + int mib[] = {base, name}; \ + size_t len = sizeof(var); \ + sysctl(mib, NELEM(mib), NULL, &len, NULL, 0); \ + sysctl(mib, NELEM(mib), var, &len, NULL, 0); \ + } while (0) - SYSCTL_GET(release, CTL_KERN, KERN_OSRELEASE); - SYSCTL_GET(type, CTL_KERN, KERN_OSTYPE); - SYSCTL_GET(arch, CTL_HW, HW_MACHINE); + SYSCTL_GET(release, CTL_KERN, KERN_OSRELEASE); + SYSCTL_GET(type, CTL_KERN, KERN_OSTYPE); + SYSCTL_GET(arch, CTL_HW, HW_MACHINE); #undef SYSCTL_KERN - // I know strcat is not good, but stpcpy is not universally - // available yet. - char buf[128] = {0}; - strcat(buf, type); - strcat(buf, " "); - strcat(buf, release); - strcat(buf, " "); - strcat(buf, arch); + // I know strcat is not good, but stpcpy is not universally + // available yet. + char buf[128] = {0}; + strcat(buf, type); + strcat(buf, " "); + strcat(buf, release); + strcat(buf, " "); + strcat(buf, arch); - version = buf; + version = buf; - __atomic_store_n(&initialized, 1, __ATOMIC_SEQ_CST); - } + __atomic_store_n(&initialized, 1, __ATOMIC_SEQ_CST); + } - return version; + return version; } void ScreensaverAllow(bool allow) { - // no-op + // no-op } diff --git a/common/src/Utilities/Darwin/DarwinSemaphore.cpp b/common/src/Utilities/Darwin/DarwinSemaphore.cpp index 8171a54d5c..9f615f8fa8 100644 --- a/common/src/Utilities/Darwin/DarwinSemaphore.cpp +++ b/common/src/Utilities/Darwin/DarwinSemaphore.cpp @@ -14,17 +14,17 @@ */ #include -#include // assert +#include // assert -#include // pthread_setcancelstate() +#include // pthread_setcancelstate() -#include // gettimeofday() +#include // gettimeofday() #include -#include // semaphore_create() and semaphore_destroy() -#include // semaphore_*() -#include // mach_error_string() -#include // mach_absolute_time() +#include // semaphore_create() and semaphore_destroy() +#include // semaphore_*() +#include // mach_error_string() +#include // mach_absolute_time() #include "PrecompiledHeader.h" @@ -47,105 +47,105 @@ // // -------------------------------------------------------------------------------------- -#define MACH_CHECK(mach_retval) \ - do { \ - kern_return_t _kr = (mach_retval); \ - if (_kr != KERN_SUCCESS) { \ - fprintf(stderr, "mach error: %s", mach_error_string(_kr)); \ - assert(_kr == KERN_SUCCESS); \ - } \ - } while (0) +#define MACH_CHECK(mach_retval) \ + do { \ + kern_return_t _kr = (mach_retval); \ + if (_kr != KERN_SUCCESS) { \ + fprintf(stderr, "mach error: %s", mach_error_string(_kr)); \ + assert(_kr == KERN_SUCCESS); \ + } \ + } while (0) Threading::Semaphore::Semaphore() { - // other platforms explicitly make a thread-private (unshared) semaphore - // here. But it seems Mach doesn't support that. - MACH_CHECK(semaphore_create(mach_task_self(), (semaphore_t *)&m_sema, SYNC_POLICY_FIFO, 0)); - __atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST); + // other platforms explicitly make a thread-private (unshared) semaphore + // here. But it seems Mach doesn't support that. + MACH_CHECK(semaphore_create(mach_task_self(), (semaphore_t *)&m_sema, SYNC_POLICY_FIFO, 0)); + __atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST); } Threading::Semaphore::~Semaphore() throw() { - MACH_CHECK(semaphore_destroy(mach_task_self(), (semaphore_t) m_sema)); - __atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST); + MACH_CHECK(semaphore_destroy(mach_task_self(), (semaphore_t)m_sema)); + __atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST); } void Threading::Semaphore::Reset() { - MACH_CHECK(semaphore_destroy(mach_task_self(), (semaphore_t) m_sema)); - MACH_CHECK(semaphore_create(mach_task_self(), (semaphore_t *) &m_sema, SYNC_POLICY_FIFO, 0)); - __atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST); + MACH_CHECK(semaphore_destroy(mach_task_self(), (semaphore_t)m_sema)); + MACH_CHECK(semaphore_create(mach_task_self(), (semaphore_t *)&m_sema, SYNC_POLICY_FIFO, 0)); + __atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST); } void Threading::Semaphore::Post() { - MACH_CHECK(semaphore_signal(m_sema)); - __atomic_add_fetch(&m_counter, 1, __ATOMIC_SEQ_CST); + MACH_CHECK(semaphore_signal(m_sema)); + __atomic_add_fetch(&m_counter, 1, __ATOMIC_SEQ_CST); } void Threading::Semaphore::Post(int multiple) { - for (int i = 0; i < multiple; ++i) { - MACH_CHECK(semaphore_signal(m_sema)); - } - __atomic_add_fetch(&m_counter, multiple, __ATOMIC_SEQ_CST); + for (int i = 0; i < multiple; ++i) { + MACH_CHECK(semaphore_signal(m_sema)); + } + __atomic_add_fetch(&m_counter, multiple, __ATOMIC_SEQ_CST); } void Threading::Semaphore::WaitWithoutYield() { - pxAssertMsg(!wxThread::IsMain(), "Unyielding semaphore wait issued from the main/gui thread. Please use Wait() instead."); - MACH_CHECK(semaphore_wait(m_sema)); - __atomic_sub_fetch(&m_counter, 1, __ATOMIC_SEQ_CST); + pxAssertMsg(!wxThread::IsMain(), "Unyielding semaphore wait issued from the main/gui thread. Please use Wait() instead."); + MACH_CHECK(semaphore_wait(m_sema)); + __atomic_sub_fetch(&m_counter, 1, __ATOMIC_SEQ_CST); } -bool Threading::Semaphore::WaitWithoutYield(const wxTimeSpan& timeout) +bool Threading::Semaphore::WaitWithoutYield(const wxTimeSpan &timeout) { - // This method is the reason why there has to be a special Darwin - // implementation of Semaphore. Note that semaphore_timedwait() is prone - // to returning with KERN_ABORTED, which basically signifies that some - // signal has worken it up. The best official "documentation" for - // semaphore_timedwait() is the way it's used in Grand Central Dispatch, - // which is open-source. + // This method is the reason why there has to be a special Darwin + // implementation of Semaphore. Note that semaphore_timedwait() is prone + // to returning with KERN_ABORTED, which basically signifies that some + // signal has worken it up. The best official "documentation" for + // semaphore_timedwait() is the way it's used in Grand Central Dispatch, + // which is open-source. - // on x86 platforms, mach_absolute_time() returns nanoseconds - // TODO(aktau): on iOS a scale value from mach_timebase_info will be necessary - u64 const kOneThousand = 1000; - u64 const kOneBillion = kOneThousand * kOneThousand * kOneThousand; - u64 const delta = timeout.GetMilliseconds().GetValue() * (kOneThousand * kOneThousand); - mach_timespec_t ts; - kern_return_t kr = KERN_ABORTED; - for (u64 now = mach_absolute_time(), deadline = now + delta; - kr == KERN_ABORTED; now = mach_absolute_time()) { - if (now > deadline) { - // timed out by definition - return false; - } + // on x86 platforms, mach_absolute_time() returns nanoseconds + // TODO(aktau): on iOS a scale value from mach_timebase_info will be necessary + u64 const kOneThousand = 1000; + u64 const kOneBillion = kOneThousand * kOneThousand * kOneThousand; + u64 const delta = timeout.GetMilliseconds().GetValue() * (kOneThousand * kOneThousand); + mach_timespec_t ts; + kern_return_t kr = KERN_ABORTED; + for (u64 now = mach_absolute_time(), deadline = now + delta; + kr == KERN_ABORTED; now = mach_absolute_time()) { + if (now > deadline) { + // timed out by definition + return false; + } - u64 timeleft = deadline - now; - ts.tv_sec = timeleft / kOneBillion; - ts.tv_nsec = timeleft % kOneBillion; + u64 timeleft = deadline - now; + ts.tv_sec = timeleft / kOneBillion; + ts.tv_nsec = timeleft % kOneBillion; - // possible return values of semaphore_timedwait() (from XNU sources): - // internal kernel val -> return value - // THREAD_INTERRUPTED -> KERN_ABORTED - // THREAD_TIMED_OUT -> KERN_OPERATION_TIMED_OUT - // THREAD_AWAKENED -> KERN_SUCCESS - // THREAD_RESTART -> KERN_TERMINATED - // default -> KERN_FAILURE - kr = semaphore_timedwait(m_sema, ts); - } + // possible return values of semaphore_timedwait() (from XNU sources): + // internal kernel val -> return value + // THREAD_INTERRUPTED -> KERN_ABORTED + // THREAD_TIMED_OUT -> KERN_OPERATION_TIMED_OUT + // THREAD_AWAKENED -> KERN_SUCCESS + // THREAD_RESTART -> KERN_TERMINATED + // default -> KERN_FAILURE + kr = semaphore_timedwait(m_sema, ts); + } - if (kr == KERN_OPERATION_TIMED_OUT) { - return false; - } + if (kr == KERN_OPERATION_TIMED_OUT) { + return false; + } - // while it's entirely possible to have KERN_FAILURE here, we should - // probably assert so we can study and correct the actual error here - // (the thread dying while someone is wainting for it). - MACH_CHECK(kr); + // while it's entirely possible to have KERN_FAILURE here, we should + // probably assert so we can study and correct the actual error here + // (the thread dying while someone is wainting for it). + MACH_CHECK(kr); - __atomic_sub_fetch(&m_counter, 1, __ATOMIC_SEQ_CST); - return true; + __atomic_sub_fetch(&m_counter, 1, __ATOMIC_SEQ_CST); + return true; } // This is a wxApp-safe implementation of Wait, which makes sure and executes the App's @@ -155,20 +155,18 @@ bool Threading::Semaphore::WaitWithoutYield(const wxTimeSpan& timeout) void Threading::Semaphore::Wait() { #if wxUSE_GUI - if(!wxThread::IsMain() || (wxTheApp == NULL)) { - WaitWithoutYield(); - } - else if(_WaitGui_RecursionGuard( L"Semaphore::Wait" )) { - ScopedBusyCursor hourglass( Cursor_ReallyBusy ); - WaitWithoutYield(); - } - else { - while (!WaitWithoutYield(def_yieldgui_interval)) { - YieldToMain(); - } - } + if (!wxThread::IsMain() || (wxTheApp == NULL)) { + WaitWithoutYield(); + } else if (_WaitGui_RecursionGuard(L"Semaphore::Wait")) { + ScopedBusyCursor hourglass(Cursor_ReallyBusy); + WaitWithoutYield(); + } else { + while (!WaitWithoutYield(def_yieldgui_interval)) { + YieldToMain(); + } + } #else - WaitWithoutYield(); + WaitWithoutYield(); #endif } @@ -181,30 +179,29 @@ void Threading::Semaphore::Wait() // false if the wait timed out before the semaphore was signaled, or true if the signal was // reached prior to timeout. // -bool Threading::Semaphore::Wait(const wxTimeSpan& timeout) +bool Threading::Semaphore::Wait(const wxTimeSpan &timeout) { #if wxUSE_GUI - if(!wxThread::IsMain() || (wxTheApp == NULL)) { - return WaitWithoutYield(timeout); - } - else if (_WaitGui_RecursionGuard( L"Semaphore::TimedWait")) { - ScopedBusyCursor hourglass(Cursor_ReallyBusy); - return WaitWithoutYield(timeout); - } - else { - //ScopedBusyCursor hourglass( Cursor_KindaBusy ); - wxTimeSpan countdown((timeout)); + if (!wxThread::IsMain() || (wxTheApp == NULL)) { + return WaitWithoutYield(timeout); + } else if (_WaitGui_RecursionGuard(L"Semaphore::TimedWait")) { + ScopedBusyCursor hourglass(Cursor_ReallyBusy); + return WaitWithoutYield(timeout); + } else { + //ScopedBusyCursor hourglass( Cursor_KindaBusy ); + wxTimeSpan countdown((timeout)); - do { - if (WaitWithoutYield(def_yieldgui_interval)) break; - YieldToMain(); - countdown -= def_yieldgui_interval; - } while (countdown.GetMilliseconds() > 0); + do { + if (WaitWithoutYield(def_yieldgui_interval)) + break; + YieldToMain(); + countdown -= def_yieldgui_interval; + } while (countdown.GetMilliseconds() > 0); - return countdown.GetMilliseconds() > 0; - } + return countdown.GetMilliseconds() > 0; + } #else - return WaitWithoutYield(timeout); + return WaitWithoutYield(timeout); #endif } @@ -223,21 +220,21 @@ bool Threading::Semaphore::Wait(const wxTimeSpan& timeout) // POSIX threads), this should work. -- aktau void Threading::Semaphore::WaitNoCancel() { - int oldstate; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); - Wait(); - pthread_setcancelstate(oldstate, NULL); + int oldstate; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); + Wait(); + pthread_setcancelstate(oldstate, NULL); } -void Threading::Semaphore::WaitNoCancel(const wxTimeSpan& timeout) +void Threading::Semaphore::WaitNoCancel(const wxTimeSpan &timeout) { - int oldstate; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); - Wait(timeout); - pthread_setcancelstate(oldstate, NULL); + int oldstate; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); + Wait(timeout); + pthread_setcancelstate(oldstate, NULL); } int Threading::Semaphore::Count() { - return __atomic_load_n(&m_counter, __ATOMIC_SEQ_CST); + return __atomic_load_n(&m_counter, __ATOMIC_SEQ_CST); } diff --git a/common/src/Utilities/Darwin/DarwinThreads.cpp b/common/src/Utilities/Darwin/DarwinThreads.cpp index 6fb6520a43..b769d3543d 100644 --- a/common/src/Utilities/Darwin/DarwinThreads.cpp +++ b/common/src/Utilities/Darwin/DarwinThreads.cpp @@ -19,7 +19,7 @@ #include #if !defined(__APPLE__) -# error "DarwinThreads.cpp should only be compiled by projects or makefiles targeted at OSX." +#error "DarwinThreads.cpp should only be compiled by projects or makefiles targeted at OSX." #else #include @@ -30,7 +30,7 @@ // the LOCK prefix. The prefix works on single core CPUs fine (but is slow), but not // having the LOCK prefix is very bad indeed. -__forceinline void Threading::Sleep( int ms ) +__forceinline void Threading::Sleep(int ms) { usleep(1000 * ms); } @@ -41,7 +41,7 @@ __forceinline void Threading::SpinWait() { // If this doesn't compile you can just comment it out (it only serves as a // performance hint and isn't required). - __asm__ ( "pause" ); + __asm__("pause"); } __forceinline void Threading::EnableHiresScheduler() @@ -66,21 +66,22 @@ u64 Threading::GetThreadTicksPerSecond() // gets the CPU time used by the current thread (both system and user), in // microseconds, returns 0 on failure -static u64 getthreadtime(thread_port_t thread) { +static u64 getthreadtime(thread_port_t thread) +{ mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; thread_basic_info_data_t info; kern_return_t kr = thread_info(thread, THREAD_BASIC_INFO, - (thread_info_t) &info, &count); + (thread_info_t)&info, &count); if (kr != KERN_SUCCESS) { return 0; } // add system and user time - return (u64) info.user_time.seconds * (u64) 1e6 + - (u64) info.user_time.microseconds + - (u64) info.system_time.seconds * (u64) 1e6 + - (u64) info.system_time.microseconds; + return (u64)info.user_time.seconds * (u64)1e6 + + (u64)info.user_time.microseconds + + (u64)info.system_time.seconds * (u64)1e6 + + (u64)info.system_time.microseconds; } // Returns the current timestamp (not relative to a real world clock) in @@ -109,19 +110,19 @@ u64 Threading::pxThread::GetCpuTime() const return 0; } - return getthreadtime((thread_port_t) m_native_id) * 10ULL; + return getthreadtime((thread_port_t)m_native_id) * 10ULL; } void Threading::pxThread::_platform_specific_OnStartInThread() { - m_native_id = (uptr) mach_thread_self(); + m_native_id = (uptr)mach_thread_self(); } void Threading::pxThread::_platform_specific_OnCleanupInThread() { // cleanup of handles that were upened in // _platform_specific_OnStartInThread - mach_port_deallocate(mach_task_self(), (thread_port_t) m_native_id); + mach_port_deallocate(mach_task_self(), (thread_port_t)m_native_id); } // name can be up to 16 bytes diff --git a/common/src/Utilities/Exceptions.cpp b/common/src/Utilities/Exceptions.cpp index 801b8a4479..2cde2b6f5e 100644 --- a/common/src/Utilities/Exceptions.cpp +++ b/common/src/Utilities/Exceptions.cpp @@ -43,37 +43,37 @@ Fnptr_OutOfMemory pxDoOutOfMemory = NULL; // const false). // #ifdef PCSX2_DEVBUILD -# define DEVASSERT_INLINE __noinline +#define DEVASSERT_INLINE __noinline #else -# define DEVASSERT_INLINE __fi +#define DEVASSERT_INLINE __fi #endif // Using a threadlocal assertion guard. Separate threads can assert at the same time. // That's ok. What we don't want is the *same* thread recurse-asserting. -static DeclareTls(int) s_assert_guard( 0 ); +static DeclareTls(int) s_assert_guard(0); -pxDoAssertFnType* pxDoAssert = pxAssertImpl_LogIt; +pxDoAssertFnType *pxDoAssert = pxAssertImpl_LogIt; // make life easier for people using VC++ IDE by using this format, which allows double-click // response times from the Output window... -wxString DiagnosticOrigin::ToString( const wxChar* msg ) const +wxString DiagnosticOrigin::ToString(const wxChar *msg) const { - FastFormatUnicode message; + FastFormatUnicode message; - message.Write( L"%ls(%d) : assertion failed:\n", srcfile, line ); + message.Write(L"%ls(%d) : assertion failed:\n", srcfile, line); - if( function != NULL ) - message.Write( " Function: %s\n", function ); + if (function != NULL) + message.Write(" Function: %s\n", function); - message.Write(L" Thread: %s\n", WX_STR(Threading::pxGetCurrentThreadName()) ); + message.Write(L" Thread: %s\n", WX_STR(Threading::pxGetCurrentThreadName())); - if( condition != NULL ) - message.Write(L" Condition: %ls\n", condition); + if (condition != NULL) + message.Write(L" Condition: %ls\n", condition); - if( msg != NULL ) - message.Write(L" Message: %ls\n", msg); + if (msg != NULL) + message.Write(L" Message: %ls\n", msg); - return message; + return message; } @@ -83,71 +83,72 @@ void pxTrap() #if defined(__WXMSW__) && !defined(__WXMICROWIN__) __debugbreak(); #elif defined(__WXMAC__) && !defined(__DARWIN__) - #if __powerc - Debugger(); - #else - SysBreak(); - #endif +#if __powerc + Debugger(); +#else + SysBreak(); +#endif #elif defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS Debugger(); #elif defined(__UNIX__) raise(SIGTRAP); #else - // TODO +// TODO #endif // Win/Unix } -bool pxAssertImpl_LogIt( const DiagnosticOrigin& origin, const wxChar *msg ) +bool pxAssertImpl_LogIt(const DiagnosticOrigin &origin, const wxChar *msg) { - //wxLogError( L"%s", origin.ToString( msg ).c_str() ); - wxMessageOutputDebug().Printf( L"%s", origin.ToString( msg ).c_str() ); - pxTrap(); - return false; + //wxLogError( L"%s", origin.ToString( msg ).c_str() ); + wxMessageOutputDebug().Printf(L"%s", origin.ToString(msg).c_str()); + pxTrap(); + return false; } -DEVASSERT_INLINE void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg ) +DEVASSERT_INLINE void pxOnAssert(const DiagnosticOrigin &origin, const wxChar *msg) { - // Recursion guard: Allow at least one recursive call. This is useful because sometimes - // we get meaningless assertions while unwinding stack traces after exceptions have occurred. + // Recursion guard: Allow at least one recursive call. This is useful because sometimes + // we get meaningless assertions while unwinding stack traces after exceptions have occurred. - RecursionGuard guard( s_assert_guard ); - if (guard.Counter > 2) { return pxTrap(); } + RecursionGuard guard(s_assert_guard); + if (guard.Counter > 2) { + return pxTrap(); + } - // wxWidgets doesn't come with debug builds on some Linux distros, and other distros make - // it difficult to use the debug build (compilation failures). To handle these I've had to - // bypass the internal wxWidgets assertion handler entirely, since it may not exist even if - // PCSX2 itself is compiled in debug mode (assertions enabled). + // wxWidgets doesn't come with debug builds on some Linux distros, and other distros make + // it difficult to use the debug build (compilation failures). To handle these I've had to + // bypass the internal wxWidgets assertion handler entirely, since it may not exist even if + // PCSX2 itself is compiled in debug mode (assertions enabled). - bool trapit; + bool trapit; - if( pxDoAssert == NULL ) - { - // Note: Format uses MSVC's syntax for output window hotlinking. - trapit = pxAssertImpl_LogIt( origin, msg ); - } - else - { - trapit = pxDoAssert( origin, msg ); - } + if (pxDoAssert == NULL) { + // Note: Format uses MSVC's syntax for output window hotlinking. + trapit = pxAssertImpl_LogIt(origin, msg); + } else { + trapit = pxDoAssert(origin, msg); + } - if( trapit ) { pxTrap(); } + if (trapit) { + pxTrap(); + } } -__fi void pxOnAssert( const DiagnosticOrigin& origin, const char* msg) +__fi void pxOnAssert(const DiagnosticOrigin &origin, const char *msg) { - pxOnAssert( origin, fromUTF8(msg) ); + pxOnAssert(origin, fromUTF8(msg)); } -__fi void pxOnAssert( const DiagnosticOrigin& origin, const wxString& msg) +__fi void pxOnAssert(const DiagnosticOrigin &origin, const wxString &msg) { - pxOnAssert( origin, msg.wc_str() ); + pxOnAssert(origin, msg.wc_str()); } -__fi void pxOnAssert( const DiagnosticOrigin& origin, const FastFormatUnicode& msg) +__fi void pxOnAssert(const DiagnosticOrigin &origin, const FastFormatUnicode &msg) { - pxOnAssert( origin, msg.c_str()); + pxOnAssert(origin, msg.c_str()); } // -------------------------------------------------------------------------------------- @@ -156,136 +157,132 @@ __fi void pxOnAssert( const DiagnosticOrigin& origin, const FastFormatUnicode& m BaseException::~BaseException() throw() {} -BaseException& BaseException::SetBothMsgs( const wxChar* msg_diag ) +BaseException &BaseException::SetBothMsgs(const wxChar *msg_diag) { - m_message_user = msg_diag ? wxString(wxGetTranslation( msg_diag )) : wxString(""); - return SetDiagMsg( msg_diag ); + m_message_user = msg_diag ? wxString(wxGetTranslation(msg_diag)) : wxString(""); + return SetDiagMsg(msg_diag); } -BaseException& BaseException::SetDiagMsg( const wxString& msg_diag ) +BaseException &BaseException::SetDiagMsg(const wxString &msg_diag) { - m_message_diag = msg_diag; - return *this; + m_message_diag = msg_diag; + return *this; } -BaseException& BaseException::SetUserMsg( const wxString& msg_user ) +BaseException &BaseException::SetUserMsg(const wxString &msg_user) { - m_message_user = msg_user; - return *this; + m_message_user = msg_user; + return *this; } wxString BaseException::FormatDiagnosticMessage() const { - return m_message_diag; + return m_message_diag; } wxString BaseException::FormatDisplayMessage() const { - return m_message_user.IsEmpty() ? m_message_diag : m_message_user; + return m_message_user.IsEmpty() ? m_message_diag : m_message_user; } // -------------------------------------------------------------------------------------- // Exception::RuntimeError (implementations) // -------------------------------------------------------------------------------------- -Exception::RuntimeError::RuntimeError( const std::runtime_error& ex, const wxString& prefix ) +Exception::RuntimeError::RuntimeError(const std::runtime_error &ex, const wxString &prefix) { - IsSilent = false; + IsSilent = false; - SetDiagMsg( pxsFmt( L"STL Runtime Error%s: %s", - (prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()), - WX_STR(fromUTF8( ex.what() )) - ) ); + SetDiagMsg(pxsFmt(L"STL Runtime Error%s: %s", + (prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()), + WX_STR(fromUTF8(ex.what())))); } -Exception::RuntimeError::RuntimeError( const std::exception& ex, const wxString& prefix ) +Exception::RuntimeError::RuntimeError(const std::exception &ex, const wxString &prefix) { - IsSilent = false; + IsSilent = false; - SetDiagMsg( pxsFmt( L"STL Exception%s: %s", - (prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()), - WX_STR(fromUTF8( ex.what() )) - ) ); + SetDiagMsg(pxsFmt(L"STL Exception%s: %s", + (prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()), + WX_STR(fromUTF8(ex.what())))); } // -------------------------------------------------------------------------------------- // Exception::OutOfMemory (implementations) // -------------------------------------------------------------------------------------- -Exception::OutOfMemory::OutOfMemory( const wxString& allocdesc ) +Exception::OutOfMemory::OutOfMemory(const wxString &allocdesc) { - AllocDescription = allocdesc; + AllocDescription = allocdesc; } wxString Exception::OutOfMemory::FormatDiagnosticMessage() const { - FastFormatUnicode retmsg; - retmsg.Write(L"Out of memory"); - if (!AllocDescription.IsEmpty()) - retmsg.Write(L" while allocating '%s'", WX_STR(AllocDescription)); + FastFormatUnicode retmsg; + retmsg.Write(L"Out of memory"); + if (!AllocDescription.IsEmpty()) + retmsg.Write(L" while allocating '%s'", WX_STR(AllocDescription)); - if (!m_message_diag.IsEmpty()) - retmsg.Write(L":\n%s", WX_STR(m_message_diag)); - - return retmsg; + if (!m_message_diag.IsEmpty()) + retmsg.Write(L":\n%s", WX_STR(m_message_diag)); + + return retmsg; } wxString Exception::OutOfMemory::FormatDisplayMessage() const { - FastFormatUnicode retmsg; - retmsg.Write( L"%s", _("Oh noes! Out of memory!") ); + FastFormatUnicode retmsg; + retmsg.Write(L"%s", _("Oh noes! Out of memory!")); - if (!m_message_user.IsEmpty()) - retmsg.Write(L"\n\n%s", WX_STR(m_message_user)); + if (!m_message_user.IsEmpty()) + retmsg.Write(L"\n\n%s", WX_STR(m_message_user)); - return retmsg; + return retmsg; } // -------------------------------------------------------------------------------------- // Exception::VirtualMemoryMapConflict (implementations) // -------------------------------------------------------------------------------------- -Exception::VirtualMemoryMapConflict::VirtualMemoryMapConflict( const wxString& allocdesc ) +Exception::VirtualMemoryMapConflict::VirtualMemoryMapConflict(const wxString &allocdesc) { - AllocDescription = allocdesc; - m_message_user = _("Virtual memory mapping failure! Your system may have conflicting device drivers, services, or may simply have insufficient memory or resources to meet PCSX2's lofty needs."); + AllocDescription = allocdesc; + m_message_user = _("Virtual memory mapping failure! Your system may have conflicting device drivers, services, or may simply have insufficient memory or resources to meet PCSX2's lofty needs."); } wxString Exception::VirtualMemoryMapConflict::FormatDiagnosticMessage() const { - FastFormatUnicode retmsg; - retmsg.Write(L"Virtual memory map failed"); - if (!AllocDescription.IsEmpty()) - retmsg.Write(L" while reserving '%s'", WX_STR(AllocDescription)); + FastFormatUnicode retmsg; + retmsg.Write(L"Virtual memory map failed"); + if (!AllocDescription.IsEmpty()) + retmsg.Write(L" while reserving '%s'", WX_STR(AllocDescription)); - if (!m_message_diag.IsEmpty()) - retmsg.Write(L":\n%s", WX_STR(m_message_diag)); - - return retmsg; + if (!m_message_diag.IsEmpty()) + retmsg.Write(L":\n%s", WX_STR(m_message_diag)); + + return retmsg; } wxString Exception::VirtualMemoryMapConflict::FormatDisplayMessage() const { - FastFormatUnicode retmsg; - retmsg.Write( L"%s", - pxE( L"There is not enough virtual memory available, or necessary virtual memory mappings have already been reserved by other processes, services, or DLLs." - ) - ); + FastFormatUnicode retmsg; + retmsg.Write(L"%s", + pxE(L"There is not enough virtual memory available, or necessary virtual memory mappings have already been reserved by other processes, services, or DLLs.")); - if (!m_message_diag.IsEmpty()) - retmsg.Write(L"\n\n%s", WX_STR(m_message_diag)); + if (!m_message_diag.IsEmpty()) + retmsg.Write(L"\n\n%s", WX_STR(m_message_diag)); - return retmsg; + return retmsg; } // ------------------------------------------------------------------------ wxString Exception::CancelEvent::FormatDiagnosticMessage() const { - return L"Action canceled: " + m_message_diag; + return L"Action canceled: " + m_message_diag; } wxString Exception::CancelEvent::FormatDisplayMessage() const { - return L"Action canceled: " + m_message_diag; + return L"Action canceled: " + m_message_diag; } // -------------------------------------------------------------------------------------- @@ -293,40 +290,40 @@ wxString Exception::CancelEvent::FormatDisplayMessage() const // -------------------------------------------------------------------------------------- wxString Exception::BadStream::FormatDiagnosticMessage() const { - FastFormatUnicode retval; - _formatDiagMsg(retval); - return retval; + FastFormatUnicode retval; + _formatDiagMsg(retval); + return retval; } wxString Exception::BadStream::FormatDisplayMessage() const { - FastFormatUnicode retval; - _formatUserMsg(retval); - return retval; + FastFormatUnicode retval; + _formatUserMsg(retval); + return retval; } -void Exception::BadStream::_formatDiagMsg( FastFormatUnicode& dest ) const +void Exception::BadStream::_formatDiagMsg(FastFormatUnicode &dest) const { - dest.Write( L"Path: " ); - if (!StreamName.IsEmpty()) - dest.Write( L"%s", WX_STR(StreamName) ); - else - dest.Write( L"[Unnamed or unknown]" ); + dest.Write(L"Path: "); + if (!StreamName.IsEmpty()) + dest.Write(L"%s", WX_STR(StreamName)); + else + dest.Write(L"[Unnamed or unknown]"); - if (!m_message_diag.IsEmpty()) - dest.Write(L"\n%s", WX_STR(m_message_diag)); + if (!m_message_diag.IsEmpty()) + dest.Write(L"\n%s", WX_STR(m_message_diag)); } -void Exception::BadStream::_formatUserMsg( FastFormatUnicode& dest ) const +void Exception::BadStream::_formatUserMsg(FastFormatUnicode &dest) const { - dest.Write( _("Path: ") ); - if (!StreamName.IsEmpty()) - dest.Write( L"%s", WX_STR(StreamName) ); - else - dest.Write( _("[Unnamed or unknown]") ); + dest.Write(_("Path: ")); + if (!StreamName.IsEmpty()) + dest.Write(L"%s", WX_STR(StreamName)); + else + dest.Write(_("[Unnamed or unknown]")); - if (!m_message_user.IsEmpty()) - dest.Write(L"\n%s", WX_STR(m_message_user)); + if (!m_message_user.IsEmpty()) + dest.Write(L"\n%s", WX_STR(m_message_user)); } // -------------------------------------------------------------------------------------- @@ -334,19 +331,19 @@ void Exception::BadStream::_formatUserMsg( FastFormatUnicode& dest ) const // -------------------------------------------------------------------------------------- wxString Exception::CannotCreateStream::FormatDiagnosticMessage() const { - FastFormatUnicode retval; - retval.Write("File could not be created."); - _formatDiagMsg(retval); - return retval; + FastFormatUnicode retval; + retval.Write("File could not be created."); + _formatDiagMsg(retval); + return retval; } wxString Exception::CannotCreateStream::FormatDisplayMessage() const { - FastFormatUnicode retval; - retval.Write(_("A file could not be created.")); - retval.Write("\n"); - _formatUserMsg(retval); - return retval; + FastFormatUnicode retval; + retval.Write(_("A file could not be created.")); + retval.Write("\n"); + _formatUserMsg(retval); + return retval; } // -------------------------------------------------------------------------------------- @@ -354,19 +351,19 @@ wxString Exception::CannotCreateStream::FormatDisplayMessage() const // -------------------------------------------------------------------------------------- wxString Exception::FileNotFound::FormatDiagnosticMessage() const { - FastFormatUnicode retval; - retval.Write("File not found.\n"); - _formatDiagMsg(retval); - return retval; + FastFormatUnicode retval; + retval.Write("File not found.\n"); + _formatDiagMsg(retval); + return retval; } wxString Exception::FileNotFound::FormatDisplayMessage() const { - FastFormatUnicode retval; - retval.Write(_("File not found.")); - retval.Write("\n"); - _formatUserMsg(retval); - return retval; + FastFormatUnicode retval; + retval.Write(_("File not found.")); + retval.Write("\n"); + _formatUserMsg(retval); + return retval; } // -------------------------------------------------------------------------------------- @@ -374,19 +371,19 @@ wxString Exception::FileNotFound::FormatDisplayMessage() const // -------------------------------------------------------------------------------------- wxString Exception::AccessDenied::FormatDiagnosticMessage() const { - FastFormatUnicode retval; - retval.Write("Permission denied to file.\n"); - _formatDiagMsg(retval); - return retval; + FastFormatUnicode retval; + retval.Write("Permission denied to file.\n"); + _formatDiagMsg(retval); + return retval; } wxString Exception::AccessDenied::FormatDisplayMessage() const { - FastFormatUnicode retval; - retval.Write(_("Permission denied while trying to open file, likely due to insufficient user account rights.")); - retval.Write("\n"); - _formatUserMsg(retval); - return retval; + FastFormatUnicode retval; + retval.Write(_("Permission denied while trying to open file, likely due to insufficient user account rights.")); + retval.Write("\n"); + _formatUserMsg(retval); + return retval; } // -------------------------------------------------------------------------------------- @@ -394,19 +391,19 @@ wxString Exception::AccessDenied::FormatDisplayMessage() const // -------------------------------------------------------------------------------------- wxString Exception::EndOfStream::FormatDiagnosticMessage() const { - FastFormatUnicode retval; - retval.Write("Unexpected end of file or stream.\n"); - _formatDiagMsg(retval); - return retval; + FastFormatUnicode retval; + retval.Write("Unexpected end of file or stream.\n"); + _formatDiagMsg(retval); + return retval; } wxString Exception::EndOfStream::FormatDisplayMessage() const { - FastFormatUnicode retval; - retval.Write(_("Unexpected end of file or stream encountered. File is probably truncated or corrupted.")); - retval.Write("\n"); - _formatUserMsg(retval); - return retval; + FastFormatUnicode retval; + retval.Write(_("Unexpected end of file or stream encountered. File is probably truncated or corrupted.")); + retval.Write("\n"); + _formatUserMsg(retval); + return retval; } // -------------------------------------------------------------------------------------- @@ -415,35 +412,34 @@ wxString Exception::EndOfStream::FormatDisplayMessage() const // Translates an Errno code into an exception. // Throws an exception based on the given error code (usually taken from ANSI C's errno) -BaseException* Exception::FromErrno( const wxString& streamname, int errcode ) +BaseException *Exception::FromErrno(const wxString &streamname, int errcode) { - pxAssumeDev( errcode != 0, "Invalid NULL error code? (errno)" ); + pxAssumeDev(errcode != 0, "Invalid NULL error code? (errno)"); - switch( errcode ) - { - case EINVAL: - pxFailDev( L"Invalid argument" ); - return &(new Exception::BadStream( streamname ))->SetDiagMsg(L"Invalid argument? (likely caused by an unforgivable programmer error!)" ); + switch (errcode) { + case EINVAL: + pxFailDev(L"Invalid argument"); + return &(new Exception::BadStream(streamname))->SetDiagMsg(L"Invalid argument? (likely caused by an unforgivable programmer error!)"); - case EACCES: // Access denied! - return new Exception::AccessDenied( streamname ); + case EACCES: // Access denied! + return new Exception::AccessDenied(streamname); - case EMFILE: // Too many open files! - return &(new Exception::CannotCreateStream( streamname ))->SetDiagMsg(L"Too many open files"); // File handle allocation failure + case EMFILE: // Too many open files! + return &(new Exception::CannotCreateStream(streamname))->SetDiagMsg(L"Too many open files"); // File handle allocation failure - case EEXIST: - return &(new Exception::CannotCreateStream( streamname ))->SetDiagMsg(L"File already exists"); + case EEXIST: + return &(new Exception::CannotCreateStream(streamname))->SetDiagMsg(L"File already exists"); - case ENOENT: // File not found! - return new Exception::FileNotFound( streamname ); + case ENOENT: // File not found! + return new Exception::FileNotFound(streamname); - case EPIPE: - return &(new Exception::BadStream( streamname ))->SetDiagMsg(L"Broken pipe"); + case EPIPE: + return &(new Exception::BadStream(streamname))->SetDiagMsg(L"Broken pipe"); - case EBADF: - return &(new Exception::BadStream( streamname ))->SetDiagMsg(L"Bad file number"); + case EBADF: + return &(new Exception::BadStream(streamname))->SetDiagMsg(L"Bad file number"); - default: - return &(new Exception::BadStream( streamname ))->SetDiagMsg(pxsFmt( L"General file/stream error [errno: %d]", errcode )); - } + default: + return &(new Exception::BadStream(streamname))->SetDiagMsg(pxsFmt(L"General file/stream error [errno: %d]", errcode)); + } } diff --git a/common/src/Utilities/FastFormatString.cpp b/common/src/Utilities/FastFormatString.cpp index 74bca23550..4823fc4cf4 100644 --- a/common/src/Utilities/FastFormatString.cpp +++ b/common/src/Utilities/FastFormatString.cpp @@ -24,9 +24,9 @@ template class SafeArray; template class SafeArray; template class SafeArray; -template class SafeAlignedArray; -template class SafeAlignedArray; -template class SafeAlignedArray; +template class SafeAlignedArray; +template class SafeAlignedArray; +template class SafeAlignedArray; // Sanity check: truncate strings if they exceed 512k in length. Anything like that // is either a bug or really horrible code that needs to be stopped before it causes @@ -35,82 +35,86 @@ static const int MaxFormattedStringLength = 0x80000; static #ifndef __linux__ -__ri + __ri #endif -void format_that_ascii_mess( CharBufferType& buffer, uint writepos, const char* fmt, va_list argptr ) + void + format_that_ascii_mess(CharBufferType &buffer, uint writepos, const char *fmt, va_list argptr) { - va_list args; - while( true ) - { - int size = buffer.GetLength(); + va_list args; + while (true) { + int size = buffer.GetLength(); - va_copy(args, argptr); - int len = vsnprintf(buffer.GetPtr(writepos), size-writepos, fmt, args); - va_end(args); + va_copy(args, argptr); + int len = vsnprintf(buffer.GetPtr(writepos), size - writepos, fmt, args); + va_end(args); - // some implementations of vsnprintf() don't NUL terminate - // the string if there is not enough space for it so - // always do it manually - buffer[size-1] = '\0'; + // some implementations of vsnprintf() don't NUL terminate + // the string if there is not enough space for it so + // always do it manually + buffer[size - 1] = '\0'; - if (size >= MaxFormattedStringLength) break; + if (size >= MaxFormattedStringLength) + break; - // vsnprintf() may return either -1 (traditional Unix behavior) or the - // total number of characters which would have been written if the - // buffer were large enough (newer standards such as Unix98) + // vsnprintf() may return either -1 (traditional Unix behavior) or the + // total number of characters which would have been written if the + // buffer were large enough (newer standards such as Unix98) - if (len < 0) - len = size + (size/4); + if (len < 0) + len = size + (size / 4); - len += writepos; - if (len < size) break; - buffer.Resize( len + 128 ); - }; + len += writepos; + if (len < size) + break; + buffer.Resize(len + 128); + }; - // performing an assertion or log of a truncated string is unsafe, so let's not; even - // though it'd be kinda nice if we did. + // performing an assertion or log of a truncated string is unsafe, so let's not; even + // though it'd be kinda nice if we did. } // returns the length of the formatted string, in characters (wxChars). static #ifndef __linux__ -__ri + __ri #endif -uint format_that_unicode_mess( CharBufferType& buffer, uint writepos, const wxChar* fmt, va_list argptr) + uint + format_that_unicode_mess(CharBufferType &buffer, uint writepos, const wxChar *fmt, va_list argptr) { - va_list args; - while( true ) - { - int size = buffer.GetLength() / sizeof(wxChar); + va_list args; + while (true) { + int size = buffer.GetLength() / sizeof(wxChar); - va_copy(args, argptr); - int len = wxVsnprintf((wxChar*)buffer.GetPtr(writepos*sizeof(wxChar)), size-writepos, fmt, args); - va_end(args); + va_copy(args, argptr); + int len = wxVsnprintf((wxChar *)buffer.GetPtr(writepos * sizeof(wxChar)), size - writepos, fmt, args); + va_end(args); - // some implementations of vsnprintf() don't NUL terminate - // the string if there is not enough space for it so - // always do it manually - ((wxChar*)buffer.GetPtr())[size-1] = L'\0'; + // some implementations of vsnprintf() don't NUL terminate + // the string if there is not enough space for it so + // always do it manually + ((wxChar *)buffer.GetPtr())[size - 1] = L'\0'; - if( size >= MaxFormattedStringLength ) return size-1; + if (size >= MaxFormattedStringLength) + return size - 1; - // vsnprintf() may return either -1 (traditional Unix behavior) or the - // total number of characters which would have been written if the - // buffer were large enough (newer standards such as Unix98) + // vsnprintf() may return either -1 (traditional Unix behavior) or the + // total number of characters which would have been written if the + // buffer were large enough (newer standards such as Unix98) - if (len < 0) - len = size + (size/4); + if (len < 0) + len = size + (size / 4); - len += writepos; - if (len < size) return len; - buffer.Resize( (len + 128) * sizeof(wxChar) ); - }; + len += writepos; + if (len < size) + return len; + buffer.Resize((len + 128) * sizeof(wxChar)); + }; - // performing an assertion or log of a truncated string is unsafe, so let's not; even - // though it'd be kinda nice if we did. + // performing an assertion or log of a truncated string is unsafe, so let's not; even + // though it'd be kinda nice if we did. - pxAssume( false ); - return 0; // unreachable. + pxAssume(false); + return 0; // unreachable. } // -------------------------------------------------------------------------------------- @@ -123,9 +127,9 @@ uint format_that_unicode_mess( CharBufferType& buffer, uint writepos, const wxCh // this class nicely in its current state. --air FastFormatUnicode::FastFormatUnicode() - : m_dest(2048) + : m_dest(2048) { - Clear(); + Clear(); } FastFormatUnicode::~FastFormatUnicode() throw() @@ -134,117 +138,117 @@ FastFormatUnicode::~FastFormatUnicode() throw() void FastFormatUnicode::Clear() { - m_Length = 0; - ((wxChar*)m_dest.GetPtr())[0] = 0; + m_Length = 0; + ((wxChar *)m_dest.GetPtr())[0] = 0; } -FastFormatUnicode& FastFormatUnicode::WriteV( const char* fmt, va_list argptr ) +FastFormatUnicode &FastFormatUnicode::WriteV(const char *fmt, va_list argptr) { - wxString converted( fromUTF8(FastFormatAscii().WriteV( fmt, argptr )) ); + wxString converted(fromUTF8(FastFormatAscii().WriteV(fmt, argptr))); - const uint inspos = m_Length; - const uint convLen = converted.Length(); - m_dest.MakeRoomFor((inspos + convLen + 64) * sizeof(wxChar)); - memcpy( &((wxChar*)m_dest.GetPtr())[inspos], converted.wc_str(), (convLen+1)*sizeof(wxChar) ); - m_Length += convLen; + const uint inspos = m_Length; + const uint convLen = converted.Length(); + m_dest.MakeRoomFor((inspos + convLen + 64) * sizeof(wxChar)); + memcpy(&((wxChar *)m_dest.GetPtr())[inspos], converted.wc_str(), (convLen + 1) * sizeof(wxChar)); + m_Length += convLen; - return *this; + return *this; } -FastFormatUnicode& FastFormatUnicode::WriteV( const wxChar* fmt, va_list argptr ) +FastFormatUnicode &FastFormatUnicode::WriteV(const wxChar *fmt, va_list argptr) { - m_Length = format_that_unicode_mess( m_dest, m_Length, fmt, argptr ); - return *this; + m_Length = format_that_unicode_mess(m_dest, m_Length, fmt, argptr); + return *this; } -FastFormatUnicode& FastFormatUnicode::Write( const char* fmt, ... ) +FastFormatUnicode &FastFormatUnicode::Write(const char *fmt, ...) { - va_list list; - va_start(list, fmt); - WriteV(fmt,list); - va_end(list); - return *this; + va_list list; + va_start(list, fmt); + WriteV(fmt, list); + va_end(list); + return *this; } -FastFormatUnicode& FastFormatUnicode::Write( const wxChar* fmt, ... ) +FastFormatUnicode &FastFormatUnicode::Write(const wxChar *fmt, ...) { - va_list list; - va_start(list, fmt); - WriteV(fmt,list); - va_end(list); - return *this; + va_list list; + va_start(list, fmt); + WriteV(fmt, list); + va_end(list); + return *this; } -FastFormatUnicode& FastFormatUnicode::Write( const wxString fmt, ... ) +FastFormatUnicode &FastFormatUnicode::Write(const wxString fmt, ...) { - va_list list; - va_start(list, fmt); - WriteV(fmt.wx_str(),list); - va_end(list); - return *this; + va_list list; + va_start(list, fmt); + WriteV(fmt.wx_str(), list); + va_end(list); + return *this; } bool FastFormatUnicode::IsEmpty() const { - return ((wxChar&)m_dest[0]) == 0; + return ((wxChar &)m_dest[0]) == 0; } -FastFormatUnicode& FastFormatUnicode::ToUpper() +FastFormatUnicode &FastFormatUnicode::ToUpper() { - wxChar* ch = (wxChar*)m_dest.GetPtr(); - for ( uint i=0; i /// Calculates a hash value for an arbitrary set of binary data. @@ -52,51 +53,53 @@ namespace HashTools { /// uint32 hashval = Hash( (const char*)&data, sizeof( data ) ); /// /// -u32 Hash(const s8 * data, int len) +u32 Hash(const s8 *data, int len) { - u32 hash = len; - int rem; + u32 hash = len; + int rem; - if (len <= 0 || data == NULL) return 0; + if (len <= 0 || data == NULL) + return 0; - rem = len & 3; - len >>= 2; + rem = len & 3; + len >>= 2; - /* Main loop */ - for (;len > 0; --len) - { - hash += get16bits (data); - u32 tmp = (get16bits (data+2) << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2*sizeof (u16); - hash += hash >> 11; - } + /* Main loop */ + for (; len > 0; --len) { + hash += get16bits(data); + u32 tmp = (get16bits(data + 2) << 11) ^ hash; + hash = (hash << 16) ^ tmp; + data += 2 * sizeof(u16); + hash += hash >> 11; + } - /* Handle end cases */ - switch (rem) - { - case 3: hash += get16bits (data); - hash ^= hash << 16; - hash ^= data[sizeof (u16)] << 18; - hash += hash >> 11; - break; - case 2: hash += get16bits (data); - hash ^= hash << 11; - hash += hash >> 17; - break; - case 1: hash += *data; - hash ^= hash << 10; - hash += hash >> 1; - } + /* Handle end cases */ + switch (rem) { + case 3: + hash += get16bits(data); + hash ^= hash << 16; + hash ^= data[sizeof(u16)] << 18; + hash += hash >> 11; + break; + case 2: + hash += get16bits(data); + hash ^= hash << 11; + hash += hash >> 17; + break; + case 1: + hash += *data; + hash ^= hash << 10; + hash += hash >> 1; + } - /* Force "avalanching" of final 127 bits */ - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 4; - hash += hash >> 17; - hash ^= hash << 25; - hash += hash >> 6; + /* Force "avalanching" of final 127 bits */ + hash ^= hash << 3; + hash += hash >> 5; + hash ^= hash << 4; + hash += hash >> 17; + hash ^= hash << 25; + hash += hash >> 6; - return hash; + return hash; } } diff --git a/common/src/Utilities/IniInterface.cpp b/common/src/Utilities/IniInterface.cpp index b91dc0b6b2..d4acc7b615 100644 --- a/common/src/Utilities/IniInterface.cpp +++ b/common/src/Utilities/IniInterface.cpp @@ -18,7 +18,7 @@ #include -const wxRect wxDefaultRect( wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord ); +const wxRect wxDefaultRect(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord); // Implement FixedPointTypes (for lack of a better location, for now) @@ -27,369 +27,396 @@ template struct FixedInt<100>; template struct FixedInt<256>; wxDirName g_fullBaseDirName = wxDirName(L""); -void SetFullBaseDir( wxDirName appRoot ) +void SetFullBaseDir(wxDirName appRoot) { - g_fullBaseDirName = appRoot; + g_fullBaseDirName = appRoot; } -static int _calcEnumLength( const wxChar* const* enumArray ) +static int _calcEnumLength(const wxChar *const *enumArray) { - int cnt = 0; - while( *enumArray != NULL ) - { - enumArray++; - cnt++; - } + int cnt = 0; + while (*enumArray != NULL) { + enumArray++; + cnt++; + } - return cnt; + return cnt; } -ScopedIniGroup::ScopedIniGroup( IniInterface& mommy, const wxString& group ) - : m_mom( mommy ) +ScopedIniGroup::ScopedIniGroup(IniInterface &mommy, const wxString &group) + : m_mom(mommy) { - pxAssertDev( wxStringTokenize( group, L"/" ).Count() <= 1, L"Cannot nest more than one group deep per instance of ScopedIniGroup." ); - m_mom.SetPath( group ); + pxAssertDev(wxStringTokenize(group, L"/").Count() <= 1, L"Cannot nest more than one group deep per instance of ScopedIniGroup."); + m_mom.SetPath(group); } ScopedIniGroup::~ScopedIniGroup() { - m_mom.SetPath( L".." ); + m_mom.SetPath(L".."); } // -------------------------------------------------------------------------------------- // IniInterface (implementations) // -------------------------------------------------------------------------------------- -IniInterface::IniInterface( wxConfigBase& config ) +IniInterface::IniInterface(wxConfigBase &config) { - m_Config = &config; + m_Config = &config; } -IniInterface::IniInterface( wxConfigBase* config ) +IniInterface::IniInterface(wxConfigBase *config) { - m_Config = config; + m_Config = config; } IniInterface::IniInterface() { - m_Config = wxConfigBase::Get( false ); + m_Config = wxConfigBase::Get(false); } IniInterface::~IniInterface() { - Flush(); + Flush(); } -void IniInterface::SetPath( const wxString& path ) +void IniInterface::SetPath(const wxString &path) { - if( m_Config ) m_Config->SetPath( path ); + if (m_Config) + m_Config->SetPath(path); } void IniInterface::Flush() { - if( m_Config ) m_Config->Flush(); + if (m_Config) + m_Config->Flush(); } // -------------------------------------------------------------------------------------- // IniLoader (implementations) // -------------------------------------------------------------------------------------- -IniLoader::IniLoader( wxConfigBase& config ) : IniInterface( config ) { } -IniLoader::IniLoader( wxConfigBase* config ) : IniInterface( config ) { } +IniLoader::IniLoader(wxConfigBase &config) + : IniInterface(config) +{ +} +IniLoader::IniLoader(wxConfigBase *config) + : IniInterface(config) +{ +} -IniLoader::IniLoader() : IniInterface() {} +IniLoader::IniLoader() + : IniInterface() +{ +} IniLoader::~IniLoader() throw() {} -void IniLoader::Entry( const wxString& var, wxString& value, const wxString defvalue ) +void IniLoader::Entry(const wxString &var, wxString &value, const wxString defvalue) { - if( m_Config ) - m_Config->Read( var, &value, defvalue ); - else - value = defvalue; + if (m_Config) + m_Config->Read(var, &value, defvalue); + else + value = defvalue; } -void IniLoader::Entry( const wxString& var, wxDirName& value, const wxDirName defvalue, bool isAllowRelative ) +void IniLoader::Entry(const wxString &var, wxDirName &value, const wxDirName defvalue, bool isAllowRelative) { - wxString dest; - if( m_Config ) m_Config->Read( var, &dest, wxEmptyString ); + wxString dest; + if (m_Config) + m_Config->Read(var, &dest, wxEmptyString); - if( dest.IsEmpty() ) - value = defvalue; - else - { - value = dest; - if( isAllowRelative ) - value = g_fullBaseDirName + value; + if (dest.IsEmpty()) + value = defvalue; + else { + value = dest; + if (isAllowRelative) + value = g_fullBaseDirName + value; - if( value.IsAbsolute() ) - value.Normalize(); - } + if (value.IsAbsolute()) + value.Normalize(); + } } -void IniLoader::Entry( const wxString& var, wxFileName& value, const wxFileName defvalue, bool isAllowRelative ) +void IniLoader::Entry(const wxString &var, wxFileName &value, const wxFileName defvalue, bool isAllowRelative) { - wxString dest( defvalue.GetFullPath() ); - if( m_Config ) m_Config->Read( var, &dest, defvalue.GetFullPath() ); - value = dest; - if( isAllowRelative ) - value = g_fullBaseDirName + value; + wxString dest(defvalue.GetFullPath()); + if (m_Config) + m_Config->Read(var, &dest, defvalue.GetFullPath()); + value = dest; + if (isAllowRelative) + value = g_fullBaseDirName + value; - if( value.IsAbsolute() ) - value.Normalize(); + if (value.IsAbsolute()) + value.Normalize(); - if (value.HasVolume()) - value.SetVolume(value.GetVolume().Upper()); + if (value.HasVolume()) + value.SetVolume(value.GetVolume().Upper()); } -void IniLoader::Entry( const wxString& var, int& value, const int defvalue ) +void IniLoader::Entry(const wxString &var, int &value, const int defvalue) { - if( m_Config ) - m_Config->Read( var, &value, defvalue ); - else - value = defvalue; + if (m_Config) + m_Config->Read(var, &value, defvalue); + else + value = defvalue; } -void IniLoader::Entry( const wxString& var, uint& value, const uint defvalue ) +void IniLoader::Entry(const wxString &var, uint &value, const uint defvalue) { - if( m_Config ) - m_Config->Read( var, (int*)&value, (int)defvalue ); - else - value = defvalue; + if (m_Config) + m_Config->Read(var, (int *)&value, (int)defvalue); + else + value = defvalue; } -void IniLoader::Entry( const wxString& var, bool& value, const bool defvalue ) +void IniLoader::Entry(const wxString &var, bool &value, const bool defvalue) { - // TODO : Stricter value checking on enabled/disabled? - wxString dest(defvalue ? L"enabled" : L"disabled"); - if( m_Config ) m_Config->Read( var, &dest, dest ); - value = (dest == L"enabled") || (dest == L"1"); + // TODO : Stricter value checking on enabled/disabled? + wxString dest(defvalue ? L"enabled" : L"disabled"); + if (m_Config) + m_Config->Read(var, &dest, dest); + value = (dest == L"enabled") || (dest == L"1"); } -bool IniLoader::EntryBitBool( const wxString& var, bool value, const bool defvalue ) +bool IniLoader::EntryBitBool(const wxString &var, bool value, const bool defvalue) { - // Note: 'value' param is used by inisaver only. - bool result; - Entry( var, result, defvalue ); - return result; + // Note: 'value' param is used by inisaver only. + bool result; + Entry(var, result, defvalue); + return result; } -int IniLoader::EntryBitfield( const wxString& var, int value, const int defvalue ) +int IniLoader::EntryBitfield(const wxString &var, int value, const int defvalue) { - int result; - Entry( var, result, defvalue ); - return result; + int result; + Entry(var, result, defvalue); + return result; } -void IniLoader::Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue ) +void IniLoader::Entry(const wxString &var, Fixed100 &value, const Fixed100 defvalue) { - // Note: the "easy" way would be to convert to double and load/save that, but floating point - // has way too much rounding error so we really need to do things out manually.. >_< + // Note: the "easy" way would be to convert to double and load/save that, but floating point + // has way too much rounding error so we really need to do things out manually.. >_< - wxString readval( value.ToString() ); - if( m_Config ) m_Config->Read( var, &readval ); - value = Fixed100::FromString( readval, value ); + wxString readval(value.ToString()); + if (m_Config) + m_Config->Read(var, &readval); + value = Fixed100::FromString(readval, value); } -void IniLoader::Entry( const wxString& var, wxPoint& value, const wxPoint defvalue ) +void IniLoader::Entry(const wxString &var, wxPoint &value, const wxPoint defvalue) { - if( !m_Config ) - { - value = defvalue; return; - } - TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue ); + if (!m_Config) { + value = defvalue; + return; + } + TryParse(value, m_Config->Read(var, ToString(defvalue)), defvalue); } -void IniLoader::Entry( const wxString& var, wxSize& value, const wxSize defvalue ) +void IniLoader::Entry(const wxString &var, wxSize &value, const wxSize defvalue) { - if( !m_Config ) - { - value = defvalue; return; - } - TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue ); + if (!m_Config) { + value = defvalue; + return; + } + TryParse(value, m_Config->Read(var, ToString(defvalue)), defvalue); } -void IniLoader::Entry( const wxString& var, wxRect& value, const wxRect defvalue ) +void IniLoader::Entry(const wxString &var, wxRect &value, const wxRect defvalue) { - if( !m_Config ) - { - value = defvalue; return; - } - TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue ); + if (!m_Config) { + value = defvalue; + return; + } + TryParse(value, m_Config->Read(var, ToString(defvalue)), defvalue); } -void IniLoader::_EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue ) +void IniLoader::_EnumEntry(const wxString &var, int &value, const wxChar *const *enumArray, int defvalue) { - // Confirm default value sanity... + // Confirm default value sanity... - const int cnt = _calcEnumLength( enumArray ); - if( !IndexBoundsCheck( L"IniLoader EnumDefaultValue", defvalue, cnt ) ) - { - Console.Error( "(LoadSettings) Default enumeration index is out of bounds. Truncating." ); - defvalue = cnt-1; - } + const int cnt = _calcEnumLength(enumArray); + if (!IndexBoundsCheck(L"IniLoader EnumDefaultValue", defvalue, cnt)) { + Console.Error("(LoadSettings) Default enumeration index is out of bounds. Truncating."); + defvalue = cnt - 1; + } - // Sanity confirmed, proceed with craziness! + // Sanity confirmed, proceed with craziness! - if( !m_Config ) - { - value = defvalue; - return; - } + if (!m_Config) { + value = defvalue; + return; + } - wxString retval; - m_Config->Read( var, &retval, enumArray[defvalue] ); + wxString retval; + m_Config->Read(var, &retval, enumArray[defvalue]); - int i=0; - while( enumArray[i] != NULL && ( retval != enumArray[i] ) ) i++; + int i = 0; + while (enumArray[i] != NULL && (retval != enumArray[i])) + i++; - if( enumArray[i] == NULL ) - { - Console.Warning( L"(LoadSettings) Warning: Unrecognized value '%s' on key '%s'\n\tUsing the default setting of '%s'.", - WX_STR(retval), WX_STR(var), enumArray[defvalue] - ); - value = defvalue; - } - else - value = i; + if (enumArray[i] == NULL) { + Console.Warning(L"(LoadSettings) Warning: Unrecognized value '%s' on key '%s'\n\tUsing the default setting of '%s'.", + WX_STR(retval), WX_STR(var), enumArray[defvalue]); + value = defvalue; + } else + value = i; } // -------------------------------------------------------------------------------------- // IniSaver (implementations) // -------------------------------------------------------------------------------------- -IniSaver::IniSaver( wxConfigBase& config ) : IniInterface( config ) { } -IniSaver::IniSaver( wxConfigBase* config ) : IniInterface( config ) { } +IniSaver::IniSaver(wxConfigBase &config) + : IniInterface(config) +{ +} +IniSaver::IniSaver(wxConfigBase *config) + : IniInterface(config) +{ +} -IniSaver::IniSaver() : IniInterface() {} +IniSaver::IniSaver() + : IniInterface() +{ +} IniSaver::~IniSaver() {} -void IniSaver::Entry( const wxString& var, wxString& value, const wxString defvalue ) +void IniSaver::Entry(const wxString &var, wxString &value, const wxString defvalue) { - if( !m_Config ) return; - m_Config->Write( var, value ); + if (!m_Config) + return; + m_Config->Write(var, value); } -void IniSaver::Entry( const wxString& var, wxDirName& value, const wxDirName defvalue, bool isAllowRelative ) +void IniSaver::Entry(const wxString &var, wxDirName &value, const wxDirName defvalue, bool isAllowRelative) { - if( !m_Config ) return; - wxDirName res(value); + if (!m_Config) + return; + wxDirName res(value); - if ( res.IsAbsolute() ) - res.Normalize(); - - if (isAllowRelative) - res = wxDirName::MakeAutoRelativeTo( res, g_fullBaseDirName.ToString() ); + if (res.IsAbsolute()) + res.Normalize(); + + if (isAllowRelative) + res = wxDirName::MakeAutoRelativeTo(res, g_fullBaseDirName.ToString()); - /*if( value == defvalue ) + /*if( value == defvalue ) m_Config->Write( var, wxString() ); else*/ - m_Config->Write( var, res.ToString() ); + m_Config->Write(var, res.ToString()); } -void IniSaver::Entry( const wxString& var, wxFileName& value, const wxFileName defvalue, bool isAllowRelative ) +void IniSaver::Entry(const wxString &var, wxFileName &value, const wxFileName defvalue, bool isAllowRelative) { - if( !m_Config ) return; - wxFileName res(value); + if (!m_Config) + return; + wxFileName res(value); - if ( res.IsAbsolute() ) - res.Normalize(); - - if (isAllowRelative) - res = wxDirName::MakeAutoRelativeTo( res, g_fullBaseDirName.ToString() ); - - m_Config->Write( var, res.GetFullPath() ); + if (res.IsAbsolute()) + res.Normalize(); + + if (isAllowRelative) + res = wxDirName::MakeAutoRelativeTo(res, g_fullBaseDirName.ToString()); + + m_Config->Write(var, res.GetFullPath()); } -void IniSaver::Entry( const wxString& var, int& value, const int defvalue ) +void IniSaver::Entry(const wxString &var, int &value, const int defvalue) { - if( !m_Config ) return; - m_Config->Write( var, value ); + if (!m_Config) + return; + m_Config->Write(var, value); } -void IniSaver::Entry( const wxString& var, uint& value, const uint defvalue ) +void IniSaver::Entry(const wxString &var, uint &value, const uint defvalue) { - if( !m_Config ) return; - m_Config->Write( var, (int)value ); + if (!m_Config) + return; + m_Config->Write(var, (int)value); } -void IniSaver::Entry( const wxString& var, bool& value, const bool defvalue ) +void IniSaver::Entry(const wxString &var, bool &value, const bool defvalue) { - if( !m_Config ) return; - m_Config->Write( var, value ? L"enabled" : L"disabled" ); + if (!m_Config) + return; + m_Config->Write(var, value ? L"enabled" : L"disabled"); } -bool IniSaver::EntryBitBool( const wxString& var, bool value, const bool defvalue ) +bool IniSaver::EntryBitBool(const wxString &var, bool value, const bool defvalue) { - if( m_Config ) m_Config->Write( var, value ? L"enabled" : L"disabled" ); - return value; + if (m_Config) + m_Config->Write(var, value ? L"enabled" : L"disabled"); + return value; } -int IniSaver::EntryBitfield( const wxString& var, int value, const int defvalue ) +int IniSaver::EntryBitfield(const wxString &var, int value, const int defvalue) { - if( m_Config ) m_Config->Write( var, value ); - return value; + if (m_Config) + m_Config->Write(var, value); + return value; } -void IniSaver::Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue ) +void IniSaver::Entry(const wxString &var, Fixed100 &value, const Fixed100 defvalue) { - if( !m_Config ) return; + if (!m_Config) + return; - // Note: the "easy" way would be to convert to double and load/save that, but floating point - // has way too much rounding error so we really need to do things out manually, using strings. + // Note: the "easy" way would be to convert to double and load/save that, but floating point + // has way too much rounding error so we really need to do things out manually, using strings. - m_Config->Write( var, value.ToString() ); + m_Config->Write(var, value.ToString()); } -void IniSaver::Entry( const wxString& var, wxPoint& value, const wxPoint defvalue ) +void IniSaver::Entry(const wxString &var, wxPoint &value, const wxPoint defvalue) { - if( !m_Config ) return; - m_Config->Write( var, ToString( value ) ); + if (!m_Config) + return; + m_Config->Write(var, ToString(value)); } -void IniSaver::Entry( const wxString& var, wxSize& value, const wxSize defvalue ) +void IniSaver::Entry(const wxString &var, wxSize &value, const wxSize defvalue) { - if( !m_Config ) return; - m_Config->Write( var, ToString( value ) ); + if (!m_Config) + return; + m_Config->Write(var, ToString(value)); } -void IniSaver::Entry( const wxString& var, wxRect& value, const wxRect defvalue ) +void IniSaver::Entry(const wxString &var, wxRect &value, const wxRect defvalue) { - if( !m_Config ) return; - m_Config->Write( var, ToString( value ) ); + if (!m_Config) + return; + m_Config->Write(var, ToString(value)); } -void IniSaver::_EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue ) +void IniSaver::_EnumEntry(const wxString &var, int &value, const wxChar *const *enumArray, int defvalue) { - const int cnt = _calcEnumLength( enumArray ); + const int cnt = _calcEnumLength(enumArray); - // Confirm default value sanity... + // Confirm default value sanity... - if( !IndexBoundsCheck( L"IniSaver EnumDefaultValue", defvalue, cnt ) ) - { - Console.Error( "(SaveSettings) Default enumeration index is out of bounds. Truncating." ); - defvalue = cnt-1; - } + if (!IndexBoundsCheck(L"IniSaver EnumDefaultValue", defvalue, cnt)) { + Console.Error("(SaveSettings) Default enumeration index is out of bounds. Truncating."); + defvalue = cnt - 1; + } - if( !m_Config ) return; + if (!m_Config) + return; - if( value >= cnt ) - { - Console.Warning( L"(SaveSettings) An illegal enumerated index was detected when saving '%s'", WX_STR(var) ); - Console.Indent().Warning( - L"Illegal Value: %d\n" - L"Using Default: %d (%s)\n", - value, defvalue, enumArray[defvalue] - ); + if (value >= cnt) { + Console.Warning(L"(SaveSettings) An illegal enumerated index was detected when saving '%s'", WX_STR(var)); + Console.Indent().Warning( + L"Illegal Value: %d\n" + L"Using Default: %d (%s)\n", + value, defvalue, enumArray[defvalue]); - // Cause a debug assertion, since this is a fully recoverable error. - pxAssert( value < cnt ); + // Cause a debug assertion, since this is a fully recoverable error. + pxAssert(value < cnt); - value = defvalue; - } + value = defvalue; + } - m_Config->Write( var, enumArray[value] ); + m_Config->Write(var, enumArray[value]); } - diff --git a/common/src/Utilities/Linux/LnxHostSys.cpp b/common/src/Utilities/Linux/LnxHostSys.cpp index d400411e0e..9c5250d053 100644 --- a/common/src/Utilities/Linux/LnxHostSys.cpp +++ b/common/src/Utilities/Linux/LnxHostSys.cpp @@ -27,205 +27,206 @@ // Apple uses the MAP_ANON define instead of MAP_ANONYMOUS, but they mean // the same thing. #if defined(__APPLE__) && !defined(MAP_ANONYMOUS) -# define MAP_ANONYMOUS MAP_ANON +#define MAP_ANONYMOUS MAP_ANON #endif extern void SignalExit(int sig); -static const uptr m_pagemask = getpagesize()-1; +static const uptr m_pagemask = getpagesize() - 1; // Linux implementation of SIGSEGV handler. Bind it using sigaction(). -static void SysPageFaultSignalFilter( int signal, siginfo_t *siginfo, void * ) +static void SysPageFaultSignalFilter(int signal, siginfo_t *siginfo, void *) { - // [TODO] : Add a thread ID filter to the Linux Signal handler here. - // Rationale: On windows, the __try/__except model allows per-thread specific behavior - // for page fault handling. On linux, there is a single signal handler for the whole - // process, but the handler is executed by the thread that caused the exception. + // [TODO] : Add a thread ID filter to the Linux Signal handler here. + // Rationale: On windows, the __try/__except model allows per-thread specific behavior + // for page fault handling. On linux, there is a single signal handler for the whole + // process, but the handler is executed by the thread that caused the exception. - // Stdio Usage note: SIGSEGV handling is a synchronous in-thread signal. It is done - // from the context of the current thread and stackframe. So long as the thread is not - // the main/ui thread, use of the px assertion system should be safe. Use of stdio should - // be safe even on the main thread. - // (in other words, stdio limitations only really apply to process-level asynchronous - // signals) + // Stdio Usage note: SIGSEGV handling is a synchronous in-thread signal. It is done + // from the context of the current thread and stackframe. So long as the thread is not + // the main/ui thread, use of the px assertion system should be safe. Use of stdio should + // be safe even on the main thread. + // (in other words, stdio limitations only really apply to process-level asynchronous + // signals) - // Note: Use of stdio functions isn't safe here. Avoid console logs, - // assertions, file logs, or just about anything else useful. + // Note: Use of stdio functions isn't safe here. Avoid console logs, + // assertions, file logs, or just about anything else useful. - // Note: This signal can be accessed by the EE or MTVU thread - // Source_PageFault is a global variable with its own state information - // so for now we lock this exception code unless someone can fix this better... - Threading::ScopedLock lock(PageFault_Mutex); + // Note: This signal can be accessed by the EE or MTVU thread + // Source_PageFault is a global variable with its own state information + // so for now we lock this exception code unless someone can fix this better... + Threading::ScopedLock lock(PageFault_Mutex); - Source_PageFault->Dispatch( PageFaultInfo( (uptr)siginfo->si_addr & ~m_pagemask ) ); + Source_PageFault->Dispatch(PageFaultInfo((uptr)siginfo->si_addr & ~m_pagemask)); - // resumes execution right where we left off (re-executes instruction that - // caused the SIGSEGV). - if (Source_PageFault->WasHandled()) return; + // resumes execution right where we left off (re-executes instruction that + // caused the SIGSEGV). + if (Source_PageFault->WasHandled()) + return; - if (!wxThread::IsMain()) - { - pxFailRel(pxsFmt("Unhandled page fault @ 0x%08x", siginfo->si_addr)); - } + if (!wxThread::IsMain()) { + pxFailRel(pxsFmt("Unhandled page fault @ 0x%08x", siginfo->si_addr)); + } - // Bad mojo! Completely invalid address. - // Instigate a trap if we're in a debugger, and if not then do a SIGKILL. + // Bad mojo! Completely invalid address. + // Instigate a trap if we're in a debugger, and if not then do a SIGKILL. - pxTrap(); - if (!IsDebugBuild) raise( SIGKILL ); + pxTrap(); + if (!IsDebugBuild) + raise(SIGKILL); } void _platform_InstallSignalHandler() { - Console.WriteLn("Installing POSIX SIGSEGV handler..."); - struct sigaction sa; + Console.WriteLn("Installing POSIX SIGSEGV handler..."); + struct sigaction sa; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_SIGINFO; - sa.sa_sigaction = SysPageFaultSignalFilter; - sigaction(SIGSEGV, &sa, NULL); + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = SysPageFaultSignalFilter; + sigaction(SIGSEGV, &sa, NULL); } -static __ri void PageSizeAssertionTest( size_t size ) +static __ri void PageSizeAssertionTest(size_t size) { - pxAssertMsg( (__pagesize == getpagesize()), pxsFmt( - "Internal system error: Operating system pagesize does not match compiled pagesize.\n\t" - L"\tOS Page Size: 0x%x (%d), Compiled Page Size: 0x%x (%u)", - getpagesize(), getpagesize(), __pagesize, __pagesize ) - ); + pxAssertMsg((__pagesize == getpagesize()), pxsFmt( + "Internal system error: Operating system pagesize does not match compiled pagesize.\n\t" + L"\tOS Page Size: 0x%x (%d), Compiled Page Size: 0x%x (%u)", + getpagesize(), getpagesize(), __pagesize, __pagesize)); - pxAssertDev( (size & (__pagesize-1)) == 0, pxsFmt( - L"Memory block size must be a multiple of the target platform's page size.\n" - L"\tPage Size: 0x%x (%u), Block Size: 0x%x (%u)", - __pagesize, __pagesize, size, size ) - ); + pxAssertDev((size & (__pagesize - 1)) == 0, pxsFmt( + L"Memory block size must be a multiple of the target platform's page size.\n" + L"\tPage Size: 0x%x (%u), Block Size: 0x%x (%u)", + __pagesize, __pagesize, size, size)); } // returns FALSE if the mprotect call fails with an ENOMEM. // Raises assertions on other types of POSIX errors (since those typically reflect invalid object // or memory states). -static bool _memprotect( void* baseaddr, size_t size, const PageProtectionMode& mode ) +static bool _memprotect(void *baseaddr, size_t size, const PageProtectionMode &mode) { - PageSizeAssertionTest(size); + PageSizeAssertionTest(size); - uint lnxmode = 0; + uint lnxmode = 0; - if (mode.CanWrite()) lnxmode |= PROT_WRITE; - if (mode.CanRead()) lnxmode |= PROT_READ; - if (mode.CanExecute()) lnxmode |= PROT_EXEC | PROT_READ; + if (mode.CanWrite()) + lnxmode |= PROT_WRITE; + if (mode.CanRead()) + lnxmode |= PROT_READ; + if (mode.CanExecute()) + lnxmode |= PROT_EXEC | PROT_READ; - const int result = mprotect( baseaddr, size, lnxmode ); + const int result = mprotect(baseaddr, size, lnxmode); - if (result == 0) return true; + if (result == 0) + return true; - switch(errno) - { - case EINVAL: - pxFailDev(pxsFmt(L"mprotect returned EINVAL @ 0x%08X -> 0x%08X (mode=%s)", - baseaddr, (uptr)baseaddr+size, WX_STR(mode.ToString())) - ); - break; + switch (errno) { + case EINVAL: + pxFailDev(pxsFmt(L"mprotect returned EINVAL @ 0x%08X -> 0x%08X (mode=%s)", + baseaddr, (uptr)baseaddr + size, WX_STR(mode.ToString()))); + break; - case EACCES: - pxFailDev(pxsFmt(L"mprotect returned EACCES @ 0x%08X -> 0x%08X (mode=%s)", - baseaddr, (uptr)baseaddr+size, WX_STR(mode.ToString())) - ); - break; + case EACCES: + pxFailDev(pxsFmt(L"mprotect returned EACCES @ 0x%08X -> 0x%08X (mode=%s)", + baseaddr, (uptr)baseaddr + size, WX_STR(mode.ToString()))); + break; - case ENOMEM: - // caller handles assertion or exception, or whatever. - break; - } - return false; + case ENOMEM: + // caller handles assertion or exception, or whatever. + break; + } + return false; } -void* HostSys::MmapReservePtr(void* base, size_t size) +void *HostSys::MmapReservePtr(void *base, size_t size) { - PageSizeAssertionTest(size); + PageSizeAssertionTest(size); - // On linux a reserve-without-commit is performed by using mmap on a read-only - // or anonymous source, with PROT_NONE (no-access) permission. Since the mapping - // is completely inaccessible, the OS will simply reserve it and will not put it - // against the commit table. - return mmap(base, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + // On linux a reserve-without-commit is performed by using mmap on a read-only + // or anonymous source, with PROT_NONE (no-access) permission. Since the mapping + // is completely inaccessible, the OS will simply reserve it and will not put it + // against the commit table. + return mmap(base, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); } -bool HostSys::MmapCommitPtr(void* base, size_t size, const PageProtectionMode& mode) +bool HostSys::MmapCommitPtr(void *base, size_t size, const PageProtectionMode &mode) { - // In linux, reserved memory is automatically committed when its permissions are - // changed to something other than PROT_NONE. If the user is committing memory - // as PROT_NONE, then just ignore this call (memory will be committed automatically - // later when the user changes permissions to something useful via calls to MemProtect). + // In linux, reserved memory is automatically committed when its permissions are + // changed to something other than PROT_NONE. If the user is committing memory + // as PROT_NONE, then just ignore this call (memory will be committed automatically + // later when the user changes permissions to something useful via calls to MemProtect). - if (mode.IsNone()) return false; + if (mode.IsNone()) + return false; - if (_memprotect( base, size, mode )) return true; + if (_memprotect(base, size, mode)) + return true; - if (!pxDoOutOfMemory) return false; - pxDoOutOfMemory(size); - return _memprotect( base, size, mode ); + if (!pxDoOutOfMemory) + return false; + pxDoOutOfMemory(size); + return _memprotect(base, size, mode); } -void HostSys::MmapResetPtr(void* base, size_t size) +void HostSys::MmapResetPtr(void *base, size_t size) { - // On linux the only way to reset the memory is to unmap and remap it as PROT_NONE. - // That forces linux to unload all committed pages and start from scratch. + // On linux the only way to reset the memory is to unmap and remap it as PROT_NONE. + // That forces linux to unload all committed pages and start from scratch. - // FIXME: Ideally this code would have some threading lock on it to prevent any other - // malloc/free code in the current process from interfering with the operation, but I - // can't think of any good way to do that. (generally it shouldn't be a problem in - // PCSX2 anyway, since MmapReset is only called when the ps2vm is suspended; so that - // pretty well stops all PCSX2 threads anyway). + // FIXME: Ideally this code would have some threading lock on it to prevent any other + // malloc/free code in the current process from interfering with the operation, but I + // can't think of any good way to do that. (generally it shouldn't be a problem in + // PCSX2 anyway, since MmapReset is only called when the ps2vm is suspended; so that + // pretty well stops all PCSX2 threads anyway). - Munmap(base, size); - void* result = MmapReservePtr(base, size); + Munmap(base, size); + void *result = MmapReservePtr(base, size); - pxAssertRel ((uptr)result == (uptr)base, pxsFmt( - "Virtual memory decommit failed: memory at 0x%08X -> 0x%08X could not be remapped. " - "This is likely caused by multi-thread memory contention.", base, (uptr)base+size - )); + pxAssertRel((uptr)result == (uptr)base, pxsFmt( + "Virtual memory decommit failed: memory at 0x%08X -> 0x%08X could not be remapped. " + "This is likely caused by multi-thread memory contention.", + base, (uptr)base + size)); } -void* HostSys::MmapReserve(uptr base, size_t size) +void *HostSys::MmapReserve(uptr base, size_t size) { - return MmapReservePtr((void*)base, size); + return MmapReservePtr((void *)base, size); } -bool HostSys::MmapCommit(uptr base, size_t size, const PageProtectionMode& mode) +bool HostSys::MmapCommit(uptr base, size_t size, const PageProtectionMode &mode) { - return MmapCommitPtr( (void*)base, size, mode ); + return MmapCommitPtr((void *)base, size, mode); } void HostSys::MmapReset(uptr base, size_t size) { - MmapResetPtr((void*)base, size); + MmapResetPtr((void *)base, size); } -void* HostSys::Mmap(uptr base, size_t size) +void *HostSys::Mmap(uptr base, size_t size) { - PageSizeAssertionTest(size); + PageSizeAssertionTest(size); - // MAP_ANONYMOUS - means we have no associated file handle (or device). + // MAP_ANONYMOUS - means we have no associated file handle (or device). - return mmap((void*)base, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + return mmap((void *)base, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); } void HostSys::Munmap(uptr base, size_t size) { - if (!base) return; - munmap((void*)base, size); + if (!base) + return; + munmap((void *)base, size); } -void HostSys::MemProtect( void* baseaddr, size_t size, const PageProtectionMode& mode ) +void HostSys::MemProtect(void *baseaddr, size_t size, const PageProtectionMode &mode) { - if (!_memprotect(baseaddr, size, mode)) - { - throw Exception::OutOfMemory( L"MemProtect" ) - .SetDiagMsg(pxsFmt( L"mprotect failed @ 0x%08X -> 0x%08X (mode=%s)", - baseaddr, (uptr)baseaddr+size, WX_STR(mode.ToString()) - ) - ); - } + if (!_memprotect(baseaddr, size, mode)) { + throw Exception::OutOfMemory(L"MemProtect") + .SetDiagMsg(pxsFmt(L"mprotect failed @ 0x%08X -> 0x%08X (mode=%s)", + baseaddr, (uptr)baseaddr + size, WX_STR(mode.ToString()))); + } } diff --git a/common/src/Utilities/Linux/LnxMisc.cpp b/common/src/Utilities/Linux/LnxMisc.cpp index 4443465119..d00bbd5a80 100644 --- a/common/src/Utilities/Linux/LnxMisc.cpp +++ b/common/src/Utilities/Linux/LnxMisc.cpp @@ -24,13 +24,13 @@ // Returns 0 on failure (not supported by the operating system). u64 GetPhysicalMemory() { - u64 pages = 0; + u64 pages = 0; #ifdef _SC_PHYS_PAGES - pages = sysconf(_SC_PHYS_PAGES); + pages = sysconf(_SC_PHYS_PAGES); #endif - return pages * getpagesize(); + return pages * getpagesize(); } @@ -40,22 +40,22 @@ void InitCPUTicks() u64 GetTickFrequency() { - return 1000000; // unix measures in microseconds + return 1000000; // unix measures in microseconds } u64 GetCPUTicks() { - struct timeval t; - gettimeofday(&t, NULL); - return ((u64)t.tv_sec*GetTickFrequency())+t.tv_usec; + struct timeval t; + gettimeofday(&t, NULL); + return ((u64)t.tv_sec * GetTickFrequency()) + t.tv_usec; } wxString GetOSVersionString() { - return wxGetOsDescription(); + return wxGetOsDescription(); } void ScreensaverAllow(bool allow) { - // no-op + // no-op } diff --git a/common/src/Utilities/Linux/LnxThreads.cpp b/common/src/Utilities/Linux/LnxThreads.cpp index fb6c2c1503..fe7e24cbcb 100644 --- a/common/src/Utilities/Linux/LnxThreads.cpp +++ b/common/src/Utilities/Linux/LnxThreads.cpp @@ -29,7 +29,7 @@ #if !defined(__unix__) -# pragma message( "LnxThreads.cpp should only be compiled by projects or makefiles targeted at Linux/BSD distros.") +#pragma message("LnxThreads.cpp should only be compiled by projects or makefiles targeted at Linux/BSD distros.") #else @@ -37,23 +37,23 @@ // the LOCK prefix. The prefix works on single core CPUs fine (but is slow), but not // having the LOCK prefix is very bad indeed. -__forceinline void Threading::Sleep( int ms ) +__forceinline void Threading::Sleep(int ms) { - usleep( 1000*ms ); + usleep(1000 * ms); } // For use in spin/wait loops, Acts as a hint to Intel CPUs and should, in theory // improve performance and reduce cpu power consumption. __forceinline void Threading::SpinWait() { - // If this doesn't compile you can just comment it out (it only serves as a - // performance hint and isn't required). - __asm__ ( "pause" ); + // If this doesn't compile you can just comment it out (it only serves as a + // performance hint and isn't required). + __asm__("pause"); } __forceinline void Threading::EnableHiresScheduler() { - // Don't know if linux has a customizable scheduler resolution like Windows (doubtful) + // Don't know if linux has a customizable scheduler resolution like Windows (doubtful) } __forceinline void Threading::DisableHiresScheduler() @@ -63,66 +63,69 @@ __forceinline void Threading::DisableHiresScheduler() // Unit of time of GetThreadCpuTime/GetCpuTime u64 Threading::GetThreadTicksPerSecond() { - return 1000000; + return 1000000; } // Helper function to get either either the current cpu usage // in called thread or in id thread static u64 get_thread_time(uptr id = 0) { - clockid_t cid; - if (id) { - int err = pthread_getcpuclockid((pthread_t)id, &cid); - if (err) return 0; - } else { - cid = CLOCK_THREAD_CPUTIME_ID; - } + clockid_t cid; + if (id) { + int err = pthread_getcpuclockid((pthread_t)id, &cid); + if (err) + return 0; + } else { + cid = CLOCK_THREAD_CPUTIME_ID; + } - struct timespec ts; - int err = clock_gettime(cid, &ts); - if (err) return 0; + struct timespec ts; + int err = clock_gettime(cid, &ts); + if (err) + return 0; - return (u64) ts.tv_sec * (u64) 1e6 + (u64) ts.tv_nsec / (u64) 1e3; + return (u64)ts.tv_sec * (u64)1e6 + (u64)ts.tv_nsec / (u64)1e3; } // Returns the current timestamp (not relative to a real world clock) u64 Threading::GetThreadCpuTime() { - return get_thread_time(); + return get_thread_time(); } u64 Threading::pxThread::GetCpuTime() const { - // Get the cpu time for the thread belonging to this object. Use m_native_id and/or - // m_native_handle to implement it. Return value should be a measure of total time the - // thread has used on the CPU (scaled by the value returned by GetThreadTicksPerSecond(), - // which typically would be an OS-provided scalar or some sort). + // Get the cpu time for the thread belonging to this object. Use m_native_id and/or + // m_native_handle to implement it. Return value should be a measure of total time the + // thread has used on the CPU (scaled by the value returned by GetThreadTicksPerSecond(), + // which typically would be an OS-provided scalar or some sort). - if (!m_native_id) return 0; + if (!m_native_id) + return 0; - return get_thread_time(m_native_id); + return get_thread_time(m_native_id); } void Threading::pxThread::_platform_specific_OnStartInThread() { - // Obtain linux-specific thread IDs or Handles here, which can be used to query - // kernel scheduler performance information. - m_native_id = (uptr) pthread_self(); + // Obtain linux-specific thread IDs or Handles here, which can be used to query + // kernel scheduler performance information. + m_native_id = (uptr)pthread_self(); } void Threading::pxThread::_platform_specific_OnCleanupInThread() { - // Cleanup handles here, which were opened above. + // Cleanup handles here, which were opened above. } -void Threading::pxThread::_DoSetThreadName( const char* name ) +void Threading::pxThread::_DoSetThreadName(const char *name) { #if defined(__linux__) - // Extract of manpage: "The name can be up to 16 bytes long, and should be - // null-terminated if it contains fewer bytes." - prctl(PR_SET_NAME, name, 0, 0, 0); + // Extract of manpage: "The name can be up to 16 bytes long, and should be + // null-terminated if it contains fewer bytes." + prctl(PR_SET_NAME, name, 0, 0, 0); #elif defined(__unix__) - pthread_set_name_np(pthread_self(), name); + pthread_set_name_np(pthread_self(), name); #endif } diff --git a/common/src/Utilities/Mutex.cpp b/common/src/Utilities/Mutex.cpp index 7171f6f620..99cf8333be 100644 --- a/common/src/Utilities/Mutex.cpp +++ b/common/src/Utilities/Mutex.cpp @@ -23,8 +23,8 @@ namespace Threading { - static std::atomic _attr_refcount(0); - static pthread_mutexattr_t _attr_recursive; +static std::atomic _attr_refcount(0); +static pthread_mutexattr_t _attr_recursive; } // -------------------------------------------------------------------------------------- @@ -38,7 +38,7 @@ namespace Threading // We have to emulate pthread_mutex_timedlock(). This could be a serious // performance drain if its used a lot. -#include // gettimeofday() +#include // gettimeofday() // sleep for 10ms at a time #define TIMEDLOCK_EMU_SLEEP_NS 10000000ULL @@ -55,87 +55,91 @@ namespace Threading // This is an implementation that emulates pthread_mutex_timedlock() via // pthread_mutex_trylock(). static int xpthread_mutex_timedlock( - pthread_mutex_t *mutex, - const struct timespec *abs_timeout) + pthread_mutex_t *mutex, + const struct timespec *abs_timeout) { - int err = 0; + int err = 0; - while ((err = pthread_mutex_trylock(mutex)) == EBUSY) { - // acquiring lock failed, sleep some - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = TIMEDLOCK_EMU_SLEEP_NS; - int status; - while ((status = nanosleep(&ts, &ts)) == -1); + while ((err = pthread_mutex_trylock(mutex)) == EBUSY) { + // acquiring lock failed, sleep some + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = TIMEDLOCK_EMU_SLEEP_NS; + int status; + while ((status = nanosleep(&ts, &ts)) == -1) + ; - // check if the timeout has expired, gettimeofday() is implemented - // efficiently (in userspace) on OSX - struct timeval now; - int res = gettimeofday(&now, NULL); - if (abs_timeout->tv_sec == 0 || now.tv_sec > abs_timeout->tv_sec || - (u64) now.tv_usec * 1000ULL > (u64) abs_timeout->tv_nsec) { - return ETIMEDOUT; - } - } + // check if the timeout has expired, gettimeofday() is implemented + // efficiently (in userspace) on OSX + struct timeval now; + int res = gettimeofday(&now, NULL); + if (abs_timeout->tv_sec == 0 || now.tv_sec > abs_timeout->tv_sec || + (u64)now.tv_usec * 1000ULL > (u64)abs_timeout->tv_nsec) { + return ETIMEDOUT; + } + } - return err; + return err; } #endif Threading::Mutex::Mutex() { - pthread_mutex_init( &m_mutex, NULL ); + pthread_mutex_init(&m_mutex, NULL); } -static wxTimeSpan def_detach_timeout( 0, 0, 6, 0 ); +static wxTimeSpan def_detach_timeout(0, 0, 6, 0); void Threading::Mutex::Detach() { - if( EBUSY != pthread_mutex_destroy(&m_mutex) ) return; + if (EBUSY != pthread_mutex_destroy(&m_mutex)) + return; - if( IsRecursive() ) - { - // Sanity check: Recursive locks could be held by our own thread, which would - // be considered an assertion failure, but can also be handled gracefully. - // (note: if the mutex is locked recursively more than twice then this assert won't - // detect it) + if (IsRecursive()) { + // Sanity check: Recursive locks could be held by our own thread, which would + // be considered an assertion failure, but can also be handled gracefully. + // (note: if the mutex is locked recursively more than twice then this assert won't + // detect it) - Release(); Release(); // in case of double recursion. - int result = pthread_mutex_destroy( &m_mutex ); - if( pxAssertDev( result != EBUSY, "Detachment of a recursively-locked mutex (self-locked!)." ) ) return; - } + Release(); + Release(); // in case of double recursion. + int result = pthread_mutex_destroy(&m_mutex); + if (pxAssertDev(result != EBUSY, "Detachment of a recursively-locked mutex (self-locked!).")) + return; + } - if( Wait(def_detach_timeout) ) - pthread_mutex_destroy( &m_mutex ); - else - Console.Error( "(Thread Log) Mutex cleanup failed due to possible deadlock."); + if (Wait(def_detach_timeout)) + pthread_mutex_destroy(&m_mutex); + else + Console.Error("(Thread Log) Mutex cleanup failed due to possible deadlock."); } Threading::Mutex::~Mutex() throw() { - try { - Mutex::Detach(); - } DESTRUCTOR_CATCHALL; + try { + Mutex::Detach(); + } + DESTRUCTOR_CATCHALL; } -Threading::MutexRecursive::MutexRecursive() : Mutex( false ) +Threading::MutexRecursive::MutexRecursive() + : Mutex(false) { - if( ++_attr_refcount == 1 ) - { - if( 0 != pthread_mutexattr_init( &_attr_recursive ) ) - throw Exception::OutOfMemory(L"Recursive mutexing attributes"); + if (++_attr_refcount == 1) { + if (0 != pthread_mutexattr_init(&_attr_recursive)) + throw Exception::OutOfMemory(L"Recursive mutexing attributes"); - pthread_mutexattr_settype( &_attr_recursive, PTHREAD_MUTEX_RECURSIVE ); - } + pthread_mutexattr_settype(&_attr_recursive, PTHREAD_MUTEX_RECURSIVE); + } - if (pthread_mutex_init( &m_mutex, &_attr_recursive )) - Console.Error( "(Thread Log) Failed to initialize mutex."); + if (pthread_mutex_init(&m_mutex, &_attr_recursive)) + Console.Error("(Thread Log) Failed to initialize mutex."); } Threading::MutexRecursive::~MutexRecursive() throw() { - if( --_attr_refcount == 0 ) - pthread_mutexattr_destroy( &_attr_recursive ); + if (--_attr_refcount == 0) + pthread_mutexattr_destroy(&_attr_recursive); } // This is a bit of a hackish function, which is technically unsafe, but can be useful for allowing @@ -144,8 +148,8 @@ Threading::MutexRecursive::~MutexRecursive() throw() // the deeper meanings of the universe for eternity. void Threading::Mutex::Recreate() { - Detach(); - pthread_mutex_init( &m_mutex, NULL ); + Detach(); + pthread_mutex_init(&m_mutex, NULL); } // Returns: @@ -153,12 +157,11 @@ void Threading::Mutex::Recreate() // unlocked. bool Threading::Mutex::RecreateIfLocked() { - if( !Wait(def_detach_timeout) ) - { - Recreate(); - return true; - } - return false; + if (!Wait(def_detach_timeout)) { + Recreate(); + return true; + } + return false; } @@ -168,25 +171,25 @@ bool Threading::Mutex::RecreateIfLocked() // other than the main thread. void Threading::Mutex::AcquireWithoutYield() { - pxAssertMsg( !wxThread::IsMain(), "Unyielding mutex acquire issued from the main/gui thread. Please use Acquire() instead." ); - pthread_mutex_lock( &m_mutex ); + pxAssertMsg(!wxThread::IsMain(), "Unyielding mutex acquire issued from the main/gui thread. Please use Acquire() instead."); + pthread_mutex_lock(&m_mutex); } -bool Threading::Mutex::AcquireWithoutYield( const wxTimeSpan& timeout ) +bool Threading::Mutex::AcquireWithoutYield(const wxTimeSpan &timeout) { - wxDateTime megafail( wxDateTime::UNow() + timeout ); - const timespec fail = { megafail.GetTicks(), megafail.GetMillisecond() * 1000000 }; - return xpthread_mutex_timedlock( &m_mutex, &fail ) == 0; + wxDateTime megafail(wxDateTime::UNow() + timeout); + const timespec fail = {megafail.GetTicks(), megafail.GetMillisecond() * 1000000}; + return xpthread_mutex_timedlock(&m_mutex, &fail) == 0; } void Threading::Mutex::Release() { - pthread_mutex_unlock( &m_mutex ); + pthread_mutex_unlock(&m_mutex); } bool Threading::Mutex::TryAcquire() { - return EBUSY != pthread_mutex_trylock( &m_mutex ); + return EBUSY != pthread_mutex_trylock(&m_mutex); } // This is a wxApp-safe rendition of AcquireWithoutYield, which makes sure to execute pending app events @@ -195,54 +198,45 @@ bool Threading::Mutex::TryAcquire() void Threading::Mutex::Acquire() { #if wxUSE_GUI - if( !wxThread::IsMain() || (wxTheApp == NULL) ) - { - pthread_mutex_lock( &m_mutex ); - } - else if( _WaitGui_RecursionGuard( L"Mutex::Acquire" ) ) - { - ScopedBusyCursor hourglass( Cursor_ReallyBusy ); - pthread_mutex_lock( &m_mutex ); - } - else - { - //ScopedBusyCursor hourglass( Cursor_KindaBusy ); - while( !AcquireWithoutYield(def_yieldgui_interval) ) - YieldToMain(); - } + if (!wxThread::IsMain() || (wxTheApp == NULL)) { + pthread_mutex_lock(&m_mutex); + } else if (_WaitGui_RecursionGuard(L"Mutex::Acquire")) { + ScopedBusyCursor hourglass(Cursor_ReallyBusy); + pthread_mutex_lock(&m_mutex); + } else { + //ScopedBusyCursor hourglass( Cursor_KindaBusy ); + while (!AcquireWithoutYield(def_yieldgui_interval)) + YieldToMain(); + } #else - pthread_mutex_lock( &m_mutex ); + pthread_mutex_lock(&m_mutex); #endif } -bool Threading::Mutex::Acquire( const wxTimeSpan& timeout ) +bool Threading::Mutex::Acquire(const wxTimeSpan &timeout) { #if wxUSE_GUI - if( !wxThread::IsMain() || (wxTheApp == NULL) ) - { - return AcquireWithoutYield(timeout); - } - else if( _WaitGui_RecursionGuard( L"Mutex::TimedAcquire" ) ) - { - ScopedBusyCursor hourglass( Cursor_ReallyBusy ); - return AcquireWithoutYield( timeout ); - } - else - { - //ScopedBusyCursor hourglass( Cursor_KindaBusy ); - wxTimeSpan countdown( (timeout) ); + if (!wxThread::IsMain() || (wxTheApp == NULL)) { + return AcquireWithoutYield(timeout); + } else if (_WaitGui_RecursionGuard(L"Mutex::TimedAcquire")) { + ScopedBusyCursor hourglass(Cursor_ReallyBusy); + return AcquireWithoutYield(timeout); + } else { + //ScopedBusyCursor hourglass( Cursor_KindaBusy ); + wxTimeSpan countdown((timeout)); - do { - if( AcquireWithoutYield( def_yieldgui_interval ) ) break; - YieldToMain(); - countdown -= def_yieldgui_interval; - } while( countdown.GetMilliseconds() > 0 ); + do { + if (AcquireWithoutYield(def_yieldgui_interval)) + break; + YieldToMain(); + countdown -= def_yieldgui_interval; + } while (countdown.GetMilliseconds() > 0); - return countdown.GetMilliseconds() > 0; - } + return countdown.GetMilliseconds() > 0; + } #else - return AcquireWithoutYield(); + return AcquireWithoutYield(); #endif } @@ -255,14 +249,14 @@ bool Threading::Mutex::Acquire( const wxTimeSpan& timeout ) // void Threading::Mutex::Wait() { - Acquire(); - Release(); + Acquire(); + Release(); } void Threading::Mutex::WaitWithoutYield() { - AcquireWithoutYield(); - Release(); + AcquireWithoutYield(); + Release(); } // Performs a wait on a locked mutex, or returns instantly if the mutex is unlocked. @@ -272,24 +266,22 @@ void Threading::Mutex::WaitWithoutYield() // true if the mutex was freed and is in an unlocked state; or false if the wait timed out // and the mutex is still locked by another thread. // -bool Threading::Mutex::Wait( const wxTimeSpan& timeout ) +bool Threading::Mutex::Wait(const wxTimeSpan &timeout) { - if( Acquire(timeout) ) - { - Release(); - return true; - } - return false; + if (Acquire(timeout)) { + Release(); + return true; + } + return false; } -bool Threading::Mutex::WaitWithoutYield( const wxTimeSpan& timeout ) +bool Threading::Mutex::WaitWithoutYield(const wxTimeSpan &timeout) { - if( AcquireWithoutYield(timeout) ) - { - Release(); - return true; - } - return false; + if (AcquireWithoutYield(timeout)) { + Release(); + return true; + } + return false; } // -------------------------------------------------------------------------------------- @@ -298,67 +290,72 @@ bool Threading::Mutex::WaitWithoutYield( const wxTimeSpan& timeout ) Threading::ScopedLock::~ScopedLock() throw() { - if( m_IsLocked && m_lock ) - m_lock->Release(); + if (m_IsLocked && m_lock) + m_lock->Release(); } -Threading::ScopedLock::ScopedLock( const Mutex* locker ) +Threading::ScopedLock::ScopedLock(const Mutex *locker) { - m_IsLocked = false; - AssignAndLock( locker ); + m_IsLocked = false; + AssignAndLock(locker); } -Threading::ScopedLock::ScopedLock( const Mutex& locker ) +Threading::ScopedLock::ScopedLock(const Mutex &locker) { - m_IsLocked = false; - AssignAndLock( locker ); + m_IsLocked = false; + AssignAndLock(locker); } -void Threading::ScopedLock::AssignAndLock( const Mutex& locker ) +void Threading::ScopedLock::AssignAndLock(const Mutex &locker) { - AssignAndLock( &locker ); + AssignAndLock(&locker); } -void Threading::ScopedLock::AssignAndLock( const Mutex* locker ) +void Threading::ScopedLock::AssignAndLock(const Mutex *locker) { - pxAssert(!m_IsLocked); // if we're already locked, changing the lock is bad mojo. + pxAssert(!m_IsLocked); // if we're already locked, changing the lock is bad mojo. - m_lock = const_cast(locker); - if( !m_lock ) return; + m_lock = const_cast(locker); + if (!m_lock) + return; - m_IsLocked = true; - m_lock->Acquire(); + m_IsLocked = true; + m_lock->Acquire(); } -void Threading::ScopedLock::Assign( const Mutex& locker ) +void Threading::ScopedLock::Assign(const Mutex &locker) { - m_lock = const_cast(&locker); + m_lock = const_cast(&locker); } -void Threading::ScopedLock::Assign( const Mutex* locker ) +void Threading::ScopedLock::Assign(const Mutex *locker) { - m_lock = const_cast(locker); + m_lock = const_cast(locker); } // Provides manual unlocking of a scoped lock prior to object destruction. void Threading::ScopedLock::Release() { - if( !m_IsLocked ) return; - m_IsLocked = false; - if( m_lock ) m_lock->Release(); + if (!m_IsLocked) + return; + m_IsLocked = false; + if (m_lock) + m_lock->Release(); } // provides manual locking of a scoped lock, to re-lock after a manual unlocking. void Threading::ScopedLock::Acquire() { - if( m_IsLocked || !m_lock ) return; - m_lock->Acquire(); - m_IsLocked = true; + if (m_IsLocked || !m_lock) + return; + m_lock->Acquire(); + m_IsLocked = true; } -Threading::ScopedLock::ScopedLock( const Mutex& locker, bool isTryLock ) +Threading::ScopedLock::ScopedLock(const Mutex &locker, bool isTryLock) { - m_lock = const_cast(&locker); - if( !m_lock ) return; - m_IsLocked = isTryLock ? m_lock->TryAcquire() : false; + m_lock = const_cast(&locker); + if (!m_lock) + return; + m_IsLocked = isTryLock ? m_lock->TryAcquire() : false; } diff --git a/common/src/Utilities/PathUtils.cpp b/common/src/Utilities/PathUtils.cpp index 132717cc5a..4fbdd5f168 100644 --- a/common/src/Utilities/PathUtils.cpp +++ b/common/src/Utilities/PathUtils.cpp @@ -23,72 +23,74 @@ // wxDirName (implementations) // --------------------------------------------------------------------------------- -wxFileName wxDirName::Combine( const wxFileName& right ) const +wxFileName wxDirName::Combine(const wxFileName &right) const { - pxAssertMsg( IsDir(), L"Warning: Malformed directory name detected during wxDirName concatenation." ); - if( right.IsAbsolute() ) - return right; + pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wxDirName concatenation."); + if (right.IsAbsolute()) + return right; - // Append any directory parts from right, and then set the filename. - // Except we can't do that because our m_members are private (argh!) and there is no API - // for getting each component of the path. So instead let's use Normalize: + // Append any directory parts from right, and then set the filename. + // Except we can't do that because our m_members are private (argh!) and there is no API + // for getting each component of the path. So instead let's use Normalize: - wxFileName result( right ); - result.Normalize( wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath() ); - return result; + wxFileName result(right); + result.Normalize(wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath()); + return result; } -wxDirName wxDirName::Combine( const wxDirName& right ) const +wxDirName wxDirName::Combine(const wxDirName &right) const { - pxAssertMsg( IsDir() && right.IsDir(), L"Warning: Malformed directory name detected during wDirName concatenation." ); + pxAssertMsg(IsDir() && right.IsDir(), L"Warning: Malformed directory name detected during wDirName concatenation."); - wxDirName result( right ); - result.Normalize( wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath() ); - return result; + wxDirName result(right); + result.Normalize(wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath()); + return result; } -wxDirName& wxDirName::Normalize( int flags, const wxString& cwd ) +wxDirName &wxDirName::Normalize(int flags, const wxString &cwd) { - pxAssertMsg( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." ); - if( !wxFileName::Normalize( flags, cwd ) ) - throw Exception::ParseError().SetDiagMsg( L"wxDirName::Normalize operation failed." ); - return *this; + pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wDirName normalization."); + if (!wxFileName::Normalize(flags, cwd)) + throw Exception::ParseError().SetDiagMsg(L"wxDirName::Normalize operation failed."); + return *this; } -wxDirName& wxDirName::MakeRelativeTo( const wxString& pathBase ) +wxDirName &wxDirName::MakeRelativeTo(const wxString &pathBase) { - pxAssertMsg( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." ); - if( !wxFileName::MakeRelativeTo( pathBase ) ) - throw Exception::ParseError().SetDiagMsg( L"wxDirName::MakeRelativeTo operation failed." ); - return *this; + pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wDirName normalization."); + if (!wxFileName::MakeRelativeTo(pathBase)) + throw Exception::ParseError().SetDiagMsg(L"wxDirName::MakeRelativeTo operation failed."); + return *this; } -wxDirName& wxDirName::MakeAbsolute( const wxString& cwd ) +wxDirName &wxDirName::MakeAbsolute(const wxString &cwd) { - pxAssertMsg( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." ); - if( !wxFileName::MakeAbsolute( cwd ) ) - throw Exception::ParseError().SetDiagMsg( L"wxDirName::MakeAbsolute operation failed." ); - return *this; + pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wDirName normalization."); + if (!wxFileName::MakeAbsolute(cwd)) + throw Exception::ParseError().SetDiagMsg(L"wxDirName::MakeAbsolute operation failed."); + return *this; } void wxDirName::Rmdir() { - if( !Exists() ) return; - wxFileName::Rmdir(); - // TODO : Throw exception if operation failed? Do we care? + if (!Exists()) + return; + wxFileName::Rmdir(); + // TODO : Throw exception if operation failed? Do we care? } bool wxDirName::Mkdir() { - // wxWidgets recurses directory creation for us. +// wxWidgets recurses directory creation for us. - // only exist in wx2.9 and above +// only exist in wx2.9 and above #ifndef wxS_DIR_DEFAULT #define wxS_DIR_DEFAULT 0777 #endif - if( Exists() ) return true; - return wxFileName::Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); + if (Exists()) + return true; + return wxFileName::Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); } @@ -97,110 +99,111 @@ bool wxDirName::Mkdir() // --------------------------------------------------------------------------------- -bool Path::IsRelative( const wxString& path ) +bool Path::IsRelative(const wxString &path) { - return wxDirName( path ).IsRelative(); + return wxDirName(path).IsRelative(); } // Returns -1 if the file does not exist. -s64 Path::GetFileSize( const wxString& path ) +s64 Path::GetFileSize(const wxString &path) { - if( !wxFile::Exists( path.c_str() ) ) return -1; - return (s64)wxFileName::GetSize( path ).GetValue(); + if (!wxFile::Exists(path.c_str())) + return -1; + return (s64)wxFileName::GetSize(path).GetValue(); } -wxString Path::Normalize( const wxString& src ) +wxString Path::Normalize(const wxString &src) { - wxFileName normalize( src ); - normalize.Normalize(); - return normalize.GetFullPath(); + wxFileName normalize(src); + normalize.Normalize(); + return normalize.GetFullPath(); } -wxString Path::Normalize( const wxDirName& src ) +wxString Path::Normalize(const wxDirName &src) { - return wxDirName(src).Normalize().ToString(); + return wxDirName(src).Normalize().ToString(); } -wxString Path::MakeAbsolute( const wxString& src ) +wxString Path::MakeAbsolute(const wxString &src) { - wxFileName absolute( src ); - absolute.MakeAbsolute(); - return absolute.GetFullPath(); + wxFileName absolute(src); + absolute.MakeAbsolute(); + return absolute.GetFullPath(); } // Concatenates two pathnames together, inserting delimiters (backslash on win32) // as needed! Assumes the 'dest' is allocated to at least g_MaxPath length. // -wxString Path::Combine( const wxString& srcPath, const wxString& srcFile ) +wxString Path::Combine(const wxString &srcPath, const wxString &srcFile) { - return (wxDirName( srcPath ) + srcFile).GetFullPath(); + return (wxDirName(srcPath) + srcFile).GetFullPath(); } -wxString Path::Combine( const wxDirName& srcPath, const wxFileName& srcFile ) +wxString Path::Combine(const wxDirName &srcPath, const wxFileName &srcFile) { - return (srcPath + srcFile).GetFullPath(); + return (srcPath + srcFile).GetFullPath(); } -wxString Path::Combine( const wxString& srcPath, const wxDirName& srcFile ) +wxString Path::Combine(const wxString &srcPath, const wxDirName &srcFile) { - return (wxDirName( srcPath ) + srcFile).ToString(); + return (wxDirName(srcPath) + srcFile).ToString(); } // Replaces the extension of the file with the one given. // This function works for path names as well as file names. -wxString Path::ReplaceExtension( const wxString& src, const wxString& ext ) +wxString Path::ReplaceExtension(const wxString &src, const wxString &ext) { - wxFileName jojo( src ); - jojo.SetExt( ext ); - return jojo.GetFullPath(); + wxFileName jojo(src); + jojo.SetExt(ext); + return jojo.GetFullPath(); } -wxString Path::ReplaceFilename( const wxString& src, const wxString& newfilename ) +wxString Path::ReplaceFilename(const wxString &src, const wxString &newfilename) { - wxFileName jojo( src ); - jojo.SetFullName( newfilename ); - return jojo.GetFullPath(); + wxFileName jojo(src); + jojo.SetFullName(newfilename); + return jojo.GetFullPath(); } -wxString Path::GetFilename( const wxString& src ) +wxString Path::GetFilename(const wxString &src) { - return wxFileName(src).GetFullName(); + return wxFileName(src).GetFullName(); } -wxString Path::GetFilenameWithoutExt( const wxString& src ) +wxString Path::GetFilenameWithoutExt(const wxString &src) { - return wxFileName(src).GetName(); + return wxFileName(src).GetName(); } -wxString Path::GetDirectory( const wxString& src ) +wxString Path::GetDirectory(const wxString &src) { - return wxFileName(src).GetPath(); + return wxFileName(src).GetPath(); } // returns the base/root directory of the given path. // Example /this/that/something.txt -> dest == "/" -wxString Path::GetRootDirectory( const wxString& src ) +wxString Path::GetRootDirectory(const wxString &src) { - size_t pos = src.find_first_of( wxFileName::GetPathSeparators() ); - if( pos == wxString::npos ) - return wxString(); - else - return wxString( src.begin(), src.begin()+pos ); + size_t pos = src.find_first_of(wxFileName::GetPathSeparators()); + if (pos == wxString::npos) + return wxString(); + else + return wxString(src.begin(), src.begin() + pos); } // ------------------------------------------------------------------------ // Launches the specified file according to its mime type // -void pxLaunch( const wxString& filename ) +void pxLaunch(const wxString &filename) { - wxLaunchDefaultBrowser( filename ); + wxLaunchDefaultBrowser(filename); } void pxLaunch(const char *filename) { - pxLaunch( fromUTF8(filename) ); + pxLaunch(fromUTF8(filename)); } // ------------------------------------------------------------------------ @@ -209,12 +212,12 @@ void pxLaunch(const char *filename) // bypasses wxWidgets internal filename checking, which can end up launching things // through browser more often than desired. // -void pxExplore( const wxString& path ) +void pxExplore(const wxString &path) { - wxLaunchDefaultBrowser( !path.Contains( L"://") ? L"file://" + path : path ); + wxLaunchDefaultBrowser(!path.Contains(L"://") ? L"file://" + path : path); } void pxExplore(const char *path) { - pxExplore( fromUTF8(path) ); + pxExplore(fromUTF8(path)); } diff --git a/common/src/Utilities/Perf.cpp b/common/src/Utilities/Perf.cpp index ce6c284ca6..25027cfb64 100644 --- a/common/src/Utilities/Perf.cpp +++ b/common/src/Utilities/Perf.cpp @@ -23,118 +23,125 @@ namespace Perf { - // Warning object aren't thread safe - InfoVector any(""); - InfoVector ee("EE"); - InfoVector iop("IOP"); - InfoVector vu("VU"); +// Warning object aren't thread safe +InfoVector any(""); +InfoVector ee("EE"); +InfoVector iop("IOP"); +InfoVector vu("VU"); // Perf is only supported on linux #if defined(__linux__) && defined(ProfileWithPerf) - //////////////////////////////////////////////////////////////////////////////// - // Implementation of the Info object - //////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Implementation of the Info object +//////////////////////////////////////////////////////////////////////////////// - Info::Info(uptr x86, u32 size, const char* symbol) : m_x86(x86), m_size(size), m_dynamic(false) - { - strncpy(m_symbol, symbol, sizeof(m_symbol)); - } +Info::Info(uptr x86, u32 size, const char *symbol) + : m_x86(x86) + , m_size(size) + , m_dynamic(false) +{ + strncpy(m_symbol, symbol, sizeof(m_symbol)); +} - Info::Info(uptr x86, u32 size, const char* symbol, u32 pc) : m_x86(x86), m_size(size), m_dynamic(true) - { - snprintf(m_symbol, sizeof(m_symbol), "%s_0x%08x", symbol, pc); - } +Info::Info(uptr x86, u32 size, const char *symbol, u32 pc) + : m_x86(x86) + , m_size(size) + , m_dynamic(true) +{ + snprintf(m_symbol, sizeof(m_symbol), "%s_0x%08x", symbol, pc); +} - void Info::Print(FILE* fp) - { - fprintf(fp, "%x %x %s\n", m_x86, m_size, m_symbol); - } +void Info::Print(FILE *fp) +{ + fprintf(fp, "%x %x %s\n", m_x86, m_size, m_symbol); +} - //////////////////////////////////////////////////////////////////////////////// - // Implementation of the InfoVector object - //////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Implementation of the InfoVector object +//////////////////////////////////////////////////////////////////////////////// - InfoVector::InfoVector(const char* prefix) - { - strncpy(m_prefix, prefix, sizeof(m_prefix)); - } +InfoVector::InfoVector(const char *prefix) +{ + strncpy(m_prefix, prefix, sizeof(m_prefix)); +} - void InfoVector::print(FILE* fp) - { - for(auto&& it : m_v) it.Print(fp); - } +void InfoVector::print(FILE *fp) +{ + for (auto &&it : m_v) + it.Print(fp); +} - void InfoVector::map(uptr x86, u32 size, const char* symbol) - { - // This function is typically used for dispatcher and recompiler. - // Dispatchers are on a page and must always be kept. - // Recompilers are much bigger (TODO check VIF) and are only - // useful when MERGE_BLOCK_RESULT is defined +void InfoVector::map(uptr x86, u32 size, const char *symbol) +{ +// This function is typically used for dispatcher and recompiler. +// Dispatchers are on a page and must always be kept. +// Recompilers are much bigger (TODO check VIF) and are only +// useful when MERGE_BLOCK_RESULT is defined #ifdef MERGE_BLOCK_RESULT - m_v.emplace_back(x86, size, symbol); + m_v.emplace_back(x86, size, symbol); #else - if (size < 8 * _1kb) m_v.emplace_back(x86, size, symbol); + if (size < 8 * _1kb) + m_v.emplace_back(x86, size, symbol); +#endif +} + +void InfoVector::map(uptr x86, u32 size, u32 pc) +{ +#ifndef MERGE_BLOCK_RESULT + m_v.emplace_back(x86, size, m_prefix, pc); +#endif +} + +void InfoVector::reset() +{ + auto dynamic = std::remove_if(m_v.begin(), m_v.end(), [](Info i) { return i.m_dynamic; }); + m_v.erase(dynamic, m_v.end()); +} + +//////////////////////////////////////////////////////////////////////////////// +// Global function +//////////////////////////////////////////////////////////////////////////////// + +void dump() +{ + char file[256]; + snprintf(file, 250, "/tmp/perf-%d.map", getpid()); + FILE *fp = fopen(file, "w"); + + any.print(fp); + ee.print(fp); + iop.print(fp); + vu.print(fp); + + if (fp) + fclose(fp); +} + +void dump_and_reset() +{ + dump(); + + any.reset(); + ee.reset(); + iop.reset(); + vu.reset(); +} + +#else + +//////////////////////////////////////////////////////////////////////////////// +// Dummy implementation +//////////////////////////////////////////////////////////////////////////////// + +InfoVector::InfoVector(const char *prefix) {} +void InfoVector::map(uptr x86, u32 size, const char *symbol) {} +void InfoVector::map(uptr x86, u32 size, u32 pc) {} +void InfoVector::reset() {} + +void dump() {} +void dump_and_reset() {} + #endif - } - - void InfoVector::map(uptr x86, u32 size, u32 pc) - { -#ifndef MERGE_BLOCK_RESULT - m_v.emplace_back(x86, size, m_prefix, pc); -#endif - } - - void InfoVector::reset() - { - auto dynamic = std::remove_if(m_v.begin(), m_v.end(), [](Info i) { return i.m_dynamic; }); - m_v.erase(dynamic, m_v.end()); - } - - //////////////////////////////////////////////////////////////////////////////// - // Global function - //////////////////////////////////////////////////////////////////////////////// - - void dump() - { - char file[256]; - snprintf(file, 250, "/tmp/perf-%d.map", getpid()); - FILE* fp = fopen(file, "w"); - - any.print(fp); - ee.print(fp); - iop.print(fp); - vu.print(fp); - - if (fp) - fclose(fp); - } - - void dump_and_reset() - { - dump(); - - any.reset(); - ee.reset(); - iop.reset(); - vu.reset(); - } - -#else - - //////////////////////////////////////////////////////////////////////////////// - // Dummy implementation - //////////////////////////////////////////////////////////////////////////////// - - InfoVector::InfoVector(const char* prefix) {} - void InfoVector::map(uptr x86, u32 size, const char* symbol) {} - void InfoVector::map(uptr x86, u32 size, u32 pc) {} - void InfoVector::reset() {} - - void dump() {} - void dump_and_reset() {} - -#endif - } diff --git a/common/src/Utilities/PrecompiledHeader.h b/common/src/Utilities/PrecompiledHeader.h index b09fb3efd2..bcf1f64bb3 100644 --- a/common/src/Utilities/PrecompiledHeader.h +++ b/common/src/Utilities/PrecompiledHeader.h @@ -28,4 +28,3 @@ #include "General.h" #endif - diff --git a/common/src/Utilities/RwMutex.cpp b/common/src/Utilities/RwMutex.cpp index bab4f7ff03..2b191a881e 100644 --- a/common/src/Utilities/RwMutex.cpp +++ b/common/src/Utilities/RwMutex.cpp @@ -21,92 +21,95 @@ // -------------------------------------------------------------------------------------- Threading::RwMutex::RwMutex() { - pthread_rwlock_init( &m_rwlock, NULL ); + pthread_rwlock_init(&m_rwlock, NULL); } Threading::RwMutex::~RwMutex() throw() { - pthread_rwlock_destroy( &m_rwlock ); + pthread_rwlock_destroy(&m_rwlock); } void Threading::RwMutex::AcquireRead() { - pthread_rwlock_rdlock( &m_rwlock ); + pthread_rwlock_rdlock(&m_rwlock); } void Threading::RwMutex::AcquireWrite() { - pthread_rwlock_wrlock( &m_rwlock ); + pthread_rwlock_wrlock(&m_rwlock); } bool Threading::RwMutex::TryAcquireRead() { - return pthread_rwlock_tryrdlock( &m_rwlock ) != EBUSY; + return pthread_rwlock_tryrdlock(&m_rwlock) != EBUSY; } bool Threading::RwMutex::TryAcquireWrite() { - return pthread_rwlock_trywrlock( &m_rwlock ) != EBUSY; + return pthread_rwlock_trywrlock(&m_rwlock) != EBUSY; } void Threading::RwMutex::Release() { - pthread_rwlock_unlock( &m_rwlock ); + pthread_rwlock_unlock(&m_rwlock); } // -------------------------------------------------------------------------------------- -// +// // -------------------------------------------------------------------------------------- Threading::BaseScopedReadWriteLock::~BaseScopedReadWriteLock() throw() { - if( m_IsLocked ) - m_lock.Release(); + if (m_IsLocked) + m_lock.Release(); } // Provides manual unlocking of a scoped lock prior to object destruction. void Threading::BaseScopedReadWriteLock::Release() { - if( !m_IsLocked ) return; - m_IsLocked = false; - m_lock.Release(); + if (!m_IsLocked) + return; + m_IsLocked = false; + m_lock.Release(); } // -------------------------------------------------------------------------------------- // ScopedReadLock / ScopedWriteLock // -------------------------------------------------------------------------------------- -Threading::ScopedReadLock::ScopedReadLock( RwMutex& locker ) - : BaseScopedReadWriteLock( locker ) +Threading::ScopedReadLock::ScopedReadLock(RwMutex &locker) + : BaseScopedReadWriteLock(locker) { - m_IsLocked = true; - m_lock.AcquireRead(); + m_IsLocked = true; + m_lock.AcquireRead(); } // provides manual locking of a scoped lock, to re-lock after a manual unlocking. void Threading::ScopedReadLock::Acquire() { - if( m_IsLocked ) return; - m_lock.AcquireRead(); - m_IsLocked = true; + if (m_IsLocked) + return; + m_lock.AcquireRead(); + m_IsLocked = true; } -Threading::ScopedWriteLock::ScopedWriteLock( RwMutex& locker ) - : BaseScopedReadWriteLock( locker ) +Threading::ScopedWriteLock::ScopedWriteLock(RwMutex &locker) + : BaseScopedReadWriteLock(locker) { - m_IsLocked = true; - m_lock.AcquireWrite(); + m_IsLocked = true; + m_lock.AcquireWrite(); } // provides manual locking of a scoped lock, to re-lock after a manual unlocking. void Threading::ScopedWriteLock::Acquire() { - if( m_IsLocked ) return; - m_lock.AcquireWrite(); - m_IsLocked = true; + if (m_IsLocked) + return; + m_lock.AcquireWrite(); + m_IsLocked = true; } // Special constructor used by ScopedTryLock -Threading::ScopedWriteLock::ScopedWriteLock( RwMutex& locker, bool isTryLock ) - : BaseScopedReadWriteLock( locker ) +Threading::ScopedWriteLock::ScopedWriteLock(RwMutex &locker, bool isTryLock) + : BaseScopedReadWriteLock(locker) { - //m_IsLocked = isTryLock ? m_lock.TryAcquireWrite() : false; + //m_IsLocked = isTryLock ? m_lock.TryAcquireWrite() : false; } diff --git a/common/src/Utilities/Semaphore.cpp b/common/src/Utilities/Semaphore.cpp index a10ad4a9ab..75a95cbc2b 100644 --- a/common/src/Utilities/Semaphore.cpp +++ b/common/src/Utilities/Semaphore.cpp @@ -27,50 +27,49 @@ Threading::Semaphore::Semaphore() { - sem_init( &m_sema, false, 0 ); + sem_init(&m_sema, false, 0); } Threading::Semaphore::~Semaphore() throw() { - sem_destroy( &m_sema ); + sem_destroy(&m_sema); } void Threading::Semaphore::Reset() { - sem_destroy( &m_sema ); - sem_init( &m_sema, false, 0 ); + sem_destroy(&m_sema); + sem_init(&m_sema, false, 0); } void Threading::Semaphore::Post() { - sem_post( &m_sema ); + sem_post(&m_sema); } -void Threading::Semaphore::Post( int multiple ) +void Threading::Semaphore::Post(int multiple) { #if defined(_MSC_VER) - sem_post_multiple( &m_sema, multiple ); + sem_post_multiple(&m_sema, multiple); #else - // Only w32pthreads has the post_multiple, but it's easy enough to fake: - while( multiple > 0 ) - { - multiple--; - sem_post( &m_sema ); - } + // Only w32pthreads has the post_multiple, but it's easy enough to fake: + while (multiple > 0) { + multiple--; + sem_post(&m_sema); + } #endif } void Threading::Semaphore::WaitWithoutYield() { - pxAssertMsg( !wxThread::IsMain(), "Unyielding semaphore wait issued from the main/gui thread. Please use Wait() instead." ); - sem_wait( &m_sema ); + pxAssertMsg(!wxThread::IsMain(), "Unyielding semaphore wait issued from the main/gui thread. Please use Wait() instead."); + sem_wait(&m_sema); } -bool Threading::Semaphore::WaitWithoutYield( const wxTimeSpan& timeout ) +bool Threading::Semaphore::WaitWithoutYield(const wxTimeSpan &timeout) { - wxDateTime megafail( wxDateTime::UNow() + timeout ); - const timespec fail = { megafail.GetTicks(), megafail.GetMillisecond() * 1000000 }; - return sem_timedwait( &m_sema, &fail ) == 0; + wxDateTime megafail(wxDateTime::UNow() + timeout); + const timespec fail = {megafail.GetTicks(), megafail.GetMillisecond() * 1000000}; + return sem_timedwait(&m_sema, &fail) == 0; } @@ -82,23 +81,18 @@ bool Threading::Semaphore::WaitWithoutYield( const wxTimeSpan& timeout ) void Threading::Semaphore::Wait() { #if wxUSE_GUI - if( !wxThread::IsMain() || (wxTheApp == NULL) ) - { - sem_wait( &m_sema ); - } - else if( _WaitGui_RecursionGuard( L"Semaphore::Wait" ) ) - { - ScopedBusyCursor hourglass( Cursor_ReallyBusy ); - sem_wait( &m_sema ); - } - else - { - //ScopedBusyCursor hourglass( Cursor_KindaBusy ); - while( !WaitWithoutYield( def_yieldgui_interval ) ) - YieldToMain(); - } + if (!wxThread::IsMain() || (wxTheApp == NULL)) { + sem_wait(&m_sema); + } else if (_WaitGui_RecursionGuard(L"Semaphore::Wait")) { + ScopedBusyCursor hourglass(Cursor_ReallyBusy); + sem_wait(&m_sema); + } else { + //ScopedBusyCursor hourglass( Cursor_KindaBusy ); + while (!WaitWithoutYield(def_yieldgui_interval)) + YieldToMain(); + } #else - sem_wait( &m_sema ); + sem_wait(&m_sema); #endif } @@ -111,33 +105,29 @@ void Threading::Semaphore::Wait() // false if the wait timed out before the semaphore was signaled, or true if the signal was // reached prior to timeout. // -bool Threading::Semaphore::Wait( const wxTimeSpan& timeout ) +bool Threading::Semaphore::Wait(const wxTimeSpan &timeout) { #if wxUSE_GUI - if( !wxThread::IsMain() || (wxTheApp == NULL) ) - { - return WaitWithoutYield( timeout ); - } - else if( _WaitGui_RecursionGuard( L"Semaphore::TimedWait" ) ) - { - ScopedBusyCursor hourglass( Cursor_ReallyBusy ); - return WaitWithoutYield( timeout ); - } - else - { - //ScopedBusyCursor hourglass( Cursor_KindaBusy ); - wxTimeSpan countdown( (timeout) ); + if (!wxThread::IsMain() || (wxTheApp == NULL)) { + return WaitWithoutYield(timeout); + } else if (_WaitGui_RecursionGuard(L"Semaphore::TimedWait")) { + ScopedBusyCursor hourglass(Cursor_ReallyBusy); + return WaitWithoutYield(timeout); + } else { + //ScopedBusyCursor hourglass( Cursor_KindaBusy ); + wxTimeSpan countdown((timeout)); - do { - if( WaitWithoutYield( def_yieldgui_interval ) ) break; - YieldToMain(); - countdown -= def_yieldgui_interval; - } while( countdown.GetMilliseconds() > 0 ); + do { + if (WaitWithoutYield(def_yieldgui_interval)) + break; + YieldToMain(); + countdown -= def_yieldgui_interval; + } while (countdown.GetMilliseconds() > 0); - return countdown.GetMilliseconds() > 0; - } + return countdown.GetMilliseconds() > 0; + } #else - return WaitWithoutYield( timeout ); + return WaitWithoutYield(timeout); #endif } @@ -151,25 +141,25 @@ bool Threading::Semaphore::Wait( const wxTimeSpan& timeout ) // to do a lot of no-cancel waits in a tight loop worker thread, for example. void Threading::Semaphore::WaitNoCancel() { - int oldstate; - pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldstate ); - //WaitWithoutYield(); - Wait(); - pthread_setcancelstate( oldstate, NULL ); + int oldstate; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); + //WaitWithoutYield(); + Wait(); + pthread_setcancelstate(oldstate, NULL); } -void Threading::Semaphore::WaitNoCancel( const wxTimeSpan& timeout ) +void Threading::Semaphore::WaitNoCancel(const wxTimeSpan &timeout) { - int oldstate; - pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldstate ); - //WaitWithoutYield( timeout ); - Wait( timeout ); - pthread_setcancelstate( oldstate, NULL ); + int oldstate; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); + //WaitWithoutYield( timeout ); + Wait(timeout); + pthread_setcancelstate(oldstate, NULL); } int Threading::Semaphore::Count() { - int retval; - sem_getvalue( &m_sema, &retval ); - return retval; + int retval; + sem_getvalue(&m_sema, &retval); + return retval; } diff --git a/common/src/Utilities/StringHelpers.cpp b/common/src/Utilities/StringHelpers.cpp index 6b2e749023..0b2af8b08e 100644 --- a/common/src/Utilities/StringHelpers.cpp +++ b/common/src/Utilities/StringHelpers.cpp @@ -14,61 +14,61 @@ */ #include "PrecompiledHeader.h" -#include // for wxPoint/wxRect stuff +#include // for wxPoint/wxRect stuff -__fi wxString fromUTF8( const char* src ) +__fi wxString fromUTF8(const char *src) { - // IMPORTANT: We cannot use wxString::FromUTF8 because it *stupidly* relies on a C++ global instance of - // wxMBConvUTF8(). C++ initializes and destroys these globals at random, so any object constructor or - // destructor that attempts to do logging may crash the app (either during startup or during exit) unless - // we use a LOCAL instance of wxMBConvUTF8(). --air + // IMPORTANT: We cannot use wxString::FromUTF8 because it *stupidly* relies on a C++ global instance of + // wxMBConvUTF8(). C++ initializes and destroys these globals at random, so any object constructor or + // destructor that attempts to do logging may crash the app (either during startup or during exit) unless + // we use a LOCAL instance of wxMBConvUTF8(). --air - // Performance? No worries. wxMBConvUTF8() is virtually free. Initializing a stack copy of the class - // is just as efficient as passing a pointer to a pre-instanced global. (which makes me wonder wh wxWidgets - // uses the stupid globals in the first place!) --air + // Performance? No worries. wxMBConvUTF8() is virtually free. Initializing a stack copy of the class + // is just as efficient as passing a pointer to a pre-instanced global. (which makes me wonder wh wxWidgets + // uses the stupid globals in the first place!) --air - return wxString( src, wxMBConvUTF8() ); + return wxString(src, wxMBConvUTF8()); } -__fi wxString fromAscii( const char* src ) +__fi wxString fromAscii(const char *src) { - return wxString::FromAscii( src ); + return wxString::FromAscii(src); } wxString u128::ToString() const { - return pxsFmt( L"0x%08X.%08X.%08X.%08X", _u32[0], _u32[1], _u32[2], _u32[3] ); + return pxsFmt(L"0x%08X.%08X.%08X.%08X", _u32[0], _u32[1], _u32[2], _u32[3]); } wxString u128::ToString64() const { - return pxsFmt( L"0x%08X%08X.%08X%08X", _u32[0], _u32[1], _u32[2], _u32[3] ); + return pxsFmt(L"0x%08X%08X.%08X%08X", _u32[0], _u32[1], _u32[2], _u32[3]); } wxString u128::ToString8() const { - FastFormatUnicode result; - result.Write( L"0x%02X.%02X", _u8[0], _u8[1] ); - for (uint i=2; i<16; i+=2) - result.Write( L".%02X.%02X", _u8[i], _u8[i+1] ); - return result; + FastFormatUnicode result; + result.Write(L"0x%02X.%02X", _u8[0], _u8[1]); + for (uint i = 2; i < 16; i += 2) + result.Write(L".%02X.%02X", _u8[i], _u8[i + 1]); + return result; } -void u128::WriteTo( FastFormatAscii& dest ) const +void u128::WriteTo(FastFormatAscii &dest) const { - dest.Write( "0x%08X.%08X.%08X.%08X", _u32[0], _u32[1], _u32[2], _u32[3] ); + dest.Write("0x%08X.%08X.%08X.%08X", _u32[0], _u32[1], _u32[2], _u32[3]); } -void u128::WriteTo64( FastFormatAscii& dest ) const +void u128::WriteTo64(FastFormatAscii &dest) const { - dest.Write( "0x%08X%08X.%08X%08X", _u32[0], _u32[1], _u32[2], _u32[3] ); + dest.Write("0x%08X%08X.%08X%08X", _u32[0], _u32[1], _u32[2], _u32[3]); } -void u128::WriteTo8( FastFormatAscii& dest ) const +void u128::WriteTo8(FastFormatAscii &dest) const { - dest.Write( "0x%02X.%02X", _u8[0], _u8[1] ); - for (uint i=2; i<16; i+=2) - dest.Write( ".%02X.%02X", _u8[i], _u8[i+1] ); + dest.Write("0x%02X.%02X", _u8[0], _u8[1]); + for (uint i = 2; i < 16; i += 2) + dest.Write(".%02X.%02X", _u8[i], _u8[i + 1]); } // Splits a string into parts and adds the parts into the given SafeList. @@ -77,11 +77,11 @@ void u128::WriteTo8( FastFormatAscii& dest ) const // // Note: wxWidgets 2.9 / 3.0 has a wxSplit function, but we're using 2.8 so I had to make // my own. -void SplitString( wxArrayString& dest, const wxString& src, const wxString& delims, wxStringTokenizerMode mode ) +void SplitString(wxArrayString &dest, const wxString &src, const wxString &delims, wxStringTokenizerMode mode) { - wxStringTokenizer parts( src, delims, mode ); - while( parts.HasMoreTokens() ) - dest.Add( parts.GetNextToken() ); + wxStringTokenizer parts(src, delims, mode); + while (parts.HasMoreTokens()) + dest.Add(parts.GetNextToken()); } // Joins a list of strings into one larger string, using the given string concatenation @@ -90,32 +90,32 @@ void SplitString( wxArrayString& dest, const wxString& src, const wxString& deli // // Note: wxWidgets 2.9 / 3.0 has a wxJoin function, but we're using 2.8 so I had to make // my own. -wxString JoinString( const wxArrayString& src, const wxString& separator ) +wxString JoinString(const wxArrayString &src, const wxString &separator) { - wxString dest; - for( int i=0, len=src.GetCount(); i -T Parse( const wxString& src, const wxString& separators=L",") +template +T Parse(const wxString &src, const wxString &separators = L",") { - T retval; - if( !TryParse( retval, src, separators ) ) - throw Exception::ParseError( "Parse failure on call to " + fromUTF8(__WXFUNCTION__) + ": " + src ); - return retval; + T retval; + if (!TryParse(retval, src, separators)) + throw Exception::ParseError("Parse failure on call to " + fromUTF8(__WXFUNCTION__) + ": " + src); + return retval; } @@ -140,98 +140,104 @@ T Parse( const wxString& src, const wxString& separators=L",") // -------------------------------------------------------------------------------------- // Converts a wxPoint into a comma-delimited string! -wxString ToString( const wxPoint& src, const wxString& separator ) +wxString ToString(const wxPoint &src, const wxString &separator) { - return wxString() << src.x << separator << src.y; + return wxString() << src.x << separator << src.y; } -wxString ToString( const wxSize& src, const wxString& separator ) +wxString ToString(const wxSize &src, const wxString &separator) { - return wxString() << src.GetWidth() << separator << src.GetHeight(); + return wxString() << src.GetWidth() << separator << src.GetHeight(); } // Converts a wxRect into a comma-delimited string! // Example: 32,64,128,5 -wxString ToString( const wxRect& src, const wxString& separator ) +wxString ToString(const wxRect &src, const wxString &separator) { - return ToString( src.GetLeftTop(), separator ) << separator << ToString( src.GetSize(), separator ); + return ToString(src.GetLeftTop(), separator) << separator << ToString(src.GetSize(), separator); } // -------------------------------------------------------------------------------------- // Parse helpers for wxString! // -------------------------------------------------------------------------------------- -bool TryParse( wxPoint& dest, wxStringTokenizer& parts ) +bool TryParse(wxPoint &dest, wxStringTokenizer &parts) { - long result[2]; + long result[2]; - if( !parts.HasMoreTokens() || !parts.GetNextToken().ToLong( &result[0] ) ) return false; - if( !parts.HasMoreTokens() || !parts.GetNextToken().ToLong( &result[1] ) ) return false; - dest.x = result[0]; - dest.y = result[1]; + if (!parts.HasMoreTokens() || !parts.GetNextToken().ToLong(&result[0])) + return false; + if (!parts.HasMoreTokens() || !parts.GetNextToken().ToLong(&result[1])) + return false; + dest.x = result[0]; + dest.y = result[1]; - return true; + return true; } -bool TryParse( wxSize& dest, wxStringTokenizer& parts ) +bool TryParse(wxSize &dest, wxStringTokenizer &parts) { - long result[2]; + long result[2]; - if( !parts.HasMoreTokens() || !parts.GetNextToken().ToLong( &result[0] ) ) return false; - if( !parts.HasMoreTokens() || !parts.GetNextToken().ToLong( &result[1] ) ) return false; - dest.SetWidth( result[0] ); - dest.SetHeight( result[1] ); + if (!parts.HasMoreTokens() || !parts.GetNextToken().ToLong(&result[0])) + return false; + if (!parts.HasMoreTokens() || !parts.GetNextToken().ToLong(&result[1])) + return false; + dest.SetWidth(result[0]); + dest.SetHeight(result[1]); - return true; + return true; } // Tries to parse the given string into a wxPoint value at 'dest.' If the parse fails, the // method aborts and returns false. -bool TryParse( wxPoint& dest, const wxString& src, const wxPoint& defval, const wxString& separators ) +bool TryParse(wxPoint &dest, const wxString &src, const wxPoint &defval, const wxString &separators) { - dest = defval; - wxStringTokenizer parts( src, separators ); - return TryParse( dest, parts ); + dest = defval; + wxStringTokenizer parts(src, separators); + return TryParse(dest, parts); } -bool TryParse( wxSize& dest, const wxString& src, const wxSize& defval, const wxString& separators ) +bool TryParse(wxSize &dest, const wxString &src, const wxSize &defval, const wxString &separators) { - dest = defval; - wxStringTokenizer parts( src, separators ); - return TryParse( dest, parts ); + dest = defval; + wxStringTokenizer parts(src, separators); + return TryParse(dest, parts); } -bool TryParse( wxRect& dest, const wxString& src, const wxRect& defval, const wxString& separators ) +bool TryParse(wxRect &dest, const wxString &src, const wxRect &defval, const wxString &separators) { - dest = defval; + dest = defval; - wxStringTokenizer parts( src, separators ); + wxStringTokenizer parts(src, separators); - wxPoint point; - wxSize size; + wxPoint point; + wxSize size; - if( !TryParse( point, parts ) ) return false; - if( !TryParse( size, parts ) ) return false; + if (!TryParse(point, parts)) + return false; + if (!TryParse(size, parts)) + return false; - dest = wxRect( point, size ); - return true; + dest = wxRect(point, size); + return true; } // returns TRUE if the parse is valid, or FALSE if it's a comment. -bool pxParseAssignmentString( const wxString& src, wxString& ldest, wxString& rdest ) +bool pxParseAssignmentString(const wxString &src, wxString &ldest, wxString &rdest) { - if( src.StartsWith(L"--") || src.StartsWith( L"//" ) || src.StartsWith( L";" ) ) - return false; + if (src.StartsWith(L"--") || src.StartsWith(L"//") || src.StartsWith(L";")) + return false; - ldest = src.BeforeFirst(L'=').Trim(true).Trim(false); - rdest = src.AfterFirst(L'=').Trim(true).Trim(false); - - return true; + ldest = src.BeforeFirst(L'=').Trim(true).Trim(false); + rdest = src.AfterFirst(L'=').Trim(true).Trim(false); + + return true; } -ParsedAssignmentString::ParsedAssignmentString( const wxString& src ) +ParsedAssignmentString::ParsedAssignmentString(const wxString &src) { - IsComment = pxParseAssignmentString( src, lvalue, rvalue ); + IsComment = pxParseAssignmentString(src, lvalue, rvalue); } // Performs a cross-platform puts operation, which adds CRs to naked LFs on Win32 platforms, @@ -242,40 +248,37 @@ ParsedAssignmentString::ParsedAssignmentString( const wxString& src ) // from incoming data. Mac platforms may need an implementation of their own that converts // newlines to CRs...? // -void px_fputs( FILE* fp, const char* src ) +void px_fputs(FILE *fp, const char *src) { - if( fp == NULL ) return; + if (fp == NULL) + return; #ifdef _WIN32 - // Windows needs CR's partnered with all newlines, or else notepad.exe can't view - // the stupid logfile. Best way is to write one char at a time.. >_< + // Windows needs CR's partnered with all newlines, or else notepad.exe can't view + // the stupid logfile. Best way is to write one char at a time.. >_< - const char* curchar = src; - bool prevcr = false; - while( *curchar != 0 ) - { - if( *curchar == '\r' ) - { - prevcr = true; - } - else - { - // Only write a CR/LF pair if the current LF is not prefixed nor - // post-fixed by a CR. - if( *curchar == '\n' && !prevcr && (*(curchar+1) != '\r') ) - fputs( "\r\n", fp ); - else - fputc( *curchar, fp ); + const char *curchar = src; + bool prevcr = false; + while (*curchar != 0) { + if (*curchar == '\r') { + prevcr = true; + } else { + // Only write a CR/LF pair if the current LF is not prefixed nor + // post-fixed by a CR. + if (*curchar == '\n' && !prevcr && (*(curchar + 1) != '\r')) + fputs("\r\n", fp); + else + fputc(*curchar, fp); - prevcr = false; - } - ++curchar; - } + prevcr = false; + } + ++curchar; + } #else - // Linux is happy with plain old LFs. Not sure about Macs... does OSX still - // go by the old school Mac style of using Crs only? + // Linux is happy with plain old LFs. Not sure about Macs... does OSX still + // go by the old school Mac style of using Crs only? - fputs( src, fp ); // fputs does not do automatic newlines, so it's ok! + fputs(src, fp); // fputs does not do automatic newlines, so it's ok! #endif } diff --git a/common/src/Utilities/ThreadTools.cpp b/common/src/Utilities/ThreadTools.cpp index f2aa848d93..129c4f7acd 100644 --- a/common/src/Utilities/ThreadTools.cpp +++ b/common/src/Utilities/ThreadTools.cpp @@ -17,7 +17,7 @@ #include "PrecompiledHeader.h" #ifdef __linux__ -# include // for pthread_kill, which is in pthread.h on w32-pthreads +#include // for pthread_kill, which is in pthread.h on w32-pthreads #endif #include "PersistentThread.h" @@ -27,21 +27,20 @@ using namespace Threading; -template class EventSource< EventListener_Thread >; +template class EventSource; // 100ms interval for waitgui (issued from blocking semaphore waits on the main thread, // to avoid gui deadlock). -const wxTimeSpan Threading::def_yieldgui_interval( 0, 0, 0, 100 ); +const wxTimeSpan Threading::def_yieldgui_interval(0, 0, 0, 100); ConsoleLogSource_Threading::ConsoleLogSource_Threading() { - static const TraceLogDescriptor myDesc = - { - L"p&xThread", L"pxThread", - pxLt("Threading activity: start, detach, sync, deletion, etc.") - }; + static const TraceLogDescriptor myDesc = + { + L"p&xThread", L"pxThread", + pxLt("Threading activity: start, detach, sync, deletion, etc.")}; - m_Descriptor = &myDesc; + m_Descriptor = &myDesc; } ConsoleLogSource_Threading pxConLog_Thread; @@ -50,133 +49,131 @@ ConsoleLogSource_Threading pxConLog_Thread; class StaticMutex : public Mutex { protected: - bool& m_DeletedFlag; + bool &m_DeletedFlag; public: - StaticMutex( bool& deletedFlag ) - : m_DeletedFlag( deletedFlag ) - { - } + StaticMutex(bool &deletedFlag) + : m_DeletedFlag(deletedFlag) + { + } - virtual ~StaticMutex() throw() - { - m_DeletedFlag = true; - } + virtual ~StaticMutex() throw() + { + m_DeletedFlag = true; + } }; -static pthread_key_t curthread_key = 0; -static s32 total_key_count = 0; +static pthread_key_t curthread_key = 0; +static s32 total_key_count = 0; -static bool tkl_destructed = false; -static StaticMutex total_key_lock( tkl_destructed ); +static bool tkl_destructed = false; +static StaticMutex total_key_lock(tkl_destructed); -static void make_curthread_key( const pxThread* thr ) +static void make_curthread_key(const pxThread *thr) { - pxAssumeDev( !tkl_destructed, "total_key_lock is destroyed; program is shutting down; cannot create new thread key." ); + pxAssumeDev(!tkl_destructed, "total_key_lock is destroyed; program is shutting down; cannot create new thread key."); - ScopedLock lock( total_key_lock ); - if( total_key_count++ != 0 ) return; + ScopedLock lock(total_key_lock); + if (total_key_count++ != 0) + return; - if( 0 != pthread_key_create(&curthread_key, NULL) ) - { - pxThreadLog.Error( thr->GetName(), L"Thread key creation failed (probably out of memory >_<)" ); - curthread_key = 0; - } + if (0 != pthread_key_create(&curthread_key, NULL)) { + pxThreadLog.Error(thr->GetName(), L"Thread key creation failed (probably out of memory >_<)"); + curthread_key = 0; + } } static void unmake_curthread_key() { - ScopedLock lock; - if( !tkl_destructed ) - lock.AssignAndLock( total_key_lock ); + ScopedLock lock; + if (!tkl_destructed) + lock.AssignAndLock(total_key_lock); - if( --total_key_count > 0 ) return; + if (--total_key_count > 0) + return; - if( curthread_key ) - pthread_key_delete( curthread_key ); + if (curthread_key) + pthread_key_delete(curthread_key); - curthread_key = 0; + curthread_key = 0; } void Threading::pxTestCancel() { - pthread_testcancel(); + pthread_testcancel(); } // Returns a handle to the current persistent thread. If the current thread does not belong // to the pxThread table, NULL is returned. Since the main/ui thread is not created // through pxThread it will also return NULL. Callers can use wxThread::IsMain() to // test if the NULL thread is the main thread. -pxThread* Threading::pxGetCurrentThread() +pxThread *Threading::pxGetCurrentThread() { - return !curthread_key ? NULL : (pxThread*)pthread_getspecific( curthread_key ); + return !curthread_key ? NULL : (pxThread *)pthread_getspecific(curthread_key); } // returns the name of the current thread, or "Unknown" if the thread is neither a pxThread // nor the Main/UI thread. wxString Threading::pxGetCurrentThreadName() { - if( pxThread* thr = pxGetCurrentThread() ) - { - return thr->GetName(); - } - else if( wxThread::IsMain() ) - { - return L"Main/UI"; - } + if (pxThread *thr = pxGetCurrentThread()) { + return thr->GetName(); + } else if (wxThread::IsMain()) { + return L"Main/UI"; + } - return L"Unknown"; + return L"Unknown"; } -void Threading::pxYield( int ms ) +void Threading::pxYield(int ms) { - if( pxThread* thr = pxGetCurrentThread() ) - thr->Yield( ms ); - else - Sleep( ms ); + if (pxThread *thr = pxGetCurrentThread()) + thr->Yield(ms); + else + Sleep(ms); } // (intended for internal use only) // Returns true if the Wait is recursive, or false if the Wait is safe and should be // handled via normal yielding methods. -bool Threading::_WaitGui_RecursionGuard( const wxChar* name ) +bool Threading::_WaitGui_RecursionGuard(const wxChar *name) { - AffinityAssert_AllowFrom_MainUI(); - - // In order to avoid deadlock we need to make sure we cut some time to handle messages. - // But this can result in recursive yield calls, which would crash the app. Protect - // against them here and, if recursion is detected, perform a standard blocking wait. + AffinityAssert_AllowFrom_MainUI(); - static int __Guard = 0; - RecursionGuard guard( __Guard ); + // In order to avoid deadlock we need to make sure we cut some time to handle messages. + // But this can result in recursive yield calls, which would crash the app. Protect + // against them here and, if recursion is detected, perform a standard blocking wait. - //if( pxAssertDev( !guard.IsReentrant(), "Recursion during UI-bound threading wait object." ) ) return false; + static int __Guard = 0; + RecursionGuard guard(__Guard); - if( !guard.IsReentrant() ) return false; - pxThreadLog.Write( pxGetCurrentThreadName(), - pxsFmt(L"Yield recursion in %s; opening modal dialog.", name) - ); - return true; + //if( pxAssertDev( !guard.IsReentrant(), "Recursion during UI-bound threading wait object." ) ) return false; + + if (!guard.IsReentrant()) + return false; + pxThreadLog.Write(pxGetCurrentThreadName(), + pxsFmt(L"Yield recursion in %s; opening modal dialog.", name)); + return true; } __fi void Threading::Timeslice() { - sched_yield(); + sched_yield(); } -void Threading::pxThread::_pt_callback_cleanup( void* handle ) +void Threading::pxThread::_pt_callback_cleanup(void *handle) { - ((pxThread*)handle)->_ThreadCleanup(); + ((pxThread *)handle)->_ThreadCleanup(); } -Threading::pxThread::pxThread( const wxString& name ) - : m_name( name ) - , m_thread() - , m_native_id(0) - , m_native_handle(0) - , m_detached(true) // start out with m_thread in detached/invalid state - , m_running(false) +Threading::pxThread::pxThread(const wxString &name) + : m_name(name) + , m_thread() + , m_native_id(0) + , m_native_handle(0) + , m_detached(true) // start out with m_thread in detached/invalid state + , m_running(false) { } @@ -189,51 +186,50 @@ Threading::pxThread::pxThread( const wxString& name ) // like marrying your sister, and then cheating on her with your daughter. Threading::pxThread::~pxThread() throw() { - try - { - pxThreadLog.Write( GetName(), L"Executing default destructor!" ); + try { + pxThreadLog.Write(GetName(), L"Executing default destructor!"); - if( m_running ) - { - pxThreadLog.Write( GetName(), L"Waiting for running thread to end..."); - m_mtx_InThread.Wait(); - pxThreadLog.Write( GetName(), L"Thread ended gracefully."); - } - Threading::Sleep( 1 ); - Detach(); - } - DESTRUCTOR_CATCHALL + if (m_running) { + pxThreadLog.Write(GetName(), L"Waiting for running thread to end..."); + m_mtx_InThread.Wait(); + pxThreadLog.Write(GetName(), L"Thread ended gracefully."); + } + Threading::Sleep(1); + Detach(); + } + DESTRUCTOR_CATCHALL } -bool Threading::pxThread::AffinityAssert_AllowFromSelf( const DiagnosticOrigin& origin ) const +bool Threading::pxThread::AffinityAssert_AllowFromSelf(const DiagnosticOrigin &origin) const { - if( IsSelf() ) return true; + if (IsSelf()) + return true; - if( IsDevBuild ) - pxOnAssert( origin, pxsFmt( L"Thread affinity violation: Call allowed from '%s' thread only.", WX_STR(GetName()) ) ); + if (IsDevBuild) + pxOnAssert(origin, pxsFmt(L"Thread affinity violation: Call allowed from '%s' thread only.", WX_STR(GetName()))); - return false; + return false; } -bool Threading::pxThread::AffinityAssert_DisallowFromSelf( const DiagnosticOrigin& origin ) const +bool Threading::pxThread::AffinityAssert_DisallowFromSelf(const DiagnosticOrigin &origin) const { - if( !IsSelf() ) return true; + if (!IsSelf()) + return true; - if( IsDevBuild ) - pxOnAssert( origin, pxsFmt( L"Thread affinity violation: Call is *not* allowed from '%s' thread.", WX_STR(GetName()) ) ); + if (IsDevBuild) + pxOnAssert(origin, pxsFmt(L"Thread affinity violation: Call is *not* allowed from '%s' thread.", WX_STR(GetName()))); - return false; + return false; } -void Threading::pxThread::FrankenMutex( Mutex& mutex ) +void Threading::pxThread::FrankenMutex(Mutex &mutex) { - if( mutex.RecreateIfLocked() ) - { - // Our lock is bupkis, which means the previous thread probably deadlocked. - // Let's create a new mutex lock to replace it. + if (mutex.RecreateIfLocked()) { + // Our lock is bupkis, which means the previous thread probably deadlocked. + // Let's create a new mutex lock to replace it. - pxThreadLog.Error( GetName(), L"Possible deadlock detected on restarted mutex!" ); - } + pxThreadLog.Error(GetName(), L"Possible deadlock detected on restarted mutex!"); + } } // Main entry point for starting or e-starting a persistent thread. This function performs necessary @@ -244,44 +240,42 @@ void Threading::pxThread::FrankenMutex( Mutex& mutex ) // This function should not be called from the owner thread. void Threading::pxThread::Start() { - // Prevents sudden parallel startup, and or parallel startup + cancel: - ScopedLock startlock( m_mtx_start ); - if( m_running ) - { - pxThreadLog.Write(GetName(), L"Start() called on running thread; ignorning..."); - return; - } + // Prevents sudden parallel startup, and or parallel startup + cancel: + ScopedLock startlock(m_mtx_start); + if (m_running) { + pxThreadLog.Write(GetName(), L"Start() called on running thread; ignorning..."); + return; + } - Detach(); // clean up previous thread handle, if one exists. - OnStart(); + Detach(); // clean up previous thread handle, if one exists. + OnStart(); - m_except = NULL; + m_except = NULL; - pxThreadLog.Write(GetName(), L"Calling pthread_create..."); - if( pthread_create( &m_thread, NULL, _internal_callback, this ) != 0 ) - throw Exception::ThreadCreationError( this ).SetDiagMsg( L"Thread creation error: " + wxString(std::strerror(errno)) ); + pxThreadLog.Write(GetName(), L"Calling pthread_create..."); + if (pthread_create(&m_thread, NULL, _internal_callback, this) != 0) + throw Exception::ThreadCreationError(this).SetDiagMsg(L"Thread creation error: " + wxString(std::strerror(errno))); - if( !m_sem_startup.WaitWithoutYield( wxTimeSpan( 0, 0, 3, 0 ) ) ) - { - RethrowException(); + if (!m_sem_startup.WaitWithoutYield(wxTimeSpan(0, 0, 3, 0))) { + RethrowException(); - // And if the thread threw nothing of its own: - throw Exception::ThreadCreationError( this ).SetDiagMsg( L"Thread creation error: %s thread never posted startup semaphore." ); - } + // And if the thread threw nothing of its own: + throw Exception::ThreadCreationError(this).SetDiagMsg(L"Thread creation error: %s thread never posted startup semaphore."); + } - // Event Rationale (above): Performing this semaphore wait on the created thread is "slow" in the - // sense that it stalls the calling thread completely until the new thread is created - // (which may not always be desirable). But too bad. In order to safely use 'running' locks - // and detachment management, this *has* to be done. By rule, starting new threads shouldn't - // be done very often anyway, hence the concept of Threadpooling for rapidly rotating tasks. - // (and indeed, this semaphore wait might, in fact, be very swift compared to other kernel - // overhead in starting threads). + // Event Rationale (above): Performing this semaphore wait on the created thread is "slow" in the + // sense that it stalls the calling thread completely until the new thread is created + // (which may not always be desirable). But too bad. In order to safely use 'running' locks + // and detachment management, this *has* to be done. By rule, starting new threads shouldn't + // be done very often anyway, hence the concept of Threadpooling for rapidly rotating tasks. + // (and indeed, this semaphore wait might, in fact, be very swift compared to other kernel + // overhead in starting threads). - // (this could also be done using operating system specific calls, since any threaded OS has - // functions that allow us to see if a thread is running or not, and to block against it even if - // it's been detached -- removing the need for m_mtx_InThread and the semaphore wait above. But - // pthreads kinda lacks that stuff, since pthread_join() has no timeout option making it im- - // possible to safely block against a running thread) + // (this could also be done using operating system specific calls, since any threaded OS has + // functions that allow us to see if a thread is running or not, and to block against it even if + // it's been detached -- removing the need for m_mtx_InThread and the semaphore wait above. But + // pthreads kinda lacks that stuff, since pthread_join() has no timeout option making it im- + // possible to safely block against a running thread) } // Returns: TRUE if the detachment was performed, or FALSE if the thread was @@ -289,25 +283,26 @@ void Threading::pxThread::Start() // This function should not be called from the owner thread. bool Threading::pxThread::Detach() { - AffinityAssert_DisallowFromSelf(pxDiagSpot); + AffinityAssert_DisallowFromSelf(pxDiagSpot); - if( m_detached.exchange(true) ) return false; - pthread_detach( m_thread ); - return true; + if (m_detached.exchange(true)) + return false; + pthread_detach(m_thread); + return true; } bool Threading::pxThread::_basecancel() { - if( !m_running ) return false; + if (!m_running) + return false; - if( m_detached ) - { - pxThreadLog.Warn(GetName(), L"Ignoring attempted cancellation of detached thread."); - return false; - } + if (m_detached) { + pxThreadLog.Warn(GetName(), L"Ignoring attempted cancellation of detached thread."); + return false; + } - pthread_cancel( m_thread ); - return true; + pthread_cancel(m_thread); + return true; } // Remarks: @@ -324,34 +319,36 @@ bool Threading::pxThread::_basecancel() // Exceptions raised by the blocking thread will be re-thrown into the main thread. If isBlocking // is false then no exceptions will occur. // -void Threading::pxThread::Cancel( bool isBlocking ) +void Threading::pxThread::Cancel(bool isBlocking) { - AffinityAssert_DisallowFromSelf( pxDiagSpot ); + AffinityAssert_DisallowFromSelf(pxDiagSpot); - // Prevent simultaneous startup and cancel, necessary to avoid - ScopedLock startlock( m_mtx_start ); + // Prevent simultaneous startup and cancel, necessary to avoid + ScopedLock startlock(m_mtx_start); - if( !_basecancel() ) return; + if (!_basecancel()) + return; - if( isBlocking ) - { - WaitOnSelf( m_mtx_InThread ); - Detach(); - } + if (isBlocking) { + WaitOnSelf(m_mtx_InThread); + Detach(); + } } -bool Threading::pxThread::Cancel( const wxTimeSpan& timespan ) +bool Threading::pxThread::Cancel(const wxTimeSpan ×pan) { - AffinityAssert_DisallowFromSelf( pxDiagSpot ); + AffinityAssert_DisallowFromSelf(pxDiagSpot); - // Prevent simultaneous startup and cancel: - ScopedLock startlock( m_mtx_start ); + // Prevent simultaneous startup and cancel: + ScopedLock startlock(m_mtx_start); - if( !_basecancel() ) return true; + if (!_basecancel()) + return true; - if( !WaitOnSelf( m_mtx_InThread, timespan ) ) return false; - Detach(); - return true; + if (!WaitOnSelf(m_mtx_InThread, timespan)) + return false; + Detach(); + return true; } @@ -367,21 +364,21 @@ bool Threading::pxThread::Cancel( const wxTimeSpan& timespan ) // void Threading::pxThread::Block() { - AffinityAssert_DisallowFromSelf(pxDiagSpot); - WaitOnSelf( m_mtx_InThread ); + AffinityAssert_DisallowFromSelf(pxDiagSpot); + WaitOnSelf(m_mtx_InThread); } -bool Threading::pxThread::Block( const wxTimeSpan& timeout ) +bool Threading::pxThread::Block(const wxTimeSpan &timeout) { - AffinityAssert_DisallowFromSelf(pxDiagSpot); - return WaitOnSelf( m_mtx_InThread, timeout ); + AffinityAssert_DisallowFromSelf(pxDiagSpot); + return WaitOnSelf(m_mtx_InThread, timeout); } bool Threading::pxThread::IsSelf() const { - // Detached threads may have their pthread handles recycled as newer threads, causing - // false IsSelf reports. - return !m_detached && (pthread_self() == m_thread); + // Detached threads may have their pthread handles recycled as newer threads, causing + // false IsSelf reports. + return !m_detached && (pthread_self() == m_thread); } bool Threading::pxThread::IsRunning() const @@ -389,10 +386,10 @@ bool Threading::pxThread::IsRunning() const return m_running; } -void Threading::pxThread::AddListener( EventListener_Thread& evt ) +void Threading::pxThread::AddListener(EventListener_Thread &evt) { - evt.SetThread( this ); - m_evtsrc_OnDelete.Add( evt ); + evt.SetThread(this); + m_evtsrc_OnDelete.Add(evt); } // Throws an exception if the thread encountered one. Uses the BaseException's Rethrow() method, @@ -400,52 +397,49 @@ void Threading::pxThread::AddListener( EventListener_Thread& evt ) // the thread will have allowed itself to terminate properly. void Threading::pxThread::RethrowException() const { - // Thread safety note: always detach the m_except pointer. If we checked it for NULL, the - // pointer might still be invalid after detachment, so might as well just detach and check - // after. + // Thread safety note: always detach the m_except pointer. If we checked it for NULL, the + // pointer might still be invalid after detachment, so might as well just detach and check + // after. - ScopedExcept ptr( const_cast(this)->m_except.DetachPtr() ); - if (ptr) - ptr->Rethrow(); + ScopedExcept ptr(const_cast(this)->m_except.DetachPtr()); + if (ptr) + ptr->Rethrow(); } static bool m_BlockDeletions = false; bool Threading::AllowDeletions() { - AffinityAssert_AllowFrom_MainUI(); - return !m_BlockDeletions; + AffinityAssert_AllowFrom_MainUI(); + return !m_BlockDeletions; } void Threading::YieldToMain() { - m_BlockDeletions = true; - wxTheApp->Yield( true ); - m_BlockDeletions = false; + m_BlockDeletions = true; + wxTheApp->Yield(true); + m_BlockDeletions = false; } -void Threading::pxThread::_selfRunningTest( const wxChar* name ) const +void Threading::pxThread::_selfRunningTest(const wxChar *name) const { - if( HasPendingException() ) - { - pxThreadLog.Error( GetName(), pxsFmt(L"An exception was thrown while waiting on a %s.", name) ); - RethrowException(); - } + if (HasPendingException()) { + pxThreadLog.Error(GetName(), pxsFmt(L"An exception was thrown while waiting on a %s.", name)); + RethrowException(); + } - if( !m_running ) - { - throw Exception::CancelEvent( pxsFmt( - L"Blocking thread %s was terminated while another thread was waiting on a %s.", - WX_STR(GetName()), name ) - ); - } + if (!m_running) { + throw Exception::CancelEvent(pxsFmt( + L"Blocking thread %s was terminated while another thread was waiting on a %s.", + WX_STR(GetName()), name)); + } - // Thread is still alive and kicking (for now) -- yield to other messages and hope - // that impending chaos does not ensue. [it shouldn't since we block pxThread - // objects from being deleted until outside the scope of a mutex/semaphore wait). + // Thread is still alive and kicking (for now) -- yield to other messages and hope + // that impending chaos does not ensue. [it shouldn't since we block pxThread + // objects from being deleted until outside the scope of a mutex/semaphore wait). - if( (wxTheApp != NULL) && wxThread::IsMain() && !_WaitGui_RecursionGuard( L"WaitForSelf" ) ) - Threading::YieldToMain(); + if ((wxTheApp != NULL) && wxThread::IsMain() && !_WaitGui_RecursionGuard(L"WaitForSelf")) + Threading::YieldToMain(); } // This helper function is a deadlock-safe method of waiting on a semaphore in a pxThread. If the @@ -459,15 +453,16 @@ void Threading::pxThread::_selfRunningTest( const wxChar* name ) const // This function will rethrow exceptions raised by the persistent thread, if it throws an error // while the calling thread is blocking (which also means the persistent thread has terminated). // -void Threading::pxThread::WaitOnSelf( Semaphore& sem ) const +void Threading::pxThread::WaitOnSelf(Semaphore &sem) const { - if( !AffinityAssert_DisallowFromSelf(pxDiagSpot) ) return; + if (!AffinityAssert_DisallowFromSelf(pxDiagSpot)) + return; - while( true ) - { - if( sem.WaitWithoutYield( wxTimeSpan(0, 0, 0, 333) ) ) return; - _selfRunningTest( L"semaphore" ); - } + while (true) { + if (sem.WaitWithoutYield(wxTimeSpan(0, 0, 0, 333))) + return; + _selfRunningTest(L"semaphore"); + } } // This helper function is a deadlock-safe method of waiting on a mutex in a pxThread. @@ -483,49 +478,52 @@ void Threading::pxThread::WaitOnSelf( Semaphore& sem ) const // error while the calling thread is blocking (which also means the persistent thread has // terminated). // -void Threading::pxThread::WaitOnSelf( Mutex& mutex ) const +void Threading::pxThread::WaitOnSelf(Mutex &mutex) const { - if( !AffinityAssert_DisallowFromSelf(pxDiagSpot) ) return; + if (!AffinityAssert_DisallowFromSelf(pxDiagSpot)) + return; - while( true ) - { - if( mutex.WaitWithoutYield( wxTimeSpan(0, 0, 0, 333) ) ) return; - _selfRunningTest( L"mutex" ); - } + while (true) { + if (mutex.WaitWithoutYield(wxTimeSpan(0, 0, 0, 333))) + return; + _selfRunningTest(L"mutex"); + } } -static const wxTimeSpan SelfWaitInterval( 0,0,0,333 ); +static const wxTimeSpan SelfWaitInterval(0, 0, 0, 333); -bool Threading::pxThread::WaitOnSelf( Semaphore& sem, const wxTimeSpan& timeout ) const +bool Threading::pxThread::WaitOnSelf(Semaphore &sem, const wxTimeSpan &timeout) const { - if( !AffinityAssert_DisallowFromSelf(pxDiagSpot) ) return true; + if (!AffinityAssert_DisallowFromSelf(pxDiagSpot)) + return true; - wxTimeSpan runningout( timeout ); + wxTimeSpan runningout(timeout); - while( runningout.GetMilliseconds() > 0 ) - { - const wxTimeSpan interval( (SelfWaitInterval < runningout) ? SelfWaitInterval : runningout ); - if( sem.WaitWithoutYield( interval ) ) return true; - _selfRunningTest( L"semaphore" ); - runningout -= interval; - } - return false; + while (runningout.GetMilliseconds() > 0) { + const wxTimeSpan interval((SelfWaitInterval < runningout) ? SelfWaitInterval : runningout); + if (sem.WaitWithoutYield(interval)) + return true; + _selfRunningTest(L"semaphore"); + runningout -= interval; + } + return false; } -bool Threading::pxThread::WaitOnSelf( Mutex& mutex, const wxTimeSpan& timeout ) const +bool Threading::pxThread::WaitOnSelf(Mutex &mutex, const wxTimeSpan &timeout) const { - if( !AffinityAssert_DisallowFromSelf(pxDiagSpot) ) return true; + if (!AffinityAssert_DisallowFromSelf(pxDiagSpot)) + return true; - wxTimeSpan runningout( timeout ); + wxTimeSpan runningout(timeout); - while( runningout.GetMilliseconds() > 0 ) - { - const wxTimeSpan interval( (SelfWaitInterval < runningout) ? SelfWaitInterval : runningout ); - if( mutex.WaitWithoutYield( interval ) ) return true; - _selfRunningTest( L"mutex" ); - runningout -= interval; - } - return false; + while (runningout.GetMilliseconds() > 0) { + const wxTimeSpan interval((SelfWaitInterval < runningout) ? SelfWaitInterval : runningout); + if (mutex.WaitWithoutYield(interval)) + return true; + _selfRunningTest(L"mutex"); + runningout -= interval; + } + return false; } // Inserts a thread cancellation point. If the thread has received a cancel request, this @@ -534,38 +532,36 @@ bool Threading::pxThread::WaitOnSelf( Mutex& mutex, const wxTimeSpan& timeout ) // and cleanup, or use the DoThreadCleanup() override to perform resource cleanup). void Threading::pxThread::TestCancel() const { - AffinityAssert_AllowFromSelf(pxDiagSpot); - pthread_testcancel(); + AffinityAssert_AllowFromSelf(pxDiagSpot); + pthread_testcancel(); } // Executes the virtual member method -void Threading::pxThread::_try_virtual_invoke( void (pxThread::*method)() ) +void Threading::pxThread::_try_virtual_invoke(void (pxThread::*method)()) { - try { - (this->*method)(); - } + try { + (this->*method)(); + } - // ---------------------------------------------------------------------------- - // Neat repackaging for STL Runtime errors... - // - catch( std::runtime_error& ex ) - { - m_except = new Exception::RuntimeError( ex, WX_STR(GetName()) ); - } + // ---------------------------------------------------------------------------- + // Neat repackaging for STL Runtime errors... + // + catch (std::runtime_error &ex) { + m_except = new Exception::RuntimeError(ex, WX_STR(GetName())); + } - // ---------------------------------------------------------------------------- - catch( Exception::RuntimeError& ex ) - { - BaseException* woot = ex.Clone(); - woot->DiagMsg() += pxsFmt( L"(thread:%s)", WX_STR(GetName()) ); - m_except = woot; - } + // ---------------------------------------------------------------------------- + catch (Exception::RuntimeError &ex) { + BaseException *woot = ex.Clone(); + woot->DiagMsg() += pxsFmt(L"(thread:%s)", WX_STR(GetName())); + m_except = woot; + } #ifndef PCSX2_DEVBUILD - // ---------------------------------------------------------------------------- - // Bleh... don't bother with std::exception. runtime_error should catch anything - // useful coming out of the core STL libraries anyway, and these are best handled by - // the MSVC debugger (or by silent random annoying fail on debug-less linux). - /*catch( std::logic_error& ex ) + // ---------------------------------------------------------------------------- + // Bleh... don't bother with std::exception. runtime_error should catch anything + // useful coming out of the core STL libraries anyway, and these are best handled by + // the MSVC debugger (or by silent random annoying fail on debug-less linux). + /*catch( std::logic_error& ex ) { throw BaseException( pxsFmt( L"STL Logic Error (thread:%s): %s", WX_STR(GetName()), WX_STR(fromUTF8( ex.what() )) ) @@ -577,15 +573,14 @@ void Threading::pxThread::_try_virtual_invoke( void (pxThread::*method)() ) WX_STR(GetName()), WX_STR(fromUTF8( ex.what() )) ) ); }*/ - // ---------------------------------------------------------------------------- - // BaseException -- same deal as LogicErrors. - // - catch( BaseException& ex ) - { - BaseException* woot = ex.Clone(); - woot->DiagMsg() += pxsFmt( L"(thread:%s)", WX_STR(GetName()) ); - m_except = woot; - } + // ---------------------------------------------------------------------------- + // BaseException -- same deal as LogicErrors. + // + catch (BaseException &ex) { + BaseException *woot = ex.Clone(); + woot->DiagMsg() += pxsFmt(L"(thread:%s)", WX_STR(GetName())); + m_except = woot; + } #endif } @@ -593,25 +588,25 @@ void Threading::pxThread::_try_virtual_invoke( void (pxThread::*method)() ) // OnCleanupInThread() to extend cleanup functionality. void Threading::pxThread::_ThreadCleanup() { - AffinityAssert_AllowFromSelf(pxDiagSpot); - _try_virtual_invoke( &pxThread::OnCleanupInThread ); - m_mtx_InThread.Release(); + AffinityAssert_AllowFromSelf(pxDiagSpot); + _try_virtual_invoke(&pxThread::OnCleanupInThread); + m_mtx_InThread.Release(); - // Must set m_running LAST, as thread destructors depend on this value (it is used - // to avoid destruction of the thread until all internal data use has stopped. - m_running = false; + // Must set m_running LAST, as thread destructors depend on this value (it is used + // to avoid destruction of the thread until all internal data use has stopped. + m_running = false; } wxString Threading::pxThread::GetName() const { - ScopedLock lock(m_mtx_ThreadName); - return m_name; + ScopedLock lock(m_mtx_ThreadName); + return m_name; } -void Threading::pxThread::SetName( const wxString& newname ) +void Threading::pxThread::SetName(const wxString &newname) { - ScopedLock lock(m_mtx_ThreadName); - m_name = newname; + ScopedLock lock(m_mtx_ThreadName); + m_name = newname; } // This override is called by PeristentThread when the thread is first created, prior to @@ -623,72 +618,73 @@ void Threading::pxThread::SetName( const wxString& newname ) // void Threading::pxThread::OnStartInThread() { - m_detached = false; - m_running = true; + m_detached = false; + m_running = true; - _platform_specific_OnStartInThread(); + _platform_specific_OnStartInThread(); } void Threading::pxThread::_internal_execute() { - m_mtx_InThread.Acquire(); + m_mtx_InThread.Acquire(); - _DoSetThreadName( GetName() ); - make_curthread_key(this); - if( curthread_key ) - pthread_setspecific( curthread_key, this ); + _DoSetThreadName(GetName()); + make_curthread_key(this); + if (curthread_key) + pthread_setspecific(curthread_key, this); - OnStartInThread(); - m_sem_startup.Post(); + OnStartInThread(); + m_sem_startup.Post(); - _try_virtual_invoke( &pxThread::ExecuteTaskInThread ); + _try_virtual_invoke(&pxThread::ExecuteTaskInThread); } // Called by Start, prior to actual starting of the thread, and after any previous // running thread has been canceled or detached. void Threading::pxThread::OnStart() { - m_native_handle = 0; - m_native_id = 0; + m_native_handle = 0; + m_native_id = 0; - FrankenMutex( m_mtx_InThread ); - m_sem_event.Reset(); - m_sem_startup.Reset(); + FrankenMutex(m_mtx_InThread); + m_sem_event.Reset(); + m_sem_startup.Reset(); } // Extending classes that override this method should always call it last from their // personal implementations. void Threading::pxThread::OnCleanupInThread() { - if( curthread_key ) - pthread_setspecific( curthread_key, NULL ); + if (curthread_key) + pthread_setspecific(curthread_key, NULL); - unmake_curthread_key(); + unmake_curthread_key(); - _platform_specific_OnCleanupInThread(); + _platform_specific_OnCleanupInThread(); - m_native_handle = 0; - m_native_id = 0; + m_native_handle = 0; + m_native_id = 0; - m_evtsrc_OnDelete.Dispatch( 0 ); + m_evtsrc_OnDelete.Dispatch(0); } // passed into pthread_create, and is used to dispatch the thread's object oriented // callback function -void* Threading::pxThread::_internal_callback( void* itsme ) +void *Threading::pxThread::_internal_callback(void *itsme) { - if( !pxAssertDev( itsme != NULL, wxNullChar ) ) return NULL; - pxThread& owner = *((pxThread*)itsme); + if (!pxAssertDev(itsme != NULL, wxNullChar)) + return NULL; + pxThread &owner = *((pxThread *)itsme); - pthread_cleanup_push( _pt_callback_cleanup, itsme ); - owner._internal_execute(); - pthread_cleanup_pop( true ); - return NULL; + pthread_cleanup_push(_pt_callback_cleanup, itsme); + owner._internal_execute(); + pthread_cleanup_pop(true); + return NULL; } -void Threading::pxThread::_DoSetThreadName( const wxString& name ) +void Threading::pxThread::_DoSetThreadName(const wxString &name) { - _DoSetThreadName( static_cast(name.ToUTF8()) ); + _DoSetThreadName(static_cast(name.ToUTF8())); } // -------------------------------------------------------------------------------------- @@ -698,53 +694,54 @@ void Threading::pxThread::_DoSetThreadName( const wxString& name ) // Tells the thread to exit and then waits for thread termination. void Threading::BaseTaskThread::Block() { - if( !IsRunning() ) return; - m_Done = true; - m_sem_event.Post(); - pxThread::Block(); + if (!IsRunning()) + return; + m_Done = true; + m_sem_event.Post(); + pxThread::Block(); } // Initiates the new task. This should be called after your own StartTask has // initialized internal variables / preparations for task execution. void Threading::BaseTaskThread::PostTask() { - pxAssert( !m_detached ); + pxAssert(!m_detached); - ScopedLock locker( m_lock_TaskComplete ); - m_TaskPending = true; - m_post_TaskComplete.Reset(); - m_sem_event.Post(); + ScopedLock locker(m_lock_TaskComplete); + m_TaskPending = true; + m_post_TaskComplete.Reset(); + m_sem_event.Post(); } // Blocks current thread execution pending the completion of the parallel task. void Threading::BaseTaskThread::WaitForResult() { - if( m_detached || !m_running ) return; - if( m_TaskPending ) - #if wxUSE_GUI - m_post_TaskComplete.Wait(); - #else - m_post_TaskComplete.WaitWithoutYield(); - #endif + if (m_detached || !m_running) + return; + if (m_TaskPending) +#if wxUSE_GUI + m_post_TaskComplete.Wait(); +#else + m_post_TaskComplete.WaitWithoutYield(); +#endif - m_post_TaskComplete.Reset(); + m_post_TaskComplete.Reset(); } void Threading::BaseTaskThread::ExecuteTaskInThread() { - while( !m_Done ) - { - // Wait for a job -- or get a pthread_cancel. I'm easy. - m_sem_event.WaitWithoutYield(); + while (!m_Done) { + // Wait for a job -- or get a pthread_cancel. I'm easy. + m_sem_event.WaitWithoutYield(); - Task(); - m_lock_TaskComplete.Acquire(); - m_TaskPending = false; - m_post_TaskComplete.Post(); - m_lock_TaskComplete.Release(); - }; + Task(); + m_lock_TaskComplete.Acquire(); + m_TaskPending = false; + m_post_TaskComplete.Post(); + m_lock_TaskComplete.Release(); + }; - return; + return; } // -------------------------------------------------------------------------------------- @@ -788,23 +785,23 @@ void Threading::WaitEvent::Wait() wxString Exception::BaseThreadError::FormatDiagnosticMessage() const { - wxString null_str(L"Null Thread Object"); - return pxsFmt( m_message_diag, (m_thread==NULL) ? WX_STR(null_str) : WX_STR(m_thread->GetName())); + wxString null_str(L"Null Thread Object"); + return pxsFmt(m_message_diag, (m_thread == NULL) ? WX_STR(null_str) : WX_STR(m_thread->GetName())); } wxString Exception::BaseThreadError::FormatDisplayMessage() const { - wxString null_str(L"Null Thread Object"); - return pxsFmt( m_message_user, (m_thread==NULL) ? WX_STR(null_str) : WX_STR(m_thread->GetName())); + wxString null_str(L"Null Thread Object"); + return pxsFmt(m_message_user, (m_thread == NULL) ? WX_STR(null_str) : WX_STR(m_thread->GetName())); } -pxThread& Exception::BaseThreadError::Thread() +pxThread &Exception::BaseThreadError::Thread() { - pxAssertDev( m_thread != NULL, "NULL thread object on ThreadError exception." ); - return *m_thread; + pxAssertDev(m_thread != NULL, "NULL thread object on ThreadError exception."); + return *m_thread; } -const pxThread& Exception::BaseThreadError::Thread() const +const pxThread &Exception::BaseThreadError::Thread() const { - pxAssertDev( m_thread != NULL, "NULL thread object on ThreadError exception." ); - return *m_thread; + pxAssertDev(m_thread != NULL, "NULL thread object on ThreadError exception."); + return *m_thread; } diff --git a/common/src/Utilities/ThreadingDialogs.cpp b/common/src/Utilities/ThreadingDialogs.cpp index 1871f4cde0..e81435d00f 100644 --- a/common/src/Utilities/ThreadingDialogs.cpp +++ b/common/src/Utilities/ThreadingDialogs.cpp @@ -26,58 +26,60 @@ wxDEFINE_EVENT(pxEvt_ThreadedTaskComplete, wxCommandEvent); // -------------------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(WaitForTaskDialog, wxDialogWithHelpers) -Threading::WaitForTaskDialog::WaitForTaskDialog( const wxString& title, const wxString& heading ) - : wxDialogWithHelpers( NULL, _("Waiting for tasks...") ) - //, m_Timer(this) +Threading::WaitForTaskDialog::WaitForTaskDialog(const wxString &title, const wxString &heading) + : wxDialogWithHelpers(NULL, _("Waiting for tasks...")) +//, m_Timer(this) { - SetMinWidth( 300 ); + SetMinWidth(300); - //m_sem = sem; - //m_mutex = mutex; + //m_sem = sem; + //m_mutex = mutex; - wxString m_title( title ); - wxString m_heading( heading ); + wxString m_title(title); + wxString m_heading(heading); - if( m_title.IsEmpty() ) m_title = _("Waiting for task..."); - if( m_heading.IsEmpty() ) m_heading = m_title; + if (m_title.IsEmpty()) + m_title = _("Waiting for task..."); + if (m_heading.IsEmpty()) + m_heading = m_title; - Bind(pxEvt_ThreadedTaskComplete, &WaitForTaskDialog::OnTaskComplete, this); + Bind(pxEvt_ThreadedTaskComplete, &WaitForTaskDialog::OnTaskComplete, this); - *this += 12; - *this += Heading(m_heading).Unwrapped() | StdExpand(); - *this += 12; - - // TODO : Implement a cancel button. Not quite sure the best way to do - // that, since it requires a thread or event handler context, or something. + *this += 12; + *this += Heading(m_heading).Unwrapped() | StdExpand(); + *this += 12; - //applyDlg += new wxButton( &applyDlg, wxID_CANCEL ) | pxCenter; - //applyDlg += 6; + // TODO : Implement a cancel button. Not quite sure the best way to do + // that, since it requires a thread or event handler context, or something. - //Bind(wxEVT_TIMER, &WaitForTaskDialog::OnTimer, this, m_Timer.GetId()); - //m_Timer.Start( 200 ); - //GetSysExecutorThread().PostEvent( new SysExecEvent_ApplyPlugins( this, m_sync ) ); + //applyDlg += new wxButton( &applyDlg, wxID_CANCEL ) | pxCenter; + //applyDlg += 6; + + //Bind(wxEVT_TIMER, &WaitForTaskDialog::OnTimer, this, m_Timer.GetId()); + //m_Timer.Start( 200 ); + //GetSysExecutorThread().PostEvent( new SysExecEvent_ApplyPlugins( this, m_sync ) ); } -void Threading::WaitForTaskDialog::OnTaskComplete( wxCommandEvent& evt ) +void Threading::WaitForTaskDialog::OnTaskComplete(wxCommandEvent &evt) { - evt.Skip(); + evt.Skip(); - // Note: we don't throw exceptions from the pending task here. - // Instead we wait until we exit the modal loop below -- this gives - // the caller a chance to handle the exception themselves, and if - // not the exception will still fall back on the standard app-level - // exception handler. + // Note: we don't throw exceptions from the pending task here. + // Instead we wait until we exit the modal loop below -- this gives + // the caller a chance to handle the exception themselves, and if + // not the exception will still fall back on the standard app-level + // exception handler. - // (this also avoids any sticky business with the modal dialog not getting - // closed out right due to stack unwinding skipping dialog closure crap) + // (this also avoids any sticky business with the modal dialog not getting + // closed out right due to stack unwinding skipping dialog closure crap) - m_sync.WaitForResult_NoExceptions(); - EndModal( wxID_OK ); + m_sync.WaitForResult_NoExceptions(); + EndModal(wxID_OK); } int Threading::WaitForTaskDialog::ShowModal() { - int result = _parent::ShowModal(); - m_sync.RethrowException(); - return result; + int result = _parent::ShowModal(); + m_sync.RethrowException(); + return result; } diff --git a/common/src/Utilities/ThreadingInternal.h b/common/src/Utilities/ThreadingInternal.h index cd55134222..12de207e89 100644 --- a/common/src/Utilities/ThreadingInternal.h +++ b/common/src/Utilities/ThreadingInternal.h @@ -21,11 +21,10 @@ namespace Threading { - extern const wxTimeSpan def_yieldgui_interval; +extern const wxTimeSpan def_yieldgui_interval; - extern bool _WaitGui_RecursionGuard( const wxChar* name ); - - extern void YieldToMain(); - extern bool AllowDeletions(); +extern bool _WaitGui_RecursionGuard(const wxChar *name); + +extern void YieldToMain(); +extern bool AllowDeletions(); } - diff --git a/common/src/Utilities/VirtualMemory.cpp b/common/src/Utilities/VirtualMemory.cpp index edbfbbf853..44f47f2137 100644 --- a/common/src/Utilities/VirtualMemory.cpp +++ b/common/src/Utilities/VirtualMemory.cpp @@ -23,20 +23,20 @@ #include "EventSource.inl" #include "MemsetFast.inl" -template class EventSource< IEventListener_PageFault >; +template class EventSource; -SrcType_PageFault* Source_PageFault = NULL; -Threading::Mutex PageFault_Mutex; +SrcType_PageFault *Source_PageFault = NULL; +Threading::Mutex PageFault_Mutex; void pxInstallSignalHandler() { - if(!Source_PageFault) { - Source_PageFault = new SrcType_PageFault(); - } + if (!Source_PageFault) { + Source_PageFault = new SrcType_PageFault(); + } - _platform_InstallSignalHandler(); + _platform_InstallSignalHandler(); - // NOP on Win32 systems -- we use __try{} __except{} instead. + // NOP on Win32 systems -- we use __try{} __except{} instead. } // -------------------------------------------------------------------------------------- @@ -44,62 +44,63 @@ void pxInstallSignalHandler() // -------------------------------------------------------------------------------------- EventListener_PageFault::EventListener_PageFault() { - pxAssert(Source_PageFault); - Source_PageFault->Add( *this ); + pxAssert(Source_PageFault); + Source_PageFault->Add(*this); } EventListener_PageFault::~EventListener_PageFault() throw() { - if (Source_PageFault) - Source_PageFault->Remove( *this ); + if (Source_PageFault) + Source_PageFault->Remove(*this); } -void SrcType_PageFault::Dispatch( const PageFaultInfo& params ) +void SrcType_PageFault::Dispatch(const PageFaultInfo ¶ms) { - m_handled = false; - _parent::Dispatch( params ); + m_handled = false; + _parent::Dispatch(params); } -void SrcType_PageFault::_DispatchRaw( ListenerIterator iter, const ListenerIterator& iend, const PageFaultInfo& evt ) +void SrcType_PageFault::_DispatchRaw(ListenerIterator iter, const ListenerIterator &iend, const PageFaultInfo &evt) { - do { - (*iter)->DispatchEvent( evt, m_handled ); - } while( (++iter != iend) && !m_handled ); + do { + (*iter)->DispatchEvent(evt, m_handled); + } while ((++iter != iend) && !m_handled); } // -------------------------------------------------------------------------------------- // VirtualMemoryReserve (implementations) // -------------------------------------------------------------------------------------- -VirtualMemoryReserve::VirtualMemoryReserve( const wxString& name, size_t size ) - : m_name( name ) +VirtualMemoryReserve::VirtualMemoryReserve(const wxString &name, size_t size) + : m_name(name) { - m_defsize = size; + m_defsize = size; - m_pages_commited = 0; - m_pages_reserved = 0; - m_baseptr = NULL; - m_prot_mode = PageAccess_None(); - m_allow_writes = true; + m_pages_commited = 0; + m_pages_reserved = 0; + m_baseptr = NULL; + m_prot_mode = PageAccess_None(); + m_allow_writes = true; } -VirtualMemoryReserve& VirtualMemoryReserve::SetName( const wxString& newname ) +VirtualMemoryReserve &VirtualMemoryReserve::SetName(const wxString &newname) { - m_name = newname; - return *this; + m_name = newname; + return *this; } -VirtualMemoryReserve& VirtualMemoryReserve::SetBaseAddr( uptr newaddr ) +VirtualMemoryReserve &VirtualMemoryReserve::SetBaseAddr(uptr newaddr) { - if (!pxAssertDev(!m_pages_reserved, "Invalid object state: you must release the virtual memory reserve prior to changing its base address!")) return *this; + if (!pxAssertDev(!m_pages_reserved, "Invalid object state: you must release the virtual memory reserve prior to changing its base address!")) + return *this; - m_baseptr = (void*)newaddr; - return *this; + m_baseptr = (void *)newaddr; + return *this; } -VirtualMemoryReserve& VirtualMemoryReserve::SetPageAccessOnCommit( const PageProtectionMode& mode ) +VirtualMemoryReserve &VirtualMemoryReserve::SetPageAccessOnCommit(const PageProtectionMode &mode) { - m_prot_mode = mode; - return *this; + m_prot_mode = mode; + return *this; } // Notes: @@ -114,95 +115,99 @@ VirtualMemoryReserve& VirtualMemoryReserve::SetPageAccessOnCommit( const PagePro // upper_bounds - criteria that must be met for the allocation to be valid. // If the OS refuses to allocate the memory below the specified address, the // object will fail to initialize and an exception will be thrown. -void* VirtualMemoryReserve::Reserve( size_t size, uptr base, uptr upper_bounds ) +void *VirtualMemoryReserve::Reserve(size_t size, uptr base, uptr upper_bounds) { - if (!pxAssertDev( m_baseptr == NULL, "(VirtualMemoryReserve) Invalid object state; object has already been reserved." )) - return m_baseptr; + if (!pxAssertDev(m_baseptr == NULL, "(VirtualMemoryReserve) Invalid object state; object has already been reserved.")) + return m_baseptr; - if (!size) size = m_defsize; - if (!size) return NULL; + if (!size) + size = m_defsize; + if (!size) + return NULL; - m_pages_reserved = (size + __pagesize-4) / __pagesize; - uptr reserved_bytes = m_pages_reserved * __pagesize; + m_pages_reserved = (size + __pagesize - 4) / __pagesize; + uptr reserved_bytes = m_pages_reserved * __pagesize; - m_baseptr = (void*)HostSys::MmapReserve(base, reserved_bytes); + m_baseptr = (void *)HostSys::MmapReserve(base, reserved_bytes); - if (!m_baseptr || (upper_bounds != 0 && (((uptr)m_baseptr + reserved_bytes) > upper_bounds))) - { - DevCon.Warning( L"%s: host memory @ %ls -> %ls is unavailable; attempting to map elsewhere...", - WX_STR(m_name), pxsPtr(base), pxsPtr(base + size) ); + if (!m_baseptr || (upper_bounds != 0 && (((uptr)m_baseptr + reserved_bytes) > upper_bounds))) { + DevCon.Warning(L"%s: host memory @ %ls -> %ls is unavailable; attempting to map elsewhere...", + WX_STR(m_name), pxsPtr(base), pxsPtr(base + size)); - SafeSysMunmap(m_baseptr, reserved_bytes); + SafeSysMunmap(m_baseptr, reserved_bytes); - if (base) - { - // Let's try again at an OS-picked memory area, and then hope it meets needed - // boundschecking criteria below. - m_baseptr = HostSys::MmapReserve( 0, reserved_bytes ); - } - } + if (base) { + // Let's try again at an OS-picked memory area, and then hope it meets needed + // boundschecking criteria below. + m_baseptr = HostSys::MmapReserve(0, reserved_bytes); + } + } - if ((upper_bounds != 0) && (((uptr)m_baseptr + reserved_bytes) > upper_bounds)) - { - SafeSysMunmap(m_baseptr, reserved_bytes); - // returns null, caller should throw an exception or handle appropriately. - } + if ((upper_bounds != 0) && (((uptr)m_baseptr + reserved_bytes) > upper_bounds)) { + SafeSysMunmap(m_baseptr, reserved_bytes); + // returns null, caller should throw an exception or handle appropriately. + } - if (!m_baseptr) return NULL; + if (!m_baseptr) + return NULL; - FastFormatUnicode mbkb; - uint mbytes = reserved_bytes / _1mb; - if (mbytes) - mbkb.Write( "[%umb]", mbytes ); - else - mbkb.Write( "[%ukb]", reserved_bytes / 1024 ); + FastFormatUnicode mbkb; + uint mbytes = reserved_bytes / _1mb; + if (mbytes) + mbkb.Write("[%umb]", mbytes); + else + mbkb.Write("[%ukb]", reserved_bytes / 1024); - DevCon.WriteLn( Color_Gray, L"%-32s @ %ls -> %ls %ls", WX_STR(m_name), - pxsPtr(m_baseptr), pxsPtr((uptr)m_baseptr+reserved_bytes), mbkb.c_str()); + DevCon.WriteLn(Color_Gray, L"%-32s @ %ls -> %ls %ls", WX_STR(m_name), + pxsPtr(m_baseptr), pxsPtr((uptr)m_baseptr + reserved_bytes), mbkb.c_str()); - return m_baseptr; + return m_baseptr; } -void VirtualMemoryReserve::ReprotectCommittedBlocks( const PageProtectionMode& newmode ) +void VirtualMemoryReserve::ReprotectCommittedBlocks(const PageProtectionMode &newmode) { - if (!m_pages_commited) return; - HostSys::MemProtect(m_baseptr, m_pages_commited*__pagesize, newmode); + if (!m_pages_commited) + return; + HostSys::MemProtect(m_baseptr, m_pages_commited * __pagesize, newmode); } // Clears all committed blocks, restoring the allocation to a reserve only. void VirtualMemoryReserve::Reset() { - if (!m_pages_commited) return; + if (!m_pages_commited) + return; - ReprotectCommittedBlocks(PageAccess_None()); - HostSys::MmapResetPtr(m_baseptr, m_pages_commited*__pagesize); - m_pages_commited = 0; + ReprotectCommittedBlocks(PageAccess_None()); + HostSys::MmapResetPtr(m_baseptr, m_pages_commited * __pagesize); + m_pages_commited = 0; } void VirtualMemoryReserve::Release() { - SafeSysMunmap(m_baseptr, m_pages_reserved*__pagesize); + SafeSysMunmap(m_baseptr, m_pages_reserved * __pagesize); } bool VirtualMemoryReserve::Commit() { - if (!m_pages_reserved) return false; - if (!pxAssert(!m_pages_commited)) return true; + if (!m_pages_reserved) + return false; + if (!pxAssert(!m_pages_commited)) + return true; - m_pages_commited = m_pages_reserved; - return HostSys::MmapCommitPtr(m_baseptr, m_pages_reserved*__pagesize, m_prot_mode); + m_pages_commited = m_pages_reserved; + return HostSys::MmapCommitPtr(m_baseptr, m_pages_reserved * __pagesize, m_prot_mode); } void VirtualMemoryReserve::AllowModification() { - m_allow_writes = true; - HostSys::MemProtect(m_baseptr, m_pages_commited*__pagesize, m_prot_mode); + m_allow_writes = true; + HostSys::MemProtect(m_baseptr, m_pages_commited * __pagesize, m_prot_mode); } void VirtualMemoryReserve::ForbidModification() { - m_allow_writes = false; - HostSys::MemProtect(m_baseptr, m_pages_commited*__pagesize, PageProtectionMode(m_prot_mode).Write(false)); + m_allow_writes = false; + HostSys::MemProtect(m_baseptr, m_pages_commited * __pagesize, PageProtectionMode(m_prot_mode).Write(false)); } @@ -215,125 +220,115 @@ void VirtualMemoryReserve::ForbidModification() // // Parameters: // newsize - new size of the reserved buffer, in bytes. -bool VirtualMemoryReserve::TryResize( uint newsize ) +bool VirtualMemoryReserve::TryResize(uint newsize) { - uint newPages = (newsize + __pagesize - 1) / __pagesize; + uint newPages = (newsize + __pagesize - 1) / __pagesize; - if (newPages > m_pages_reserved) - { - uint toReservePages = newPages - m_pages_reserved; - uint toReserveBytes = toReservePages * __pagesize; + if (newPages > m_pages_reserved) { + uint toReservePages = newPages - m_pages_reserved; + uint toReserveBytes = toReservePages * __pagesize; - DevCon.WriteLn( L"%-32s is being expanded by %u pages.", WX_STR(m_name), toReservePages); + DevCon.WriteLn(L"%-32s is being expanded by %u pages.", WX_STR(m_name), toReservePages); - m_baseptr = (void*)HostSys::MmapReserve((uptr)GetPtrEnd(), toReserveBytes); + m_baseptr = (void *)HostSys::MmapReserve((uptr)GetPtrEnd(), toReserveBytes); - if (!m_baseptr) - { - Console.Warning("%-32s could not be passively resized due to virtual memory conflict!"); - Console.Indent().Warning("(attempted to map memory @ %08p -> %08p)", m_baseptr, (uptr)m_baseptr+toReserveBytes); - } + if (!m_baseptr) { + Console.Warning("%-32s could not be passively resized due to virtual memory conflict!"); + Console.Indent().Warning("(attempted to map memory @ %08p -> %08p)", m_baseptr, (uptr)m_baseptr + toReserveBytes); + } - DevCon.WriteLn( Color_Gray, L"%-32s @ %08p -> %08p [%umb]", WX_STR(m_name), - m_baseptr, (uptr)m_baseptr+toReserveBytes, toReserveBytes / _1mb); - } - else if (newPages < m_pages_reserved) - { - if (m_pages_commited > newsize) return false; + DevCon.WriteLn(Color_Gray, L"%-32s @ %08p -> %08p [%umb]", WX_STR(m_name), + m_baseptr, (uptr)m_baseptr + toReserveBytes, toReserveBytes / _1mb); + } else if (newPages < m_pages_reserved) { + if (m_pages_commited > newsize) + return false; - uint toRemovePages = m_pages_reserved - newPages; - uint toRemoveBytes = toRemovePages * __pagesize; + uint toRemovePages = m_pages_reserved - newPages; + uint toRemoveBytes = toRemovePages * __pagesize; - DevCon.WriteLn( L"%-32s is being shrunk by %u pages.", WX_STR(m_name), toRemovePages); + DevCon.WriteLn(L"%-32s is being shrunk by %u pages.", WX_STR(m_name), toRemovePages); - HostSys::MmapResetPtr(GetPtrEnd(), toRemoveBytes); + HostSys::MmapResetPtr(GetPtrEnd(), toRemoveBytes); - DevCon.WriteLn( Color_Gray, L"%-32s @ %08p -> %08p [%umb]", WX_STR(m_name), - m_baseptr, (uptr)m_baseptr+toRemoveBytes, toRemoveBytes / _1mb); - } + DevCon.WriteLn(Color_Gray, L"%-32s @ %08p -> %08p [%umb]", WX_STR(m_name), + m_baseptr, (uptr)m_baseptr + toRemoveBytes, toRemoveBytes / _1mb); + } - return true; + return true; } // -------------------------------------------------------------------------------------- // BaseVmReserveListener (implementations) // -------------------------------------------------------------------------------------- -BaseVmReserveListener::BaseVmReserveListener( const wxString& name, size_t size ) - : VirtualMemoryReserve( name, size ) - , m_pagefault_listener( this ) +BaseVmReserveListener::BaseVmReserveListener(const wxString &name, size_t size) + : VirtualMemoryReserve(name, size) + , m_pagefault_listener(this) { - m_blocksize = __pagesize; + m_blocksize = __pagesize; } -void BaseVmReserveListener::CommitBlocks( uptr page, uint blocks ) +void BaseVmReserveListener::CommitBlocks(uptr page, uint blocks) { - const uptr blocksbytes = blocks * m_blocksize * __pagesize; - void* blockptr = (u8*)m_baseptr + (page * __pagesize); + const uptr blocksbytes = blocks * m_blocksize * __pagesize; + void *blockptr = (u8 *)m_baseptr + (page * __pagesize); - // Depending on the operating system, this call could fail if the system is low on either - // physical ram or virtual memory. - if (!HostSys::MmapCommitPtr(blockptr, blocksbytes, m_prot_mode)) - { - throw Exception::OutOfMemory(m_name) - .SetDiagMsg(pxsFmt("An additional %u blocks @ 0x%08x were requested, but could not be committed!", blocks, blockptr)); - } + // Depending on the operating system, this call could fail if the system is low on either + // physical ram or virtual memory. + if (!HostSys::MmapCommitPtr(blockptr, blocksbytes, m_prot_mode)) { + throw Exception::OutOfMemory(m_name) + .SetDiagMsg(pxsFmt("An additional %u blocks @ 0x%08x were requested, but could not be committed!", blocks, blockptr)); + } - u8* init = (u8*)blockptr; - u8* endpos = init + blocksbytes; - for( ; init= m_pages_reserved)) return; + sptr offset = (info.addr - (uptr)m_baseptr) / __pagesize; + if ((offset < 0) || ((uptr)offset >= m_pages_reserved)) + return; - if (!m_allow_writes) - { - pxFailRel( pxsFmt( - L"Memory Protection Fault @ %ls (%s)\n" - L"Modification of this reserve has been disabled (m_allow_writes == false).", - pxsPtr(info.addr), WX_STR(m_name)) - ); - return; - } + if (!m_allow_writes) { + pxFailRel(pxsFmt( + L"Memory Protection Fault @ %ls (%s)\n" + L"Modification of this reserve has been disabled (m_allow_writes == false).", + pxsPtr(info.addr), WX_STR(m_name))); + return; + } - // Linux Note! the SIGNAL handler is very limited in what it can do, and not only can't - // we let the C++ exception try to unwind the stack, we may not be able to log it either. - // (but we might as well try -- kernel/posix rules says not to do it, but Linux kernel - // implementations seem to support it). - // Note also that logging the exception and/or issuing an assertion dialog are always - // possible if the thread handling the signal is not the main thread. +// Linux Note! the SIGNAL handler is very limited in what it can do, and not only can't +// we let the C++ exception try to unwind the stack, we may not be able to log it either. +// (but we might as well try -- kernel/posix rules says not to do it, but Linux kernel +// implementations seem to support it). +// Note also that logging the exception and/or issuing an assertion dialog are always +// possible if the thread handling the signal is not the main thread. - // In windows we can let exceptions bubble out of the page fault handler. SEH will more - // or less handle them in a semi-expected way, and might even avoid a GPF long enough - // for the system to log the error or something. +// In windows we can let exceptions bubble out of the page fault handler. SEH will more +// or less handle them in a semi-expected way, and might even avoid a GPF long enough +// for the system to log the error or something. - #ifndef __WXMSW__ - try { - #endif - DoCommitAndProtect( offset ); - handled = true; +#ifndef __WXMSW__ + try { +#endif + DoCommitAndProtect(offset); + handled = true; - #ifndef __WXMSW__ - } - catch (Exception::BaseException& ex) - { - handled = false; - if (!wxThread::IsMain()) - { - pxFailRel( ex.FormatDiagnosticMessage() ); - } - else - { - pxTrap(); - } - } - #endif +#ifndef __WXMSW__ + } catch (Exception::BaseException &ex) { + handled = false; + if (!wxThread::IsMain()) { + pxFailRel(ex.FormatDiagnosticMessage()); + } else { + pxTrap(); + } + } +#endif } // -------------------------------------------------------------------------------------- @@ -341,22 +336,27 @@ void BaseVmReserveListener::OnPageFaultEvent(const PageFaultInfo& info, bool& ha // -------------------------------------------------------------------------------------- wxString PageProtectionMode::ToString() const { - wxString modeStr; + wxString modeStr; - if (m_read) modeStr += L"Read"; - if (m_write) modeStr += L"Write"; - if (m_exec) modeStr += L"Exec"; + if (m_read) + modeStr += L"Read"; + if (m_write) + modeStr += L"Write"; + if (m_exec) + modeStr += L"Exec"; - if (modeStr.IsEmpty()) return L"NoAccess"; - if (modeStr.Length() <= 5) modeStr += L"Only"; + if (modeStr.IsEmpty()) + return L"NoAccess"; + if (modeStr.Length() <= 5) + modeStr += L"Only"; - return modeStr; + return modeStr; } // -------------------------------------------------------------------------------------- // Common HostSys implementation // -------------------------------------------------------------------------------------- -void HostSys::Munmap( void* base, size_t size ) +void HostSys::Munmap(void *base, size_t size) { - Munmap( (uptr)base, size); + Munmap((uptr)base, size); } diff --git a/common/src/Utilities/Windows/WinHostSys.cpp b/common/src/Utilities/Windows/WinHostSys.cpp index 82b936e1fa..6b6059e90b 100644 --- a/common/src/Utilities/Windows/WinHostSys.cpp +++ b/common/src/Utilities/Windows/WinHostSys.cpp @@ -19,139 +19,133 @@ #include -static int DoSysPageFaultExceptionFilter( EXCEPTION_POINTERS* eps ) +static int DoSysPageFaultExceptionFilter(EXCEPTION_POINTERS *eps) { - if( eps->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION ) - return EXCEPTION_CONTINUE_SEARCH; + if (eps->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION) + return EXCEPTION_CONTINUE_SEARCH; - // Note: This exception can be accessed by the EE or MTVU thread - // Source_PageFault is a global variable with its own state information - // so for now we lock this exception code unless someone can fix this better... - Threading::ScopedLock lock(PageFault_Mutex); - Source_PageFault->Dispatch( PageFaultInfo( (uptr)eps->ExceptionRecord->ExceptionInformation[1] ) ); - return Source_PageFault->WasHandled() ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH; + // Note: This exception can be accessed by the EE or MTVU thread + // Source_PageFault is a global variable with its own state information + // so for now we lock this exception code unless someone can fix this better... + Threading::ScopedLock lock(PageFault_Mutex); + Source_PageFault->Dispatch(PageFaultInfo((uptr)eps->ExceptionRecord->ExceptionInformation[1])); + return Source_PageFault->WasHandled() ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH; } -int SysPageFaultExceptionFilter( EXCEPTION_POINTERS* eps ) +int SysPageFaultExceptionFilter(EXCEPTION_POINTERS *eps) { - // Prevent recursive exception filtering by catching the exception from the filter here. - // In the event that the filter causes an access violation (happened during shutdown - // because Source_PageFault was deallocated), this will allow the debugger to catch the - // exception. - // TODO: find a reliable way to debug the filter itself, I've come up with a few ways that - // work but I don't fully understand why some do and some don't. - __try { - return DoSysPageFaultExceptionFilter(eps); - } __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { - return EXCEPTION_CONTINUE_SEARCH; - } + // Prevent recursive exception filtering by catching the exception from the filter here. + // In the event that the filter causes an access violation (happened during shutdown + // because Source_PageFault was deallocated), this will allow the debugger to catch the + // exception. + // TODO: find a reliable way to debug the filter itself, I've come up with a few ways that + // work but I don't fully understand why some do and some don't. + __try { + return DoSysPageFaultExceptionFilter(eps); + } __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { + return EXCEPTION_CONTINUE_SEARCH; + } } void _platform_InstallSignalHandler() { - // NOP on Win32 systems -- we use __try{} __except{} instead. + // NOP on Win32 systems -- we use __try{} __except{} instead. } -static DWORD ConvertToWinApi( const PageProtectionMode& mode ) +static DWORD ConvertToWinApi(const PageProtectionMode &mode) { - DWORD winmode = PAGE_NOACCESS; + DWORD winmode = PAGE_NOACCESS; - // Windows has some really bizarre memory protection enumeration that uses bitwise - // numbering (like flags) but is in fact not a flag value. *Someone* from the early - // microsoft days wasn't a very good coder, me thinks. --air + // Windows has some really bizarre memory protection enumeration that uses bitwise + // numbering (like flags) but is in fact not a flag value. *Someone* from the early + // microsoft days wasn't a very good coder, me thinks. --air - if (mode.CanExecute()) - { - winmode = mode.CanWrite() ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ; - } - else if (mode.CanRead()) - { - winmode = mode.CanWrite() ? PAGE_READWRITE : PAGE_READONLY; - } + if (mode.CanExecute()) { + winmode = mode.CanWrite() ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ; + } else if (mode.CanRead()) { + winmode = mode.CanWrite() ? PAGE_READWRITE : PAGE_READONLY; + } - return winmode; + return winmode; } -void* HostSys::MmapReservePtr(void* base, size_t size) +void *HostSys::MmapReservePtr(void *base, size_t size) { - return VirtualAlloc(base, size, MEM_RESERVE, PAGE_NOACCESS); + return VirtualAlloc(base, size, MEM_RESERVE, PAGE_NOACCESS); } -bool HostSys::MmapCommitPtr(void* base, size_t size, const PageProtectionMode& mode) +bool HostSys::MmapCommitPtr(void *base, size_t size, const PageProtectionMode &mode) { - void* result = VirtualAlloc(base, size, MEM_COMMIT, ConvertToWinApi(mode)); - if (result) return true; + void *result = VirtualAlloc(base, size, MEM_COMMIT, ConvertToWinApi(mode)); + if (result) + return true; - const DWORD errcode = GetLastError(); - if (errcode == ERROR_COMMITMENT_MINIMUM) - { - Console.Warning("(MmapCommit) Received windows error %u {Virtual Memory Minimum Too Low}.", ERROR_COMMITMENT_MINIMUM); - Sleep(1000); // Cut windows some time to rework its memory... - } - else if (errcode != ERROR_NOT_ENOUGH_MEMORY && errcode != ERROR_OUTOFMEMORY) - { - pxFailDev(L"VirtualAlloc COMMIT failed: " + Exception::WinApiError().GetMsgFromWindows()); - return false; - } + const DWORD errcode = GetLastError(); + if (errcode == ERROR_COMMITMENT_MINIMUM) { + Console.Warning("(MmapCommit) Received windows error %u {Virtual Memory Minimum Too Low}.", ERROR_COMMITMENT_MINIMUM); + Sleep(1000); // Cut windows some time to rework its memory... + } else if (errcode != ERROR_NOT_ENOUGH_MEMORY && errcode != ERROR_OUTOFMEMORY) { + pxFailDev(L"VirtualAlloc COMMIT failed: " + Exception::WinApiError().GetMsgFromWindows()); + return false; + } - if (!pxDoOutOfMemory) return false; - pxDoOutOfMemory(size); - return VirtualAlloc(base, size, MEM_COMMIT, ConvertToWinApi(mode)) != NULL; + if (!pxDoOutOfMemory) + return false; + pxDoOutOfMemory(size); + return VirtualAlloc(base, size, MEM_COMMIT, ConvertToWinApi(mode)) != NULL; } -void HostSys::MmapResetPtr(void* base, size_t size) +void HostSys::MmapResetPtr(void *base, size_t size) { - VirtualFree(base, size, MEM_DECOMMIT); + VirtualFree(base, size, MEM_DECOMMIT); } -void* HostSys::MmapReserve(uptr base, size_t size) +void *HostSys::MmapReserve(uptr base, size_t size) { - return MmapReservePtr((void*)base, size); + return MmapReservePtr((void *)base, size); } -bool HostSys::MmapCommit(uptr base, size_t size, const PageProtectionMode& mode) +bool HostSys::MmapCommit(uptr base, size_t size, const PageProtectionMode &mode) { - return MmapCommitPtr( (void*)base, size, mode ); + return MmapCommitPtr((void *)base, size, mode); } void HostSys::MmapReset(uptr base, size_t size) { - MmapResetPtr((void*)base, size); + MmapResetPtr((void *)base, size); } -void* HostSys::Mmap(uptr base, size_t size) +void *HostSys::Mmap(uptr base, size_t size) { - return VirtualAlloc((void*)base, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); + return VirtualAlloc((void *)base, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); } void HostSys::Munmap(uptr base, size_t size) { - if (!base) return; - //VirtualFree((void*)base, size, MEM_DECOMMIT); - VirtualFree((void*)base, 0, MEM_RELEASE); + if (!base) + return; + //VirtualFree((void*)base, size, MEM_DECOMMIT); + VirtualFree((void *)base, 0, MEM_RELEASE); } -void HostSys::MemProtect( void* baseaddr, size_t size, const PageProtectionMode& mode ) +void HostSys::MemProtect(void *baseaddr, size_t size, const PageProtectionMode &mode) { - pxAssertDev( ((size & (__pagesize-1)) == 0), pxsFmt( - L"Memory block size must be a multiple of the target platform's page size.\n" - L"\tPage Size: 0x%04x (%d), Block Size: 0x%04x (%d)", - __pagesize, __pagesize, size, size ) - ); - - DWORD OldProtect; // enjoy my uselessness, yo! - if (!VirtualProtect( baseaddr, size, ConvertToWinApi(mode), &OldProtect )) - { - Exception::WinApiError apiError; - - apiError.SetDiagMsg( - pxsFmt(L"VirtualProtect failed @ 0x%08X -> 0x%08X (mode=%s)", - baseaddr, (uptr)baseaddr + size, mode.ToString().c_str() - )); + pxAssertDev(((size & (__pagesize - 1)) == 0), pxsFmt( + L"Memory block size must be a multiple of the target platform's page size.\n" + L"\tPage Size: 0x%04x (%d), Block Size: 0x%04x (%d)", + __pagesize, __pagesize, size, size)); - pxFailDev( apiError.FormatDiagnosticMessage() ); - } + DWORD OldProtect; // enjoy my uselessness, yo! + if (!VirtualProtect(baseaddr, size, ConvertToWinApi(mode), &OldProtect)) { + Exception::WinApiError apiError; + + apiError.SetDiagMsg( + pxsFmt(L"VirtualProtect failed @ 0x%08X -> 0x%08X (mode=%s)", + baseaddr, (uptr)baseaddr + size, mode.ToString().c_str())); + + pxFailDev(apiError.FormatDiagnosticMessage()); + } } diff --git a/common/src/Utilities/Windows/WinMisc.cpp b/common/src/Utilities/Windows/WinMisc.cpp index 43be0bfbbd..96cd056a3a 100644 --- a/common/src/Utilities/Windows/WinMisc.cpp +++ b/common/src/Utilities/Windows/WinMisc.cpp @@ -24,58 +24,58 @@ static __aligned16 LARGE_INTEGER lfreq; void InitCPUTicks() { - QueryPerformanceFrequency( &lfreq ); + QueryPerformanceFrequency(&lfreq); } u64 GetTickFrequency() { - return lfreq.QuadPart; + return lfreq.QuadPart; } u64 GetCPUTicks() { - LARGE_INTEGER count; - QueryPerformanceCounter( &count ); - return count.QuadPart; + LARGE_INTEGER count; + QueryPerformanceCounter(&count); + return count.QuadPart; } u64 GetPhysicalMemory() { - MEMORYSTATUSEX status; - status.dwLength = sizeof(status); - GlobalMemoryStatusEx(&status); - return status.ullTotalPhys; + MEMORYSTATUSEX status; + status.dwLength = sizeof(status); + GlobalMemoryStatusEx(&status); + return status.ullTotalPhys; } // Windows SDK 7 provides this but previous ones do not, so roll our own in those cases: #ifndef VER_SUITE_WH_SERVER -# define VER_SUITE_WH_SERVER 0x00008000 +#define VER_SUITE_WH_SERVER 0x00008000 #endif -typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); -typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); +typedef void(WINAPI *PGNSI)(LPSYSTEM_INFO); +typedef BOOL(WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); // Win 10 SDK #ifndef PRODUCT_CORE_N -# define PRODUCT_CORE_N 0x00000062 +#define PRODUCT_CORE_N 0x00000062 #endif #ifndef PRODUCT_CORE -# define PRODUCT_CORE 0x00000065 +#define PRODUCT_CORE 0x00000065 #endif #ifndef PRODUCT_PROFESSIONAL_WMC -# define PRODUCT_PROFESSIONAL_WMC 0x00000067 +#define PRODUCT_PROFESSIONAL_WMC 0x00000067 #endif #ifndef PRODUCT_EDUCATION -# define PRODUCT_EDUCATION 0x00000079 +#define PRODUCT_EDUCATION 0x00000079 #endif #ifndef PRODUCT_EDUCATION_N -# define PRODUCT_EDUCATION_N 0x0000007A +#define PRODUCT_EDUCATION_N 0x0000007A #endif #ifndef PRODUCT_ENTERPRISE_S -# define PRODUCT_ENTERPRISE_S 0x0000007D +#define PRODUCT_ENTERPRISE_S 0x0000007D #endif #ifndef PRODUCT_ENTERPRISE_S_N -# define PRODUCT_ENTERPRISE_S_N 0x0000007E +#define PRODUCT_ENTERPRISE_S_N 0x0000007E #endif // Calculates the Windows OS Version and install information, and returns it as a @@ -83,205 +83,261 @@ typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); // (Handy function borrowed from Microsoft's MSDN Online, and reformatted to use wxString.) wxString GetOSVersionString() { - wxString retval; + wxString retval; - OSVERSIONINFOEX osvi; - SYSTEM_INFO si; - PGNSI pGNSI; - PGPI pGPI; - BOOL bOsVersionInfoEx; - DWORD dwType; + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + PGNSI pGNSI; + PGPI pGPI; + BOOL bOsVersionInfoEx; + DWORD dwType; - memzero( si ); - memzero( osvi ); + memzero(si); + memzero(osvi); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) - return L"GetVersionEx Error!"; + if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi))) + return L"GetVersionEx Error!"; - // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. + // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. - pGNSI = (PGNSI) GetProcAddress( GetModuleHandle(L"kernel32.dll"), "GetNativeSystemInfo" ); - if(NULL != pGNSI) - pGNSI( &si ); - else - GetSystemInfo( &si ); + pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetNativeSystemInfo"); + if (NULL != pGNSI) + pGNSI(&si); + else + GetSystemInfo(&si); - if ( VER_PLATFORM_WIN32_NT!=osvi.dwPlatformId || osvi.dwMajorVersion <= 4 ) - return L"Unsupported Operating System!"; + if (VER_PLATFORM_WIN32_NT != osvi.dwPlatformId || osvi.dwMajorVersion <= 4) + return L"Unsupported Operating System!"; - retval += L"Microsoft "; + retval += L"Microsoft "; - // Test for the specific product. + // Test for the specific product. - if ( osvi.dwMajorVersion == 10 ) - { - if( osvi.dwMinorVersion == 0 ) - retval += ( osvi.wProductType == VER_NT_WORKSTATION ) ? L"Windows 10 " : L"Windows Server 2016 "; + if (osvi.dwMajorVersion == 10) { + if (osvi.dwMinorVersion == 0) + retval += (osvi.wProductType == VER_NT_WORKSTATION) ? L"Windows 10 " : L"Windows Server 2016 "; - pGPI = (PGPI) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo"); + pGPI = (PGPI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo"); - pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType); + pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType); - switch( dwType ) - { - case PRODUCT_CORE: retval += L"Home"; break; - case PRODUCT_CORE_N: retval += L"Home N"; break; - case PRODUCT_PROFESSIONAL: retval += L"Pro"; break; - case PRODUCT_PROFESSIONAL_N: retval += L"Pro N"; break; - case PRODUCT_ENTERPRISE: retval += L"Enterprise"; break; - case PRODUCT_ENTERPRISE_N: retval += L"Enterprise N"; break; - case PRODUCT_ENTERPRISE_S: retval += L"Enterprise 2015 LTSB"; break; - case PRODUCT_ENTERPRISE_S_N: retval += L"Enterprise 2015 LTSB N"; break; - case PRODUCT_EDUCATION: retval += L"Education"; break; - case PRODUCT_EDUCATION_N: retval += L"Education N"; break; - } - } + switch (dwType) { + case PRODUCT_CORE: + retval += L"Home"; + break; + case PRODUCT_CORE_N: + retval += L"Home N"; + break; + case PRODUCT_PROFESSIONAL: + retval += L"Pro"; + break; + case PRODUCT_PROFESSIONAL_N: + retval += L"Pro N"; + break; + case PRODUCT_ENTERPRISE: + retval += L"Enterprise"; + break; + case PRODUCT_ENTERPRISE_N: + retval += L"Enterprise N"; + break; + case PRODUCT_ENTERPRISE_S: + retval += L"Enterprise 2015 LTSB"; + break; + case PRODUCT_ENTERPRISE_S_N: + retval += L"Enterprise 2015 LTSB N"; + break; + case PRODUCT_EDUCATION: + retval += L"Education"; + break; + case PRODUCT_EDUCATION_N: + retval += L"Education N"; + break; + } + } - if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion > 1 ) - { - if ( osvi.dwMinorVersion == 2 ) - retval += ( osvi.wProductType == VER_NT_WORKSTATION ) ? L"Windows 8 " : L"Windows Server 2012 "; + if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion > 1) { + if (osvi.dwMinorVersion == 2) + retval += (osvi.wProductType == VER_NT_WORKSTATION) ? L"Windows 8 " : L"Windows Server 2012 "; - if ( osvi.dwMinorVersion == 3 ) - retval += ( osvi.wProductType == VER_NT_WORKSTATION ) ? L"Windows 8.1 " : L"Windows Server 2012 R2 "; + if (osvi.dwMinorVersion == 3) + retval += (osvi.wProductType == VER_NT_WORKSTATION) ? L"Windows 8.1 " : L"Windows Server 2012 R2 "; - pGPI = (PGPI) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo"); + pGPI = (PGPI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo"); - pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType); + pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType); - switch( dwType ) - { - case PRODUCT_PROFESSIONAL: retval += L"Pro"; break; - case PRODUCT_PROFESSIONAL_N: retval += L"Pro N"; break; - case PRODUCT_PROFESSIONAL_WMC: retval += L"Pro with Media Center"; break; - case PRODUCT_ENTERPRISE: retval += L"Enterprise"; break; - case PRODUCT_ENTERPRISE_N: retval += L"Enterprise N"; break; - case PRODUCT_SERVER_FOUNDATION: retval += L"Foundation"; break; - case PRODUCT_STANDARD_SERVER: retval += L"Standard"; break; - case PRODUCT_STANDARD_SERVER_CORE: retval += L"Standard (core)"; break; - case PRODUCT_DATACENTER_SERVER: retval += L"Datacenter"; break; - case PRODUCT_DATACENTER_SERVER_CORE: retval += L"Datacenter (core)"; break; - } - } + switch (dwType) { + case PRODUCT_PROFESSIONAL: + retval += L"Pro"; + break; + case PRODUCT_PROFESSIONAL_N: + retval += L"Pro N"; + break; + case PRODUCT_PROFESSIONAL_WMC: + retval += L"Pro with Media Center"; + break; + case PRODUCT_ENTERPRISE: + retval += L"Enterprise"; + break; + case PRODUCT_ENTERPRISE_N: + retval += L"Enterprise N"; + break; + case PRODUCT_SERVER_FOUNDATION: + retval += L"Foundation"; + break; + case PRODUCT_STANDARD_SERVER: + retval += L"Standard"; + break; + case PRODUCT_STANDARD_SERVER_CORE: + retval += L"Standard (core)"; + break; + case PRODUCT_DATACENTER_SERVER: + retval += L"Datacenter"; + break; + case PRODUCT_DATACENTER_SERVER_CORE: + retval += L"Datacenter (core)"; + break; + } + } - if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion <= 1 ) - { - if( osvi.dwMinorVersion == 0 ) - retval += ( osvi.wProductType == VER_NT_WORKSTATION ) ? L"Windows Vista " : L"Windows Server 2008 "; + if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion <= 1) { + if (osvi.dwMinorVersion == 0) + retval += (osvi.wProductType == VER_NT_WORKSTATION) ? L"Windows Vista " : L"Windows Server 2008 "; - if ( osvi.dwMinorVersion == 1 ) - retval += ( osvi.wProductType == VER_NT_WORKSTATION ) ? L"Windows 7 " : L"Windows Server 2008 R2 "; + if (osvi.dwMinorVersion == 1) + retval += (osvi.wProductType == VER_NT_WORKSTATION) ? L"Windows 7 " : L"Windows Server 2008 R2 "; - pGPI = (PGPI) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo"); + pGPI = (PGPI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo"); - pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType); + pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType); - switch( dwType ) - { - case PRODUCT_ULTIMATE: retval += L"Ultimate Edition"; break; - case PRODUCT_HOME_PREMIUM: retval += L"Home Premium Edition"; break; - case PRODUCT_HOME_BASIC: retval += L"Home Basic Edition"; break; - case PRODUCT_ENTERPRISE: retval += L"Enterprise Edition"; break; - case PRODUCT_BUSINESS: retval += L"Business Edition"; break; - case PRODUCT_STARTER: retval += L"Starter Edition"; break; - case PRODUCT_CLUSTER_SERVER: retval += L"Cluster Server Edition"; break; - case PRODUCT_DATACENTER_SERVER: retval += L"Datacenter Edition"; break; - case PRODUCT_DATACENTER_SERVER_CORE: retval += L"Datacenter Edition (core installation)"; break; - case PRODUCT_ENTERPRISE_SERVER: retval += L"Enterprise Edition"; break; - case PRODUCT_ENTERPRISE_SERVER_CORE: retval += L"Enterprise Edition (core installation)"; break; - case PRODUCT_SMALLBUSINESS_SERVER: retval += L"Small Business Server"; break; - case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM: retval += L"Small Business Server Premium Edition"; break; - case PRODUCT_STANDARD_SERVER: retval += L"Standard Edition"; break; - case PRODUCT_STANDARD_SERVER_CORE: retval += L"Standard Edition (core installation)"; break; - case PRODUCT_WEB_SERVER: retval += L"Web Server Edition"; break; - } - } + switch (dwType) { + case PRODUCT_ULTIMATE: + retval += L"Ultimate Edition"; + break; + case PRODUCT_HOME_PREMIUM: + retval += L"Home Premium Edition"; + break; + case PRODUCT_HOME_BASIC: + retval += L"Home Basic Edition"; + break; + case PRODUCT_ENTERPRISE: + retval += L"Enterprise Edition"; + break; + case PRODUCT_BUSINESS: + retval += L"Business Edition"; + break; + case PRODUCT_STARTER: + retval += L"Starter Edition"; + break; + case PRODUCT_CLUSTER_SERVER: + retval += L"Cluster Server Edition"; + break; + case PRODUCT_DATACENTER_SERVER: + retval += L"Datacenter Edition"; + break; + case PRODUCT_DATACENTER_SERVER_CORE: + retval += L"Datacenter Edition (core installation)"; + break; + case PRODUCT_ENTERPRISE_SERVER: + retval += L"Enterprise Edition"; + break; + case PRODUCT_ENTERPRISE_SERVER_CORE: + retval += L"Enterprise Edition (core installation)"; + break; + case PRODUCT_SMALLBUSINESS_SERVER: + retval += L"Small Business Server"; + break; + case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM: + retval += L"Small Business Server Premium Edition"; + break; + case PRODUCT_STANDARD_SERVER: + retval += L"Standard Edition"; + break; + case PRODUCT_STANDARD_SERVER_CORE: + retval += L"Standard Edition (core installation)"; + break; + case PRODUCT_WEB_SERVER: + retval += L"Web Server Edition"; + break; + } + } - if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) - { - if( GetSystemMetrics(SM_SERVERR2) ) - retval += L"Windows Server 2003 R2, "; - else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER ) - retval += L"Windows Storage Server 2003"; - else if ( osvi.wSuiteMask==VER_SUITE_WH_SERVER ) - retval += L"Windows Home Server"; - else if( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) - retval += L"Windows XP Professional x64 Edition"; - else - retval += L"Windows Server 2003, "; + if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) { + if (GetSystemMetrics(SM_SERVERR2)) + retval += L"Windows Server 2003 R2, "; + else if (osvi.wSuiteMask == VER_SUITE_STORAGE_SERVER) + retval += L"Windows Storage Server 2003"; + else if (osvi.wSuiteMask == VER_SUITE_WH_SERVER) + retval += L"Windows Home Server"; + else if (osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) + retval += L"Windows XP Professional x64 Edition"; + else + retval += L"Windows Server 2003, "; - // Test for the server type. - if ( osvi.wProductType != VER_NT_WORKSTATION ) - { - if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) - { - if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) - retval += L"Datacenter x64 Edition"; - else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) - retval += L"Enterprise x64 Edition"; - else - retval += L"Standard x64 Edition"; - } + // Test for the server type. + if (osvi.wProductType != VER_NT_WORKSTATION) { + if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { + if (osvi.wSuiteMask & VER_SUITE_DATACENTER) + retval += L"Datacenter x64 Edition"; + else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) + retval += L"Enterprise x64 Edition"; + else + retval += L"Standard x64 Edition"; + } - else - { - if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER ) - retval += L"Compute Cluster Edition"; - else if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) - retval += L"Datacenter Edition"; - else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) - retval += L"Enterprise Edition"; - else if ( osvi.wSuiteMask & VER_SUITE_BLADE ) - retval += L"Web Edition"; - else - retval += L"Standard Edition"; - } - } - } + else { + if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER) + retval += L"Compute Cluster Edition"; + else if (osvi.wSuiteMask & VER_SUITE_DATACENTER) + retval += L"Datacenter Edition"; + else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) + retval += L"Enterprise Edition"; + else if (osvi.wSuiteMask & VER_SUITE_BLADE) + retval += L"Web Edition"; + else + retval += L"Standard Edition"; + } + } + } - if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) - { - retval += L"Windows XP "; - retval += ( osvi.wSuiteMask & VER_SUITE_PERSONAL ) ? L"Home Edition" : L"Professional"; - } + if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) { + retval += L"Windows XP "; + retval += (osvi.wSuiteMask & VER_SUITE_PERSONAL) ? L"Home Edition" : L"Professional"; + } - if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) - { - retval += L"Windows 2000 "; + if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) { + retval += L"Windows 2000 "; - if ( osvi.wProductType == VER_NT_WORKSTATION ) - { - retval += L"Professional"; - } - else - { - if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) - retval += L"Datacenter Server"; - else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) - retval += L"Advanced Server"; - else - retval += L"Server"; - } - } + if (osvi.wProductType == VER_NT_WORKSTATION) { + retval += L"Professional"; + } else { + if (osvi.wSuiteMask & VER_SUITE_DATACENTER) + retval += L"Datacenter Server"; + else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) + retval += L"Advanced Server"; + else + retval += L"Server"; + } + } - // Include service pack (if any) and build number. + // Include service pack (if any) and build number. - if( _tcslen(osvi.szCSDVersion) > 0 ) - retval += (wxString)L" " + osvi.szCSDVersion; + if (_tcslen(osvi.szCSDVersion) > 0) + retval += (wxString)L" " + osvi.szCSDVersion; - retval += wxsFormat( L" (build %d)", osvi.dwBuildNumber ); + retval += wxsFormat(L" (build %d)", osvi.dwBuildNumber); - if ( osvi.dwMajorVersion >= 6 ) - { - if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) - retval += L", 64-bit"; - else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL ) - retval += L", 32-bit"; - } + if (osvi.dwMajorVersion >= 6) { + if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) + retval += L", 64-bit"; + else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) + retval += L", 32-bit"; + } - return retval; + return retval; } // -------------------------------------------------------------------------------------- @@ -289,36 +345,37 @@ wxString GetOSVersionString() // -------------------------------------------------------------------------------------- Exception::WinApiError::WinApiError() { - ErrorId = GetLastError(); - m_message_diag = L"Unspecified Windows API error."; + ErrorId = GetLastError(); + m_message_diag = L"Unspecified Windows API error."; } wxString Exception::WinApiError::GetMsgFromWindows() const { - if (!ErrorId) return L"No valid error number was assigned to this exception!"; + if (!ErrorId) + return L"No valid error number was assigned to this exception!"; - const DWORD BUF_LEN = 2048; - TCHAR t_Msg[BUF_LEN]; - if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrorId, 0, t_Msg, BUF_LEN, 0)) - return wxsFormat( L"Win32 Error #%d: %s", ErrorId, t_Msg ); + const DWORD BUF_LEN = 2048; + TCHAR t_Msg[BUF_LEN]; + if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrorId, 0, t_Msg, BUF_LEN, 0)) + return wxsFormat(L"Win32 Error #%d: %s", ErrorId, t_Msg); - return wxsFormat( L"Win32 Error #%d (no text msg available)", ErrorId ); + return wxsFormat(L"Win32 Error #%d (no text msg available)", ErrorId); } wxString Exception::WinApiError::FormatDisplayMessage() const { - return m_message_user + L"\n\n" + GetMsgFromWindows(); + return m_message_user + L"\n\n" + GetMsgFromWindows(); } wxString Exception::WinApiError::FormatDiagnosticMessage() const { - return m_message_diag + L"\n\t" + GetMsgFromWindows(); + return m_message_diag + L"\n\t" + GetMsgFromWindows(); } void ScreensaverAllow(bool allow) { - EXECUTION_STATE flags = ES_CONTINUOUS; - if (!allow) - flags |= ES_DISPLAY_REQUIRED; - SetThreadExecutionState(flags); + EXECUTION_STATE flags = ES_CONTINUOUS; + if (!allow) + flags |= ES_DISPLAY_REQUIRED; + SetThreadExecutionState(flags); } diff --git a/common/src/Utilities/Windows/WinThreads.cpp b/common/src/Utilities/Windows/WinThreads.cpp index 5073cbcbfb..5e63d5375e 100644 --- a/common/src/Utilities/Windows/WinThreads.cpp +++ b/common/src/Utilities/Windows/WinThreads.cpp @@ -20,121 +20,122 @@ #ifndef __WXMSW__ -# pragma message( "WinThreads.cpp should only be compiled by projects or makefiles targeted at Microsoft Windows.") +#pragma message("WinThreads.cpp should only be compiled by projects or makefiles targeted at Microsoft Windows.") #else -__fi void Threading::Sleep( int ms ) +__fi void Threading::Sleep(int ms) { - ::Sleep( ms ); + ::Sleep(ms); } // For use in spin/wait loops, Acts as a hint to Intel CPUs and should, in theory // improve performance and reduce cpu power consumption. __fi void Threading::SpinWait() { - _mm_pause(); + _mm_pause(); } __fi void Threading::EnableHiresScheduler() { - // This improves accuracy of Sleep() by some amount, and only adds a negligible amount of - // overhead on modern CPUs. Typically desktops are already set pretty low, but laptops in - // particular may have a scheduler Period of 15 or 20ms to extend battery life. + // This improves accuracy of Sleep() by some amount, and only adds a negligible amount of + // overhead on modern CPUs. Typically desktops are already set pretty low, but laptops in + // particular may have a scheduler Period of 15 or 20ms to extend battery life. - // (note: this same trick is used by most multimedia software and games) + // (note: this same trick is used by most multimedia software and games) - timeBeginPeriod( 1 ); + timeBeginPeriod(1); } __fi void Threading::DisableHiresScheduler() { - timeEndPeriod( 1 ); + timeEndPeriod(1); } // This hacky union would probably fail on some cpu platforms if the contents of FILETIME aren't // packed (but for any x86 CPU and microsoft compiler, they will be). union FileTimeSucks { - FILETIME filetime; - u64 u64time; + FILETIME filetime; + u64 u64time; }; u64 Threading::GetThreadCpuTime() { - FileTimeSucks user, kernel; - FILETIME dummy; - GetThreadTimes( GetCurrentThread(), &dummy, &dummy, &kernel.filetime, &user.filetime ); - return user.u64time + kernel.u64time; + FileTimeSucks user, kernel; + FILETIME dummy; + GetThreadTimes(GetCurrentThread(), &dummy, &dummy, &kernel.filetime, &user.filetime); + return user.u64time + kernel.u64time; } u64 Threading::GetThreadTicksPerSecond() { - return 10000000; + return 10000000; } u64 Threading::pxThread::GetCpuTime() const { - if (!m_native_handle) return 0; + if (!m_native_handle) + return 0; - FileTimeSucks user, kernel; - FILETIME dummy; + FileTimeSucks user, kernel; + FILETIME dummy; - if( GetThreadTimes( (HANDLE)m_native_handle, &dummy, &dummy, &kernel.filetime, &user.filetime ) ) - return user.u64time + kernel.u64time; + if (GetThreadTimes((HANDLE)m_native_handle, &dummy, &dummy, &kernel.filetime, &user.filetime)) + return user.u64time + kernel.u64time; - return 0; // thread prolly doesn't exist anymore. + return 0; // thread prolly doesn't exist anymore. } void Threading::pxThread::_platform_specific_OnStartInThread() { - // OpenThread Note: Vista and Win7 need only THREAD_QUERY_LIMITED_INFORMATION (XP and 2k need more), - // however we own our process threads, so shouldn't matter in any case... + // OpenThread Note: Vista and Win7 need only THREAD_QUERY_LIMITED_INFORMATION (XP and 2k need more), + // however we own our process threads, so shouldn't matter in any case... - m_native_id = (uptr)GetCurrentThreadId(); - m_native_handle = (uptr)OpenThread( THREAD_QUERY_INFORMATION, false, (DWORD)m_native_id ); + m_native_id = (uptr)GetCurrentThreadId(); + m_native_handle = (uptr)OpenThread(THREAD_QUERY_INFORMATION, false, (DWORD)m_native_id); - pxAssertDev( m_native_handle, wxNullChar ); + pxAssertDev(m_native_handle, wxNullChar); } void Threading::pxThread::_platform_specific_OnCleanupInThread() { - CloseHandle( (HANDLE)m_native_handle ); + CloseHandle((HANDLE)m_native_handle); } -void Threading::pxThread::_DoSetThreadName( const char* name ) +void Threading::pxThread::_DoSetThreadName(const char *name) { - // This feature needs Windows headers and MSVC's SEH support: +// This feature needs Windows headers and MSVC's SEH support: #if defined(_WIN32) && defined(_MSC_VER) - // This code sample was borrowed form some obscure MSDN article. - // In a rare bout of sanity, it's an actual Microsoft-published hack - // that actually works! + // This code sample was borrowed form some obscure MSDN article. + // In a rare bout of sanity, it's an actual Microsoft-published hack + // that actually works! - static const int MS_VC_EXCEPTION = 0x406D1388; + static const int MS_VC_EXCEPTION = 0x406D1388; - #pragma pack(push,8) - struct THREADNAME_INFO - { - DWORD dwType; // Must be 0x1000. - LPCSTR szName; // Pointer to name (in user addr space). - DWORD dwThreadID; // Thread ID (-1=caller thread). - DWORD dwFlags; // Reserved for future use, must be zero. - }; - #pragma pack(pop) +#pragma pack(push, 8) + struct THREADNAME_INFO + { + DWORD dwType; // Must be 0x1000. + LPCSTR szName; // Pointer to name (in user addr space). + DWORD dwThreadID; // Thread ID (-1=caller thread). + DWORD dwFlags; // Reserved for future use, must be zero. + }; +#pragma pack(pop) - THREADNAME_INFO info; - info.dwType = 0x1000; - info.szName = name; - info.dwThreadID = GetCurrentThreadId(); - info.dwFlags = 0; + THREADNAME_INFO info; + info.dwType = 0x1000; + info.szName = name; + info.dwThreadID = GetCurrentThreadId(); + info.dwFlags = 0; - __try { - RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); - } __except(EXCEPTION_EXECUTE_HANDLER) { } + __try { + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info); + } __except (EXCEPTION_EXECUTE_HANDLER) { + } #endif } #endif - diff --git a/common/src/Utilities/pxCheckBox.cpp b/common/src/Utilities/pxCheckBox.cpp index 98888e7ed2..3b15a3268f 100644 --- a/common/src/Utilities/pxCheckBox.cpp +++ b/common/src/Utilities/pxCheckBox.cpp @@ -23,116 +23,115 @@ using namespace pxSizerFlags; // pxCheckBox Implementations // -------------------------------------------------------------------------------------- -pxCheckBox::pxCheckBox(wxWindow* parent, const wxString& label, const wxString& subtext, int flags) - : wxPanelWithHelpers( parent, wxVERTICAL ) +pxCheckBox::pxCheckBox(wxWindow *parent, const wxString &label, const wxString &subtext, int flags) + : wxPanelWithHelpers(parent, wxVERTICAL) { - Init( label, subtext, flags ); + Init(label, subtext, flags); } -pxCheckBox::pxCheckBox(wxWindow* parent, const wxString& label, int flags) - : wxPanelWithHelpers( parent, wxVERTICAL ) +pxCheckBox::pxCheckBox(wxWindow *parent, const wxString &label, int flags) + : wxPanelWithHelpers(parent, wxVERTICAL) { - Init( label, wxEmptyString, flags ); + Init(label, wxEmptyString, flags); } -void pxCheckBox::Init(const wxString& label, const wxString& subtext, int flags) +void pxCheckBox::Init(const wxString &label, const wxString &subtext, int flags) { - m_subtext = NULL; - m_subPadding= StdPadding*2; - m_checkbox = new wxCheckBox( this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize, flags ); + m_subtext = NULL; + m_subPadding = StdPadding * 2; + m_checkbox = new wxCheckBox(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize, flags); - *this += m_checkbox | pxSizerFlags::StdExpand(); + *this += m_checkbox | pxSizerFlags::StdExpand(); - static const int Indentation = 23; - if( !subtext.IsEmpty() ) - { - m_subtext = new pxStaticText( this, subtext, wxALIGN_LEFT ); + static const int Indentation = 23; + if (!subtext.IsEmpty()) { + m_subtext = new pxStaticText(this, subtext, wxALIGN_LEFT); - wxFlexGridSizer& spaced( *new wxFlexGridSizer(3) ); - spaced.AddGrowableCol( 1 ); - spaced += Indentation; - m_sizerItem_subtext = spaced.Add( m_subtext, pxBorder( wxBOTTOM, m_subPadding ).Expand() ); - //spaced += pxSizerFlags::StdPadding; + wxFlexGridSizer &spaced(*new wxFlexGridSizer(3)); + spaced.AddGrowableCol(1); + spaced += Indentation; + m_sizerItem_subtext = spaced.Add(m_subtext, pxBorder(wxBOTTOM, m_subPadding).Expand()); + //spaced += pxSizerFlags::StdPadding; - *this += &spaced | pxExpand; - } - - Bind(wxEVT_CHECKBOX, &pxCheckBox::OnCheckpartCommand, this, m_checkbox->GetId()); + *this += &spaced | pxExpand; + } + + Bind(wxEVT_CHECKBOX, &pxCheckBox::OnCheckpartCommand, this, m_checkbox->GetId()); } -pxCheckBox& pxCheckBox::SetSubPadding( int pad ) +pxCheckBox &pxCheckBox::SetSubPadding(int pad) { - m_subPadding = pad; - if( m_sizerItem_subtext ) - { - m_sizerItem_subtext->SetBorder( m_subPadding ); - Fit(); - } - return *this; + m_subPadding = pad; + if (m_sizerItem_subtext) { + m_sizerItem_subtext->SetBorder(m_subPadding); + Fit(); + } + return *this; } // applies the tooltip to both both the checkbox and it's static subtext (if present), and // performs word wrapping on platforms that need it (eg mswindows). -pxCheckBox& pxCheckBox::SetToolTip( const wxString& tip ) +pxCheckBox &pxCheckBox::SetToolTip(const wxString &tip) { - pxSetToolTip( m_checkbox, tip ); - pxSetToolTip( m_subtext, tip ); - return *this; + pxSetToolTip(m_checkbox, tip); + pxSetToolTip(m_subtext, tip); + return *this; } -pxCheckBox& pxCheckBox::SetValue( bool val ) +pxCheckBox &pxCheckBox::SetValue(bool val) { - pxAssert( m_checkbox ); - m_checkbox->SetValue( val ); - return *this; + pxAssert(m_checkbox); + m_checkbox->SetValue(val); + return *this; } -pxCheckBox& pxCheckBox::SetIndeterminate() +pxCheckBox &pxCheckBox::SetIndeterminate() { - pxAssert( m_checkbox ); - m_checkbox->Set3StateValue( wxCHK_UNDETERMINED ); - return *this; + pxAssert(m_checkbox); + m_checkbox->Set3StateValue(wxCHK_UNDETERMINED); + return *this; } -pxCheckBox& pxCheckBox::SetState( wxCheckBoxState state ) +pxCheckBox &pxCheckBox::SetState(wxCheckBoxState state) { - pxAssert( m_checkbox ); - m_checkbox->Set3StateValue( state ); - return *this; + pxAssert(m_checkbox); + m_checkbox->Set3StateValue(state); + return *this; } // Forwards checkbox actions on the internal checkbox (called 'checkpart') to listeners // bound to the pxCheckBox "parent" panel. This helps the pxCheckBox behave more like a // traditional checkbox. -void pxCheckBox::OnCheckpartCommand( wxCommandEvent& evt ) +void pxCheckBox::OnCheckpartCommand(wxCommandEvent &evt) { - evt.Skip(); - - wxCommandEvent newevt( evt ); - newevt.SetEventObject( this ); - newevt.SetId( GetId() ); - GetEventHandler()->ProcessEvent( newevt ); + evt.Skip(); + + wxCommandEvent newevt(evt); + newevt.SetEventObject(this); + newevt.SetId(GetId()); + GetEventHandler()->ProcessEvent(newevt); } -void pxCheckBox::OnSubtextClicked( wxCommandEvent& evt ) +void pxCheckBox::OnSubtextClicked(wxCommandEvent &evt) { - // TODO? - // We can enable the ability to allow clicks on the subtext desc/label to toggle - // the checkmark. Not sure if that's desirable. + // TODO? + // We can enable the ability to allow clicks on the subtext desc/label to toggle + // the checkmark. Not sure if that's desirable. } -void operator+=( wxSizer& target, pxCheckBox* src ) +void operator+=(wxSizer &target, pxCheckBox *src) { - if( src ) target.Add( src, pxExpand ); + if (src) + target.Add(src, pxExpand); } -void operator+=( wxSizer& target, pxCheckBox& src ) +void operator+=(wxSizer &target, pxCheckBox &src) { - target.Add( &src, pxExpand ); + target.Add(&src, pxExpand); } -void operator+=( wxSizer* target, pxCheckBox& src ) +void operator+=(wxSizer *target, pxCheckBox &src) { - target->Add( &src, pxExpand ); + target->Add(&src, pxExpand); } diff --git a/common/src/Utilities/pxRadioPanel.cpp b/common/src/Utilities/pxRadioPanel.cpp index 16e8e93171..0a880dae3c 100644 --- a/common/src/Utilities/pxRadioPanel.cpp +++ b/common/src/Utilities/pxRadioPanel.cpp @@ -26,225 +26,232 @@ template class SafeArray; // =========================================================================================== #define VerifyRealizedState() \ - pxAssertDev( m_IsRealized, "Invalid object state: RadioButtonGroup as not been realized." ) + pxAssertDev(m_IsRealized, "Invalid object state: RadioButtonGroup as not been realized.") -void pxRadioPanel::Init( const RadioPanelItem* srcArray, int arrsize ) +void pxRadioPanel::Init(const RadioPanelItem *srcArray, int arrsize) { - m_DefaultIdx = -1; - m_IsRealized = false; + m_DefaultIdx = -1; + m_IsRealized = false; - // FIXME: This probably needs to be platform-dependent, and/or based on font size. - m_Indentation = 23; + // FIXME: This probably needs to be platform-dependent, and/or based on font size. + m_Indentation = 23; - for( int i=0; iSetToolTip(tip); + if (wxRadioButton *woot = m_objects[idx].LabelObj) + woot->SetToolTip(tip); - if( pxStaticText* woot = m_objects[idx].SubTextObj ) - woot->SetToolTip(tip); + if (pxStaticText *woot = m_objects[idx].SubTextObj) + woot->SetToolTip(tip); } // The SetToolTip API provided by this function applies the tooltip to both the radio // button and it's static subtext (if present), and performs word wrapping on platforms // that need it (eg mswindows). -pxRadioPanel& pxRadioPanel::SetToolTip(int idx, const wxString &tip) +pxRadioPanel &pxRadioPanel::SetToolTip(int idx, const wxString &tip) { - m_buttonStrings[idx].SetToolTip( tip ); + m_buttonStrings[idx].SetToolTip(tip); - if( m_IsRealized ) - _setToolTipImmediate( idx, tip ); + if (m_IsRealized) + _setToolTipImmediate(idx, tip); - return *this; + return *this; } -pxRadioPanel& pxRadioPanel::SetSelection( int idx ) +pxRadioPanel &pxRadioPanel::SetSelection(int idx) { - if( !VerifyRealizedState() ) return *this; + if (!VerifyRealizedState()) + return *this; - pxAssert( m_objects[idx].LabelObj != NULL ); - m_objects[idx].LabelObj->SetValue( true ); - return *this; + pxAssert(m_objects[idx].LabelObj != NULL); + m_objects[idx].LabelObj->SetValue(true); + return *this; } void pxRadioPanel::_RealizeDefaultOption() { - if( m_IsRealized && m_DefaultIdx != -1 ) - { - wxFont def( GetFont() ); - def.SetWeight( wxFONTWEIGHT_BOLD ); - //def.SetStyle( wxFONTSTYLE_ITALIC ); - m_objects[m_DefaultIdx].LabelObj->SetFont( def ); - m_objects[m_DefaultIdx].LabelObj->SetForegroundColour( wxColour( 20, 128, 40 ) ); - } + if (m_IsRealized && m_DefaultIdx != -1) { + wxFont def(GetFont()); + def.SetWeight(wxFONTWEIGHT_BOLD); + //def.SetStyle( wxFONTSTYLE_ITALIC ); + m_objects[m_DefaultIdx].LabelObj->SetFont(def); + m_objects[m_DefaultIdx].LabelObj->SetForegroundColour(wxColour(20, 128, 40)); + } } // Highlights (bold) the text of the default radio. // Not intended for restoring default value at later time. -pxRadioPanel& pxRadioPanel::SetDefaultItem( int idx ) +pxRadioPanel &pxRadioPanel::SetDefaultItem(int idx) { - if( idx == m_DefaultIdx ) return *this; + if (idx == m_DefaultIdx) + return *this; - if( m_IsRealized && m_DefaultIdx != -1 ) - { - wxFont def(GetFont()); - m_objects[m_DefaultIdx].LabelObj->SetFont( def ); - m_objects[m_DefaultIdx].LabelObj->SetForegroundColour( GetForegroundColour() ); - } + if (m_IsRealized && m_DefaultIdx != -1) { + wxFont def(GetFont()); + m_objects[m_DefaultIdx].LabelObj->SetFont(def); + m_objects[m_DefaultIdx].LabelObj->SetForegroundColour(GetForegroundColour()); + } - m_DefaultIdx = idx; - _RealizeDefaultOption(); + m_DefaultIdx = idx; + _RealizeDefaultOption(); - return *this; + return *this; } -pxRadioPanel& pxRadioPanel::EnableItem( int idx, bool enable ) +pxRadioPanel &pxRadioPanel::EnableItem(int idx, bool enable) { - pxAssertDev( m_IsRealized, "RadioPanel must be realized first, prior to enabling or disabling individual items." ); + pxAssertDev(m_IsRealized, "RadioPanel must be realized first, prior to enabling or disabling individual items."); - if( m_objects[idx].LabelObj ) - m_objects[idx].LabelObj->Enable( enable ); + if (m_objects[idx].LabelObj) + m_objects[idx].LabelObj->Enable(enable); - if( m_objects[idx].SubTextObj ) - m_objects[idx].SubTextObj->Enable( enable ); + if (m_objects[idx].SubTextObj) + m_objects[idx].SubTextObj->Enable(enable); - return *this; + return *this; } -const RadioPanelItem& pxRadioPanel::Item(int idx) const +const RadioPanelItem &pxRadioPanel::Item(int idx) const { - return m_buttonStrings[idx]; + return m_buttonStrings[idx]; } -RadioPanelItem& pxRadioPanel::Item(int idx) +RadioPanelItem &pxRadioPanel::Item(int idx) { - return m_buttonStrings[idx]; + return m_buttonStrings[idx]; } int pxRadioPanel::GetSelection() const { - if( !VerifyRealizedState() ) return 0; + if (!VerifyRealizedState()) + return 0; - for( uint i=0; iGetValue() ) return i; - } + for (uint i = 0; i < m_buttonStrings.size(); ++i) { + if (wxRadioButton *woot = m_objects[i].LabelObj) + if (woot->GetValue()) + return i; + } - // Technically radio buttons should never allow for a case where none are selected. - // However it *can* happen on some platforms if the program code doesn't explicitly - // select one of the members of the group (which is, as far as I'm concerned, a - // programmer error!). so Assert here in such cases, and return 0 as the assumed - // default, so that calling code has a "valid" return code in release builds. + // Technically radio buttons should never allow for a case where none are selected. + // However it *can* happen on some platforms if the program code doesn't explicitly + // select one of the members of the group (which is, as far as I'm concerned, a + // programmer error!). so Assert here in such cases, and return 0 as the assumed + // default, so that calling code has a "valid" return code in release builds. - pxFailDev( "No valid selection was found in this group!" ); - return 0; + pxFailDev("No valid selection was found in this group!"); + return 0; } // Returns the wxWindowID for the currently selected radio button. wxWindowID pxRadioPanel::GetSelectionId() const { - if( !VerifyRealizedState() ) return 0; - return m_objects[GetSelection()].LabelObj->GetId(); + if (!VerifyRealizedState()) + return 0; + return m_objects[GetSelection()].LabelObj->GetId(); } -bool pxRadioPanel::IsSelected( int idx ) const +bool pxRadioPanel::IsSelected(int idx) const { - if( !VerifyRealizedState() ) return false; - pxAssert( m_objects[idx].LabelObj != NULL ); - return m_objects[idx].LabelObj->GetValue(); + if (!VerifyRealizedState()) + return false; + pxAssert(m_objects[idx].LabelObj != NULL); + return m_objects[idx].LabelObj->GetValue(); } -pxStaticText* pxRadioPanel::GetSubText( int idx ) +pxStaticText *pxRadioPanel::GetSubText(int idx) { - if( !VerifyRealizedState() ) return NULL; - return m_objects[idx].SubTextObj; + if (!VerifyRealizedState()) + return NULL; + return m_objects[idx].SubTextObj; } -const pxStaticText* pxRadioPanel::GetSubText( int idx ) const +const pxStaticText *pxRadioPanel::GetSubText(int idx) const { - if( !VerifyRealizedState() ) return NULL; - return m_objects[idx].SubTextObj; + if (!VerifyRealizedState()) + return NULL; + return m_objects[idx].SubTextObj; } -wxRadioButton* pxRadioPanel::GetButton( int idx ) +wxRadioButton *pxRadioPanel::GetButton(int idx) { - if( !VerifyRealizedState() ) return NULL; - return m_objects[idx].LabelObj; + if (!VerifyRealizedState()) + return NULL; + return m_objects[idx].LabelObj; } -const wxRadioButton* pxRadioPanel::GetButton( int idx ) const +const wxRadioButton *pxRadioPanel::GetButton(int idx) const { - if( !VerifyRealizedState() ) return NULL; - return m_objects[idx].LabelObj; + if (!VerifyRealizedState()) + return NULL; + return m_objects[idx].LabelObj; } diff --git a/common/src/Utilities/pxStaticText.cpp b/common/src/Utilities/pxStaticText.cpp index ec45804b36..14d51da85a 100644 --- a/common/src/Utilities/pxStaticText.cpp +++ b/common/src/Utilities/pxStaticText.cpp @@ -20,33 +20,33 @@ // -------------------------------------------------------------------------------------- // pxStaticText (implementations) // -------------------------------------------------------------------------------------- -pxStaticText::pxStaticText( wxWindow* parent ) - : _parent( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER ) +pxStaticText::pxStaticText(wxWindow *parent) + : _parent(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER) { - m_align = wxALIGN_CENTRE_HORIZONTAL; - m_autowrap = true; - m_wrappedWidth = -1; - m_heightInLines = 1; + m_align = wxALIGN_CENTRE_HORIZONTAL; + m_autowrap = true; + m_wrappedWidth = -1; + m_heightInLines = 1; - SetPaddingDefaults(); + SetPaddingDefaults(); } -pxStaticText::pxStaticText( wxWindow* parent, const wxString& label, wxAlignment align ) - : _parent( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER ) +pxStaticText::pxStaticText(wxWindow *parent, const wxString &label, wxAlignment align) + : _parent(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER) { - m_heightInLines = 1; - m_align = align; + m_heightInLines = 1; + m_align = align; - SetPaddingDefaults(); - Init( label ); + SetPaddingDefaults(); + Init(label); } -void pxStaticText::Init( const wxString& label ) +void pxStaticText::Init(const wxString &label) { - m_autowrap = true; - m_wrappedWidth = -1; - m_label = label; - Bind(wxEVT_PAINT, &pxStaticText::paintEvent, this); + m_autowrap = true; + m_wrappedWidth = -1; + m_label = label; + Bind(wxEVT_PAINT, &pxStaticText::paintEvent, this); } // we need to refresh the window after changing its size as the standard @@ -54,293 +54,291 @@ void pxStaticText::Init( const wxString& label ) // the control is expanded to fit -- ie the control's size changes but the position does not) void pxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags) { - _parent::DoSetSize(x, y, w, h, sizeFlags); - Refresh(); + _parent::DoSetSize(x, y, w, h, sizeFlags); + Refresh(); } void pxStaticText::SetPaddingDefaults() { - m_paddingPix_horiz = 7; - m_paddingPix_vert = 1; + m_paddingPix_horiz = 7; + m_paddingPix_vert = 1; - m_paddingPct_horiz = 0.0f; - m_paddingPct_vert = 0.0f; + m_paddingPct_horiz = 0.0f; + m_paddingPct_vert = 0.0f; } -pxStaticText& pxStaticText::SetMinWidth( int width ) +pxStaticText &pxStaticText::SetMinWidth(int width) { - SetMinSize( wxSize( width, GetMinHeight() ) ); - return *this; + SetMinSize(wxSize(width, GetMinHeight())); + return *this; } -pxStaticText& pxStaticText::SetMinHeight( int height ) +pxStaticText &pxStaticText::SetMinHeight(int height) { - SetMinSize( wxSize( GetMinWidth(), height) ); - return *this; + SetMinSize(wxSize(GetMinWidth(), height)); + return *this; } -pxStaticText& pxStaticText::SetHeight( int lines ) +pxStaticText &pxStaticText::SetHeight(int lines) { - if( !pxAssert(lines > 0) ) lines = 2; - m_heightInLines = lines; + if (!pxAssert(lines > 0)) + lines = 2; + m_heightInLines = lines; - const int newHeight = (pxGetCharHeight(this)*m_heightInLines) + (m_paddingPix_vert*2); - SetMinSize( wxSize(GetMinWidth(), newHeight) ); + const int newHeight = (pxGetCharHeight(this) * m_heightInLines) + (m_paddingPix_vert * 2); + SetMinSize(wxSize(GetMinWidth(), newHeight)); - return *this; + return *this; } -pxStaticText& pxStaticText::Align( wxAlignment align ) +pxStaticText &pxStaticText::Align(wxAlignment align) { - m_align = align; - return *this; + m_align = align; + return *this; } -pxStaticText& pxStaticText::Bold() +pxStaticText &pxStaticText::Bold() { - wxFont bold( GetFont() ); - bold.SetWeight(wxFONTWEIGHT_BOLD); - SetFont( bold ); - return *this; + wxFont bold(GetFont()); + bold.SetWeight(wxFONTWEIGHT_BOLD); + SetFont(bold); + return *this; } -pxStaticText& pxStaticText::PaddingPixH( int pixels ) +pxStaticText &pxStaticText::PaddingPixH(int pixels) { - m_paddingPix_horiz = pixels; - UpdateWrapping( false ); - Refresh(); - return *this; + m_paddingPix_horiz = pixels; + UpdateWrapping(false); + Refresh(); + return *this; } -pxStaticText& pxStaticText::PaddingPixV( int pixels ) +pxStaticText &pxStaticText::PaddingPixV(int pixels) { - m_paddingPix_vert = pixels; - Refresh(); - return *this; + m_paddingPix_vert = pixels; + Refresh(); + return *this; } -pxStaticText& pxStaticText::PaddingPctH( float pct ) +pxStaticText &pxStaticText::PaddingPctH(float pct) { - pxAssert( pct < 0.5 ); + pxAssert(pct < 0.5); - m_paddingPct_horiz = pct; - UpdateWrapping( false ); - Refresh(); - return *this; + m_paddingPct_horiz = pct; + UpdateWrapping(false); + Refresh(); + return *this; } -pxStaticText& pxStaticText::PaddingPctV( float pct ) +pxStaticText &pxStaticText::PaddingPctV(float pct) { - pxAssert( pct < 0.5 ); + pxAssert(pct < 0.5); - m_paddingPct_vert = pct; - Refresh(); - return *this; + m_paddingPct_vert = pct; + Refresh(); + return *this; } -pxStaticText& pxStaticText::Unwrapped() +pxStaticText &pxStaticText::Unwrapped() { - m_autowrap = false; - UpdateWrapping( false ); - return *this; + m_autowrap = false; + UpdateWrapping(false); + return *this; } -int pxStaticText::calcPaddingWidth( int newWidth ) const +int pxStaticText::calcPaddingWidth(int newWidth) const { - return (int)(newWidth*m_paddingPct_horiz*2) + (m_paddingPix_horiz*2); + return (int)(newWidth * m_paddingPct_horiz * 2) + (m_paddingPix_horiz * 2); } -int pxStaticText::calcPaddingHeight( int newHeight ) const +int pxStaticText::calcPaddingHeight(int newHeight) const { - return (int)(newHeight*m_paddingPct_vert*2) + (m_paddingPix_vert*2); + return (int)(newHeight * m_paddingPct_vert * 2) + (m_paddingPix_vert * 2); } -wxSize pxStaticText::GetBestWrappedSize( const wxClientDC& dc ) const +wxSize pxStaticText::GetBestWrappedSize(const wxClientDC &dc) const { - pxAssert( m_autowrap ); + pxAssert(m_autowrap); - // Find an ideal(-ish) width, based on a search of all parent controls and their - // valid Minimum sizes. + // Find an ideal(-ish) width, based on a search of all parent controls and their + // valid Minimum sizes. - int idealWidth = wxDefaultCoord; - int parentalAdjust = 0; - double parentalFactor = 1.0; - const wxWindow* millrun = this; - - while( millrun ) - { - // IMPORTANT : wxWizard changes its min size and then expects everything else - // to play nice and NOT resize according to the new min size. (wtf stupid) - // Anyway, this fixes it -- ignore min size specifier on wxWizard! - if( wxIsKindOf( millrun, wxWizard ) ) break; + int idealWidth = wxDefaultCoord; + int parentalAdjust = 0; + double parentalFactor = 1.0; + const wxWindow *millrun = this; - int min = (int)((millrun->GetMinWidth() - parentalAdjust) * parentalFactor); + while (millrun) { + // IMPORTANT : wxWizard changes its min size and then expects everything else + // to play nice and NOT resize according to the new min size. (wtf stupid) + // Anyway, this fixes it -- ignore min size specifier on wxWizard! + if (wxIsKindOf(millrun, wxWizard)) + break; - if( min > 0 && ((idealWidth < 0 ) || (min < idealWidth)) ) - { - idealWidth = min; - } + int min = (int)((millrun->GetMinWidth() - parentalAdjust) * parentalFactor); - parentalAdjust += pxSizerFlags::StdPadding*2; - millrun = millrun->GetParent(); - } + if (min > 0 && ((idealWidth < 0) || (min < idealWidth))) { + idealWidth = min; + } - if( idealWidth <= 0 ) - { - // FIXME: The minimum size of this control is unknown, so let's just pick a guess based on - // the size of the user's display area. + parentalAdjust += pxSizerFlags::StdPadding * 2; + millrun = millrun->GetParent(); + } - idealWidth = (int)(wxGetDisplaySize().GetWidth() * 0.66) - (parentalAdjust*2); - } + if (idealWidth <= 0) { + // FIXME: The minimum size of this control is unknown, so let's just pick a guess based on + // the size of the user's display area. - return dc.GetMultiLineTextExtent(pxTextWrapper().Wrap( this, m_label, idealWidth - calcPaddingWidth(idealWidth) ).GetResult()); + idealWidth = (int)(wxGetDisplaySize().GetWidth() * 0.66) - (parentalAdjust * 2); + } + + return dc.GetMultiLineTextExtent(pxTextWrapper().Wrap(this, m_label, idealWidth - calcPaddingWidth(idealWidth)).GetResult()); } -pxStaticText& pxStaticText::WrapAt( int width ) +pxStaticText &pxStaticText::WrapAt(int width) { - m_autowrap = false; + m_autowrap = false; - if( (width <= 1) || (width == m_wrappedWidth) ) return *this; + if ((width <= 1) || (width == m_wrappedWidth)) + return *this; - wxString wrappedLabel; - m_wrappedWidth = width; + wxString wrappedLabel; + m_wrappedWidth = width; - if( width > 1 ) - wrappedLabel = pxTextWrapper().Wrap( this, m_label, width ).GetResult(); + if (width > 1) + wrappedLabel = pxTextWrapper().Wrap(this, m_label, width).GetResult(); - if(m_wrappedLabel != wrappedLabel ) - { - m_wrappedLabel = wrappedLabel; - wxSize area = wxClientDC( this ).GetMultiLineTextExtent(m_wrappedLabel); - SetMinSize( wxSize( - area.GetWidth() + calcPaddingWidth(area.GetWidth()), - area.GetHeight() + calcPaddingHeight(area.GetHeight()) - ) ); - } - return *this; + if (m_wrappedLabel != wrappedLabel) { + m_wrappedLabel = wrappedLabel; + wxSize area = wxClientDC(this).GetMultiLineTextExtent(m_wrappedLabel); + SetMinSize(wxSize( + area.GetWidth() + calcPaddingWidth(area.GetWidth()), + area.GetHeight() + calcPaddingHeight(area.GetHeight()))); + } + return *this; } -bool pxStaticText::_updateWrapping( bool textChanged ) +bool pxStaticText::_updateWrapping(bool textChanged) { - if( !m_autowrap ) - { - //m_wrappedLabel = wxEmptyString; - //m_wrappedWidth = -1; - return false; - } + if (!m_autowrap) { + //m_wrappedLabel = wxEmptyString; + //m_wrappedWidth = -1; + return false; + } - wxString wrappedLabel; - int newWidth = GetSize().GetWidth(); - newWidth -= (int)(newWidth*m_paddingPct_horiz*2) + (m_paddingPix_horiz*2); + wxString wrappedLabel; + int newWidth = GetSize().GetWidth(); + newWidth -= (int)(newWidth * m_paddingPct_horiz * 2) + (m_paddingPix_horiz * 2); - if( !textChanged && (newWidth == m_wrappedWidth) ) return false; + if (!textChanged && (newWidth == m_wrappedWidth)) + return false; - // Note: during various stages of sizer-calc, width can be 1, 0, or -1. - // We ignore wrapping in these cases. (the PaintEvent also checks the wrapping - // and updates it if needed, in case the control's size isn't figured out prior - // to being painted). - - m_wrappedWidth = newWidth; - if( m_wrappedWidth > 1 ) - wrappedLabel = pxTextWrapper().Wrap( this, m_label, m_wrappedWidth ).GetResult(); + // Note: during various stages of sizer-calc, width can be 1, 0, or -1. + // We ignore wrapping in these cases. (the PaintEvent also checks the wrapping + // and updates it if needed, in case the control's size isn't figured out prior + // to being painted). - if( m_wrappedLabel == wrappedLabel ) return false; - m_wrappedLabel = wrappedLabel; + m_wrappedWidth = newWidth; + if (m_wrappedWidth > 1) + wrappedLabel = pxTextWrapper().Wrap(this, m_label, m_wrappedWidth).GetResult(); - return true; + if (m_wrappedLabel == wrappedLabel) + return false; + m_wrappedLabel = wrappedLabel; + + return true; } -void pxStaticText::UpdateWrapping( bool textChanged ) +void pxStaticText::UpdateWrapping(bool textChanged) { - if( _updateWrapping( textChanged ) ) Refresh(); + if (_updateWrapping(textChanged)) + Refresh(); } -void pxStaticText::SetLabel(const wxString& label) +void pxStaticText::SetLabel(const wxString &label) { - const bool labelChanged( label != m_label ); - if( labelChanged ) - { - m_label = label; - Refresh(); - } + const bool labelChanged(label != m_label); + if (labelChanged) { + m_label = label; + Refresh(); + } - // Always update wrapping, in case window width or something else also changed. - UpdateWrapping( labelChanged ); - InvalidateBestSize(); + // Always update wrapping, in case window width or something else also changed. + UpdateWrapping(labelChanged); + InvalidateBestSize(); } wxFont pxStaticText::GetFontOk() const { - wxFont font( GetFont() ); - if( !font.Ok() ) return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); - return font; + wxFont font(GetFont()); + if (!font.Ok()) + return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + return font; } -bool pxStaticText::Enable( bool enabled ) +bool pxStaticText::Enable(bool enabled) { - if( _parent::Enable(enabled)) - { - Refresh(); - return true; - } - return false; + if (_parent::Enable(enabled)) { + Refresh(); + return true; + } + return false; } -void pxStaticText::paintEvent(wxPaintEvent& evt) +void pxStaticText::paintEvent(wxPaintEvent &evt) { - wxPaintDC dc( this ); - const int dcWidth = dc.GetSize().GetWidth(); - const int dcHeight = dc.GetSize().GetHeight(); - if( dcWidth < 1 ) return; - dc.SetFont( GetFontOk() ); - - if( IsEnabled() ) - dc.SetTextForeground(GetForegroundColour()); - else - dc.SetTextForeground(*wxLIGHT_GREY); + wxPaintDC dc(this); + const int dcWidth = dc.GetSize().GetWidth(); + const int dcHeight = dc.GetSize().GetHeight(); + if (dcWidth < 1) + return; + dc.SetFont(GetFontOk()); - pxWindowTextWriter writer( dc ); - writer.Align( m_align ); + if (IsEnabled()) + dc.SetTextForeground(GetForegroundColour()); + else + dc.SetTextForeground(*wxLIGHT_GREY); - const wxString& label( m_autowrap ? m_wrappedLabel : m_label ); - if( m_autowrap ) _updateWrapping( false ); + pxWindowTextWriter writer(dc); + writer.Align(m_align); - int tWidth, tHeight; - dc.GetMultiLineTextExtent( label, &tWidth, &tHeight ); - - writer.Align( m_align ); - if( m_align & wxALIGN_CENTER_VERTICAL ) - writer.SetY( (dcHeight - tHeight) / 2 ); - else - writer.SetY( (int)(dcHeight*m_paddingPct_vert) + m_paddingPix_vert ); - - writer.WriteLn( label ); // without formatting please. - - //dc.SetBrush( *wxTRANSPARENT_BRUSH ); - //dc.DrawRectangle(wxPoint(), dc.GetSize()); + const wxString &label(m_autowrap ? m_wrappedLabel : m_label); + if (m_autowrap) + _updateWrapping(false); + + int tWidth, tHeight; + dc.GetMultiLineTextExtent(label, &tWidth, &tHeight); + + writer.Align(m_align); + if (m_align & wxALIGN_CENTER_VERTICAL) + writer.SetY((dcHeight - tHeight) / 2); + else + writer.SetY((int)(dcHeight * m_paddingPct_vert) + m_paddingPix_vert); + + writer.WriteLn(label); // without formatting please. + + //dc.SetBrush( *wxTRANSPARENT_BRUSH ); + //dc.DrawRectangle(wxPoint(), dc.GetSize()); } // Overloaded form wxPanel and friends. wxSize pxStaticText::DoGetBestSize() const { - wxClientDC dc( const_cast(this) ); - dc.SetFont( GetFontOk() ); + wxClientDC dc(const_cast(this)); + dc.SetFont(GetFontOk()); - wxSize best; + wxSize best; - if( m_autowrap ) - { - best = GetBestWrappedSize(dc); - //best.x = wxDefaultCoord; - } - else - { - // No autowrapping, so we can force a specific size here! - best = dc.GetMultiLineTextExtent( GetLabel() ); - best.x += calcPaddingWidth( best.x ); - } + if (m_autowrap) { + best = GetBestWrappedSize(dc); + //best.x = wxDefaultCoord; + } else { + // No autowrapping, so we can force a specific size here! + best = dc.GetMultiLineTextExtent(GetLabel()); + best.x += calcPaddingWidth(best.x); + } - best.y += calcPaddingHeight( best.y ); + best.y += calcPaddingHeight(best.y); CacheBestSize(best); return best; @@ -349,35 +347,36 @@ wxSize pxStaticText::DoGetBestSize() const // -------------------------------------------------------------------------------------- // pxStaticHeading (implementations) // -------------------------------------------------------------------------------------- -pxStaticHeading::pxStaticHeading( wxWindow* parent, const wxString& label ) - : _parent( parent ) +pxStaticHeading::pxStaticHeading(wxWindow *parent, const wxString &label) + : _parent(parent) { - m_align = wxALIGN_CENTER; + m_align = wxALIGN_CENTER; - SetPaddingDefaults(); - Init( label ); + SetPaddingDefaults(); + Init(label); } void pxStaticHeading::SetPaddingDefaults() { - m_paddingPix_horiz = 4; - m_paddingPix_vert = 1; + m_paddingPix_horiz = 4; + m_paddingPix_vert = 1; - m_paddingPct_horiz = 0.08f; - m_paddingPct_vert = 0.0f; + m_paddingPct_horiz = 0.08f; + m_paddingPct_vert = 0.0f; } -void operator+=( wxSizer& target, pxStaticText* src ) +void operator+=(wxSizer &target, pxStaticText *src) { - if( src ) target.Add( src, pxExpand ); + if (src) + target.Add(src, pxExpand); } -void operator+=( wxSizer& target, pxStaticText& src ) +void operator+=(wxSizer &target, pxStaticText &src) { - target.Add( &src, pxExpand ); + target.Add(&src, pxExpand); } -void operator+=( wxSizer* target, pxStaticText& src ) +void operator+=(wxSizer *target, pxStaticText &src) { - target->Add( &src, pxExpand ); + target->Add(&src, pxExpand); } diff --git a/common/src/Utilities/pxStreams.cpp b/common/src/Utilities/pxStreams.cpp index ee9ac3ecf0..10f07c37d4 100644 --- a/common/src/Utilities/pxStreams.cpp +++ b/common/src/Utilities/pxStreams.cpp @@ -24,21 +24,22 @@ // -------------------------------------------------------------------------------------- // pxStreamBase (implementations) // -------------------------------------------------------------------------------------- -pxStreamBase::pxStreamBase(const wxString& filename) - : m_filename( filename ) +pxStreamBase::pxStreamBase(const wxString &filename) + : m_filename(filename) { } bool pxStreamBase::IsOk() const { - wxStreamBase* woot = GetWxStreamBase(); - return woot && woot->IsOk(); + wxStreamBase *woot = GetWxStreamBase(); + return woot && woot->IsOk(); } wxFileOffset pxStreamBase::Length() const { - if (!GetWxStreamBase()) return 0; - return GetWxStreamBase()->GetLength(); + if (!GetWxStreamBase()) + return 0; + return GetWxStreamBase()->GetLength(); } // -------------------------------------------------------------------------------------- @@ -47,118 +48,115 @@ wxFileOffset pxStreamBase::Length() const // Interface for reading data from a gzip stream. // -pxInputStream::pxInputStream(const wxString& filename, std::unique_ptr& input) - : pxStreamBase( filename ) - , m_stream_in( std::move(input) ) +pxInputStream::pxInputStream(const wxString &filename, std::unique_ptr &input) + : pxStreamBase(filename) + , m_stream_in(std::move(input)) { } -pxInputStream::pxInputStream(const wxString& filename, wxInputStream* input) - : pxStreamBase( filename ) - , m_stream_in( input ) +pxInputStream::pxInputStream(const wxString &filename, wxInputStream *input) + : pxStreamBase(filename) + , m_stream_in(input) { } -wxStreamBase* pxInputStream::GetWxStreamBase() const { return m_stream_in.get(); } +wxStreamBase *pxInputStream::GetWxStreamBase() const { return m_stream_in.get(); } wxFileOffset pxInputStream::Tell() const { - return m_stream_in->TellI(); + return m_stream_in->TellI(); } -wxFileOffset pxInputStream::Seek( wxFileOffset ofs, wxSeekMode mode ) +wxFileOffset pxInputStream::Seek(wxFileOffset ofs, wxSeekMode mode) { - return m_stream_in->SeekI(ofs, mode); + return m_stream_in->SeekI(ofs, mode); } -void pxInputStream::SetStream( const wxString& filename, std::unique_ptr& stream ) +void pxInputStream::SetStream(const wxString &filename, std::unique_ptr &stream) { - m_filename = filename; - m_stream_in = std::move(stream); + m_filename = filename; + m_stream_in = std::move(stream); } -void pxInputStream::SetStream( const wxString& filename, wxInputStream* stream ) +void pxInputStream::SetStream(const wxString &filename, wxInputStream *stream) { - m_filename = filename; - m_stream_in = std::unique_ptr(stream); + m_filename = filename; + m_stream_in = std::unique_ptr(stream); } -void pxInputStream::Read( void* dest, size_t size ) +void pxInputStream::Read(void *dest, size_t size) { - m_stream_in->Read(dest, size); - if (m_stream_in->GetLastError() == wxSTREAM_READ_ERROR) - { - int err = errno; - if (!err) - throw Exception::BadStream(m_filename).SetDiagMsg(L"Cannot read from file (bad file handle?)"); + m_stream_in->Read(dest, size); + if (m_stream_in->GetLastError() == wxSTREAM_READ_ERROR) { + int err = errno; + if (!err) + throw Exception::BadStream(m_filename).SetDiagMsg(L"Cannot read from file (bad file handle?)"); - ScopedExcept ex(Exception::FromErrno(m_filename, err)); - ex->SetDiagMsg( L"cannot read from file: " + ex->DiagMsg() ); - ex->Rethrow(); - } + ScopedExcept ex(Exception::FromErrno(m_filename, err)); + ex->SetDiagMsg(L"cannot read from file: " + ex->DiagMsg()); + ex->Rethrow(); + } - // IMPORTANT! The underlying file/source Eof() stuff is not really reliable, so we - // must always use the explicit check against the number of bytes read to determine - // end-of-stream conditions. + // IMPORTANT! The underlying file/source Eof() stuff is not really reliable, so we + // must always use the explicit check against the number of bytes read to determine + // end-of-stream conditions. - if ((size_t)m_stream_in->LastRead() < size) - throw Exception::EndOfStream( m_filename ); + if ((size_t)m_stream_in->LastRead() < size) + throw Exception::EndOfStream(m_filename); } // -------------------------------------------------------------------------------------- // pxOutputStream // -------------------------------------------------------------------------------------- -pxOutputStream::pxOutputStream(const wxString& filename, std::unique_ptr& output) - : pxStreamBase( filename ) - , m_stream_out( std::move(output) ) -{ - -} - -pxOutputStream::pxOutputStream(const wxString& filename, wxOutputStream* output) - : pxStreamBase( filename ) - , m_stream_out( output ) +pxOutputStream::pxOutputStream(const wxString &filename, std::unique_ptr &output) + : pxStreamBase(filename) + , m_stream_out(std::move(output)) { } -wxStreamBase* pxOutputStream::GetWxStreamBase() const { return m_stream_out.get(); } +pxOutputStream::pxOutputStream(const wxString &filename, wxOutputStream *output) + : pxStreamBase(filename) + , m_stream_out(output) +{ +} + +wxStreamBase *pxOutputStream::GetWxStreamBase() const { return m_stream_out.get(); } wxFileOffset pxOutputStream::Tell() const { - return m_stream_out->TellO(); + return m_stream_out->TellO(); } -wxFileOffset pxOutputStream::Seek( wxFileOffset ofs, wxSeekMode mode ) +wxFileOffset pxOutputStream::Seek(wxFileOffset ofs, wxSeekMode mode) { - return m_stream_out->SeekO( ofs, mode ); + return m_stream_out->SeekO(ofs, mode); } -void pxOutputStream::SetStream( const wxString& filename, std::unique_ptr& stream ) +void pxOutputStream::SetStream(const wxString &filename, std::unique_ptr &stream) { - m_filename = filename; - m_stream_out = std::move(stream); + m_filename = filename; + m_stream_out = std::move(stream); } -void pxOutputStream::SetStream( const wxString& filename, wxOutputStream* stream ) +void pxOutputStream::SetStream(const wxString &filename, wxOutputStream *stream) { - m_filename = filename; - m_stream_out = std::unique_ptr(stream); + m_filename = filename; + m_stream_out = std::unique_ptr(stream); } -void pxOutputStream::Write( const void* src, size_t size ) +void pxOutputStream::Write(const void *src, size_t size) { - m_stream_out->Write(src, size); - if(m_stream_out->GetLastError() == wxSTREAM_WRITE_ERROR) - { - int err = errno; - if (!err) - throw Exception::BadStream(m_filename).SetDiagMsg(L"Cannot write to file/stream."); + m_stream_out->Write(src, size); + if (m_stream_out->GetLastError() == wxSTREAM_WRITE_ERROR) { + int err = errno; + if (!err) + throw Exception::BadStream(m_filename).SetDiagMsg(L"Cannot write to file/stream."); - ScopedExcept ex(Exception::FromErrno(m_filename, err)); - ex->SetDiagMsg( L"Cannot write to file: " + ex->DiagMsg() ); - ex->Rethrow(); - } + ScopedExcept ex(Exception::FromErrno(m_filename, err)); + ex->SetDiagMsg(L"Cannot write to file: " + ex->DiagMsg()); + ex->Rethrow(); + } } // -------------------------------------------------------------------------------------- @@ -166,84 +164,89 @@ void pxOutputStream::Write( const void* src, size_t size ) // -------------------------------------------------------------------------------------- // Returns TRUE if the source is UTF8, or FALSE if it's just ASCII crap. -bool pxReadLine( wxInputStream& input, std::string& dest ) +bool pxReadLine(wxInputStream &input, std::string &dest) { - dest.clear(); - bool isUTF8 = false; - while ( true ) - { - char c; - input.Read(&c, sizeof(c)); - if( c == 0 ) break; - if( input.Eof() ) break; - if( c == '\n' ) break; // eat on UNIX - if( c == '\r' ) - { - input.Read(&c, sizeof(c)); - if( c == 0 ) break; - if( input.Eof() ) break; - if( c == '\n' ) break; + dest.clear(); + bool isUTF8 = false; + while (true) { + char c; + input.Read(&c, sizeof(c)); + if (c == 0) + break; + if (input.Eof()) + break; + if (c == '\n') + break; // eat on UNIX + if (c == '\r') { + input.Read(&c, sizeof(c)); + if (c == 0) + break; + if (input.Eof()) + break; + if (c == '\n') + break; - input.Ungetch(c); - break; - } - dest += c; - if( c & 0x80 ) isUTF8 = true; - } - - return isUTF8; + input.Ungetch(c); + break; + } + dest += c; + if (c & 0x80) + isUTF8 = true; + } + + return isUTF8; } -void pxReadLine( wxInputStream& input, wxString& dest, std::string& intermed ) +void pxReadLine(wxInputStream &input, wxString &dest, std::string &intermed) { - dest.clear(); - if( pxReadLine( input, intermed ) ) - dest = fromUTF8(intermed.c_str()); - else - { - // Optimized ToAscii conversion. - // wx3.0 : NOT COMPATIBLE!! (on linux anyway) - const char* ascii = intermed.c_str(); - while( *ascii != 0 ) dest += (wchar_t)(unsigned char)*ascii++; - } + dest.clear(); + if (pxReadLine(input, intermed)) + dest = fromUTF8(intermed.c_str()); + else { + // Optimized ToAscii conversion. + // wx3.0 : NOT COMPATIBLE!! (on linux anyway) + const char *ascii = intermed.c_str(); + while (*ascii != 0) + dest += (wchar_t)(unsigned char)*ascii++; + } } -void pxReadLine( wxInputStream& input, wxString& dest ) +void pxReadLine(wxInputStream &input, wxString &dest) { - std::string line; - pxReadLine( input, dest, line ); + std::string line; + pxReadLine(input, dest, line); } -wxString pxReadLine( wxInputStream& input ) +wxString pxReadLine(wxInputStream &input) { - wxString result; - pxReadLine( input, result ); - return result; + wxString result; + pxReadLine(input, result); + return result; } -void pxWriteLine( wxOutputStream& output ) +void pxWriteLine(wxOutputStream &output) { - output.Write( "\n", 1 ); + output.Write("\n", 1); } -void pxWriteLine( wxOutputStream& output, const wxString& text ) +void pxWriteLine(wxOutputStream &output, const wxString &text) { - if( !text.IsEmpty() ) - { - pxToUTF8 utf8(text); - output.Write(utf8, utf8.Length()); - } - pxWriteLine( output ); + if (!text.IsEmpty()) { + pxToUTF8 utf8(text); + output.Write(utf8, utf8.Length()); + } + pxWriteLine(output); } -void pxWriteMultiline( wxOutputStream& output, const wxString& src ) +void pxWriteMultiline(wxOutputStream &output, const wxString &src) { - if( src.IsEmpty() ) return; + if (src.IsEmpty()) + return; - wxString result( src ); - result.Replace( L"\r\n", L"\n" ); - result.Replace( L"\r", L"\n" ); - - pxToUTF8 utf8(result); - output.Write(utf8, utf8.Length()); + wxString result(src); + result.Replace(L"\r\n", L"\n"); + result.Replace(L"\r", L"\n"); + + pxToUTF8 utf8(result); + output.Write(utf8, utf8.Length()); } diff --git a/common/src/Utilities/pxTranslate.cpp b/common/src/Utilities/pxTranslate.cpp index 11ed31a6d5..8bdd518280 100644 --- a/common/src/Utilities/pxTranslate.cpp +++ b/common/src/Utilities/pxTranslate.cpp @@ -15,18 +15,18 @@ #include "PrecompiledHeader.h" -bool pxIsEnglish( int id ) +bool pxIsEnglish(int id) { - return ( id == wxLANGUAGE_ENGLISH || id == wxLANGUAGE_ENGLISH_US ); + return (id == wxLANGUAGE_ENGLISH || id == wxLANGUAGE_ENGLISH_US); } // -------------------------------------------------------------------------------------- // pxExpandMsg -- an Iconized Text Translator // Was replaced by a standard implementation of wxGetTranslation // -------------------------------------------------------------------------------------- -const wxChar* __fastcall pxExpandMsg( const wxChar* englishContent ) +const wxChar *__fastcall pxExpandMsg(const wxChar *englishContent) { - return wxGetTranslation(englishContent).wc_str(); + return wxGetTranslation(englishContent).wc_str(); } // ------------------------------------------------------------------------ @@ -35,16 +35,14 @@ const wxChar* __fastcall pxExpandMsg( const wxChar* englishContent ) // if the string seems too long for gettext lookups. Longer complicated strings should // usually be implemented used the pxMsgExpand system instead. // -const wxChar* __fastcall pxGetTranslation( const wxChar* message ) +const wxChar *__fastcall pxGetTranslation(const wxChar *message) { - if( IsDevBuild ) - { - if( wxStrlen( message ) > 128 ) - { - Console.Warning( "pxGetTranslation: Long message detected, maybe use pxE() instead?" ); - Console.WriteLn( Color_Green, L"Message: %s", message ); - } - } + if (IsDevBuild) { + if (wxStrlen(message) > 128) { + Console.Warning("pxGetTranslation: Long message detected, maybe use pxE() instead?"); + Console.WriteLn(Color_Green, L"Message: %s", message); + } + } - return wxGetTranslation(message).wc_str(); + return wxGetTranslation(message).wc_str(); } diff --git a/common/src/Utilities/pxWindowTextWriter.cpp b/common/src/Utilities/pxWindowTextWriter.cpp index fdbecfd860..c1ab3e425f 100644 --- a/common/src/Utilities/pxWindowTextWriter.cpp +++ b/common/src/Utilities/pxWindowTextWriter.cpp @@ -19,147 +19,144 @@ // -------------------------------------------------------------------------------------- // pxWindowTextWriter Implementations // -------------------------------------------------------------------------------------- -pxWindowTextWriter::pxWindowTextWriter( wxDC& dc ) - : m_dc( dc ) +pxWindowTextWriter::pxWindowTextWriter(wxDC &dc) + : m_dc(dc) { - m_curpos = wxPoint(); - m_align = wxALIGN_CENTER; - m_leading = 0; + m_curpos = wxPoint(); + m_align = wxALIGN_CENTER; + m_leading = 0; - OnFontChanged(); + OnFontChanged(); } void pxWindowTextWriter::OnFontChanged() { } -pxWindowTextWriter& pxWindowTextWriter::SetWeight( wxFontWeight weight ) +pxWindowTextWriter &pxWindowTextWriter::SetWeight(wxFontWeight weight) { - wxFont curfont( m_dc.GetFont() ); - curfont.SetWeight( weight ); - m_dc.SetFont( curfont ); + wxFont curfont(m_dc.GetFont()); + curfont.SetWeight(weight); + m_dc.SetFont(curfont); - return *this; + return *this; } -pxWindowTextWriter& pxWindowTextWriter::SetStyle( wxFontStyle style ) +pxWindowTextWriter &pxWindowTextWriter::SetStyle(wxFontStyle style) { - wxFont curfont( m_dc.GetFont() ); - curfont.SetStyle( style ); - m_dc.SetFont( curfont ); - return *this; + wxFont curfont(m_dc.GetFont()); + curfont.SetStyle(style); + m_dc.SetFont(curfont); + return *this; } -pxWindowTextWriter& pxWindowTextWriter::Normal() +pxWindowTextWriter &pxWindowTextWriter::Normal() { - wxFont curfont( m_dc.GetFont() ); - curfont.SetStyle( wxFONTSTYLE_NORMAL ); - curfont.SetWeight( wxFONTWEIGHT_NORMAL ); - m_dc.SetFont( curfont ); + wxFont curfont(m_dc.GetFont()); + curfont.SetStyle(wxFONTSTYLE_NORMAL); + curfont.SetWeight(wxFONTWEIGHT_NORMAL); + m_dc.SetFont(curfont); - return *this; + return *this; } -pxWindowTextWriter& pxWindowTextWriter::SetPos( const wxPoint& pos ) +pxWindowTextWriter &pxWindowTextWriter::SetPos(const wxPoint &pos) { - m_curpos = pos; - return *this; + m_curpos = pos; + return *this; } -pxWindowTextWriter& pxWindowTextWriter::MovePos( const wxSize& delta ) +pxWindowTextWriter &pxWindowTextWriter::MovePos(const wxSize &delta) { - m_curpos += delta; - return *this; + m_curpos += delta; + return *this; } -pxWindowTextWriter& pxWindowTextWriter::SetY( int ypos ) +pxWindowTextWriter &pxWindowTextWriter::SetY(int ypos) { - m_curpos.y = ypos; - return *this; + m_curpos.y = ypos; + return *this; } -pxWindowTextWriter& pxWindowTextWriter::MoveY( int ydelta ) +pxWindowTextWriter &pxWindowTextWriter::MoveY(int ydelta) { - m_curpos.y += ydelta; - return *this; + m_curpos.y += ydelta; + return *this; } -void pxWindowTextWriter::_DoWriteLn( const wxChar* msg ) +void pxWindowTextWriter::_DoWriteLn(const wxChar *msg) { - pxAssert( msg ); + pxAssert(msg); - int tWidth, tHeight; - m_dc.GetMultiLineTextExtent( msg, &tWidth, &tHeight ); + int tWidth, tHeight; + m_dc.GetMultiLineTextExtent(msg, &tWidth, &tHeight); - wxPoint dispos( m_curpos ); + wxPoint dispos(m_curpos); - if( m_align & wxALIGN_CENTER_HORIZONTAL ) - { - dispos.x = (m_dc.GetSize().GetWidth() - tWidth) / 2; - } - else if( m_align & wxALIGN_RIGHT ) - { - dispos.x = m_dc.GetSize().GetWidth() - tWidth; - } + if (m_align & wxALIGN_CENTER_HORIZONTAL) { + dispos.x = (m_dc.GetSize().GetWidth() - tWidth) / 2; + } else if (m_align & wxALIGN_RIGHT) { + dispos.x = m_dc.GetSize().GetWidth() - tWidth; + } - m_dc.DrawText( msg, dispos ); - m_curpos.y += tHeight + m_leading; + m_dc.DrawText(msg, dispos); + m_curpos.y += tHeight + m_leading; } -void pxWindowTextWriter::_DoWriteLn( const wxString msg ) +void pxWindowTextWriter::_DoWriteLn(const wxString msg) { - _DoWriteLn(msg.wc_str()); + _DoWriteLn(msg.wc_str()); } // Splits incoming multi-line strings into pieces, and dispatches each line individually // to the text writer. -void pxWindowTextWriter::_DoWrite( const wxChar* msg ) +void pxWindowTextWriter::_DoWrite(const wxChar *msg) { - pxAssert( msg ); + pxAssert(msg); - wxArrayString parts; - SplitString( parts, msg, L'\n' ); + wxArrayString parts; + SplitString(parts, msg, L'\n'); - for( size_t i=0; i= '0' && (c) <= '9') #ifdef __linux__ -#define _CVTBUFSIZE (309+40) +#define _CVTBUFSIZE (309 + 40) #endif static const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -63,466 +63,455 @@ static const char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; #ifdef NEED_STRLEN static size_t strnlen(const char *s, size_t count) { - const char *sc; - for (sc = s; *sc != '\0' && count--; ++sc); - return sc - s; + const char *sc; + for (sc = s; *sc != '\0' && count--; ++sc) + ; + return sc - s; } #endif -static void cvt(char (&buf)[_CVTBUFSIZE], double arg, int preci, int& decpt, int& sign, int eflag) +static void cvt(char (&buf)[_CVTBUFSIZE], double arg, int preci, int &decpt, int &sign, int eflag) { - int r2; - double fi, fj; - char *p, *p1; + int r2; + double fi, fj; + char *p, *p1; - r2 = 0; - sign = 0; - p = &buf[0]; - if (arg < 0) - { - sign = 1; - arg = -arg; - } - arg = modf(arg, &fi); - p1 = &buf[_CVTBUFSIZE]; - - if (fi != 0) - { - while (fi != 0) - { - fj = modf(fi / 10, &fi); - *--p1 = (int)((fj + .03) * 10) + '0'; - r2++; + r2 = 0; + sign = 0; + p = &buf[0]; + if (arg < 0) { + sign = 1; + arg = -arg; } - while (p1 < &buf[_CVTBUFSIZE]) *p++ = *p1++; - } - else if (arg > 0) - { - while ((fj = arg * 10) < 1) - { - arg = fj; - r2--; + arg = modf(arg, &fi); + p1 = &buf[_CVTBUFSIZE]; + + if (fi != 0) { + while (fi != 0) { + fj = modf(fi / 10, &fi); + *--p1 = (int)((fj + .03) * 10) + '0'; + r2++; + } + while (p1 < &buf[_CVTBUFSIZE]) + *p++ = *p1++; + } else if (arg > 0) { + while ((fj = arg * 10) < 1) { + arg = fj; + r2--; + } } - } - p1 = &buf[preci]; + p1 = &buf[preci]; - if (eflag == 0) p1 += r2; - decpt = r2; - if (p1 < &buf[0]) - { - buf[0] = '\0'; + if (eflag == 0) + p1 += r2; + decpt = r2; + if (p1 < &buf[0]) { + buf[0] = '\0'; + return; + } + while (p <= p1 && p < &buf[_CVTBUFSIZE]) { + arg *= 10; + arg = modf(arg, &fj); + *p++ = (int)fj + '0'; + } + if (p1 >= &buf[_CVTBUFSIZE]) { + buf[_CVTBUFSIZE - 1] = '\0'; + return; + } + p = p1; + *p1 += 5; + while (*p1 > '9') { + *p1 = '0'; + if (p1 > buf) + ++*--p1; + else { + *p1 = '1'; + decpt++; + if (eflag == 0) { + if (p > buf) + *p = '0'; + p++; + } + } + } + *p = '\0'; return; - } - while (p <= p1 && p < &buf[_CVTBUFSIZE]) - { - arg *= 10; - arg = modf(arg, &fj); - *p++ = (int) fj + '0'; - } - if (p1 >= &buf[_CVTBUFSIZE]) - { - buf[_CVTBUFSIZE - 1] = '\0'; - return; - } - p = p1; - *p1 += 5; - while (*p1 > '9') - { - *p1 = '0'; - if (p1 > buf) - ++*--p1; - else - { - *p1 = '1'; - decpt++; - if (eflag == 0) - { - if (p > buf) *p = '0'; - p++; - } - } - } - *p = '\0'; - return; } -static void ecvtbuf(char (&buf)[_CVTBUFSIZE], double arg, int preci, int& decpt, int& sign) +static void ecvtbuf(char (&buf)[_CVTBUFSIZE], double arg, int preci, int &decpt, int &sign) { - cvt(buf, arg, preci, decpt, sign, 1); + cvt(buf, arg, preci, decpt, sign, 1); } -static void fcvtbuf(char (&buf)[_CVTBUFSIZE], double arg, int preci, int& decpt, int& sign) +static void fcvtbuf(char (&buf)[_CVTBUFSIZE], double arg, int preci, int &decpt, int &sign) { - cvt(buf, arg, preci, decpt, sign, 0); + cvt(buf, arg, preci, decpt, sign, 0); } static int skip_atoi(const char **s) { - int i = 0; - while (is_digit(**s)) i = i*10 + *((*s)++) - '0'; - return i; + int i = 0; + while (is_digit(**s)) + i = i * 10 + *((*s)++) - '0'; + return i; } -template -static void number(std::string& dest, T num, int base, int size, int precision, int type) +template +static void number(std::string &dest, T num, int base, int size, int precision, int type) { - char c, sign, tmp[88]; - const char *dig = digits; - int i; + char c, sign, tmp[88]; + const char *dig = digits; + int i; - if (type & LARGE) dig = upper_digits; - if (type & LEFT) type &= ~ZEROPAD; - if (base < 2 || base > 36) return; + if (type & LARGE) + dig = upper_digits; + if (type & LEFT) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) - { - if (num < 0) - { - sign = '-'; - num = -num; - size--; - } - else if (type & PLUS) - { - sign = '+'; - size--; - } - else if (type & SPACE) - { - sign = ' '; - size--; - } - } - - if (type & SPECIAL) - { - if (base == 16) - size -= 2; - else if (base == 8) - size--; - } - - i = 0; - - if (num == 0) - tmp[i++] = '0'; - else - { - if( base == 16 ) - { - while (num != 0) - { - tmp[i++] = dig[num & 0xf]; - num = (uint)num >> 4; - } - } - else - { - while (num != 0) - { - tmp[i++] = dig[num % (uint) base]; - num /= (uint) base; - } - } - } - - if (i > precision) precision = i; - size -= precision; - if (!(type & (ZEROPAD | LEFT))) while (size-- > 0) dest += ' '; - if (sign) dest += sign; - - if (type & SPECIAL) - { - if (base == 8) - dest += '0'; - else if (base == 16) - { - dest += '0'; - dest += digits[33]; - } - } - - - if( !(type & LEFT) && size > 0) { dest.append( size, c ); size = 0; } - if( i < precision ) dest.append( precision-i, '0' ); - while (i-- > 0) dest += tmp[i]; - if( size > 0 ) dest.append( size, ' ' ); - - //if (!(type & LEFT)) while (size-- > 0) dest += c; - //while (i < precision--) dest += '0'; - //while (i-- > 0) dest += tmp[i]; - //while (size-- > 0) dest += ' '; -} - -static void eaddr( std::string& dest, unsigned char *addr, int size, int precision, int type) -{ - char tmp[24]; - const char *dig = digits; - int i, len; - - if (type & LARGE) dig = upper_digits; - len = 0; - for (i = 0; i < 6; i++) - { - if (i != 0) tmp[len++] = ':'; - tmp[len++] = dig[addr[i] >> 4]; - tmp[len++] = dig[addr[i] & 0x0F]; - } - - if (!(type & LEFT)) while (len < size--) dest += ' '; - for (i = 0; i < len; ++i) dest += tmp[i]; - while (len < size--) dest += ' '; -} - -static void iaddr( std::string& dest, unsigned char *addr, int size, int precision, int type) -{ - char tmp[24]; - int i, n, len; - - len = 0; - for (i = 0; i < 4; i++) - { - if (i != 0) tmp[len++] = '.'; - n = addr[i]; - - if (n == 0) - tmp[len++] = digits[0]; - else - { - if (n >= 100) - { - tmp[len++] = digits[n / 100]; - n = n % 100; - tmp[len++] = digits[n / 10]; - n = n % 10; - } - else if (n >= 10) - { - tmp[len++] = digits[n / 10]; - n = n % 10; - } - - tmp[len++] = digits[n]; + c = (type & ZEROPAD) ? '0' : ' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = '-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = '+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } } - } - if (!(type & LEFT)) while (len < size--) dest += ' '; - for (i = 0; i < len; ++i) dest += tmp[i]; - while (len < size--) dest += ' '; + if (type & SPECIAL) { + if (base == 16) + size -= 2; + else if (base == 8) + size--; + } + + i = 0; + + if (num == 0) + tmp[i++] = '0'; + else { + if (base == 16) { + while (num != 0) { + tmp[i++] = dig[num & 0xf]; + num = (uint)num >> 4; + } + } else { + while (num != 0) { + tmp[i++] = dig[num % (uint)base]; + num /= (uint)base; + } + } + } + + if (i > precision) + precision = i; + size -= precision; + if (!(type & (ZEROPAD | LEFT))) + while (size-- > 0) + dest += ' '; + if (sign) + dest += sign; + + if (type & SPECIAL) { + if (base == 8) + dest += '0'; + else if (base == 16) { + dest += '0'; + dest += digits[33]; + } + } + + + if (!(type & LEFT) && size > 0) { + dest.append(size, c); + size = 0; + } + if (i < precision) + dest.append(precision - i, '0'); + while (i-- > 0) + dest += tmp[i]; + if (size > 0) + dest.append(size, ' '); + + //if (!(type & LEFT)) while (size-- > 0) dest += c; + //while (i < precision--) dest += '0'; + //while (i-- > 0) dest += tmp[i]; + //while (size-- > 0) dest += ' '; +} + +static void eaddr(std::string &dest, unsigned char *addr, int size, int precision, int type) +{ + char tmp[24]; + const char *dig = digits; + int i, len; + + if (type & LARGE) + dig = upper_digits; + len = 0; + for (i = 0; i < 6; i++) { + if (i != 0) + tmp[len++] = ':'; + tmp[len++] = dig[addr[i] >> 4]; + tmp[len++] = dig[addr[i] & 0x0F]; + } + + if (!(type & LEFT)) + while (len < size--) + dest += ' '; + for (i = 0; i < len; ++i) + dest += tmp[i]; + while (len < size--) + dest += ' '; +} + +static void iaddr(std::string &dest, unsigned char *addr, int size, int precision, int type) +{ + char tmp[24]; + int i, n, len; + + len = 0; + for (i = 0; i < 4; i++) { + if (i != 0) + tmp[len++] = '.'; + n = addr[i]; + + if (n == 0) + tmp[len++] = digits[0]; + else { + if (n >= 100) { + tmp[len++] = digits[n / 100]; + n = n % 100; + tmp[len++] = digits[n / 10]; + n = n % 10; + } else if (n >= 10) { + tmp[len++] = digits[n / 10]; + n = n % 10; + } + + tmp[len++] = digits[n]; + } + } + + if (!(type & LEFT)) + while (len < size--) + dest += ' '; + for (i = 0; i < len; ++i) + dest += tmp[i]; + while (len < size--) + dest += ' '; } #ifndef NOFLOAT static void cfltcvt(double value, char *buffer, char fmt, int precision) { - int decpt, sign, exp, pos; - char cvtbuf[_CVTBUFSIZE]; - int capexp = 0; - int magnitude; + int decpt, sign, exp, pos; + char cvtbuf[_CVTBUFSIZE]; + int capexp = 0; + int magnitude; - if (fmt == 'G' || fmt == 'E') - { - capexp = 1; - fmt += 'a' - 'A'; - } - - if (fmt == 'g') - { - ecvtbuf(cvtbuf, value, precision, decpt, sign); - - magnitude = decpt - 1; - if (magnitude < -4 || magnitude > precision - 1) - { - fmt = 'e'; - precision -= 1; + if (fmt == 'G' || fmt == 'E') { + capexp = 1; + fmt += 'a' - 'A'; } - else - { - fmt = 'f'; - precision -= decpt; - } - } - if (fmt == 'e') - { - ecvtbuf(cvtbuf, value, precision+1, decpt, sign); + if (fmt == 'g') { + ecvtbuf(cvtbuf, value, precision, decpt, sign); - const char* digits = cvtbuf; - - if (sign) *buffer++ = '-'; - *buffer++ = *digits; - if (precision > 0) *buffer++ = '.'; - memcpy(buffer, digits + 1, precision); - buffer += precision; - *buffer++ = capexp ? 'E' : 'e'; - - if (decpt == 0) - { - if (value == 0.0) - exp = 0; - else - exp = -1; - } - else - exp = decpt - 1; - - if (exp < 0) - { - *buffer++ = '-'; - exp = -exp; - } - else - *buffer++ = '+'; - - buffer[2] = (exp % 10) + '0'; - exp = exp / 10; - buffer[1] = (exp % 10) + '0'; - exp = exp / 10; - buffer[0] = (exp % 10) + '0'; - buffer += 3; - } - else if (fmt == 'f') - { - fcvtbuf(cvtbuf, value, precision, decpt, sign); - - const char* digits = cvtbuf; - - if (sign) *buffer++ = '-'; - if (*digits) - { - if (decpt <= 0) - { - *buffer++ = '0'; - *buffer++ = '.'; - for (pos = 0; pos < -decpt; pos++) *buffer++ = '0'; - while (*digits) *buffer++ = *digits++; - } - else - { - pos = 0; - while (*digits) - { - if (pos++ == decpt) *buffer++ = '.'; - *buffer++ = *digits++; + magnitude = decpt - 1; + if (magnitude < -4 || magnitude > precision - 1) { + fmt = 'e'; + precision -= 1; + } else { + fmt = 'f'; + precision -= decpt; } - } } - else - { - *buffer++ = '0'; - if (precision > 0) - { - *buffer++ = '.'; - for (pos = 0; pos < precision; pos++) *buffer++ = '0'; - } - } - } - *buffer = '\0'; + if (fmt == 'e') { + ecvtbuf(cvtbuf, value, precision + 1, decpt, sign); + + const char *digits = cvtbuf; + + if (sign) + *buffer++ = '-'; + *buffer++ = *digits; + if (precision > 0) + *buffer++ = '.'; + memcpy(buffer, digits + 1, precision); + buffer += precision; + *buffer++ = capexp ? 'E' : 'e'; + + if (decpt == 0) { + if (value == 0.0) + exp = 0; + else + exp = -1; + } else + exp = decpt - 1; + + if (exp < 0) { + *buffer++ = '-'; + exp = -exp; + } else + *buffer++ = '+'; + + buffer[2] = (exp % 10) + '0'; + exp = exp / 10; + buffer[1] = (exp % 10) + '0'; + exp = exp / 10; + buffer[0] = (exp % 10) + '0'; + buffer += 3; + } else if (fmt == 'f') { + fcvtbuf(cvtbuf, value, precision, decpt, sign); + + const char *digits = cvtbuf; + + if (sign) + *buffer++ = '-'; + if (*digits) { + if (decpt <= 0) { + *buffer++ = '0'; + *buffer++ = '.'; + for (pos = 0; pos < -decpt; pos++) + *buffer++ = '0'; + while (*digits) + *buffer++ = *digits++; + } else { + pos = 0; + while (*digits) { + if (pos++ == decpt) + *buffer++ = '.'; + *buffer++ = *digits++; + } + } + } else { + *buffer++ = '0'; + if (precision > 0) { + *buffer++ = '.'; + for (pos = 0; pos < precision; pos++) + *buffer++ = '0'; + } + } + } + + *buffer = '\0'; } static void forcdecpt(char *buffer) { - while (*buffer) - { - if (*buffer == '.') return; - if (*buffer == 'e' || *buffer == 'E') break; - buffer++; - } - - if (*buffer) - { - int n = strlen(buffer); - while (n > 0) - { - buffer[n + 1] = buffer[n]; - n--; + while (*buffer) { + if (*buffer == '.') + return; + if (*buffer == 'e' || *buffer == 'E') + break; + buffer++; } - *buffer = '.'; - } - else - { - *buffer++ = '.'; - *buffer = '\0'; - } + if (*buffer) { + int n = strlen(buffer); + while (n > 0) { + buffer[n + 1] = buffer[n]; + n--; + } + + *buffer = '.'; + } else { + *buffer++ = '.'; + *buffer = '\0'; + } } static void cropzeros(char *buffer) { - char *stop; + char *stop; - while (*buffer && *buffer != '.') buffer++; - if (*buffer++) - { - while (*buffer && *buffer != 'e' && *buffer != 'E') buffer++; - stop = buffer--; - while (*buffer == '0') buffer--; - if (*buffer == '.') buffer--; - while ( (*++buffer = *stop++) != 0 ); - } + while (*buffer && *buffer != '.') + buffer++; + if (*buffer++) { + while (*buffer && *buffer != 'e' && *buffer != 'E') + buffer++; + stop = buffer--; + while (*buffer == '0') + buffer--; + if (*buffer == '.') + buffer--; + while ((*++buffer = *stop++) != 0) + ; + } } -static void flt( std::string& dest, double num, int size, int precision, char fmt, int flags) +static void flt(std::string &dest, double num, int size, int precision, char fmt, int flags) { - char tmp[80]; - char c, sign; - int n; + char tmp[80]; + char c, sign; + int n; - // Left align means no zero padding - if (flags & LEFT) flags &= ~ZEROPAD; + // Left align means no zero padding + if (flags & LEFT) + flags &= ~ZEROPAD; - // Determine padding and sign char - c = (flags & ZEROPAD) ? '0' : ' '; - sign = 0; - if (flags & SIGN) - { - if (num < 0.0) - { - sign = '-'; - num = -num; - size--; + // Determine padding and sign char + c = (flags & ZEROPAD) ? '0' : ' '; + sign = 0; + if (flags & SIGN) { + if (num < 0.0) { + sign = '-'; + num = -num; + size--; + } else if (flags & PLUS) { + sign = '+'; + size--; + } else if (flags & SPACE) { + sign = ' '; + size--; + } } - else if (flags & PLUS) - { - sign = '+'; - size--; + + // Compute the precision value + if (precision < 0) + precision = 6; // Default precision: 6 + else if (precision == 0 && fmt == 'g') + precision = 1; // ANSI specified + + // Convert floating point number to text + cfltcvt(num, tmp, fmt, precision); + + // '#' and precision == 0 means force a decimal point + if ((flags & SPECIAL) && precision == 0) + forcdecpt(tmp); + + // 'g' format means crop zero unless '#' given + if (fmt == 'g' && !(flags & SPECIAL)) + cropzeros(tmp); + + n = strlen(tmp); + + // Output number with alignment and padding + size -= n; + + if (!(flags & (ZEROPAD | LEFT)) && size > 0) { + dest.append(size, ' '); + size = 0; } - else if (flags & SPACE) - { - sign = ' '; - size--; + if (sign) + dest += sign; + if (!(flags & LEFT) && size > 0) { + dest.append(size, c); + size = 0; } - } - - // Compute the precision value - if (precision < 0) - precision = 6; // Default precision: 6 - else if (precision == 0 && fmt == 'g') - precision = 1; // ANSI specified - - // Convert floating point number to text - cfltcvt(num, tmp, fmt, precision); - - // '#' and precision == 0 means force a decimal point - if ((flags & SPECIAL) && precision == 0) forcdecpt(tmp); - - // 'g' format means crop zero unless '#' given - if (fmt == 'g' && !(flags & SPECIAL)) cropzeros(tmp); - - n = strlen(tmp); - - // Output number with alignment and padding - size -= n; - - if (!(flags & (ZEROPAD | LEFT)) && size > 0) { dest.append( size, ' ' ); size = 0; } - if (sign) dest += sign; - if (!(flags & LEFT) && size > 0) { dest.append( size, c ); size = 0; } - dest.append( tmp, n ); - if(size > 0) dest.append( size, ' ' ); + dest.append(tmp, n); + if (size > 0) + dest.append(size, ' '); } #endif @@ -530,236 +519,231 @@ static void flt( std::string& dest, double num, int size, int precision, char fm /////////////////////////////////////////////////////////////////////////// // This is a "mostly" direct replacement for vsprintf, that is more secure and easier // to use than vsnprintf or vsprintf_s. See the docs for ssprintf for usage notes. -static void vssappendf(std::string& dest, const char* format, va_list args) +static void vssappendf(std::string &dest, const char *format, va_list args) { - int base; + int base; - int flags; // Flags to number() + int flags; // Flags to number() - int field_width; // Width of output field - int precision; // Min. # of digits for integers; max number of chars for from string - int qualifier; // 'h', 'l', or 'L' for integer fields + int field_width; // Width of output field + int precision; // Min. # of digits for integers; max number of chars for from string + int qualifier; // 'h', 'l', or 'L' for integer fields - for( const char* fmt = format; *fmt; ++fmt ) - { - if (*fmt != '%') - { - dest += *fmt; - continue; - } + for (const char *fmt = format; *fmt; ++fmt) { + if (*fmt != '%') { + dest += *fmt; + continue; + } - // Process flags - flags = 0; -repeat: - fmt++; // This also skips first '%' - switch (*fmt) - { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; - } + // Process flags + flags = 0; + repeat: + fmt++; // This also skips first '%' + switch (*fmt) { + case '-': + flags |= LEFT; + goto repeat; + case '+': + flags |= PLUS; + goto repeat; + case ' ': + flags |= SPACE; + goto repeat; + case '#': + flags |= SPECIAL; + goto repeat; + case '0': + flags |= ZEROPAD; + goto repeat; + } - // Get field width - field_width = -1; - if (is_digit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == '*') - { - fmt++; - field_width = va_arg(args, int); - if (field_width < 0) - { - field_width = -field_width; - flags |= LEFT; - } - } + // Get field width + field_width = -1; + if (is_digit(*fmt)) + field_width = skip_atoi(&fmt); + else if (*fmt == '*') { + fmt++; + field_width = va_arg(args, int); + if (field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } - // Get the precision - precision = -1; - if (*fmt == '.') - { - ++fmt; - if (is_digit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == '*') - { - ++fmt; - precision = va_arg(args, int); - } - if (precision < 0) precision = 0; - } + // Get the precision + precision = -1; + if (*fmt == '.') { + ++fmt; + if (is_digit(*fmt)) + precision = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; + precision = va_arg(args, int); + } + if (precision < 0) + precision = 0; + } - // Get the conversion qualifier - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ) - { - qualifier = *fmt; - fmt++; - } + // Get the conversion qualifier + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { + qualifier = *fmt; + fmt++; + } - // Default base - base = 10; + // Default base + base = 10; - switch (*fmt) - { - case 'c': - if (!(flags & LEFT)) while (--field_width > 0) dest += ' '; - dest += (unsigned char) va_arg(args, int); - while (--field_width > 0) dest += ' '; - continue; + switch (*fmt) { + case 'c': + if (!(flags & LEFT)) + while (--field_width > 0) + dest += ' '; + dest += (unsigned char)va_arg(args, int); + while (--field_width > 0) + dest += ' '; + continue; - case 's': - { - // let's add support for std::string as a formatted parameter! (air) - if( qualifier == 'h' ) - { - static const std::string nullstring( "" ); + case 's': { + // let's add support for std::string as a formatted parameter! (air) + if (qualifier == 'h') { + static const std::string nullstring(""); - const std::string* ss = va_arg(args, std::string*); - if( ss == NULL ) ss = &nullstring; - int len = ss->length(); - if( precision < 0 ) - { - // no precision override so just copy the whole string. - if (!(flags & LEFT) && (len < field_width)) - { - dest.append( field_width - len, ' ' ); - field_width = 0; - } - dest += *ss; - } - else - { - if( len > precision ) len = precision; - if (!(flags & LEFT) && (len < field_width)) - { - dest.append( field_width - len, ' ' ); - field_width = 0; - } - dest.append( ss->begin(), ss->begin()+len ); - } + const std::string *ss = va_arg(args, std::string *); + if (ss == NULL) + ss = &nullstring; + int len = ss->length(); + if (precision < 0) { + // no precision override so just copy the whole string. + if (!(flags & LEFT) && (len < field_width)) { + dest.append(field_width - len, ' '); + field_width = 0; + } + dest += *ss; + } else { + if (len > precision) + len = precision; + if (!(flags & LEFT) && (len < field_width)) { + dest.append(field_width - len, ' '); + field_width = 0; + } + dest.append(ss->begin(), ss->begin() + len); + } - if( len < field_width ) - dest.append( field_width - len, ' ' ); - } - else - { - const char* s = va_arg(args, char *); - if (!s) s = ""; + if (len < field_width) + dest.append(field_width - len, ' '); + } else { + const char *s = va_arg(args, char *); + if (!s) + s = ""; - int len = strlen(s); - if( precision < 0 ) - { - if (!(flags & LEFT)) while (len < field_width--) dest += ' '; - dest += s; - } - else - { - if( len > precision ) len = precision; - if (!(flags & LEFT)) while (len < field_width--) dest += ' '; - dest.append( s, s+len ); - } - while (len < field_width--) dest += ' '; - } - } - continue; + int len = strlen(s); + if (precision < 0) { + if (!(flags & LEFT)) + while (len < field_width--) + dest += ' '; + dest += s; + } else { + if (len > precision) + len = precision; + if (!(flags & LEFT)) + while (len < field_width--) + dest += ' '; + dest.append(s, s + len); + } + while (len < field_width--) + dest += ' '; + } + } + continue; - case 'p': - { - if (field_width == -1) - { - field_width = 2 * sizeof(void *); - flags |= ZEROPAD; - } - // use sptr as it avoids warnings during template code gen. - number( dest, (sptr) va_arg(args, void *), 16, field_width, precision, flags ); - } - continue; + case 'p': { + if (field_width == -1) { + field_width = 2 * sizeof(void *); + flags |= ZEROPAD; + } + // use sptr as it avoids warnings during template code gen. + number(dest, (sptr)va_arg(args, void *), 16, field_width, precision, flags); + } + continue; - case 'n': - if (qualifier == 'l') - { - long *ip = va_arg(args, long *); - *ip = dest.length(); - } - else - { - int *ip = va_arg(args, int *); - *ip = dest.length(); - } - continue; + case 'n': + if (qualifier == 'l') { + long *ip = va_arg(args, long *); + *ip = dest.length(); + } else { + int *ip = va_arg(args, int *); + *ip = dest.length(); + } + continue; - // What the hell is %a? (air) - case 'A': - flags |= LARGE; + // What the hell is %a? (air) + case 'A': + flags |= LARGE; - case 'a': - if (qualifier == 'l') - eaddr(dest, va_arg(args, unsigned char *), field_width, precision, flags); - else - iaddr(dest, va_arg(args, unsigned char *), field_width, precision, flags); - continue; + case 'a': + if (qualifier == 'l') + eaddr(dest, va_arg(args, unsigned char *), field_width, precision, flags); + else + iaddr(dest, va_arg(args, unsigned char *), field_width, precision, flags); + continue; - // Integer number formats - set up the flags and "break" - case 'o': - base = 8; - break; + // Integer number formats - set up the flags and "break" + case 'o': + base = 8; + break; - case 'X': - flags |= LARGE; + case 'X': + flags |= LARGE; - case 'x': - base = 16; - break; + case 'x': + base = 16; + break; - case 'd': - case 'i': - flags |= SIGN; + case 'd': + case 'i': + flags |= SIGN; - case 'u': - break; + case 'u': + break; - #ifndef NOFLOAT +#ifndef NOFLOAT - case 'E': - case 'G': - case 'e': - case 'f': - case 'g': - flt(dest, va_arg(args, double), field_width, precision, *fmt, flags | SIGN); - continue; + case 'E': + case 'G': + case 'e': + case 'f': + case 'g': + flt(dest, va_arg(args, double), field_width, precision, *fmt, flags | SIGN); + continue; - #endif +#endif - default: - if (*fmt != '%') dest += '%'; - if (*fmt) - dest += *fmt; - else - --fmt; - continue; - } + default: + if (*fmt != '%') + dest += '%'; + if (*fmt) + dest += *fmt; + else + --fmt; + continue; + } - if (qualifier == 'L') - { - // 64-bit integer support! (air) - number(dest, va_arg(args, s64), base, field_width, precision, flags); - } - else - { - s32 num; - // Modern 32 bit compilers pass parameters into va_arg by 32 bit scale always, - // so no point in using or checking for the 'h' parameter. - /*if (qualifier == 'h') + if (qualifier == 'L') { + // 64-bit integer support! (air) + number(dest, va_arg(args, s64), base, field_width, precision, flags); + } else { + s32 num; + // Modern 32 bit compilers pass parameters into va_arg by 32 bit scale always, + // so no point in using or checking for the 'h' parameter. + /*if (qualifier == 'h') num = va_arg(args, int); - else*/ // 'l' qualifier or no qualifier means 32 bits on all our std target platforms. - num = va_arg(args, s32); + else*/ // 'l' qualifier or no qualifier means 32 bits on all our std target platforms. + num = va_arg(args, s32); - number(dest, num, base, field_width, precision, flags); - } - } + number(dest, num, base, field_width, precision, flags); + } + } } #else @@ -783,37 +767,37 @@ repeat: // Note: std::vsnprintf requires C++11 (and the function must return the total // number of characters which would have been written even if a truncation occured) // Note2: Code is only used in debugger (perf is not important) -static void vssappendf(std::string& dest, const char* format, va_list args) +static void vssappendf(std::string &dest, const char *format, va_list args) { - char first_try[128]; // this function is called 99% (100%?) of the times for small string - va_list args_copy; - va_copy(args_copy, args); + char first_try[128]; // this function is called 99% (100%?) of the times for small string + va_list args_copy; + va_copy(args_copy, args); - s32 size = std::vsnprintf(first_try, 128, format, args_copy) + 1; + s32 size = std::vsnprintf(first_try, 128, format, args_copy) + 1; - va_end(args_copy); + va_end(args_copy); - if (size < 0) - return; - if (size < 128) { - dest += first_try; - return; - } + if (size < 0) + return; + if (size < 128) { + dest += first_try; + return; + } - // VLA extension. Not sure it is supported on windows. Maybe one days in C++ standard - // Performance is not important here - char output[size]; - std::vsnprintf(output, size, format, args); - dest += output; + // VLA extension. Not sure it is supported on windows. Maybe one days in C++ standard + // Performance is not important here + char output[size]; + std::vsnprintf(output, size, format, args); + dest += output; } #endif -void ssappendf( std::string& dest, const char* format, ...) +void ssappendf(std::string &dest, const char *format, ...) { - va_list args; - va_start(args, format); - vssappendf( dest, format, args ); - va_end(args); + va_list args; + va_start(args, format); + vssappendf(dest, format, args); + va_end(args); } diff --git a/common/src/Utilities/wxAppWithHelpers.cpp b/common/src/Utilities/wxAppWithHelpers.cpp index a32cfd9fe4..635889315a 100644 --- a/common/src/Utilities/wxAppWithHelpers.cpp +++ b/common/src/Utilities/wxAppWithHelpers.cpp @@ -25,26 +25,25 @@ wxDEFINE_EVENT(pxEvt_DeleteThread, wxCommandEvent); wxDEFINE_EVENT(pxEvt_InvokeAction, pxActionEvent); wxDEFINE_EVENT(pxEvt_SynchronousCommand, pxSynchronousCommandEvent); -IMPLEMENT_DYNAMIC_CLASS( pxSimpleEvent, wxEvent ) +IMPLEMENT_DYNAMIC_CLASS(pxSimpleEvent, wxEvent) ConsoleLogSource_App::ConsoleLogSource_App() { - static const TraceLogDescriptor myDesc = - { - L"AppEvents", L"App Events", - pxLt("Includes idle event processing and some other uncommon event usages.") - }; - - m_Descriptor = &myDesc; + static const TraceLogDescriptor myDesc = + { + L"AppEvents", L"App Events", + pxLt("Includes idle event processing and some other uncommon event usages.")}; + + m_Descriptor = &myDesc; } ConsoleLogSource_App pxConLog_App; void BaseDeletableObject::DoDeletion() { - wxAppWithHelpers* app = wxDynamicCast( wxApp::GetInstance(), wxAppWithHelpers ); - pxAssert( app != NULL ); - app->DeleteObject( *this ); + wxAppWithHelpers *app = wxDynamicCast(wxApp::GetInstance(), wxAppWithHelpers); + pxAssert(app != NULL); + app->DeleteObject(*this); } @@ -52,167 +51,165 @@ void BaseDeletableObject::DoDeletion() // SynchronousActionState Implementations // -------------------------------------------------------------------------------------- -void SynchronousActionState::SetException( const BaseException& ex ) +void SynchronousActionState::SetException(const BaseException &ex) { - m_exception = ScopedExcept(ex.Clone()); + m_exception = ScopedExcept(ex.Clone()); } -void SynchronousActionState::SetException( BaseException* ex ) +void SynchronousActionState::SetException(BaseException *ex) { - if( !m_posted ) - { - m_exception = ScopedExcept(ex); - } - else if( wxTheApp ) - { - // transport the exception to the main thread, since the message is fully - // asynchronous, or has already entered an asynchronous state. Message is sent - // as a non-blocking action since proper handling of user errors on async messages - // is *usually* to log/ignore it (hah), or to suspend emulation and issue a dialog - // box to the user. + if (!m_posted) { + m_exception = ScopedExcept(ex); + } else if (wxTheApp) { + // transport the exception to the main thread, since the message is fully + // asynchronous, or has already entered an asynchronous state. Message is sent + // as a non-blocking action since proper handling of user errors on async messages + // is *usually* to log/ignore it (hah), or to suspend emulation and issue a dialog + // box to the user. - pxExceptionEvent ev( ex ); - wxTheApp->AddPendingEvent( ev ); - } + pxExceptionEvent ev(ex); + wxTheApp->AddPendingEvent(ev); + } } void SynchronousActionState::RethrowException() const { - if( m_exception ) m_exception->Rethrow(); + if (m_exception) + m_exception->Rethrow(); } int SynchronousActionState::WaitForResult() { - m_sema.WaitNoCancel(); - RethrowException(); - return return_value; + m_sema.WaitNoCancel(); + RethrowException(); + return return_value; } int SynchronousActionState::WaitForResult_NoExceptions() { - m_sema.WaitNoCancel(); - return return_value; + m_sema.WaitNoCancel(); + return return_value; } -void SynchronousActionState::PostResult( int res ) +void SynchronousActionState::PostResult(int res) { - return_value = res; - PostResult(); + return_value = res; + PostResult(); } void SynchronousActionState::ClearResult() { - m_posted = false; - m_exception = NULL; + m_posted = false; + m_exception = NULL; } void SynchronousActionState::PostResult() { - if( m_posted ) return; - m_posted = true; - m_sema.Post(); + if (m_posted) + return; + m_posted = true; + m_sema.Post(); } // -------------------------------------------------------------------------------------- // pxActionEvent Implementations // -------------------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( pxActionEvent, wxEvent ) +IMPLEMENT_DYNAMIC_CLASS(pxActionEvent, wxEvent) -pxActionEvent::pxActionEvent( SynchronousActionState* sema, int msgtype ) - : wxEvent( 0, msgtype ) +pxActionEvent::pxActionEvent(SynchronousActionState *sema, int msgtype) + : wxEvent(0, msgtype) { - m_state = sema; + m_state = sema; } -pxActionEvent::pxActionEvent( SynchronousActionState& sema, int msgtype ) - : wxEvent( 0, msgtype ) +pxActionEvent::pxActionEvent(SynchronousActionState &sema, int msgtype) + : wxEvent(0, msgtype) { - m_state = &sema; + m_state = &sema; } -pxActionEvent::pxActionEvent( const pxActionEvent& src ) - : wxEvent( src ) +pxActionEvent::pxActionEvent(const pxActionEvent &src) + : wxEvent(src) { - m_state = src.m_state; + m_state = src.m_state; } -void pxActionEvent::SetException( const BaseException& ex ) +void pxActionEvent::SetException(const BaseException &ex) { - SetException( ex.Clone() ); + SetException(ex.Clone()); } -void pxActionEvent::SetException( BaseException* ex ) +void pxActionEvent::SetException(BaseException *ex) { - const wxString& prefix( pxsFmt(L"(%s) ", GetClassInfo()->GetClassName()) ); - ex->DiagMsg() = prefix + ex->DiagMsg(); + const wxString &prefix(pxsFmt(L"(%s) ", GetClassInfo()->GetClassName())); + ex->DiagMsg() = prefix + ex->DiagMsg(); - if( !m_state ) - { - ScopedExcept exptr( ex ); // auto-delete it after handling. - ex->Rethrow(); - } + if (!m_state) { + ScopedExcept exptr(ex); // auto-delete it after handling. + ex->Rethrow(); + } - m_state->SetException( ex ); + m_state->SetException(ex); } // -------------------------------------------------------------------------------------- // pxSynchronousCommandEvent // -------------------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( pxSynchronousCommandEvent, wxCommandEvent ) +IMPLEMENT_DYNAMIC_CLASS(pxSynchronousCommandEvent, wxCommandEvent) -pxSynchronousCommandEvent::pxSynchronousCommandEvent(SynchronousActionState* sema, wxEventType commandType, int winid) - : wxCommandEvent( pxEvt_SynchronousCommand, winid ) +pxSynchronousCommandEvent::pxSynchronousCommandEvent(SynchronousActionState *sema, wxEventType commandType, int winid) + : wxCommandEvent(pxEvt_SynchronousCommand, winid) { - m_sync = sema; - m_realEvent = commandType; + m_sync = sema; + m_realEvent = commandType; } -pxSynchronousCommandEvent::pxSynchronousCommandEvent(SynchronousActionState& sema, wxEventType commandType, int winid) - : wxCommandEvent( pxEvt_SynchronousCommand ) +pxSynchronousCommandEvent::pxSynchronousCommandEvent(SynchronousActionState &sema, wxEventType commandType, int winid) + : wxCommandEvent(pxEvt_SynchronousCommand) { - m_sync = &sema; - m_realEvent = commandType; + m_sync = &sema; + m_realEvent = commandType; } -pxSynchronousCommandEvent::pxSynchronousCommandEvent(SynchronousActionState* sema, const wxCommandEvent& evt ) - : wxCommandEvent( evt ) +pxSynchronousCommandEvent::pxSynchronousCommandEvent(SynchronousActionState *sema, const wxCommandEvent &evt) + : wxCommandEvent(evt) { - m_sync = sema; - m_realEvent = evt.GetEventType(); - SetEventType( pxEvt_SynchronousCommand ); + m_sync = sema; + m_realEvent = evt.GetEventType(); + SetEventType(pxEvt_SynchronousCommand); } -pxSynchronousCommandEvent::pxSynchronousCommandEvent(SynchronousActionState& sema, const wxCommandEvent& evt ) - : wxCommandEvent( evt ) +pxSynchronousCommandEvent::pxSynchronousCommandEvent(SynchronousActionState &sema, const wxCommandEvent &evt) + : wxCommandEvent(evt) { - m_sync = &sema; - m_realEvent = evt.GetEventType(); - SetEventType( pxEvt_SynchronousCommand ); + m_sync = &sema; + m_realEvent = evt.GetEventType(); + SetEventType(pxEvt_SynchronousCommand); } -pxSynchronousCommandEvent::pxSynchronousCommandEvent( const pxSynchronousCommandEvent& src ) - : wxCommandEvent( src ) +pxSynchronousCommandEvent::pxSynchronousCommandEvent(const pxSynchronousCommandEvent &src) + : wxCommandEvent(src) { - m_sync = src.m_sync; - m_realEvent = src.m_realEvent; + m_sync = src.m_sync; + m_realEvent = src.m_realEvent; } -void pxSynchronousCommandEvent::SetException( const BaseException& ex ) +void pxSynchronousCommandEvent::SetException(const BaseException &ex) { - if( !m_sync ) ex.Rethrow(); - m_sync->SetException( ex ); + if (!m_sync) + ex.Rethrow(); + m_sync->SetException(ex); } -void pxSynchronousCommandEvent::SetException( BaseException* ex ) +void pxSynchronousCommandEvent::SetException(BaseException *ex) { - if( !m_sync ) - { - ScopedExcept exptr( ex ); // auto-delete it after handling. - ex->Rethrow(); - } + if (!m_sync) { + ScopedExcept exptr(ex); // auto-delete it after handling. + ex->Rethrow(); + } - m_sync->SetException( ex ); + m_sync->SetException(ex); } // -------------------------------------------------------------------------------------- @@ -224,61 +221,63 @@ void pxSynchronousCommandEvent::SetException( BaseException* ex ) // class pxRpcEvent : public pxActionEvent { - DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxRpcEvent) + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxRpcEvent) - typedef pxActionEvent _parent; + typedef pxActionEvent _parent; protected: - void (*m_Method)(); + void (*m_Method)(); public: - virtual ~pxRpcEvent() throw() { } - virtual pxRpcEvent *Clone() const { return new pxRpcEvent(*this); } + virtual ~pxRpcEvent() throw() {} + virtual pxRpcEvent *Clone() const { return new pxRpcEvent(*this); } - explicit pxRpcEvent( void (*method)()=NULL, SynchronousActionState* sema=NULL ) - : pxActionEvent( sema ) - { - m_Method = method; - } + explicit pxRpcEvent(void (*method)() = NULL, SynchronousActionState *sema = NULL) + : pxActionEvent(sema) + { + m_Method = method; + } - explicit pxRpcEvent( void (*method)(), SynchronousActionState& sema ) - : pxActionEvent( sema ) - { - m_Method = method; - } - - pxRpcEvent( const pxRpcEvent& src ) - : pxActionEvent( src ) - { - m_Method = src.m_Method; - } + explicit pxRpcEvent(void (*method)(), SynchronousActionState &sema) + : pxActionEvent(sema) + { + m_Method = method; + } - void SetMethod( void (*method)() ) - { - m_Method = method; - } + pxRpcEvent(const pxRpcEvent &src) + : pxActionEvent(src) + { + m_Method = src.m_Method; + } + + void SetMethod(void (*method)()) + { + m_Method = method; + } protected: - void InvokeEvent() - { - if( m_Method ) m_Method(); - } + void InvokeEvent() + { + if (m_Method) + m_Method(); + } }; -IMPLEMENT_DYNAMIC_CLASS( pxRpcEvent, pxActionEvent ) +IMPLEMENT_DYNAMIC_CLASS(pxRpcEvent, pxActionEvent) // -------------------------------------------------------------------------------------- // pxExceptionEvent implementations // -------------------------------------------------------------------------------------- -pxExceptionEvent::pxExceptionEvent( const BaseException& ex ) +pxExceptionEvent::pxExceptionEvent(const BaseException &ex) { - m_except = ex.Clone(); + m_except = ex.Clone(); } void pxExceptionEvent::InvokeEvent() { - ScopedExcept deleteMe( m_except ); - if( deleteMe ) deleteMe->Rethrow(); + ScopedExcept deleteMe(m_except); + if (deleteMe) + deleteMe->Rethrow(); } // -------------------------------------------------------------------------------------- @@ -289,22 +288,22 @@ void pxExceptionEvent::InvokeEvent() // would mean checking only one list of events per idle event, instead of two. (ie, ping // events can be appended to the idle event list, instead of into their own custom list). // -IMPLEMENT_DYNAMIC_CLASS( wxAppWithHelpers, wxApp ) +IMPLEMENT_DYNAMIC_CLASS(wxAppWithHelpers, wxApp) // Posts a method to the main thread; non-blocking. Post occurs even when called from the // main thread. -void wxAppWithHelpers::PostMethod( FnType_Void* method ) +void wxAppWithHelpers::PostMethod(FnType_Void *method) { - PostEvent( pxRpcEvent( method ) ); + PostEvent(pxRpcEvent(method)); } // Posts a method to the main thread; non-blocking. Post occurs even when called from the // main thread. -void wxAppWithHelpers::PostIdleMethod( FnType_Void* method ) +void wxAppWithHelpers::PostIdleMethod(FnType_Void *method) { - pxRpcEvent evt( method ); - AddIdleEvent( evt ); + pxRpcEvent evt(method); + AddIdleEvent(evt); } // Invokes the specified void method, or posts the method to the main thread if the calling @@ -319,15 +318,16 @@ void wxAppWithHelpers::PostIdleMethod( FnType_Void* method ) // TRUE if the method was invoked. // -bool wxAppWithHelpers::Rpc_TryInvoke( FnType_Void* method ) +bool wxAppWithHelpers::Rpc_TryInvoke(FnType_Void *method) { - if( wxThread::IsMain() ) return false; + if (wxThread::IsMain()) + return false; - SynchronousActionState sync; - PostEvent( pxRpcEvent( method, sync ) ); - sync.WaitForResult(); + SynchronousActionState sync; + PostEvent(pxRpcEvent(method, sync)); + sync.WaitForResult(); - return true; + return true; } // Invokes the specified void method, or posts the method to the main thread if the calling @@ -341,97 +341,93 @@ bool wxAppWithHelpers::Rpc_TryInvoke( FnType_Void* method ) // FALSE if the method was not posted to the main thread (meaning this IS the main thread!) // TRUE if the method was posted. // -bool wxAppWithHelpers::Rpc_TryInvokeAsync( FnType_Void* method ) +bool wxAppWithHelpers::Rpc_TryInvokeAsync(FnType_Void *method) { - if( wxThread::IsMain() ) return false; - PostEvent( pxRpcEvent( method ) ); - return true; + if (wxThread::IsMain()) + return false; + PostEvent(pxRpcEvent(method)); + return true; } -void wxAppWithHelpers::ProcessMethod( FnType_Void* method ) +void wxAppWithHelpers::ProcessMethod(FnType_Void *method) { - if( wxThread::IsMain() ) - { - method(); - return; - } + if (wxThread::IsMain()) { + method(); + return; + } - SynchronousActionState sync; - PostEvent( pxRpcEvent( method, sync ) ); - sync.WaitForResult(); + SynchronousActionState sync; + PostEvent(pxRpcEvent(method, sync)); + sync.WaitForResult(); } -void wxAppWithHelpers::PostEvent( const wxEvent& evt ) +void wxAppWithHelpers::PostEvent(const wxEvent &evt) { - // Const Cast is OK! - // Truth is, AddPendingEvent should be a const-qualified parameter, as - // it makes an immediate clone copy of the event -- but wxWidgets - // fails again in structured C/C++ design design. So I'm forcing it as such - // here. -- air + // Const Cast is OK! + // Truth is, AddPendingEvent should be a const-qualified parameter, as + // it makes an immediate clone copy of the event -- but wxWidgets + // fails again in structured C/C++ design design. So I'm forcing it as such + // here. -- air - _parent::AddPendingEvent( const_cast(evt) ); + _parent::AddPendingEvent(const_cast(evt)); } -bool wxAppWithHelpers::ProcessEvent( wxEvent& evt ) +bool wxAppWithHelpers::ProcessEvent(wxEvent &evt) { - // Note: We can't do an automatic blocking post of the message here, because wxWidgets - // isn't really designed for it (some events return data to the caller via the event - // struct, and posting the event would require a temporary clone, where changes would - // be lost). + // Note: We can't do an automatic blocking post of the message here, because wxWidgets + // isn't really designed for it (some events return data to the caller via the event + // struct, and posting the event would require a temporary clone, where changes would + // be lost). - AffinityAssert_AllowFrom_MainUI(); - return _parent::ProcessEvent( evt ); + AffinityAssert_AllowFrom_MainUI(); + return _parent::ProcessEvent(evt); } -bool wxAppWithHelpers::ProcessEvent( wxEvent* evt ) +bool wxAppWithHelpers::ProcessEvent(wxEvent *evt) { - AffinityAssert_AllowFrom_MainUI(); - std::unique_ptr deleteMe( evt ); - return _parent::ProcessEvent( *deleteMe ); + AffinityAssert_AllowFrom_MainUI(); + std::unique_ptr deleteMe(evt); + return _parent::ProcessEvent(*deleteMe); } -bool wxAppWithHelpers::ProcessEvent( pxActionEvent& evt ) +bool wxAppWithHelpers::ProcessEvent(pxActionEvent &evt) { - if( wxThread::IsMain() ) - return _parent::ProcessEvent( evt ); - else - { - SynchronousActionState sync; - evt.SetSyncState( sync ); - AddPendingEvent( evt ); - sync.WaitForResult(); - return true; - } + if (wxThread::IsMain()) + return _parent::ProcessEvent(evt); + else { + SynchronousActionState sync; + evt.SetSyncState(sync); + AddPendingEvent(evt); + sync.WaitForResult(); + return true; + } } -bool wxAppWithHelpers::ProcessEvent( pxActionEvent* evt ) +bool wxAppWithHelpers::ProcessEvent(pxActionEvent *evt) { - if( wxThread::IsMain() ) - { - std::unique_ptr deleteMe( evt ); - return _parent::ProcessEvent( *deleteMe ); - } - else - { - SynchronousActionState sync; - evt->SetSyncState( sync ); - AddPendingEvent( *evt ); - sync.WaitForResult(); - return true; - } + if (wxThread::IsMain()) { + std::unique_ptr deleteMe(evt); + return _parent::ProcessEvent(*deleteMe); + } else { + SynchronousActionState sync; + evt->SetSyncState(sync); + AddPendingEvent(*evt); + sync.WaitForResult(); + return true; + } } void wxAppWithHelpers::CleanUp() { - // I'm pretty sure the message pump is dead by now, which means we need to run through - // idle event list by hand and process the pending Deletion messages (all others can be - // ignored -- it's only deletions we want handled, and really we *could* ignore those too - // but I like to be tidy. -- air + // I'm pretty sure the message pump is dead by now, which means we need to run through + // idle event list by hand and process the pending Deletion messages (all others can be + // ignored -- it's only deletions we want handled, and really we *could* ignore those too + // but I like to be tidy. -- air - //IdleEventDispatcher( "CleanUp" ); - //DeletionDispatcher(); - _parent::CleanUp(); + //IdleEventDispatcher( "CleanUp" ); + //DeletionDispatcher(); + _parent::CleanUp(); } // Executes the event with exception handling. If the event throws an exception, the exception @@ -440,222 +436,211 @@ void wxAppWithHelpers::CleanUp() // should overload InvokeEvent() instead. void pxActionEvent::_DoInvokeEvent() { - AffinityAssert_AllowFrom_MainUI(); + AffinityAssert_AllowFrom_MainUI(); - try { - InvokeEvent(); - } - catch( BaseException& ex ) - { - SetException( ex ); - } - catch( std::runtime_error& ex ) - { - SetException( new Exception::RuntimeError( ex ) ); - } + try { + InvokeEvent(); + } catch (BaseException &ex) { + SetException(ex); + } catch (std::runtime_error &ex) { + SetException(new Exception::RuntimeError(ex)); + } - if( m_state ) m_state->PostResult(); + if (m_state) + m_state->PostResult(); } -void wxAppWithHelpers::OnSynchronousCommand( pxSynchronousCommandEvent& evt ) +void wxAppWithHelpers::OnSynchronousCommand(pxSynchronousCommandEvent &evt) { - AffinityAssert_AllowFrom_MainUI(); + AffinityAssert_AllowFrom_MainUI(); - pxAppLog.Write(L"(App) Executing command event synchronously..."); - evt.SetEventType( evt.GetRealEventType() ); + pxAppLog.Write(L"(App) Executing command event synchronously..."); + evt.SetEventType(evt.GetRealEventType()); - try { - ProcessEvent( evt ); - } - catch( BaseException& ex ) - { - evt.SetException( ex ); - } - catch( std::runtime_error& ex ) - { - evt.SetException( new Exception::RuntimeError( ex, evt.GetClassInfo()->GetClassName() ) ); - } + try { + ProcessEvent(evt); + } catch (BaseException &ex) { + evt.SetException(ex); + } catch (std::runtime_error &ex) { + evt.SetException(new Exception::RuntimeError(ex, evt.GetClassInfo()->GetClassName())); + } - if( Semaphore* sema = evt.GetSemaphore() ) sema->Post(); + if (Semaphore *sema = evt.GetSemaphore()) + sema->Post(); } -void wxAppWithHelpers::AddIdleEvent( const wxEvent& evt ) +void wxAppWithHelpers::AddIdleEvent(const wxEvent &evt) { - ScopedLock lock( m_IdleEventMutex ); - if( m_IdleEventQueue.empty() ) - PostEvent(wxCommandEvent(pxEvt_StartIdleEventTimer)); + ScopedLock lock(m_IdleEventMutex); + if (m_IdleEventQueue.empty()) + PostEvent(wxCommandEvent(pxEvt_StartIdleEventTimer)); - m_IdleEventQueue.push_back( evt.Clone() ); + m_IdleEventQueue.push_back(evt.Clone()); } -void wxAppWithHelpers::OnStartIdleEventTimer( wxCommandEvent& evt ) +void wxAppWithHelpers::OnStartIdleEventTimer(wxCommandEvent &evt) { - ScopedLock lock( m_IdleEventMutex ); - if( !m_IdleEventQueue.empty() ) - m_IdleEventTimer.Start( 100, true ); + ScopedLock lock(m_IdleEventMutex); + if (!m_IdleEventQueue.empty()) + m_IdleEventTimer.Start(100, true); } -void wxAppWithHelpers::IdleEventDispatcher( const wxChar* action ) +void wxAppWithHelpers::IdleEventDispatcher(const wxChar *action) { - // Recursion is possible thanks to modal dialogs being issued from the idle event handler. - // (recursion shouldn't hurt anything anyway, since the node system re-creates the iterator - // on each pass) - - //static int __guard=0; - //RecursionGuard guard(__guard); - //if( !pxAssertDev(!guard.IsReentrant(), "Re-entrant call to IdleEventdispatcher caught on camera!") ) return; + // Recursion is possible thanks to modal dialogs being issued from the idle event handler. + // (recursion shouldn't hurt anything anyway, since the node system re-creates the iterator + // on each pass) - wxEventList postponed; - wxEventList::iterator node; + //static int __guard=0; + //RecursionGuard guard(__guard); + //if( !pxAssertDev(!guard.IsReentrant(), "Re-entrant call to IdleEventdispatcher caught on camera!") ) return; - ScopedLock lock( m_IdleEventMutex ); + wxEventList postponed; + wxEventList::iterator node; - while( node = m_IdleEventQueue.begin(), node != m_IdleEventQueue.end() ) - { - std::unique_ptr deleteMe(*node); - m_IdleEventQueue.erase( node ); + ScopedLock lock(m_IdleEventMutex); - lock.Release(); - if( !Threading::AllowDeletions() && (deleteMe->GetEventType() == pxEvt_DeleteThread) ) - { - // Threads that have active semaphores or mutexes (other threads are waiting on them) cannot - // be deleted because those mutex/sema objects will become invalid and cause the pending - // thread to crash. So we disallow deletions when those waits are in action, and continue - // to postpone the deletion of the thread until such time that it is safe. + while (node = m_IdleEventQueue.begin(), node != m_IdleEventQueue.end()) { + std::unique_ptr deleteMe(*node); + m_IdleEventQueue.erase(node); - pxThreadLog.Write( ((pxThread*)((wxCommandEvent*)deleteMe.get())->GetClientData())->GetName(), L"Deletion postponed due to mutex or semaphore dependency." ); - postponed.push_back(deleteMe.release()); - } - else - { - pxAppLog.Write( L"(AppIdleQueue%s) Dispatching event '%s'", action, deleteMe->GetClassInfo()->GetClassName() ); - ProcessEvent( *deleteMe ); // dereference to prevent auto-deletion by ProcessEvent - } - lock.Acquire(); - } + lock.Release(); + if (!Threading::AllowDeletions() && (deleteMe->GetEventType() == pxEvt_DeleteThread)) { + // Threads that have active semaphores or mutexes (other threads are waiting on them) cannot + // be deleted because those mutex/sema objects will become invalid and cause the pending + // thread to crash. So we disallow deletions when those waits are in action, and continue + // to postpone the deletion of the thread until such time that it is safe. - m_IdleEventQueue = postponed; - if( !m_IdleEventQueue.empty() ) - pxAppLog.Write( L"(AppIdleQueue%s) %d events postponed due to dependencies.", action, m_IdleEventQueue.size() ); + pxThreadLog.Write(((pxThread *)((wxCommandEvent *)deleteMe.get())->GetClientData())->GetName(), L"Deletion postponed due to mutex or semaphore dependency."); + postponed.push_back(deleteMe.release()); + } else { + pxAppLog.Write(L"(AppIdleQueue%s) Dispatching event '%s'", action, deleteMe->GetClassInfo()->GetClassName()); + ProcessEvent(*deleteMe); // dereference to prevent auto-deletion by ProcessEvent + } + lock.Acquire(); + } + + m_IdleEventQueue = postponed; + if (!m_IdleEventQueue.empty()) + pxAppLog.Write(L"(AppIdleQueue%s) %d events postponed due to dependencies.", action, m_IdleEventQueue.size()); } -void wxAppWithHelpers::OnIdleEvent( wxIdleEvent& evt ) +void wxAppWithHelpers::OnIdleEvent(wxIdleEvent &evt) { - m_IdleEventTimer.Stop(); - IdleEventDispatcher(); + m_IdleEventTimer.Stop(); + IdleEventDispatcher(); } -void wxAppWithHelpers::OnIdleEventTimeout( wxTimerEvent& evt ) +void wxAppWithHelpers::OnIdleEventTimeout(wxTimerEvent &evt) { - IdleEventDispatcher( L"[Timeout]" ); + IdleEventDispatcher(L"[Timeout]"); } void wxAppWithHelpers::Ping() { - pxThreadLog.Write( pxGetCurrentThreadName().c_str(), L"App Event Ping Requested." ); + pxThreadLog.Write(pxGetCurrentThreadName().c_str(), L"App Event Ping Requested."); - SynchronousActionState sync; - pxActionEvent evt( sync ); - AddIdleEvent( evt ); - sync.WaitForResult(); + SynchronousActionState sync; + pxActionEvent evt(sync); + AddIdleEvent(evt); + sync.WaitForResult(); } -void wxAppWithHelpers::PostCommand( void* clientData, int evtType, int intParam, long longParam, const wxString& stringParam ) +void wxAppWithHelpers::PostCommand(void *clientData, int evtType, int intParam, long longParam, const wxString &stringParam) { - wxCommandEvent evt( evtType ); - evt.SetClientData( clientData ); - evt.SetInt( intParam ); - evt.SetExtraLong( longParam ); - evt.SetString( stringParam ); - AddPendingEvent( evt ); + wxCommandEvent evt(evtType); + evt.SetClientData(clientData); + evt.SetInt(intParam); + evt.SetExtraLong(longParam); + evt.SetString(stringParam); + AddPendingEvent(evt); } -void wxAppWithHelpers::PostCommand( int evtType, int intParam, long longParam, const wxString& stringParam ) +void wxAppWithHelpers::PostCommand(int evtType, int intParam, long longParam, const wxString &stringParam) { - PostCommand( NULL, evtType, intParam, longParam, stringParam ); + PostCommand(NULL, evtType, intParam, longParam, stringParam); } -sptr wxAppWithHelpers::ProcessCommand( void* clientData, int evtType, int intParam, long longParam, const wxString& stringParam ) +sptr wxAppWithHelpers::ProcessCommand(void *clientData, int evtType, int intParam, long longParam, const wxString &stringParam) { - SynchronousActionState sync; - pxSynchronousCommandEvent evt( sync, evtType ); + SynchronousActionState sync; + pxSynchronousCommandEvent evt(sync, evtType); - evt.SetClientData( clientData ); - evt.SetInt( intParam ); - evt.SetExtraLong( longParam ); - evt.SetString( stringParam ); - AddPendingEvent( evt ); - sync.WaitForResult(); + evt.SetClientData(clientData); + evt.SetInt(intParam); + evt.SetExtraLong(longParam); + evt.SetString(stringParam); + AddPendingEvent(evt); + sync.WaitForResult(); - return sync.return_value; + return sync.return_value; } -sptr wxAppWithHelpers::ProcessCommand( int evtType, int intParam, long longParam, const wxString& stringParam ) +sptr wxAppWithHelpers::ProcessCommand(int evtType, int intParam, long longParam, const wxString &stringParam) { - return ProcessCommand( NULL, evtType, intParam, longParam, stringParam ); + return ProcessCommand(NULL, evtType, intParam, longParam, stringParam); } -void wxAppWithHelpers::PostAction( const pxActionEvent& evt ) +void wxAppWithHelpers::PostAction(const pxActionEvent &evt) { - PostEvent( evt ); + PostEvent(evt); } -void wxAppWithHelpers::ProcessAction( pxActionEvent& evt ) +void wxAppWithHelpers::ProcessAction(pxActionEvent &evt) { - if( !wxThread::IsMain() ) - { - SynchronousActionState sync; - evt.SetSyncState( sync ); - AddPendingEvent( evt ); - sync.WaitForResult(); - } - else - evt._DoInvokeEvent(); + if (!wxThread::IsMain()) { + SynchronousActionState sync; + evt.SetSyncState(sync); + AddPendingEvent(evt); + sync.WaitForResult(); + } else + evt._DoInvokeEvent(); } -void wxAppWithHelpers::DeleteObject( BaseDeletableObject& obj ) +void wxAppWithHelpers::DeleteObject(BaseDeletableObject &obj) { - pxAssert( !obj.IsBeingDeleted() ); - wxCommandEvent evt( pxEvt_DeleteObject ); - evt.SetClientData( (void*)&obj ); - AddIdleEvent( evt ); + pxAssert(!obj.IsBeingDeleted()); + wxCommandEvent evt(pxEvt_DeleteObject); + evt.SetClientData((void *)&obj); + AddIdleEvent(evt); } -void wxAppWithHelpers::DeleteThread( pxThread& obj ) +void wxAppWithHelpers::DeleteThread(pxThread &obj) { - pxThreadLog.Write(obj.GetName(), L"Scheduling for deletion..."); - wxCommandEvent evt( pxEvt_DeleteThread ); - evt.SetClientData( (void*)&obj ); - AddIdleEvent( evt ); + pxThreadLog.Write(obj.GetName(), L"Scheduling for deletion..."); + wxCommandEvent evt(pxEvt_DeleteThread); + evt.SetClientData((void *)&obj); + AddIdleEvent(evt); } bool wxAppWithHelpers::OnInit() { - Bind(pxEvt_SynchronousCommand, &wxAppWithHelpers::OnSynchronousCommand, this); - Bind(pxEvt_InvokeAction, &wxAppWithHelpers::OnInvokeAction, this); + Bind(pxEvt_SynchronousCommand, &wxAppWithHelpers::OnSynchronousCommand, this); + Bind(pxEvt_InvokeAction, &wxAppWithHelpers::OnInvokeAction, this); - Bind(pxEvt_StartIdleEventTimer, &wxAppWithHelpers::OnStartIdleEventTimer, this); + Bind(pxEvt_StartIdleEventTimer, &wxAppWithHelpers::OnStartIdleEventTimer, this); - Bind(pxEvt_DeleteObject, &wxAppWithHelpers::OnDeleteObject, this); - Bind(pxEvt_DeleteThread, &wxAppWithHelpers::OnDeleteThread, this); + Bind(pxEvt_DeleteObject, &wxAppWithHelpers::OnDeleteObject, this); + Bind(pxEvt_DeleteThread, &wxAppWithHelpers::OnDeleteThread, this); - Bind(wxEVT_IDLE, &wxAppWithHelpers::OnIdleEvent, this); + Bind(wxEVT_IDLE, &wxAppWithHelpers::OnIdleEvent, this); - Bind(wxEVT_TIMER, &wxAppWithHelpers::OnIdleEventTimeout, this, m_IdleEventTimer.GetId()); + Bind(wxEVT_TIMER, &wxAppWithHelpers::OnIdleEventTimeout, this, m_IdleEventTimer.GetId()); - return _parent::OnInit(); + return _parent::OnInit(); } -void wxAppWithHelpers::OnInvokeAction( pxActionEvent& evt ) +void wxAppWithHelpers::OnInvokeAction(pxActionEvent &evt) { - evt._DoInvokeEvent(); // wow this is easy! + evt._DoInvokeEvent(); // wow this is easy! } -void wxAppWithHelpers::OnDeleteObject( wxCommandEvent& evt ) +void wxAppWithHelpers::OnDeleteObject(wxCommandEvent &evt) { - if( evt.GetClientData() == NULL ) return; - delete (BaseDeletableObject*)evt.GetClientData(); + if (evt.GetClientData() == NULL) + return; + delete (BaseDeletableObject *)evt.GetClientData(); } // In theory we create a Pcsx2App object which inherit from wxAppWithHelpers, @@ -665,37 +650,35 @@ void wxAppWithHelpers::OnDeleteObject( wxCommandEvent& evt ) // be called first. This constructor will build some wx objects (here wxTimer) // that require a trait. In others word, wxAppWithHelpers::CreateTraits will be // called instead -wxAppTraits* wxAppWithHelpers::CreateTraits() +wxAppTraits *wxAppWithHelpers::CreateTraits() { - return new Pcsx2AppTraits; + return new Pcsx2AppTraits; } // Threads have their own deletion handler that propagates exceptions thrown by the thread to the UI. // (thus we have a fairly automatic threaded exception system!) -void wxAppWithHelpers::OnDeleteThread( wxCommandEvent& evt ) +void wxAppWithHelpers::OnDeleteThread(wxCommandEvent &evt) { - std::unique_ptr thr( (pxThread*)evt.GetClientData() ); - if( !thr ) - { - pxThreadLog.Write( L"null", L"OnDeleteThread: NULL thread object received (and ignored)." ); - return; - } + std::unique_ptr thr((pxThread *)evt.GetClientData()); + if (!thr) { + pxThreadLog.Write(L"null", L"OnDeleteThread: NULL thread object received (and ignored)."); + return; + } - pxThreadLog.Write(thr->GetName(), wxString(wxString(L"Thread object deleted successfully") + (thr->HasPendingException() ? L" [exception pending!]" : L"")).wc_str() ); - thr->RethrowException(); + pxThreadLog.Write(thr->GetName(), wxString(wxString(L"Thread object deleted successfully") + (thr->HasPendingException() ? L" [exception pending!]" : L"")).wc_str()); + thr->RethrowException(); } wxAppWithHelpers::wxAppWithHelpers() - : m_IdleEventTimer( this ) + : m_IdleEventTimer(this) { #ifdef __WXMSW__ - // This variable assignment ensures that MSVC links in the TLS setup stubs even in - // full optimization builds. Without it, DLLs that use TLS won't work because the - // FS segment register won't have been initialized by the main exe, due to tls_insurance - // being optimized away >_< --air + // This variable assignment ensures that MSVC links in the TLS setup stubs even in + // full optimization builds. Without it, DLLs that use TLS won't work because the + // FS segment register won't have been initialized by the main exe, due to tls_insurance + // being optimized away >_< --air - static __threadlocal int tls_insurance = 0; - tls_insurance = 1; + static __threadlocal int tls_insurance = 0; + tls_insurance = 1; #endif } - diff --git a/common/src/Utilities/wxGuiTools.cpp b/common/src/Utilities/wxGuiTools.cpp index afbfb9ae97..38bf740965 100644 --- a/common/src/Utilities/wxGuiTools.cpp +++ b/common/src/Utilities/wxGuiTools.cpp @@ -21,165 +21,171 @@ #include const pxAlignmentType - pxCentre = { pxAlignmentType::Center }, // Horizontal centered alignment - pxCenter = pxCentre, - pxMiddle = { pxAlignmentType::Middle }, // vertical centered alignment + pxCentre = {pxAlignmentType::Center}, // Horizontal centered alignment + pxCenter = pxCentre, + pxMiddle = {pxAlignmentType::Middle}, // vertical centered alignment - pxAlignLeft = { pxAlignmentType::Left }, - pxAlignRight = { pxAlignmentType::Right }, - pxAlignTop = { pxAlignmentType::Top }, - pxAlignBottom = { pxAlignmentType::Bottom }; + pxAlignLeft = {pxAlignmentType::Left}, + pxAlignRight = {pxAlignmentType::Right}, + pxAlignTop = {pxAlignmentType::Top}, + pxAlignBottom = {pxAlignmentType::Bottom}; const pxStretchType - pxShrink = { pxStretchType::Shrink }, - pxExpand = { pxStretchType::Expand }, - pxShaped = { pxStretchType::Shaped }, - pxReserveHidden = { pxStretchType::ReserveHidden }, - pxFixedMinimum = { pxStretchType::FixedMinimum }; + pxShrink = {pxStretchType::Shrink}, + pxExpand = {pxStretchType::Expand}, + pxShaped = {pxStretchType::Shaped}, + pxReserveHidden = {pxStretchType::ReserveHidden}, + pxFixedMinimum = {pxStretchType::FixedMinimum}; -wxSizerFlags pxAlignmentType::Apply( wxSizerFlags flags ) const +wxSizerFlags pxAlignmentType::Apply(wxSizerFlags flags) const { - switch( intval ) - { - case Centre: - flags.Align( flags.GetFlags() | wxALIGN_CENTRE_HORIZONTAL ); - break; + switch (intval) { + case Centre: + flags.Align(flags.GetFlags() | wxALIGN_CENTRE_HORIZONTAL); + break; - case Middle: - flags.Align( flags.GetFlags() | wxALIGN_CENTRE_VERTICAL ); - break; + case Middle: + flags.Align(flags.GetFlags() | wxALIGN_CENTRE_VERTICAL); + break; - case Left: - flags.Left(); - break; + case Left: + flags.Left(); + break; - case Right: - flags.Right(); - break; + case Right: + flags.Right(); + break; - case Top: - flags.Top(); - break; + case Top: + flags.Top(); + break; - case Bottom: - flags.Bottom(); - break; - } - return flags; + case Bottom: + flags.Bottom(); + break; + } + return flags; } -wxSizerFlags pxStretchType::Apply( wxSizerFlags flags ) const +wxSizerFlags pxStretchType::Apply(wxSizerFlags flags) const { - switch( intval ) - { - case Shrink: - //pxFail( "wxSHRINK is an ignored stretch flag." ); - break; + switch (intval) { + case Shrink: + //pxFail( "wxSHRINK is an ignored stretch flag." ); + break; - case Expand: - flags.Expand(); - break; + case Expand: + flags.Expand(); + break; - case Shaped: - flags.Shaped(); - break; + case Shaped: + flags.Shaped(); + break; - case ReserveHidden: - flags.ReserveSpaceEvenIfHidden(); - break; + case ReserveHidden: + flags.ReserveSpaceEvenIfHidden(); + break; - case FixedMinimum: - flags.FixedMinSize(); - break; + case FixedMinimum: + flags.FixedMinSize(); + break; - //case Tile: - // pxAssert( "pxTile is an unsupported stretch tag (ignored)." ); - //break; - } - return flags; + //case Tile: + // pxAssert( "pxTile is an unsupported stretch tag (ignored)." ); + //break; + } + return flags; } -wxSizerFlags operator& ( const wxSizerFlags& _flgs, const wxSizerFlags& _flgs2 ) +wxSizerFlags operator&(const wxSizerFlags &_flgs, const wxSizerFlags &_flgs2) { - //return align.Apply( _flgs ); - wxSizerFlags retval; + //return align.Apply( _flgs ); + wxSizerFlags retval; - uint allflags = (_flgs.GetFlags() | _flgs2.GetFlags()); + uint allflags = (_flgs.GetFlags() | _flgs2.GetFlags()); - retval.Align( allflags & wxALIGN_MASK ); - if( allflags & wxEXPAND ) retval.Expand(); - if( allflags & wxSHAPED ) retval.Shaped(); - if( allflags & wxFIXED_MINSIZE ) retval.FixedMinSize(); - if( allflags & wxRESERVE_SPACE_EVEN_IF_HIDDEN ) retval.ReserveSpaceEvenIfHidden(); + retval.Align(allflags & wxALIGN_MASK); + if (allflags & wxEXPAND) + retval.Expand(); + if (allflags & wxSHAPED) + retval.Shaped(); + if (allflags & wxFIXED_MINSIZE) + retval.FixedMinSize(); + if (allflags & wxRESERVE_SPACE_EVEN_IF_HIDDEN) + retval.ReserveSpaceEvenIfHidden(); - // Compounding borders is probably a fair approach: - retval.Border( allflags & wxALL, _flgs.GetBorderInPixels() + _flgs2.GetBorderInPixels() ); + // Compounding borders is probably a fair approach: + retval.Border(allflags & wxALL, _flgs.GetBorderInPixels() + _flgs2.GetBorderInPixels()); - // Compounding proportions works as well, I figure. - retval.Proportion( _flgs.GetProportion() + _flgs2.GetProportion() ); + // Compounding proportions works as well, I figure. + retval.Proportion(_flgs.GetProportion() + _flgs2.GetProportion()); - return retval; + return retval; } // ---------------------------------------------------------------------------- // Reference/Handle versions! -void operator+=( wxSizer& target, wxWindow* src ) +void operator+=(wxSizer &target, wxWindow *src) { - target.Add( src ); + target.Add(src); } -void operator+=( wxSizer& target, wxSizer* src ) +void operator+=(wxSizer &target, wxSizer *src) { - target.Add( src ); + target.Add(src); } -void operator+=( wxSizer& target, wxWindow& src ) +void operator+=(wxSizer &target, wxWindow &src) { - target.Add( &src ); + target.Add(&src); } -void operator+=( wxSizer& target, wxSizer& src ) +void operator+=(wxSizer &target, wxSizer &src) { - target.Add( &src ); + target.Add(&src); } -void operator+=( wxSizer& target, int spacer ) +void operator+=(wxSizer &target, int spacer) { - target.AddSpacer( spacer ); + target.AddSpacer(spacer); } -void operator+=( wxSizer& target, const pxStretchSpacer& spacer ) +void operator+=(wxSizer &target, const pxStretchSpacer &spacer) { - target.AddStretchSpacer( spacer.proportion ); + target.AddStretchSpacer(spacer.proportion); } -void operator+=( wxWindow& target, int spacer ) +void operator+=(wxWindow &target, int spacer) { - if( !pxAssert( target.GetSizer() != NULL ) ) return; - target.GetSizer()->AddSpacer( spacer ); + if (!pxAssert(target.GetSizer() != NULL)) + return; + target.GetSizer()->AddSpacer(spacer); } -void operator+=( wxWindow& target, const pxStretchSpacer& spacer ) +void operator+=(wxWindow &target, const pxStretchSpacer &spacer) { - if( !pxAssert( target.GetSizer() != NULL ) ) return; - target.GetSizer()->AddStretchSpacer( spacer.proportion ); + if (!pxAssert(target.GetSizer() != NULL)) + return; + target.GetSizer()->AddStretchSpacer(spacer.proportion); } // ---------------------------------------------------------------------------- // Pointer versions! (note that C++ requires one of the two operator params be a // "poper" object type (non-pointer), so that's why there's only a couple of these. -void operator+=( wxSizer* target, wxWindow& src ) +void operator+=(wxSizer *target, wxWindow &src) { - if( !pxAssert( target != NULL ) ) return; - target->Add( &src ); + if (!pxAssert(target != NULL)) + return; + target->Add(&src); } -void operator+=( wxSizer* target, wxSizer& src ) +void operator+=(wxSizer *target, wxSizer &src) { - if( !pxAssert( target != NULL ) ) return; - target->Add( &src ); + if (!pxAssert(target != NULL)) + return; + target->Add(&src); } // ---------------------------------------------------------------------------- @@ -187,14 +193,14 @@ void operator+=( wxSizer* target, wxSizer& src ) // Returns FALSE if the window position is considered invalid, which means that it's title // bar is most likely not easily grabble. Such a window should be moved to a valid or // default position. -bool pxIsValidWindowPosition( const wxWindow& window, const wxPoint& windowPos ) +bool pxIsValidWindowPosition(const wxWindow &window, const wxPoint &windowPos) { - // The height of the window is only revlevant to the height of a title bar, which is - // all we need visible for the user to be able to drag the window into view. But - // there's no way to get that info from wx, so we'll just have to guesstimate... + // The height of the window is only revlevant to the height of a title bar, which is + // all we need visible for the user to be able to drag the window into view. But + // there's no way to get that info from wx, so we'll just have to guesstimate... - wxSize sizeMatters( window.GetSize().GetWidth(), 32 ); // if some gui has 32 pixels of undraggable title bar, the user deserves to suffer. - return wxGetDisplayArea().Contains( wxRect( windowPos, sizeMatters ) ); + wxSize sizeMatters(window.GetSize().GetWidth(), 32); // if some gui has 32 pixels of undraggable title bar, the user deserves to suffer. + return wxGetDisplayArea().Contains(wxRect(windowPos, sizeMatters)); } // Retrieves the area of the screen, which can be used to enforce a valid zone for @@ -202,7 +208,7 @@ bool pxIsValidWindowPosition( const wxWindow& window, const wxPoint& windowPos ) // is the resolution of the desktop). wxRect wxGetDisplayArea() { - return wxRect( wxPoint(), wxGetDisplaySize() ); + return wxRect(wxPoint(), wxGetDisplaySize()); } // -------------------------------------------------------------------------------------- @@ -218,17 +224,17 @@ wxRect wxGetDisplayArea() // wxSizerFlags pxSizerFlags::StdSpace() { - return wxSizerFlags().Border( wxALL, StdPadding ); + return wxSizerFlags().Border(wxALL, StdPadding); } wxSizerFlags pxSizerFlags::StdCenter() { - return wxSizerFlags().Align( wxALIGN_CENTER ).DoubleBorder(); + return wxSizerFlags().Align(wxALIGN_CENTER).DoubleBorder(); } wxSizerFlags pxSizerFlags::StdExpand() { - return StdSpace().Expand(); + return StdSpace().Expand(); } // A good sizer flags setting for top-level static boxes or top-level picture boxes. @@ -236,7 +242,7 @@ wxSizerFlags pxSizerFlags::StdExpand() // manually by using a spacer. wxSizerFlags pxSizerFlags::TopLevelBox() { - return pxBorder( wxLEFT | wxBOTTOM | wxRIGHT, StdPadding ).Expand(); + return pxBorder(wxLEFT | wxBOTTOM | wxRIGHT, StdPadding).Expand(); } // Flags intended for use on grouped StaticBox controls. These flags are ideal for @@ -245,9 +251,9 @@ wxSizerFlags pxSizerFlags::TopLevelBox() // "tight"). wxSizerFlags pxSizerFlags::SubGroup() { - // Groups look better with a slightly smaller margin than standard. - // (basically this accounts for the group's frame) - return pxBorder( wxLEFT | wxBOTTOM | wxRIGHT, StdPadding-2 ).Expand(); + // Groups look better with a slightly smaller margin than standard. + // (basically this accounts for the group's frame) + return pxBorder(wxLEFT | wxBOTTOM | wxRIGHT, StdPadding - 2).Expand(); } // This force-aligns the std button sizer to the right, where (at least) us win32 platform @@ -255,12 +261,12 @@ wxSizerFlags pxSizerFlags::SubGroup() // just because it's *not* where win32 sticks it. Too bad! wxSizerFlags pxSizerFlags::StdButton() { - return pxBorder().Align( wxALIGN_RIGHT ); + return pxBorder().Align(wxALIGN_RIGHT); } wxSizerFlags pxSizerFlags::Checkbox() { - return StdExpand(); + return StdExpand(); } // -------------------------------------------------------------------------------------- @@ -269,43 +275,44 @@ wxSizerFlags pxSizerFlags::Checkbox() static bool is_cjk_char(const uint ch) { - /** + /** * You can check these range at http://unicode.org/charts/ * see the "East Asian Scripts" part. * Notice that not all characters in that part is still in use today, so don't list them all here. */ - // FIXME: add range from Japanese-specific and Korean-specific section if you know the - // characters are used today. + // FIXME: add range from Japanese-specific and Korean-specific section if you know the + // characters are used today. - if (ch < 0x2e80) return false; // shortcut for common non-CJK + if (ch < 0x2e80) + return false; // shortcut for common non-CJK - return - // Han Ideographs: all except Supplement - (ch >= 0x4e00 && ch < 0x9fcf) || - (ch >= 0x3400 && ch < 0x4dbf) || - (ch >= 0x20000 && ch < 0x2a6df) || - (ch >= 0xf900 && ch < 0xfaff) || - (ch >= 0x3190 && ch < 0x319f) || + return + // Han Ideographs: all except Supplement + (ch >= 0x4e00 && ch < 0x9fcf) || + (ch >= 0x3400 && ch < 0x4dbf) || + (ch >= 0x20000 && ch < 0x2a6df) || + (ch >= 0xf900 && ch < 0xfaff) || + (ch >= 0x3190 && ch < 0x319f) || - // Radicals: all except Ideographic Description - (ch >= 0x2e80 && ch < 0x2eff) || - (ch >= 0x2f00 && ch < 0x2fdf) || - (ch >= 0x31c0 && ch < 0x31ef) || + // Radicals: all except Ideographic Description + (ch >= 0x2e80 && ch < 0x2eff) || + (ch >= 0x2f00 && ch < 0x2fdf) || + (ch >= 0x31c0 && ch < 0x31ef) || - // Chinese-specific: Bopomofo - (ch >= 0x3000 && ch < 0x303f) || + // Chinese-specific: Bopomofo + (ch >= 0x3000 && ch < 0x303f) || - // Japanese-specific: Halfwidth Katakana - (ch >= 0xff00 && ch < 0xffef) || + // Japanese-specific: Halfwidth Katakana + (ch >= 0xff00 && ch < 0xffef) || - // Japanese-specific: Hiragana, Katakana - (ch >= 0x3040 && ch <= 0x309f) || - (ch >= 0x30a0 && ch <= 0x30ff) || + // Japanese-specific: Hiragana, Katakana + (ch >= 0x3040 && ch <= 0x309f) || + (ch >= 0x30a0 && ch <= 0x30ff) || - // Korean-specific: Hangul Syllables, Halfwidth Jamo - (ch >= 0xac00 && ch < 0xd7af) || - (ch >= 0xff00 && ch < 0xffef); + // Korean-specific: Hangul Syllables, Halfwidth Jamo + (ch >= 0xac00 && ch < 0xd7af) || + (ch >= 0xff00 && ch < 0xffef); } /* @@ -325,119 +332,113 @@ static bool is_cjk_char(const uint ch) */ static bool no_break_after(const uint ch) { - switch( ch ) - { - /** - * don't break after these Japanese/Chinese characters - */ - case 0x2018: case 0x201c: case 0x3008: case 0x300a: - case 0x300c: case 0x300e: case 0x3010: case 0x3014: - case 0x3016: case 0x301a: case 0x301d: - case 0xff08: case 0xff3b: case 0xff5b: + // clang-format off + switch (ch) { + /** + * don't break after these Japanese/Chinese characters + */ + case 0x2018: case 0x201c: case 0x3008: case 0x300a: + case 0x300c: case 0x300e: case 0x3010: case 0x3014: + case 0x3016: case 0x301a: case 0x301d: + case 0xff08: case 0xff3b: case 0xff5b: - /** - * FIXME don't break after these Korean characters - */ + /** + * FIXME don't break after these Korean characters + */ - return true; - } + return true; + } + // clang-format on - return false; + return false; } static bool no_break_before(const uint ch) { - switch(ch) - { - /** - * don't break before these Japanese characters - */ - case 0x2019: case 0x201d: case 0x2026: case 0x3001: case 0x3002: - case 0x3005: case 0x3009: case 0x300b: case 0x300d: case 0x300f: - case 0x301c: case 0x3011: case 0x3015: case 0x3017: case 0x301b: - case 0x301e: case 0x3041: case 0x3043: case 0x3045: - case 0x3047: case 0x3049: case 0x3063: case 0x3083: case 0x3085: - case 0x3087: case 0x308e: case 0x309d: case 0x309e: case 0x30a1: - case 0x30a3: case 0x30a5: case 0x30a7: case 0x30a9: case 0x30c3: - case 0x30e3: case 0x30e5: case 0x30e7: case 0x30ee: case 0x30f5: - case 0x30f6: case 0x30fb: case 0x30fc: case 0x30fd: case 0x30fe: - case 0xff01: case 0xff09: case 0xff0c: case 0xff0d: case 0xff0e: case 0xff1a: - case 0xff1b: case 0xff1f: case 0xff3d: case 0xff5d: case 0xff64: case 0xff65: + // clang-format off + switch (ch) { + /** + * don't break before these Japanese characters + */ + case 0x2019: case 0x201d: case 0x2026: case 0x3001: case 0x3002: + case 0x3005: case 0x3009: case 0x300b: case 0x300d: case 0x300f: + case 0x301c: case 0x3011: case 0x3015: case 0x3017: case 0x301b: + case 0x301e: case 0x3041: case 0x3043: case 0x3045: + case 0x3047: case 0x3049: case 0x3063: case 0x3083: case 0x3085: + case 0x3087: case 0x308e: case 0x309d: case 0x309e: case 0x30a1: + case 0x30a3: case 0x30a5: case 0x30a7: case 0x30a9: case 0x30c3: + case 0x30e3: case 0x30e5: case 0x30e7: case 0x30ee: case 0x30f5: + case 0x30f6: case 0x30fb: case 0x30fc: case 0x30fd: case 0x30fe: + case 0xff01: case 0xff09: case 0xff0c: case 0xff0d: case 0xff0e: case 0xff1a: + case 0xff1b: case 0xff1f: case 0xff3d: case 0xff5d: case 0xff64: case 0xff65: - /** - * FIXME don't break before these Korean characters - */ + /** + * FIXME don't break before these Korean characters + */ - /** - * don't break before these Chinese characters - * contains - * many Chinese punctuations that should not start a line - * and right side of different kinds of brackets, quotes - */ - - - return true; - } - return false; + /** + * don't break before these Chinese characters + * contains + * many Chinese punctuations that should not start a line + * and right side of different kinds of brackets, quotes + */ + + return true; + } + // clang-format on + + return false; } -pxTextWrapperBase& pxTextWrapperBase::Wrap( const wxWindow& win, const wxString& text, int widthMax ) +pxTextWrapperBase &pxTextWrapperBase::Wrap(const wxWindow &win, const wxString &text, int widthMax) { - if( text.IsEmpty() ) return *this; + if (text.IsEmpty()) + return *this; const wxChar *lastSpace = NULL; bool wasWrapped = false; wxString line; - line.Alloc( text.Length()+12 ); + line.Alloc(text.Length() + 12); - const wxChar* lineStart = text.wc_str(); - for ( const wxChar *p = lineStart; ; p++ ) - { - if ( IsStartOfNewLine() ) - { + const wxChar *lineStart = text.wc_str(); + for (const wxChar *p = lineStart;; p++) { + if (IsStartOfNewLine()) { OnNewLine(); lastSpace = NULL; lineStart = p; - if(wasWrapped) - line = m_indent; - else - line.clear(); + if (wasWrapped) + line = m_indent; + else + line.clear(); } - if ( *p == L'\n' || *p == L'\0' ) - { - wasWrapped = false; + if (*p == L'\n' || *p == L'\0') { + wasWrapped = false; DoOutputLine(line); - if ( *p == L'\0' ) + if (*p == L'\0') break; - } - else // not EOL + } else // not EOL { - if (is_cjk_char(*p)) - { - if (!no_break_before(*p)) - { - if (p == lineStart || !no_break_after(*(p-1))) - lastSpace = p; - } - } - else if ( *p == L' ' || *p == L',' || *p == L'/' ) + if (is_cjk_char(*p)) { + if (!no_break_before(*p)) { + if (p == lineStart || !no_break_after(*(p - 1))) + lastSpace = p; + } + } else if (*p == L' ' || *p == L',' || *p == L'/') lastSpace = p; line += *p; - if ( widthMax >= 0 && lastSpace ) - { + if (widthMax >= 0 && lastSpace) { int width; win.GetTextExtent(line, &width, NULL); - if ( width > widthMax ) - { - wasWrapped = true; + if (width > widthMax) { + wasWrapped = true; // remove the last word from this line line.erase(lastSpace - lineStart, p + 1 - lineStart); @@ -447,9 +448,8 @@ pxTextWrapperBase& pxTextWrapperBase::Wrap( const wxWindow& win, const wxString& // output yet p = lastSpace; - if ( *p != L' ' ) - p--; - + if (*p != L' ') + p--; } } //else: no wrapping at all or impossible to wrap @@ -459,11 +459,11 @@ pxTextWrapperBase& pxTextWrapperBase::Wrap( const wxWindow& win, const wxString& return *this; } -void pxTextWrapperBase::DoOutputLine(const wxString& line) +void pxTextWrapperBase::DoOutputLine(const wxString &line) { - OnOutputLine(line); - m_linecount++; - m_eol = true; + OnOutputLine(line); + m_linecount++; + m_eol = true; } // this function is a destructive inspector: when it returns true it also @@ -471,99 +471,106 @@ void pxTextWrapperBase::DoOutputLine(const wxString& line) // more bool pxTextWrapperBase::IsStartOfNewLine() { - if ( !m_eol ) - return false; + if (!m_eol) + return false; - m_eol = false; - return true; + m_eol = false; + return true; } -pxTextWrapper& pxTextWrapper::Wrap( const wxWindow& win, const wxString& text, int widthMax ) +pxTextWrapper &pxTextWrapper::Wrap(const wxWindow &win, const wxString &text, int widthMax) { - _parent::Wrap( win, text, widthMax ); - return *this; + _parent::Wrap(win, text, widthMax); + return *this; } -pxTextWrapper& pxTextWrapper::Wrap( const wxWindow* win, const wxString& text, int widthMax ) +pxTextWrapper &pxTextWrapper::Wrap(const wxWindow *win, const wxString &text, int widthMax) { - if( win ) _parent::Wrap( *win, text, widthMax ); - return *this; + if (win) + _parent::Wrap(*win, text, widthMax); + return *this; } -void pxTextWrapper::OnOutputLine(const wxString& line) +void pxTextWrapper::OnOutputLine(const wxString &line) { - m_text += line; + m_text += line; } void pxTextWrapper::OnNewLine() { - m_text += L'\n'; + m_text += L'\n'; } // -------------------------------------------------------------------------------------- // ScopedBusyCursor (implementations) // -------------------------------------------------------------------------------------- -std::stack ScopedBusyCursor::m_cursorStack; -BusyCursorType ScopedBusyCursor::m_defBusyType; +std::stack ScopedBusyCursor::m_cursorStack; +BusyCursorType ScopedBusyCursor::m_defBusyType; -ScopedBusyCursor::ScopedBusyCursor( BusyCursorType busytype ) +ScopedBusyCursor::ScopedBusyCursor(BusyCursorType busytype) { - pxAssert( wxTheApp != NULL ); + pxAssert(wxTheApp != NULL); - BusyCursorType curtype = Cursor_NotBusy; - if( !m_cursorStack.empty() ) - curtype = m_cursorStack.top(); + BusyCursorType curtype = Cursor_NotBusy; + if (!m_cursorStack.empty()) + curtype = m_cursorStack.top(); - if( curtype < busytype ) - SetManualBusyCursor( curtype=busytype ); + if (curtype < busytype) + SetManualBusyCursor(curtype = busytype); - m_cursorStack.push( curtype ); + m_cursorStack.push(curtype); } ScopedBusyCursor::~ScopedBusyCursor() throw() { - if( !pxAssert( wxTheApp != NULL ) ) return; + if (!pxAssert(wxTheApp != NULL)) + return; - if( !pxAssert( !m_cursorStack.empty() ) ) - { - SetManualBusyCursor( m_defBusyType ); - return; - } + if (!pxAssert(!m_cursorStack.empty())) { + SetManualBusyCursor(m_defBusyType); + return; + } - BusyCursorType curtype = m_cursorStack.top(); - m_cursorStack.pop(); + BusyCursorType curtype = m_cursorStack.top(); + m_cursorStack.pop(); - if( m_cursorStack.empty() ) - SetManualBusyCursor( m_defBusyType ); - else if( m_cursorStack.top() != curtype ) - SetManualBusyCursor( m_cursorStack.top() ); + if (m_cursorStack.empty()) + SetManualBusyCursor(m_defBusyType); + else if (m_cursorStack.top() != curtype) + SetManualBusyCursor(m_cursorStack.top()); } -void ScopedBusyCursor::SetDefault( BusyCursorType busytype ) +void ScopedBusyCursor::SetDefault(BusyCursorType busytype) { - if( busytype == m_defBusyType ) return; - m_defBusyType = busytype; + if (busytype == m_defBusyType) + return; + m_defBusyType = busytype; - if( m_cursorStack.empty() ) - SetManualBusyCursor( busytype ); + if (m_cursorStack.empty()) + SetManualBusyCursor(busytype); } -void ScopedBusyCursor::SetManualBusyCursor( BusyCursorType busytype ) +void ScopedBusyCursor::SetManualBusyCursor(BusyCursorType busytype) { - switch( busytype ) - { - case Cursor_NotBusy: wxSetCursor( wxNullCursor ); break; - case Cursor_KindaBusy: wxSetCursor( StockCursors.GetArrowWait() ); break; - case Cursor_ReallyBusy: wxSetCursor( *wxHOURGLASS_CURSOR ); break; - } + switch (busytype) { + case Cursor_NotBusy: + wxSetCursor(wxNullCursor); + break; + case Cursor_KindaBusy: + wxSetCursor(StockCursors.GetArrowWait()); + break; + case Cursor_ReallyBusy: + wxSetCursor(*wxHOURGLASS_CURSOR); + break; + } } -const wxCursor& MoreStockCursors::GetArrowWait() +const wxCursor &MoreStockCursors::GetArrowWait() { - if( !m_arrowWait ) - m_arrowWait = std::unique_ptr(new wxCursor( wxCURSOR_ARROWWAIT )); - return *m_arrowWait; + if (!m_arrowWait) + m_arrowWait = std::unique_ptr(new wxCursor(wxCURSOR_ARROWWAIT)); + return *m_arrowWait; } MoreStockCursors StockCursors; @@ -575,37 +582,39 @@ MoreStockCursors StockCursors; // extends the tooltip time to the maximum possible. GTK seems to have indefinite // tooltips, I don't know about OS X. -void pxSetToolTip( wxWindow* wind, const wxString& src ) +void pxSetToolTip(wxWindow *wind, const wxString &src) { - if( wind == NULL ) return; // Silently ignore nulls - wind->SetToolTip(src); + if (wind == NULL) + return; // Silently ignore nulls + wind->SetToolTip(src); - // Make tooltips show for as long as possible on Windows. Linux (GTK) can - // show tooltips indefinitely. +// Make tooltips show for as long as possible on Windows. Linux (GTK) can +// show tooltips indefinitely. #ifdef __WXMSW__ - wind->GetToolTip()->SetAutoPop(32767); + wind->GetToolTip()->SetAutoPop(32767); #endif } -void pxSetToolTip( wxWindow& wind, const wxString& src ) +void pxSetToolTip(wxWindow &wind, const wxString &src) { - pxSetToolTip( &wind, src ); + pxSetToolTip(&wind, src); } -wxFont pxGetFixedFont( int ptsize, wxFontWeight weight ) +wxFont pxGetFixedFont(int ptsize, wxFontWeight weight) { - return wxFont( - ptsize, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, weight, false + return wxFont( + ptsize, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, weight, false #ifdef __WXMSW__ - ,L"Lucida Console" // better than courier new (win32 only) + , + L"Lucida Console" // better than courier new (win32 only) #endif - ); + ); } wxString pxGetAppName() { - pxAssert( wxTheApp ); - return wxTheApp->GetAppName(); + pxAssert(wxTheApp); + return wxTheApp->GetAppName(); } diff --git a/common/src/Utilities/wxHelpers.cpp b/common/src/Utilities/wxHelpers.cpp index 1cfea691db..822468a9d3 100644 --- a/common/src/Utilities/wxHelpers.cpp +++ b/common/src/Utilities/wxHelpers.cpp @@ -22,7 +22,7 @@ #ifdef __linux__ // I do not know if it is a GCC issue or a bug in wxwidget ! // Anyway the code isn't used (m_hasContextHelp always false) so I remove -// it for linux. The 'vtable' issue appears with the include of +// it for linux. The 'vtable' issue appears with the include of // -- Gregory #define GCC_4_6_LTO_COMPILATION_ISSUE #endif @@ -37,7 +37,7 @@ using namespace pxSizerFlags; pxDialogCreationFlags pxDialogFlags() { - return pxDialogCreationFlags().CloseBox().Caption().Vertical(); + return pxDialogCreationFlags().CloseBox().Caption().Vertical(); } @@ -49,29 +49,29 @@ pxDialogCreationFlags pxDialogFlags() // bool BaseDeletableObject::MarkForDeletion() { - return !m_IsBeingDeleted.exchange(true); + return !m_IsBeingDeleted.exchange(true); } void BaseDeletableObject::DeleteSelf() { - if( MarkForDeletion() ) - DoDeletion(); + if (MarkForDeletion()) + DoDeletion(); } BaseDeletableObject::BaseDeletableObject() { - #ifdef _MSC_VER - // Bleh, this fails because _CrtIsValidHeapPointer calls HeapValidate on the - // pointer, but the pointer is a virtual base class, so it's not a valid block. >_< - //pxAssertDev( _CrtIsValidHeapPointer( this ), "BaseDeletableObject types cannot be created on the stack or as temporaries!" ); - #endif +#ifdef _MSC_VER +// Bleh, this fails because _CrtIsValidHeapPointer calls HeapValidate on the +// pointer, but the pointer is a virtual base class, so it's not a valid block. >_< +//pxAssertDev( _CrtIsValidHeapPointer( this ), "BaseDeletableObject types cannot be created on the stack or as temporaries!" ); +#endif - m_IsBeingDeleted.store(false, std::memory_order_relaxed); + m_IsBeingDeleted.store(false, std::memory_order_relaxed); } BaseDeletableObject::~BaseDeletableObject() throw() { - AffinityAssert_AllowFrom_MainUI(); + AffinityAssert_AllowFrom_MainUI(); } @@ -80,37 +80,37 @@ BaseDeletableObject::~BaseDeletableObject() throw() // Creates a text control which is right-justified and has it's minimum width configured to suit // the number of digits requested. -wxTextCtrl* CreateNumericalTextCtrl( wxWindow* parent, int digits, long flags ) +wxTextCtrl *CreateNumericalTextCtrl(wxWindow *parent, int digits, long flags) { - wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY ); - ctrl->SetWindowStyleFlag( flags ); - pxFitToDigits( ctrl, digits ); - return ctrl; + wxTextCtrl *ctrl = new wxTextCtrl(parent, wxID_ANY); + ctrl->SetWindowStyleFlag(flags); + pxFitToDigits(ctrl, digits); + return ctrl; } -void pxFitToDigits( wxWindow* win, int digits ) +void pxFitToDigits(wxWindow *win, int digits) { - int ex; - win->GetTextExtent( wxString( L'0', digits+1 ), &ex, NULL ); - win->SetMinSize( wxSize( ex+10, wxDefaultCoord ) ); // +10 for text control borders/insets and junk. + int ex; + win->GetTextExtent(wxString(L'0', digits + 1), &ex, NULL); + win->SetMinSize(wxSize(ex + 10, wxDefaultCoord)); // +10 for text control borders/insets and junk. } -void pxFitToDigits( wxSpinCtrl* win, int digits ) +void pxFitToDigits(wxSpinCtrl *win, int digits) { - // HACK!! The better way would be to create a pxSpinCtrl class that extends wxSpinCtrl and thus - // have access to wxSpinButton::DoGetBestSize(). But since I don't want to do that, we'll just - // make/fake it with a value it's pretty common to Win32/GTK/Mac: + // HACK!! The better way would be to create a pxSpinCtrl class that extends wxSpinCtrl and thus + // have access to wxSpinButton::DoGetBestSize(). But since I don't want to do that, we'll just + // make/fake it with a value it's pretty common to Win32/GTK/Mac: - static const int MagicSpinnerSize = 18; + static const int MagicSpinnerSize = 18; - int ex; - win->GetTextExtent( wxString( L'0', digits+1 ), &ex, NULL ); - win->SetMinSize( wxSize( ex+10+MagicSpinnerSize, wxDefaultCoord ) ); // +10 for text control borders/insets and junk. + int ex; + win->GetTextExtent(wxString(L'0', digits + 1), &ex, NULL); + win->SetMinSize(wxSize(ex + 10 + MagicSpinnerSize, wxDefaultCoord)); // +10 for text control borders/insets and junk. } -bool pxDialogExists( const wxString& name ) +bool pxDialogExists(const wxString &name) { - return wxFindWindowByName( name ) != NULL; + return wxFindWindowByName(name) != NULL; } // ===================================================================================================== @@ -123,129 +123,124 @@ IMPLEMENT_DYNAMIC_CLASS(wxDialogWithHelpers, wxDialog) wxDialogWithHelpers::wxDialogWithHelpers() { - m_hasContextHelp = false; - m_extraButtonSizer = NULL; + m_hasContextHelp = false; + m_extraButtonSizer = NULL; - Init( pxDialogFlags() ); + Init(pxDialogFlags()); } -wxDialogWithHelpers::wxDialogWithHelpers( wxWindow* parent, const wxString& title, const pxDialogCreationFlags& cflags ) - : wxDialog( parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, cflags.GetWxWindowFlags() ) +wxDialogWithHelpers::wxDialogWithHelpers(wxWindow *parent, const wxString &title, const pxDialogCreationFlags &cflags) + : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, cflags.GetWxWindowFlags()) { - m_hasContextHelp = cflags.hasContextHelp; - if( (int)cflags.BoxSizerOrient != 0 ) - { - SetSizer( new wxBoxSizer( cflags.BoxSizerOrient ) ); - *this += StdPadding; - } + m_hasContextHelp = cflags.hasContextHelp; + if ((int)cflags.BoxSizerOrient != 0) { + SetSizer(new wxBoxSizer(cflags.BoxSizerOrient)); + *this += StdPadding; + } - Init( cflags ); - SetMinSize( cflags.MinimumSize ); + Init(cflags); + SetMinSize(cflags.MinimumSize); } wxDialogWithHelpers::~wxDialogWithHelpers() throw() { } -void wxDialogWithHelpers::Init( const pxDialogCreationFlags& cflags ) +void wxDialogWithHelpers::Init(const pxDialogCreationFlags &cflags) { - // Note to self: if any comments indicate platform specific behaviour then - // ifdef them out to see if they fix the issue. I wasted too much time - // figuring out why the close box wouldn't work on wxGTK modal dialogs that - // had a minimise button. +// Note to self: if any comments indicate platform specific behaviour then +// ifdef them out to see if they fix the issue. I wasted too much time +// figuring out why the close box wouldn't work on wxGTK modal dialogs that +// had a minimise button. #if _WIN32 - // This fixes it so that the dialogs show up in the task bar in Vista: - // (otherwise they go stupid iconized mode if the user minimizes them) - if( cflags.hasMinimizeBox ) - SetExtraStyle(GetExtraStyle() & ~wxTOPLEVEL_EX_DIALOG); + // This fixes it so that the dialogs show up in the task bar in Vista: + // (otherwise they go stupid iconized mode if the user minimizes them) + if (cflags.hasMinimizeBox) + SetExtraStyle(GetExtraStyle() & ~wxTOPLEVEL_EX_DIALOG); #endif - m_extraButtonSizer = NULL; + m_extraButtonSizer = NULL; #ifndef GCC_4_6_LTO_COMPILATION_ISSUE - if( m_hasContextHelp ) - delete wxHelpProvider::Set( new wxSimpleHelpProvider() ); + if (m_hasContextHelp) + delete wxHelpProvider::Set(new wxSimpleHelpProvider()); #endif - Bind(pxEvt_OnDialogCreated, &wxDialogWithHelpers::OnDialogCreated, this); + Bind(pxEvt_OnDialogCreated, &wxDialogWithHelpers::OnDialogCreated, this); - Bind(wxEVT_BUTTON, &wxDialogWithHelpers::OnOkCancel, this, wxID_OK); - Bind(wxEVT_BUTTON, &wxDialogWithHelpers::OnOkCancel, this, wxID_CANCEL); + Bind(wxEVT_BUTTON, &wxDialogWithHelpers::OnOkCancel, this, wxID_OK); + Bind(wxEVT_BUTTON, &wxDialogWithHelpers::OnOkCancel, this, wxID_CANCEL); - wxCommandEvent createEvent( pxEvt_OnDialogCreated ); - createEvent.SetId( GetId() ); - AddPendingEvent( createEvent ); + wxCommandEvent createEvent(pxEvt_OnDialogCreated); + createEvent.SetId(GetId()); + AddPendingEvent(createEvent); } -void wxDialogWithHelpers::OnDialogCreated( wxCommandEvent& evt ) +void wxDialogWithHelpers::OnDialogCreated(wxCommandEvent &evt) { - evt.Skip(); - if( (evt.GetId() == GetId()) && !GetDialogName().IsEmpty() ) - SetName( L"Dialog:" + GetDialogName() ); + evt.Skip(); + if ((evt.GetId() == GetId()) && !GetDialogName().IsEmpty()) + SetName(L"Dialog:" + GetDialogName()); } wxString wxDialogWithHelpers::GetDialogName() const { - return wxEmptyString; + return wxEmptyString; } void wxDialogWithHelpers::DoAutoCenter() { - // Smart positioning logic! If our parent window is larger than our window by some - // good amount, then we center on that. If not, center relative to the screen. This - // avoids the popup automatically eclipsing the parent window (which happens in PCSX2 - // a lot since the main window is small). + // Smart positioning logic! If our parent window is larger than our window by some + // good amount, then we center on that. If not, center relative to the screen. This + // avoids the popup automatically eclipsing the parent window (which happens in PCSX2 + // a lot since the main window is small). - bool centerfail = true; - if( wxWindow* parent = GetParent() ) - { - const wxSize parentSize( parent->GetSize() ); + bool centerfail = true; + if (wxWindow *parent = GetParent()) { + const wxSize parentSize(parent->GetSize()); - if( (parentSize.x > ((int)GetSize().x * 1.5)) || (parentSize.y > ((int)GetSize().y * 1.5)) ) - { - CenterOnParent(); - centerfail = false; - } - } + if ((parentSize.x > ((int)GetSize().x * 1.5)) || (parentSize.y > ((int)GetSize().y * 1.5))) { + CenterOnParent(); + centerfail = false; + } + } - if( centerfail ) CenterOnScreen(); + if (centerfail) + CenterOnScreen(); } void wxDialogWithHelpers::SmartCenterFit() { - Fit(); + Fit(); - const wxString dlgName( GetDialogName() ); - if( dlgName.IsEmpty() ) - { - DoAutoCenter(); return; - } + const wxString dlgName(GetDialogName()); + if (dlgName.IsEmpty()) { + DoAutoCenter(); + return; + } - if( wxConfigBase* cfg = wxConfigBase::Get( false ) ) - { - wxRect screenRect( GetScreenRect() ); + if (wxConfigBase *cfg = wxConfigBase::Get(false)) { + wxRect screenRect(GetScreenRect()); - IniLoader loader( cfg ); - ScopedIniGroup group( loader, L"DialogPositions" ); - cfg->SetRecordDefaults( false ); + IniLoader loader(cfg); + ScopedIniGroup group(loader, L"DialogPositions"); + cfg->SetRecordDefaults(false); - if( GetWindowStyle() & wxRESIZE_BORDER ) - { - wxSize size; - loader.Entry( dlgName + L"_Size", size, screenRect.GetSize() ); - SetSize( size ); - } + if (GetWindowStyle() & wxRESIZE_BORDER) { + wxSize size; + loader.Entry(dlgName + L"_Size", size, screenRect.GetSize()); + SetSize(size); + } - if( !cfg->Exists( dlgName + L"_Pos" ) ) - DoAutoCenter(); - else - { - wxPoint pos; - loader.Entry( dlgName + L"_Pos", pos, screenRect.GetPosition() ); - SetPosition( pos ); - } - cfg->SetRecordDefaults( true ); - } + if (!cfg->Exists(dlgName + L"_Pos")) + DoAutoCenter(); + else { + wxPoint pos; + loader.Entry(dlgName + L"_Pos", pos, screenRect.GetPosition()); + SetPosition(pos); + } + cfg->SetRecordDefaults(true); + } } // Overrides wxDialog behavior to include automatic Fit() and CenterOnParent/Screen. The centering @@ -253,142 +248,138 @@ void wxDialogWithHelpers::SmartCenterFit() // 75% larger than the fitted dialog. int wxDialogWithHelpers::ShowModal() { - SmartCenterFit(); - m_CreatedRect = GetScreenRect(); - return wxDialog::ShowModal(); + SmartCenterFit(); + m_CreatedRect = GetScreenRect(); + return wxDialog::ShowModal(); } // Overrides wxDialog behavior to include automatic Fit() and CenterOnParent/Screen. The centering // is based on a heuristic the centers against the parent window if the parent window is at least // 75% larger than the fitted dialog. -bool wxDialogWithHelpers::Show( bool show ) +bool wxDialogWithHelpers::Show(bool show) { - if( show ) - { - SmartCenterFit(); - m_CreatedRect = GetScreenRect(); - } - return wxDialog::Show( show ); + if (show) { + SmartCenterFit(); + m_CreatedRect = GetScreenRect(); + } + return wxDialog::Show(show); } -wxStaticText& wxDialogWithHelpers::Label( const wxString& label ) +wxStaticText &wxDialogWithHelpers::Label(const wxString &label) { - return *new wxStaticText( this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_VERTICAL ); + return *new wxStaticText(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_VERTICAL); } -pxStaticText& wxDialogWithHelpers::Text( const wxString& label ) +pxStaticText &wxDialogWithHelpers::Text(const wxString &label) { - return *new pxStaticText( this, label ); + return *new pxStaticText(this, label); } -pxStaticText& wxDialogWithHelpers::Heading( const wxString& label ) +pxStaticText &wxDialogWithHelpers::Heading(const wxString &label) { - return *new pxStaticHeading( this, label ); + return *new pxStaticHeading(this, label); } void wxDialogWithHelpers::RememberPosition() { - // Save the dialog position if the dialog is named... - // FIXME : This doesn't get called if the app is exited by alt-f4'ing the main app window. - // ... not sure how to fix that yet. I could register a list of open windows into wxAppWithHelpers - // that systematically get closed. Seems like work, maybe later. --air + // Save the dialog position if the dialog is named... + // FIXME : This doesn't get called if the app is exited by alt-f4'ing the main app window. + // ... not sure how to fix that yet. I could register a list of open windows into wxAppWithHelpers + // that systematically get closed. Seems like work, maybe later. --air - if( wxConfigBase* cfg = IsIconized() ? NULL : wxConfigBase::Get( false ) ) - { - const wxString dlgName( GetDialogName() ); - const wxRect screenRect( GetScreenRect() ); - if( !dlgName.IsEmpty() && ( m_CreatedRect != screenRect) ) - { - wxPoint pos( screenRect.GetPosition() ); - IniSaver saver( cfg ); - ScopedIniGroup group( saver, L"DialogPositions" ); + if (wxConfigBase *cfg = IsIconized() ? NULL : wxConfigBase::Get(false)) { + const wxString dlgName(GetDialogName()); + const wxRect screenRect(GetScreenRect()); + if (!dlgName.IsEmpty() && (m_CreatedRect != screenRect)) { + wxPoint pos(screenRect.GetPosition()); + IniSaver saver(cfg); + ScopedIniGroup group(saver, L"DialogPositions"); - if( GetWindowStyle() & wxRESIZE_BORDER ) - { - wxSize size( screenRect.GetSize() ); - saver.Entry( dlgName + L"_Size", size, screenRect.GetSize() ); - } - saver.Entry( dlgName + L"_Pos", pos, screenRect.GetPosition() ); - } - } + if (GetWindowStyle() & wxRESIZE_BORDER) { + wxSize size(screenRect.GetSize()); + saver.Entry(dlgName + L"_Size", size, screenRect.GetSize()); + } + saver.Entry(dlgName + L"_Pos", pos, screenRect.GetPosition()); + } + } } -void wxDialogWithHelpers::OnOkCancel( wxCommandEvent& evt ) +void wxDialogWithHelpers::OnOkCancel(wxCommandEvent &evt) { - RememberPosition(); + RememberPosition(); - // Modal dialogs should be destroyed after ShowModal returns, otherwise there - // might be double delete problems if the dialog was declared on the stack. - if (!IsModal()) - Destroy(); - else - evt.Skip(); + // Modal dialogs should be destroyed after ShowModal returns, otherwise there + // might be double delete problems if the dialog was declared on the stack. + if (!IsModal()) + Destroy(); + else + evt.Skip(); } -void wxDialogWithHelpers::AddOkCancel( wxSizer &sizer, bool hasApply ) +void wxDialogWithHelpers::AddOkCancel(wxSizer &sizer, bool hasApply) { - wxStdDialogButtonSizer& s_buttons( *new wxStdDialogButtonSizer() ); + wxStdDialogButtonSizer &s_buttons(*new wxStdDialogButtonSizer()); - s_buttons.AddButton( new wxButton( this, wxID_OK ) ); - s_buttons.AddButton( new wxButton( this, wxID_CANCEL ) ); + s_buttons.AddButton(new wxButton(this, wxID_OK)); + s_buttons.AddButton(new wxButton(this, wxID_CANCEL)); - if( hasApply ) - s_buttons.AddButton( new wxButton( this, wxID_APPLY ) ); + if (hasApply) + s_buttons.AddButton(new wxButton(this, wxID_APPLY)); - m_extraButtonSizer = new wxBoxSizer( wxHORIZONTAL ); + m_extraButtonSizer = new wxBoxSizer(wxHORIZONTAL); #ifndef GCC_4_6_LTO_COMPILATION_ISSUE - // Add the context-sensitive help button on the caption for the platforms - // which support it (currently MSW only) - if( m_hasContextHelp ) - { - SetExtraStyle( wxDIALOG_EX_CONTEXTHELP ); + // Add the context-sensitive help button on the caption for the platforms + // which support it (currently MSW only) + if (m_hasContextHelp) { + SetExtraStyle(wxDIALOG_EX_CONTEXTHELP); #ifndef __WXMSW__ - *m_extraButtonSizer += new wxContextHelpButton(this) | StdButton(); + *m_extraButtonSizer += new wxContextHelpButton(this) | StdButton(); #endif - } + } #endif - // create a sizer to hold the help and ok/cancel buttons, for platforms - // that need a custom help icon. [fixme: help icon prolly better off somewhere else] - wxFlexGridSizer& flex( *new wxFlexGridSizer( 2 ) ); - flex.AddGrowableCol( 0, 1 ); - flex.AddGrowableCol( 1, 15 ); + // create a sizer to hold the help and ok/cancel buttons, for platforms + // that need a custom help icon. [fixme: help icon prolly better off somewhere else] + wxFlexGridSizer &flex(*new wxFlexGridSizer(2)); + flex.AddGrowableCol(0, 1); + flex.AddGrowableCol(1, 15); - flex += m_extraButtonSizer | pxAlignLeft; - flex += s_buttons | (pxExpand & pxCenter); + flex += m_extraButtonSizer | pxAlignLeft; + flex += s_buttons | (pxExpand & pxCenter); - sizer += flex | StdExpand(); + sizer += flex | StdExpand(); - s_buttons.Realize(); + s_buttons.Realize(); } -void wxDialogWithHelpers::AddOkCancel( wxSizer *sizer, bool hasApply ) +void wxDialogWithHelpers::AddOkCancel(wxSizer *sizer, bool hasApply) { - if( sizer == NULL ) sizer = GetSizer(); - pxAssert( sizer ); - AddOkCancel( *sizer, hasApply ); + if (sizer == NULL) + sizer = GetSizer(); + pxAssert(sizer); + AddOkCancel(*sizer, hasApply); } -wxDialogWithHelpers& wxDialogWithHelpers::SetMinWidth( int newWidth ) +wxDialogWithHelpers &wxDialogWithHelpers::SetMinWidth(int newWidth) { - SetMinSize( wxSize( newWidth, GetMinHeight() ) ); - if( wxSizer* sizer = GetSizer() ) - sizer->SetMinSize( wxSize( newWidth, sizer->GetMinSize().GetHeight() ) ); - return *this; + SetMinSize(wxSize(newWidth, GetMinHeight())); + if (wxSizer *sizer = GetSizer()) + sizer->SetMinSize(wxSize(newWidth, sizer->GetMinSize().GetHeight())); + return *this; } -wxDialogWithHelpers& wxDialogWithHelpers::SetMinHeight( int newHeight ) +wxDialogWithHelpers &wxDialogWithHelpers::SetMinHeight(int newHeight) { - SetMinSize( wxSize( GetMinWidth(), newHeight ) ); - if( wxSizer* sizer = GetSizer() ) - sizer->SetMinSize( wxSize( sizer->GetMinSize().GetWidth(), newHeight ) ); - return *this; + SetMinSize(wxSize(GetMinWidth(), newHeight)); + if (wxSizer *sizer = GetSizer()) + sizer->SetMinSize(wxSize(sizer->GetMinSize().GetWidth(), newHeight)); + return *this; } int wxDialogWithHelpers::GetCharHeight() const { - return pxGetCharHeight( this, 1 ); + return pxGetCharHeight(this, 1); } // -------------------------------------------------------------------------------------- @@ -405,83 +396,84 @@ void wxPanelWithHelpers::Init() // sizer for this panel. If the panel already has a sizer set, then that sizer will be // transfered to the new StaticBoxSizer (and will be the first item in it's list, retaining // consistent and expected layout) -wxPanelWithHelpers* wxPanelWithHelpers::AddFrame( const wxString& label, wxOrientation orient ) +wxPanelWithHelpers *wxPanelWithHelpers::AddFrame(const wxString &label, wxOrientation orient) { - wxSizer* oldSizer = GetSizer(); + wxSizer *oldSizer = GetSizer(); - SetSizer( new wxStaticBoxSizer( orient, this, label ), false ); - Init(); + SetSizer(new wxStaticBoxSizer(orient, this, label), false); + Init(); - if( oldSizer ) - *this += oldSizer | pxExpand; + if (oldSizer) + *this += oldSizer | pxExpand; - return this; + return this; } -wxStaticText& wxPanelWithHelpers::Label( const wxString& label ) +wxStaticText &wxPanelWithHelpers::Label(const wxString &label) { - return *new wxStaticText( this, wxID_ANY, label ); + return *new wxStaticText(this, wxID_ANY, label); } -pxStaticText& wxPanelWithHelpers::Text( const wxString& label ) +pxStaticText &wxPanelWithHelpers::Text(const wxString &label) { - return *new pxStaticText( this, label ); + return *new pxStaticText(this, label); } -pxStaticText& wxPanelWithHelpers::Heading( const wxString& label ) +pxStaticText &wxPanelWithHelpers::Heading(const wxString &label) { - return *new pxStaticHeading( this, label ); + return *new pxStaticHeading(this, label); } -wxPanelWithHelpers::wxPanelWithHelpers( wxWindow* parent, wxOrientation orient, const wxString& staticBoxLabel ) - : wxPanel( parent ) +wxPanelWithHelpers::wxPanelWithHelpers(wxWindow *parent, wxOrientation orient, const wxString &staticBoxLabel) + : wxPanel(parent) { - SetSizer( new wxStaticBoxSizer( orient, this, staticBoxLabel ) ); - Init(); + SetSizer(new wxStaticBoxSizer(orient, this, staticBoxLabel)); + Init(); } -wxPanelWithHelpers::wxPanelWithHelpers( wxWindow* parent, wxOrientation orient ) - : wxPanel( parent ) +wxPanelWithHelpers::wxPanelWithHelpers(wxWindow *parent, wxOrientation orient) + : wxPanel(parent) { - SetSizer( new wxBoxSizer( orient ) ); - Init(); + SetSizer(new wxBoxSizer(orient)); + Init(); } -wxPanelWithHelpers::wxPanelWithHelpers( wxWindow* parent ) - : wxPanel( parent ) +wxPanelWithHelpers::wxPanelWithHelpers(wxWindow *parent) + : wxPanel(parent) { - Init(); + Init(); } -wxPanelWithHelpers::wxPanelWithHelpers( wxWindow* parent, const wxPoint& pos, const wxSize& size ) - : wxPanel( parent, wxID_ANY, pos, size ) +wxPanelWithHelpers::wxPanelWithHelpers(wxWindow *parent, const wxPoint &pos, const wxSize &size) + : wxPanel(parent, wxID_ANY, pos, size) { - Init(); + Init(); } -wxPanelWithHelpers& wxPanelWithHelpers::SetMinWidth( int newWidth ) +wxPanelWithHelpers &wxPanelWithHelpers::SetMinWidth(int newWidth) { - SetMinSize( wxSize( newWidth, GetMinHeight() ) ); - if( wxSizer* sizer = GetSizer() ) - sizer->SetMinSize( wxSize( newWidth, sizer->GetMinSize().GetHeight() ) ); - return *this; + SetMinSize(wxSize(newWidth, GetMinHeight())); + if (wxSizer *sizer = GetSizer()) + sizer->SetMinSize(wxSize(newWidth, sizer->GetMinSize().GetHeight())); + return *this; } -int pxGetCharHeight( const wxWindow* wind, int rows ) +int pxGetCharHeight(const wxWindow *wind, int rows) { - if( !wind ) return 0; - wxClientDC dc(wx_const_cast(wxWindow*, wind)); - dc.SetFont( wind->GetFont() ); + if (!wind) + return 0; + wxClientDC dc(wx_const_cast(wxWindow *, wind)); + dc.SetFont(wind->GetFont()); #ifdef __linux__ - // It seems there is a bad detection of the size of the font (non standard dpi ???). Font are cut in top or bottom. - // Add a correction factor to leave enough room. Visualy 1.7 seems fine but feel free to tune it -- Gregory - return (dc.GetCharHeight() * 1.7 + 1 ) * rows; + // It seems there is a bad detection of the size of the font (non standard dpi ???). Font are cut in top or bottom. + // Add a correction factor to leave enough room. Visualy 1.7 seems fine but feel free to tune it -- Gregory + return (dc.GetCharHeight() * 1.7 + 1) * rows; #else - return (dc.GetCharHeight() + 1 ) * rows; + return (dc.GetCharHeight() + 1) * rows; #endif } -int pxGetCharHeight( const wxWindow& wind, int rows ) +int pxGetCharHeight(const wxWindow &wind, int rows) { - return pxGetCharHeight( &wind, rows ); + return pxGetCharHeight(&wind, rows); } diff --git a/common/src/Utilities/x86/MemcpyFast.cpp b/common/src/Utilities/x86/MemcpyFast.cpp index 2dcd56b346..144809328b 100644 --- a/common/src/Utilities/x86/MemcpyFast.cpp +++ b/common/src/Utilities/x86/MemcpyFast.cpp @@ -4,7 +4,7 @@ #include "PrecompiledHeader.h" #ifdef _MSC_VER -#pragma warning(disable:4414) +#pragma warning(disable : 4414) #endif // Inline assembly syntax for use with Visual C++ @@ -15,11 +15,11 @@ // returns 0 is equal, nonzero value if not equal // ~10 times faster than standard memcmp // (zerofrog) -u8 memcmp_mmx(const void* src1, const void* src2, int cmpsize) +u8 memcmp_mmx(const void *src1, const void *src2, int cmpsize) { - pxAssert( (cmpsize&7) == 0 ); + pxAssert((cmpsize & 7) == 0); - __asm { + __asm { mov ecx, cmpsize mov edx, src1 mov esi, src2 @@ -27,7 +27,7 @@ u8 memcmp_mmx(const void* src1, const void* src2, int cmpsize) cmp ecx, 32 jl Done4 - // custom test first 8 to make sure things are ok + // custom test first 8 to make sure things are ok movq mm0, [esi] movq mm1, [esi+8] pcmpeqd mm0, [edx] @@ -37,7 +37,7 @@ u8 memcmp_mmx(const void* src1, const void* src2, int cmpsize) pmovmskb eax, mm0 movq mm3, [esi+24] - // check if eq + // check if eq cmp eax, 0xff je NextComp mov eax, 1 @@ -53,7 +53,7 @@ NextComp: add esi, 32 add edx, 32 - // check if eq + // check if eq cmp eax, 0xff je ContinueTest mov eax, 1 @@ -88,7 +88,7 @@ Cmp8: pand mm0, mm7 pmovmskb eax, mm0 - // check if eq + // check if eq cmp eax, 0xff je Continue mov eax, 1 @@ -121,7 +121,7 @@ Done8: add esi, 32 add edx, 32 - // check if eq + // check if eq cmp eax, 0xff je Done4 mov eax, 1 @@ -140,7 +140,7 @@ Done4: pand mm0, mm2 pmovmskb eax, mm0 - // check if eq + // check if eq cmp eax, 0xff setne al jmp End @@ -156,7 +156,7 @@ Done2: pand mm0, mm1 pmovmskb eax, mm0 - // check if eq + // check if eq cmp eax, 0xff setne al jmp End @@ -182,7 +182,7 @@ Done: End: emms - } + } } #endif diff --git a/common/src/x86emitter/LnxCpuDetect.cpp b/common/src/x86emitter/LnxCpuDetect.cpp index de2f913e05..66a5b4caba 100644 --- a/common/src/x86emitter/LnxCpuDetect.cpp +++ b/common/src/x86emitter/LnxCpuDetect.cpp @@ -22,10 +22,10 @@ // FreeBSD/OsX need something far more complicated (apparently) void x86capabilities::CountLogicalCores() { - // Note : GetCPUCount uses sysconf( _SC_NPROCESSORS_ONLN ) internally, which can return 1 - // if sysconf info isn't available (a long standing linux bug). There are no fallbacks or - // alternatives, apparently. - LogicalCores = wxThread::GetCPUCount(); + // Note : GetCPUCount uses sysconf( _SC_NPROCESSORS_ONLN ) internally, which can return 1 + // if sysconf info isn't available (a long standing linux bug). There are no fallbacks or + // alternatives, apparently. + LogicalCores = wxThread::GetCPUCount(); } // Not implemented yet for linux (see cpudetect_internal.h for details) diff --git a/common/src/x86emitter/PrecompiledHeader.h b/common/src/x86emitter/PrecompiledHeader.h index 06d76f5543..2ebb4dea2f 100644 --- a/common/src/x86emitter/PrecompiledHeader.h +++ b/common/src/x86emitter/PrecompiledHeader.h @@ -23,8 +23,8 @@ #include "Pcsx2Defs.h" #include -#include // string.h under c++ -#include // stdio.h under c++ +#include // string.h under c++ +#include // stdio.h under c++ #include #include "Utilities/Console.h" @@ -33,4 +33,3 @@ #include "Utilities/MemcpyFast.h" #endif - diff --git a/common/src/x86emitter/WinCpuDetect.cpp b/common/src/x86emitter/WinCpuDetect.cpp index f612404d83..b92a491cb6 100644 --- a/common/src/x86emitter/WinCpuDetect.cpp +++ b/common/src/x86emitter/WinCpuDetect.cpp @@ -19,65 +19,64 @@ void x86capabilities::CountLogicalCores() { - DWORD_PTR vProcessCPUs; - DWORD_PTR vSystemCPUs; + DWORD_PTR vProcessCPUs; + DWORD_PTR vSystemCPUs; - LogicalCores = 1; + LogicalCores = 1; - if (!GetProcessAffinityMask(GetCurrentProcess(), &vProcessCPUs, &vSystemCPUs)) - return; + if (!GetProcessAffinityMask(GetCurrentProcess(), &vProcessCPUs, &vSystemCPUs)) + return; - uint CPUs = 0; - for (DWORD_PTR bit = 1; bit != 0; bit <<= 1) - if (vSystemCPUs & bit) - CPUs++; + uint CPUs = 0; + for (DWORD_PTR bit = 1; bit != 0; bit <<= 1) + if (vSystemCPUs & bit) + CPUs++; - LogicalCores = CPUs; + LogicalCores = CPUs; } SingleCoreAffinity::SingleCoreAffinity() { - s_threadId = nullptr; - s_oldmask = ERROR_INVALID_PARAMETER; + s_threadId = nullptr; + s_oldmask = ERROR_INVALID_PARAMETER; - DWORD_PTR availProcCpus; - DWORD_PTR availSysCpus; - if (!GetProcessAffinityMask(GetCurrentProcess(), &availProcCpus, &availSysCpus)) - return; + DWORD_PTR availProcCpus; + DWORD_PTR availSysCpus; + if (!GetProcessAffinityMask(GetCurrentProcess(), &availProcCpus, &availSysCpus)) + return; - int cpu = 0; - DWORD_PTR affinityMask; - for (affinityMask = 1; affinityMask != 0; affinityMask <<= 1, ++cpu) - if (availProcCpus & affinityMask) - break; + int cpu = 0; + DWORD_PTR affinityMask; + for (affinityMask = 1; affinityMask != 0; affinityMask <<= 1, ++cpu) + if (availProcCpus & affinityMask) + break; - s_threadId = GetCurrentThread(); - s_oldmask = SetThreadAffinityMask(s_threadId, affinityMask); + s_threadId = GetCurrentThread(); + s_oldmask = SetThreadAffinityMask(s_threadId, affinityMask); - if (s_oldmask == ERROR_INVALID_PARAMETER) { - const int hexWidth = 2 * sizeof(DWORD_PTR); - Console.Warning( - "CpuDetect: SetThreadAffinityMask failed...\n" - "\tSystem Affinity : 0x%0*x\n" - "\tProcess Affinity: 0x%0*x\n" - "\tAttempted Thread Affinity CPU: %i", - hexWidth, availProcCpus, hexWidth, availSysCpus, cpu - ); - } + if (s_oldmask == ERROR_INVALID_PARAMETER) { + const int hexWidth = 2 * sizeof(DWORD_PTR); + Console.Warning( + "CpuDetect: SetThreadAffinityMask failed...\n" + "\tSystem Affinity : 0x%0*x\n" + "\tProcess Affinity: 0x%0*x\n" + "\tAttempted Thread Affinity CPU: %i", + hexWidth, availProcCpus, hexWidth, availSysCpus, cpu); + } - Sleep(2); + Sleep(2); - // Sleep Explained: I arbitrarily pick Core 0 to lock to for running the CPU test. This - // means that the current thread will need to be switched to Core 0 if it's currently - // scheduled on a difference cpu/core. However, Windows does not necessarily perform - // that scheduling immediately upon the call to SetThreadAffinityMask (seems dependent - // on version: XP does, Win7 does not). So by issuing a Sleep here we give Win7 time - // to issue a timeslice and move our thread to Core 0. Without this, it tends to move - // the thread during the cpuSpeed test instead, causing totally wacky results. + // Sleep Explained: I arbitrarily pick Core 0 to lock to for running the CPU test. This + // means that the current thread will need to be switched to Core 0 if it's currently + // scheduled on a difference cpu/core. However, Windows does not necessarily perform + // that scheduling immediately upon the call to SetThreadAffinityMask (seems dependent + // on version: XP does, Win7 does not). So by issuing a Sleep here we give Win7 time + // to issue a timeslice and move our thread to Core 0. Without this, it tends to move + // the thread during the cpuSpeed test instead, causing totally wacky results. }; SingleCoreAffinity::~SingleCoreAffinity() throw() { - if (s_oldmask != ERROR_INVALID_PARAMETER) - SetThreadAffinityMask(s_threadId, s_oldmask); + if (s_oldmask != ERROR_INVALID_PARAMETER) + SetThreadAffinityMask(s_threadId, s_oldmask); } diff --git a/common/src/x86emitter/bmi.cpp b/common/src/x86emitter/bmi.cpp index cd5ce7db8d..33303b7518 100644 --- a/common/src/x86emitter/bmi.cpp +++ b/common/src/x86emitter/bmi.cpp @@ -17,16 +17,20 @@ #include "internal.h" #include "tools.h" -namespace x86Emitter { +namespace x86Emitter +{ - const xImplBMI_RVM xMULX = { 0xF2, 0x38, 0xF6 }; - const xImplBMI_RVM xPDEP = { 0xF2, 0x38, 0xF5 }; - const xImplBMI_RVM xPEXT = { 0xF3, 0x38, 0xF5 }; - const xImplBMI_RVM xANDN_S = { 0x00, 0x38, 0xF2 }; - - void xImplBMI_RVM::operator()( const xRegisterInt& to, const xRegisterInt& from1, const xRegisterInt& from2) const - { xOpWriteC4(Prefix, MbPrefix, Opcode, to, from1, from2); } - void xImplBMI_RVM::operator()( const xRegisterInt& to, const xRegisterInt& from1, const xIndirectVoid& from2) const - { xOpWriteC4(Prefix, MbPrefix, Opcode, to, from1, from2); } +const xImplBMI_RVM xMULX = {0xF2, 0x38, 0xF6}; +const xImplBMI_RVM xPDEP = {0xF2, 0x38, 0xF5}; +const xImplBMI_RVM xPEXT = {0xF3, 0x38, 0xF5}; +const xImplBMI_RVM xANDN_S = {0x00, 0x38, 0xF2}; +void xImplBMI_RVM::operator()(const xRegisterInt &to, const xRegisterInt &from1, const xRegisterInt &from2) const +{ + xOpWriteC4(Prefix, MbPrefix, Opcode, to, from1, from2); +} +void xImplBMI_RVM::operator()(const xRegisterInt &to, const xRegisterInt &from1, const xIndirectVoid &from2) const +{ + xOpWriteC4(Prefix, MbPrefix, Opcode, to, from1, from2); +} } diff --git a/common/src/x86emitter/cpudetect.cpp b/common/src/x86emitter/cpudetect.cpp index 0a117e79ca..2854f6dd51 100644 --- a/common/src/x86emitter/cpudetect.cpp +++ b/common/src/x86emitter/cpudetect.cpp @@ -22,24 +22,24 @@ using namespace x86Emitter; __aligned16 x86capabilities x86caps; -x86capabilities::x86capabilities() : - isIdentified(false), - VendorID(x86Vendor_Unknown), - FamilyID(0), - Model(0), - TypeID(0), - StepID(0), - Flags(0), - Flags2(0), - EFlags(0), - EFlags2(0), - SEFlag(0), - AllCapabilities(0), - PhysicalCores(0), - LogicalCores(0) +x86capabilities::x86capabilities() + : isIdentified(false) + , VendorID(x86Vendor_Unknown) + , FamilyID(0) + , Model(0) + , TypeID(0) + , StepID(0) + , Flags(0) + , Flags2(0) + , EFlags(0) + , EFlags2(0) + , SEFlag(0) + , AllCapabilities(0) + , PhysicalCores(0) + , LogicalCores(0) { - memzero(VendorName); - memzero(FamilyName); + memzero(VendorName); + memzero(FamilyName); } // Warning! We've had problems with the MXCSR detection code causing stack corruption in @@ -49,28 +49,28 @@ x86capabilities::x86capabilities() : // Note: recSSE was deleted void x86capabilities::SIMD_EstablishMXCSRmask() { - if( !hasStreamingSIMDExtensions ) return; + if (!hasStreamingSIMDExtensions) + return; - MXCSR_Mask.bitmask = 0xFFBF; // MMX/SSE default + MXCSR_Mask.bitmask = 0xFFBF; // MMX/SSE default - if( hasStreamingSIMD2Extensions ) - { - // This is generally safe assumption, but FXSAVE is the "correct" way to - // detect MXCSR masking features of the cpu, so we use it's result below - // and override this. + if (hasStreamingSIMD2Extensions) { + // This is generally safe assumption, but FXSAVE is the "correct" way to + // detect MXCSR masking features of the cpu, so we use it's result below + // and override this. - MXCSR_Mask.bitmask = 0xFFFF; // SSE2 features added - } + MXCSR_Mask.bitmask = 0xFFFF; // SSE2 features added + } - __aligned16 u8 targetFXSAVE[512]; + __aligned16 u8 targetFXSAVE[512]; - // Work for recent enough GCC/CLANG/MSVC 2012 - _fxsave(&targetFXSAVE); + // Work for recent enough GCC/CLANG/MSVC 2012 + _fxsave(&targetFXSAVE); - u32 result; - memcpy(&result, &targetFXSAVE[28], 4); // bytes 28->32 are the MXCSR_Mask. - if( result != 0 ) - MXCSR_Mask.bitmask = result; + u32 result; + memcpy(&result, &targetFXSAVE[28], 4); // bytes 28->32 are the MXCSR_Mask. + if (result != 0) + MXCSR_Mask.bitmask = result; } // Counts the number of cpu cycles executed over the requested number of PerformanceCounter @@ -78,244 +78,250 @@ void x86capabilities::SIMD_EstablishMXCSRmask() // For best results you should pick a period of time long enough to get a reading that won't // be prone to rounding error; but short enough that it'll be highly unlikely to be interrupted // by the operating system task switches. -s64 x86capabilities::_CPUSpeedHz( u64 time ) const +s64 x86capabilities::_CPUSpeedHz(u64 time) const { - u64 timeStart, timeStop; - s64 startCycle, endCycle; + u64 timeStart, timeStop; + s64 startCycle, endCycle; - if( ! hasTimeStampCounter ) - return 0; + if (!hasTimeStampCounter) + return 0; - SingleCoreAffinity affinity_lock; + SingleCoreAffinity affinity_lock; - // Align the cpu execution to a cpuTick boundary. + // Align the cpu execution to a cpuTick boundary. - // GCC 4.8 has __rdtsc but apparently it causes a crash. Only known working on MSVC - do { - timeStart = GetCPUTicks(); + // GCC 4.8 has __rdtsc but apparently it causes a crash. Only known working on MSVC + do { + timeStart = GetCPUTicks(); #ifdef _MSC_VER - startCycle = __rdtsc(); + startCycle = __rdtsc(); #elif defined(_M_X86_64) - unsigned long long low, high; - __asm__ __volatile__("rdtsc" : "=a"(low), "=d"(high)); - startCycle = low | (high << 32); + unsigned long long low, high; + __asm__ __volatile__("rdtsc" + : "=a"(low), "=d"(high)); + startCycle = low | (high << 32); #else - __asm__ __volatile__("rdtsc" : "=A"(startCycle)); + __asm__ __volatile__("rdtsc" + : "=A"(startCycle)); #endif - } while( GetCPUTicks() == timeStart ); + } while (GetCPUTicks() == timeStart); - do { - timeStop = GetCPUTicks(); + do { + timeStop = GetCPUTicks(); #ifdef _MSC_VER - endCycle = __rdtsc(); + endCycle = __rdtsc(); #elif defined(_M_X86_64) - unsigned long long low, high; - __asm__ __volatile__("rdtsc" : "=a"(low), "=d"(high)); - endCycle = low | (high << 32); + unsigned long long low, high; + __asm__ __volatile__("rdtsc" + : "=a"(low), "=d"(high)); + endCycle = low | (high << 32); #else - __asm__ __volatile__("rdtsc" : "=A"(endCycle)); + __asm__ __volatile__("rdtsc" + : "=A"(endCycle)); #endif - } while( ( timeStop - timeStart ) < time ); + } while ((timeStop - timeStart) < time); - s64 cycleCount = endCycle - startCycle; - s64 timeCount = timeStop - timeStart; - s64 overrun = timeCount - time; - if( !overrun ) return cycleCount; + s64 cycleCount = endCycle - startCycle; + s64 timeCount = timeStop - timeStart; + s64 overrun = timeCount - time; + if (!overrun) + return cycleCount; - // interference could cause us to overshoot the target time, compensate: + // interference could cause us to overshoot the target time, compensate: - double cyclesPerTick = (double)cycleCount / (double)timeCount; - double newCycleCount = (double)cycleCount - (cyclesPerTick * overrun); + double cyclesPerTick = (double)cycleCount / (double)timeCount; + double newCycleCount = (double)cycleCount - (cyclesPerTick * overrun); - return (s64)newCycleCount; + return (s64)newCycleCount; } wxString x86capabilities::GetTypeName() const { - switch( TypeID ) - { - case 0: return L"Standard OEM"; - case 1: return L"Overdrive"; - case 2: return L"Dual"; - case 3: return L"Reserved"; - default: return L"Unknown"; - } + switch (TypeID) { + case 0: + return L"Standard OEM"; + case 1: + return L"Overdrive"; + case 2: + return L"Dual"; + case 3: + return L"Reserved"; + default: + return L"Unknown"; + } } void x86capabilities::CountCores() { - Identify(); + Identify(); - s32 regs[ 4 ]; - u32 cmds; + s32 regs[4]; + u32 cmds; - cpuid( regs, 0x80000000 ); - cmds = regs[ 0 ]; + cpuid(regs, 0x80000000); + cmds = regs[0]; - // detect multicore for AMD cpu + // detect multicore for AMD cpu - if ((cmds >= 0x80000008) && (VendorID == x86Vendor_AMD) ) - { - // AMD note: they don't support hyperthreading, but they like to flag this true - // anyway. Let's force-unflag it until we come up with a better solution. - // (note: seems to affect some Phenom II's only? -- Athlon X2's and PhenomI's do - // not seem to do this) --air - hasMultiThreading = 0; - } + if ((cmds >= 0x80000008) && (VendorID == x86Vendor_AMD)) { + // AMD note: they don't support hyperthreading, but they like to flag this true + // anyway. Let's force-unflag it until we come up with a better solution. + // (note: seems to affect some Phenom II's only? -- Athlon X2's and PhenomI's do + // not seem to do this) --air + hasMultiThreading = 0; + } - // This will assign values into LogicalCores and PhysicalCores - CountLogicalCores(); + // This will assign values into LogicalCores and PhysicalCores + CountLogicalCores(); } -static const char* tbl_x86vendors[] = -{ - "GenuineIntel", - "AuthenticAMD", - "Unknown ", +static const char *tbl_x86vendors[] = + { + "GenuineIntel", + "AuthenticAMD", + "Unknown ", }; // Performs all _cpuid-related activity. This fills *most* of the x86caps structure, except for // the cpuSpeed and the mxcsr masks. Those must be completed manually. void x86capabilities::Identify() { - if( isIdentified ) return; - isIdentified = true; + if (isIdentified) + return; + isIdentified = true; - s32 regs[ 4 ]; - u32 cmds; + s32 regs[4]; + u32 cmds; - //AMD 64 STUFF +//AMD 64 STUFF #ifdef __x86_64__ - u32 x86_64_8BITBRANDID; - u32 x86_64_12BITBRANDID; + u32 x86_64_8BITBRANDID; + u32 x86_64_12BITBRANDID; #endif - memzero( VendorName ); - cpuid( regs, 0 ); + memzero(VendorName); + cpuid(regs, 0); - cmds = regs[ 0 ]; - memcpy(&VendorName[0], ®s[1], 4); - memcpy(&VendorName[4], ®s[3], 4); - memcpy(&VendorName[8], ®s[2], 4); + cmds = regs[0]; + memcpy(&VendorName[0], ®s[1], 4); + memcpy(&VendorName[4], ®s[3], 4); + memcpy(&VendorName[8], ®s[2], 4); - // Determine Vendor Specifics! - // It's really not recommended that we base much (if anything) on CPU vendor names, - // however it's currently necessary in order to gain a (pseudo)reliable count of cores - // and threads used by the CPU (AMD and Intel can't agree on how to make this info available). + // Determine Vendor Specifics! + // It's really not recommended that we base much (if anything) on CPU vendor names, + // however it's currently necessary in order to gain a (pseudo)reliable count of cores + // and threads used by the CPU (AMD and Intel can't agree on how to make this info available). - int vid; - for( vid=0; vid(vid); + int vid; + for (vid = 0; vid < x86Vendor_Unknown; ++vid) { + if (memcmp(VendorName, tbl_x86vendors[vid], 12) == 0) + break; + } + VendorID = static_cast(vid); - if ( cmds >= 0x00000001 ) - { - cpuid( regs, 0x00000001 ); + if (cmds >= 0x00000001) { + cpuid(regs, 0x00000001); - StepID = regs[ 0 ] & 0xf; - Model = (regs[ 0 ] >> 4) & 0xf; - FamilyID = (regs[ 0 ] >> 8) & 0xf; - TypeID = (regs[ 0 ] >> 12) & 0x3; + StepID = regs[0] & 0xf; + Model = (regs[0] >> 4) & 0xf; + FamilyID = (regs[0] >> 8) & 0xf; + TypeID = (regs[0] >> 12) & 0x3; #ifdef __x86_64__ - x86_64_8BITBRANDID = regs[ 1 ] & 0xff; + x86_64_8BITBRANDID = regs[1] & 0xff; #endif - Flags = regs[ 3 ]; - Flags2 = regs[ 2 ]; - } + Flags = regs[3]; + Flags2 = regs[2]; + } - if ( cmds >= 0x00000007 ) - { - // Note: ECX must be 0 for AVX2 detection. - cpuidex( regs, 0x00000007, 0 ); + if (cmds >= 0x00000007) { + // Note: ECX must be 0 for AVX2 detection. + cpuidex(regs, 0x00000007, 0); - SEFlag = regs[ 1 ]; - } + SEFlag = regs[1]; + } - cpuid( regs, 0x80000000 ); - cmds = regs[ 0 ]; - if ( cmds >= 0x80000001 ) - { - cpuid( regs, 0x80000001 ); + cpuid(regs, 0x80000000); + cmds = regs[0]; + if (cmds >= 0x80000001) { + cpuid(regs, 0x80000001); #ifdef __x86_64__ - x86_64_12BITBRANDID = regs[1] & 0xfff; + x86_64_12BITBRANDID = regs[1] & 0xfff; #endif - EFlags2 = regs[ 2 ]; - EFlags = regs[ 3 ]; - } + EFlags2 = regs[2]; + EFlags = regs[3]; + } - memzero( FamilyName ); - cpuid( (int*)FamilyName, 0x80000002); - cpuid( (int*)(FamilyName+16), 0x80000003); - cpuid( (int*)(FamilyName+32), 0x80000004); + memzero(FamilyName); + cpuid((int *)FamilyName, 0x80000002); + cpuid((int *)(FamilyName + 16), 0x80000003); + cpuid((int *)(FamilyName + 32), 0x80000004); - hasFloatingPointUnit = ( Flags >> 0 ) & 1; - hasVirtual8086ModeEnhancements = ( Flags >> 1 ) & 1; - hasDebuggingExtensions = ( Flags >> 2 ) & 1; - hasPageSizeExtensions = ( Flags >> 3 ) & 1; - hasTimeStampCounter = ( Flags >> 4 ) & 1; - hasModelSpecificRegisters = ( Flags >> 5 ) & 1; - hasPhysicalAddressExtension = ( Flags >> 6 ) & 1; - hasMachineCheckArchitecture = ( Flags >> 7 ) & 1; - hasCOMPXCHG8BInstruction = ( Flags >> 8 ) & 1; - hasAdvancedProgrammableInterruptController = ( Flags >> 9 ) & 1; - hasSEPFastSystemCall = ( Flags >> 11 ) & 1; - hasMemoryTypeRangeRegisters = ( Flags >> 12 ) & 1; - hasPTEGlobalFlag = ( Flags >> 13 ) & 1; - hasMachineCheckArchitecture = ( Flags >> 14 ) & 1; - hasConditionalMoveAndCompareInstructions = ( Flags >> 15 ) & 1; - hasFGPageAttributeTable = ( Flags >> 16 ) & 1; - has36bitPageSizeExtension = ( Flags >> 17 ) & 1; - hasProcessorSerialNumber = ( Flags >> 18 ) & 1; - hasCFLUSHInstruction = ( Flags >> 19 ) & 1; - hasDebugStore = ( Flags >> 21 ) & 1; - hasACPIThermalMonitorAndClockControl = ( Flags >> 22 ) & 1; - hasFastStreamingSIMDExtensionsSaveRestore = ( Flags >> 24 ) & 1; - hasStreamingSIMDExtensions = ( Flags >> 25 ) & 1; //sse - hasStreamingSIMD2Extensions = ( Flags >> 26 ) & 1; //sse2 - hasSelfSnoop = ( Flags >> 27 ) & 1; - hasMultiThreading = ( Flags >> 28 ) & 1; - hasThermalMonitor = ( Flags >> 29 ) & 1; - hasIntel64BitArchitecture = ( Flags >> 30 ) & 1; + hasFloatingPointUnit = (Flags >> 0) & 1; + hasVirtual8086ModeEnhancements = (Flags >> 1) & 1; + hasDebuggingExtensions = (Flags >> 2) & 1; + hasPageSizeExtensions = (Flags >> 3) & 1; + hasTimeStampCounter = (Flags >> 4) & 1; + hasModelSpecificRegisters = (Flags >> 5) & 1; + hasPhysicalAddressExtension = (Flags >> 6) & 1; + hasMachineCheckArchitecture = (Flags >> 7) & 1; + hasCOMPXCHG8BInstruction = (Flags >> 8) & 1; + hasAdvancedProgrammableInterruptController = (Flags >> 9) & 1; + hasSEPFastSystemCall = (Flags >> 11) & 1; + hasMemoryTypeRangeRegisters = (Flags >> 12) & 1; + hasPTEGlobalFlag = (Flags >> 13) & 1; + hasMachineCheckArchitecture = (Flags >> 14) & 1; + hasConditionalMoveAndCompareInstructions = (Flags >> 15) & 1; + hasFGPageAttributeTable = (Flags >> 16) & 1; + has36bitPageSizeExtension = (Flags >> 17) & 1; + hasProcessorSerialNumber = (Flags >> 18) & 1; + hasCFLUSHInstruction = (Flags >> 19) & 1; + hasDebugStore = (Flags >> 21) & 1; + hasACPIThermalMonitorAndClockControl = (Flags >> 22) & 1; + hasFastStreamingSIMDExtensionsSaveRestore = (Flags >> 24) & 1; + hasStreamingSIMDExtensions = (Flags >> 25) & 1; //sse + hasStreamingSIMD2Extensions = (Flags >> 26) & 1; //sse2 + hasSelfSnoop = (Flags >> 27) & 1; + hasMultiThreading = (Flags >> 28) & 1; + hasThermalMonitor = (Flags >> 29) & 1; + hasIntel64BitArchitecture = (Flags >> 30) & 1; - // ------------------------------------------------- - // --> SSE3 / SSSE3 / SSE4.1 / SSE 4.2 detection <-- - // ------------------------------------------------- + // ------------------------------------------------- + // --> SSE3 / SSSE3 / SSE4.1 / SSE 4.2 detection <-- + // ------------------------------------------------- - hasStreamingSIMD3Extensions = ( Flags2 >> 0 ) & 1; //sse3 - hasSupplementalStreamingSIMD3Extensions = ( Flags2 >> 9 ) & 1; //ssse3 - hasStreamingSIMD4Extensions = ( Flags2 >> 19 ) & 1; //sse4.1 - hasStreamingSIMD4Extensions2 = ( Flags2 >> 20 ) & 1; //sse4.2 + hasStreamingSIMD3Extensions = (Flags2 >> 0) & 1; //sse3 + hasSupplementalStreamingSIMD3Extensions = (Flags2 >> 9) & 1; //ssse3 + hasStreamingSIMD4Extensions = (Flags2 >> 19) & 1; //sse4.1 + hasStreamingSIMD4Extensions2 = (Flags2 >> 20) & 1; //sse4.2 - if((Flags2 >> 27) & 1) // OSXSAVE - { - if((_xgetbv(0) & 6) == 6) // XFEATURE_ENABLED_MASK[2:1] = '11b' (XMM state and YMM state are enabled by OS). - { - hasAVX = ( Flags2 >> 28 ) & 1; //avx - hasFMA = ( Flags2 >> 12 ) & 1; //fma - hasAVX2 = ( SEFlag >> 5 ) & 1; //avx2 - } - } + if ((Flags2 >> 27) & 1) // OSXSAVE + { + if ((_xgetbv(0) & 6) == 6) // XFEATURE_ENABLED_MASK[2:1] = '11b' (XMM state and YMM state are enabled by OS). + { + hasAVX = (Flags2 >> 28) & 1; //avx + hasFMA = (Flags2 >> 12) & 1; //fma + hasAVX2 = (SEFlag >> 5) & 1; //avx2 + } + } - hasBMI1 = ( SEFlag >> 3 ) & 1; - hasBMI2 = ( SEFlag >> 8 ) & 1; + hasBMI1 = (SEFlag >> 3) & 1; + hasBMI2 = (SEFlag >> 8) & 1; - // Ones only for AMDs: - hasAMD64BitArchitecture = ( EFlags >> 29 ) & 1; //64bit cpu - hasStreamingSIMD4ExtensionsA = ( EFlags2 >> 6 ) & 1; //INSERTQ / EXTRQ / MOVNT + // Ones only for AMDs: + hasAMD64BitArchitecture = (EFlags >> 29) & 1; //64bit cpu + hasStreamingSIMD4ExtensionsA = (EFlags2 >> 6) & 1; //INSERTQ / EXTRQ / MOVNT - isIdentified = true; + isIdentified = true; } u32 x86capabilities::CalculateMHz() const { - InitCPUTicks(); - u64 span = GetTickFrequency(); + InitCPUTicks(); + u64 span = GetTickFrequency(); - if( (span % 1000) < 400 ) // helps minimize rounding errors - return (u32)( _CPUSpeedHz( span / 1000 ) / 1000 ); - else - return (u32)( _CPUSpeedHz( span / 500 ) / 2000 ); + if ((span % 1000) < 400) // helps minimize rounding errors + return (u32)(_CPUSpeedHz(span / 1000) / 1000); + else + return (u32)(_CPUSpeedHz(span / 500) / 2000); } diff --git a/common/src/x86emitter/cpudetect_internal.h b/common/src/x86emitter/cpudetect_internal.h index 1e39a85c3e..90b2fc0faf 100644 --- a/common/src/x86emitter/cpudetect_internal.h +++ b/common/src/x86emitter/cpudetect_internal.h @@ -27,13 +27,12 @@ class SingleCoreAffinity { protected: - #ifdef _WIN32 - HANDLE s_threadId; - DWORD_PTR s_oldmask; + HANDLE s_threadId; + DWORD_PTR s_oldmask; #endif public: - SingleCoreAffinity(); - virtual ~SingleCoreAffinity() throw(); + SingleCoreAffinity(); + virtual ~SingleCoreAffinity() throw(); }; diff --git a/common/src/x86emitter/fpu.cpp b/common/src/x86emitter/fpu.cpp index 4ac2e43768..c833917f99 100644 --- a/common/src/x86emitter/fpu.cpp +++ b/common/src/x86emitter/fpu.cpp @@ -20,54 +20,54 @@ // FPU instructions //------------------------------------------------------------------ /* fld m32 to fpu reg stack */ -emitterT void FLD32( u32 from ) +emitterT void FLD32(u32 from) { - xWrite8( 0xD9 ); - ModRM( 0, 0x0, DISP32 ); - xWrite32( MEMADDR(from, 4) ); + xWrite8(0xD9); + ModRM(0, 0x0, DISP32); + xWrite32(MEMADDR(from, 4)); } // fld st(i) -emitterT void FLD(int st) { xWrite16(0xc0d9+(st<<8)); } -emitterT void FLD1() { xWrite16(0xe8d9); } -emitterT void FLDL2E() { xWrite16(0xead9); } +emitterT void FLD(int st) { xWrite16(0xc0d9 + (st << 8)); } +emitterT void FLD1() { xWrite16(0xe8d9); } +emitterT void FLDL2E() { xWrite16(0xead9); } /* fstp m32 from fpu reg stack */ -emitterT void FSTP32( u32 to ) +emitterT void FSTP32(u32 to) { - xWrite8( 0xD9 ); - ModRM( 0, 0x3, DISP32 ); - xWrite32( MEMADDR(to, 4) ); + xWrite8(0xD9); + ModRM(0, 0x3, DISP32); + xWrite32(MEMADDR(to, 4)); } // fstp st(i) -emitterT void FSTP(int st) { xWrite16(0xd8dd+(st<<8)); } +emitterT void FSTP(int st) { xWrite16(0xd8dd + (st << 8)); } -emitterT void FRNDINT() { xWrite16(0xfcd9); } -emitterT void FXCH(int st) { xWrite16(0xc8d9+(st<<8)); } -emitterT void F2XM1() { xWrite16(0xf0d9); } -emitterT void FSCALE() { xWrite16(0xfdd9); } -emitterT void FPATAN(void) { xWrite16(0xf3d9); } -emitterT void FSIN(void) { xWrite16(0xfed9); } +emitterT void FRNDINT() { xWrite16(0xfcd9); } +emitterT void FXCH(int st) { xWrite16(0xc8d9 + (st << 8)); } +emitterT void F2XM1() { xWrite16(0xf0d9); } +emitterT void FSCALE() { xWrite16(0xfdd9); } +emitterT void FPATAN(void) { xWrite16(0xf3d9); } +emitterT void FSIN(void) { xWrite16(0xfed9); } /* fadd ST(0) to fpu reg stack ST(src) */ -emitterT void FADD320toR( x86IntRegType src ) +emitterT void FADD320toR(x86IntRegType src) { - xWrite8( 0xDC ); - xWrite8( 0xC0 + src ); + xWrite8(0xDC); + xWrite8(0xC0 + src); } /* fsub ST(src) to fpu reg stack ST(0) */ -emitterT void FSUB32Rto0( x86IntRegType src ) +emitterT void FSUB32Rto0(x86IntRegType src) { - xWrite8( 0xD8 ); - xWrite8( 0xE0 + src ); + xWrite8(0xD8); + xWrite8(0xE0 + src); } /* fmul m32 to fpu reg stack */ -emitterT void FMUL32( u32 from ) +emitterT void FMUL32(u32 from) { - xWrite8( 0xD8 ); - ModRM( 0, 0x1, DISP32 ); - xWrite32( MEMADDR(from, 4) ); + xWrite8(0xD8); + ModRM(0, 0x1, DISP32); + xWrite32(MEMADDR(from, 4)); } diff --git a/common/src/x86emitter/groups.cpp b/common/src/x86emitter/groups.cpp index 4b1e05c658..350901a68c 100644 --- a/common/src/x86emitter/groups.cpp +++ b/common/src/x86emitter/groups.cpp @@ -32,7 +32,8 @@ #include "internal.h" #include "implement/helpers.h" -namespace x86Emitter { +namespace x86Emitter +{ // ===================================================================================================== // Group 1 Instructions - ADD, SUB, ADC, etc. @@ -41,228 +42,216 @@ namespace x86Emitter { // Note on "[Indirect],Imm" forms : use int as the source operand since it's "reasonably inert" from a // compiler perspective. (using uint tends to make the compiler try and fail to match signed immediates // with one of the other overloads). -static void _g1_IndirectImm( G1Type InstType, const xIndirect64orLess& sibdest, int imm ) +static void _g1_IndirectImm(G1Type InstType, const xIndirect64orLess &sibdest, int imm) { - if( sibdest.Is8BitOp() ) - { - xOpWrite( sibdest.GetPrefix16(), 0x80, InstType, sibdest ); + if (sibdest.Is8BitOp()) { + xOpWrite(sibdest.GetPrefix16(), 0x80, InstType, sibdest); - xWrite( imm ); - } - else - { - u8 opcode = is_s8( imm ) ? 0x83 : 0x81; - xOpWrite( sibdest.GetPrefix16(), opcode, InstType, sibdest ); + xWrite(imm); + } else { + u8 opcode = is_s8(imm) ? 0x83 : 0x81; + xOpWrite(sibdest.GetPrefix16(), opcode, InstType, sibdest); - if( is_s8( imm ) ) - xWrite( imm ); - else - sibdest.xWriteImm( imm ); - } + if (is_s8(imm)) + xWrite(imm); + else + sibdest.xWriteImm(imm); + } } -void _g1_EmitOp( G1Type InstType, const xRegisterInt& to, const xRegisterInt& from ) +void _g1_EmitOp(G1Type InstType, const xRegisterInt &to, const xRegisterInt &from) { - pxAssert( to.GetOperandSize() == from.GetOperandSize() ); + pxAssert(to.GetOperandSize() == from.GetOperandSize()); - u8 opcode = (to.Is8BitOp() ? 0 : 1) | (InstType<<3); - xOpWrite( to.GetPrefix16(), opcode, from, to ); + u8 opcode = (to.Is8BitOp() ? 0 : 1) | (InstType << 3); + xOpWrite(to.GetPrefix16(), opcode, from, to); } -static void _g1_EmitOp( G1Type InstType, const xIndirectVoid& sibdest, const xRegisterInt& from ) +static void _g1_EmitOp(G1Type InstType, const xIndirectVoid &sibdest, const xRegisterInt &from) { - u8 opcode = (from.Is8BitOp() ? 0 : 1) | (InstType<<3); - xOpWrite( from.GetPrefix16(), opcode, from, sibdest ); + u8 opcode = (from.Is8BitOp() ? 0 : 1) | (InstType << 3); + xOpWrite(from.GetPrefix16(), opcode, from, sibdest); } -static void _g1_EmitOp( G1Type InstType, const xRegisterInt& to, const xIndirectVoid& sibsrc ) +static void _g1_EmitOp(G1Type InstType, const xRegisterInt &to, const xIndirectVoid &sibsrc) { - u8 opcode = (to.Is8BitOp() ? 2 : 3) | (InstType<<3); - xOpWrite( to.GetPrefix16(), opcode, to, sibsrc ); + u8 opcode = (to.Is8BitOp() ? 2 : 3) | (InstType << 3); + xOpWrite(to.GetPrefix16(), opcode, to, sibsrc); } -static void _g1_EmitOp( G1Type InstType, const xRegisterInt& to, int imm ) +static void _g1_EmitOp(G1Type InstType, const xRegisterInt &to, int imm) { - if( !to.Is8BitOp() && is_s8( imm ) ) - { - xOpWrite( to.GetPrefix16(), 0x83, InstType, to ); - xWrite( imm ); - } - else - { - if( to.IsAccumulator() ) { - u8 opcode = (to.Is8BitOp() ? 4 : 5) | (InstType<<3); - xOpAccWrite( to.GetPrefix16(), opcode, InstType, to ); - } - else - { - u8 opcode = to.Is8BitOp() ? 0x80 : 0x81; - xOpWrite( to.GetPrefix16(), opcode, InstType, to ); - } - to.xWriteImm( imm ); - } + if (!to.Is8BitOp() && is_s8(imm)) { + xOpWrite(to.GetPrefix16(), 0x83, InstType, to); + xWrite(imm); + } else { + if (to.IsAccumulator()) { + u8 opcode = (to.Is8BitOp() ? 4 : 5) | (InstType << 3); + xOpAccWrite(to.GetPrefix16(), opcode, InstType, to); + } else { + u8 opcode = to.Is8BitOp() ? 0x80 : 0x81; + xOpWrite(to.GetPrefix16(), opcode, InstType, to); + } + to.xWriteImm(imm); + } } -#define ImplementGroup1( g1type, insttype ) \ - void g1type::operator()( const xRegisterInt& to, const xRegisterInt& from ) const { _g1_EmitOp( insttype, to, from ); } \ - void g1type::operator()( const xIndirectVoid& to, const xRegisterInt& from ) const { _g1_EmitOp( insttype, to, from ); } \ - void g1type::operator()( const xRegisterInt& to, const xIndirectVoid& from ) const { _g1_EmitOp( insttype, to, from ); } \ - void g1type::operator()( const xRegisterInt& to, int imm ) const { _g1_EmitOp( insttype, to, imm ); } \ - void g1type::operator()( const xIndirect64orLess& sibdest, int imm ) const { _g1_IndirectImm( insttype, sibdest, imm ); } +#define ImplementGroup1(g1type, insttype) \ + void g1type::operator()(const xRegisterInt &to, const xRegisterInt &from) const { _g1_EmitOp(insttype, to, from); } \ + void g1type::operator()(const xIndirectVoid &to, const xRegisterInt &from) const { _g1_EmitOp(insttype, to, from); } \ + void g1type::operator()(const xRegisterInt &to, const xIndirectVoid &from) const { _g1_EmitOp(insttype, to, from); } \ + void g1type::operator()(const xRegisterInt &to, int imm) const { _g1_EmitOp(insttype, to, imm); } \ + void g1type::operator()(const xIndirect64orLess &sibdest, int imm) const { _g1_IndirectImm(insttype, sibdest, imm); } -ImplementGroup1( xImpl_Group1, InstType ) -ImplementGroup1( xImpl_G1Logic, InstType ) -ImplementGroup1( xImpl_G1Arith, InstType ) -ImplementGroup1( xImpl_G1Compare, G1Type_CMP ) +ImplementGroup1(xImpl_Group1, InstType) + ImplementGroup1(xImpl_G1Logic, InstType) + ImplementGroup1(xImpl_G1Arith, InstType) + ImplementGroup1(xImpl_G1Compare, G1Type_CMP) -const xImpl_G1Logic xAND = { G1Type_AND, { 0x00, 0x54 }, { 0x66, 0x54 } }; -const xImpl_G1Logic xOR = { G1Type_OR, { 0x00, 0x56 }, { 0x66, 0x56 } }; -const xImpl_G1Logic xXOR = { G1Type_XOR, { 0x00, 0x57 }, { 0x66, 0x57 } }; + const xImpl_G1Logic xAND = {G1Type_AND, {0x00, 0x54}, {0x66, 0x54}}; +const xImpl_G1Logic xOR = {G1Type_OR, {0x00, 0x56}, {0x66, 0x56}}; +const xImpl_G1Logic xXOR = {G1Type_XOR, {0x00, 0x57}, {0x66, 0x57}}; -const xImpl_G1Arith xADD = { G1Type_ADD, { 0x00, 0x58 }, { 0x66, 0x58 }, { 0xf3, 0x58 }, { 0xf2, 0x58 } }; -const xImpl_G1Arith xSUB = { G1Type_SUB, { 0x00, 0x5c }, { 0x66, 0x5c }, { 0xf3, 0x5c }, { 0xf2, 0x5c } }; -const xImpl_G1Compare xCMP = { { 0x00, 0xc2 }, { 0x66, 0xc2 }, { 0xf3, 0xc2 }, { 0xf2, 0xc2 } }; +const xImpl_G1Arith xADD = {G1Type_ADD, {0x00, 0x58}, {0x66, 0x58}, {0xf3, 0x58}, {0xf2, 0x58}}; +const xImpl_G1Arith xSUB = {G1Type_SUB, {0x00, 0x5c}, {0x66, 0x5c}, {0xf3, 0x5c}, {0xf2, 0x5c}}; +const xImpl_G1Compare xCMP = {{0x00, 0xc2}, {0x66, 0xc2}, {0xf3, 0xc2}, {0xf2, 0xc2}}; -const xImpl_Group1 xADC = { G1Type_ADC }; -const xImpl_Group1 xSBB = { G1Type_SBB }; +const xImpl_Group1 xADC = {G1Type_ADC}; +const xImpl_Group1 xSBB = {G1Type_SBB}; // ===================================================================================================== // Group 2 Instructions - SHR, SHL, etc. // ===================================================================================================== -void xImpl_Group2::operator()( const xRegisterInt& to, const xRegisterCL& /* from */ ) const +void xImpl_Group2::operator()(const xRegisterInt &to, const xRegisterCL & /* from */) const { - xOpWrite( to.GetPrefix16(), to.Is8BitOp() ? 0xd2 : 0xd3, InstType, to ); + xOpWrite(to.GetPrefix16(), to.Is8BitOp() ? 0xd2 : 0xd3, InstType, to); } -void xImpl_Group2::operator()(const xRegisterInt& to, u8 imm ) const +void xImpl_Group2::operator()(const xRegisterInt &to, u8 imm) const { - if( imm == 0 ) return; + if (imm == 0) + return; - if( imm == 1 ) - { - // special encoding of 1's - xOpWrite( to.GetPrefix16(), to.Is8BitOp() ? 0xd0 : 0xd1, InstType, to ); - } - else - { - xOpWrite( to.GetPrefix16(), to.Is8BitOp() ? 0xc0 : 0xc1, InstType, to ); - xWrite8( imm ); - } + if (imm == 1) { + // special encoding of 1's + xOpWrite(to.GetPrefix16(), to.Is8BitOp() ? 0xd0 : 0xd1, InstType, to); + } else { + xOpWrite(to.GetPrefix16(), to.Is8BitOp() ? 0xc0 : 0xc1, InstType, to); + xWrite8(imm); + } } -void xImpl_Group2::operator()( const xIndirect64orLess& sibdest, const xRegisterCL& /* from */ ) const +void xImpl_Group2::operator()(const xIndirect64orLess &sibdest, const xRegisterCL & /* from */) const { - xOpWrite( sibdest.GetPrefix16(), sibdest.Is8BitOp() ? 0xd2 : 0xd3, InstType, sibdest ); + xOpWrite(sibdest.GetPrefix16(), sibdest.Is8BitOp() ? 0xd2 : 0xd3, InstType, sibdest); } -void xImpl_Group2::operator()( const xIndirect64orLess& sibdest, u8 imm ) const +void xImpl_Group2::operator()(const xIndirect64orLess &sibdest, u8 imm) const { - if( imm == 0 ) return; + if (imm == 0) + return; - if( imm == 1 ) - { - // special encoding of 1's - xOpWrite( sibdest.GetPrefix16(), sibdest.Is8BitOp() ? 0xd0 : 0xd1, InstType, sibdest ); - } - else - { - xOpWrite( sibdest.GetPrefix16(), sibdest.Is8BitOp() ? 0xc0 : 0xc1, InstType, sibdest ); - xWrite8( imm ); - } + if (imm == 1) { + // special encoding of 1's + xOpWrite(sibdest.GetPrefix16(), sibdest.Is8BitOp() ? 0xd0 : 0xd1, InstType, sibdest); + } else { + xOpWrite(sibdest.GetPrefix16(), sibdest.Is8BitOp() ? 0xc0 : 0xc1, InstType, sibdest); + xWrite8(imm); + } } -const xImpl_Group2 xROL = { G2Type_ROL }; -const xImpl_Group2 xROR = { G2Type_ROR }; -const xImpl_Group2 xRCL = { G2Type_RCL }; -const xImpl_Group2 xRCR = { G2Type_RCR }; -const xImpl_Group2 xSHL = { G2Type_SHL }; -const xImpl_Group2 xSHR = { G2Type_SHR }; -const xImpl_Group2 xSAR = { G2Type_SAR }; +const xImpl_Group2 xROL = {G2Type_ROL}; +const xImpl_Group2 xROR = {G2Type_ROR}; +const xImpl_Group2 xRCL = {G2Type_RCL}; +const xImpl_Group2 xRCR = {G2Type_RCR}; +const xImpl_Group2 xSHL = {G2Type_SHL}; +const xImpl_Group2 xSHR = {G2Type_SHR}; +const xImpl_Group2 xSAR = {G2Type_SAR}; // ===================================================================================================== // Group 3 Instructions - NOT, NEG, MUL, DIV // ===================================================================================================== -static void _g3_EmitOp( G3Type InstType, const xRegisterInt& from ) +static void _g3_EmitOp(G3Type InstType, const xRegisterInt &from) { - xOpWrite( from.GetPrefix16(), from.Is8BitOp() ? 0xf6 : 0xf7, InstType, from ); + xOpWrite(from.GetPrefix16(), from.Is8BitOp() ? 0xf6 : 0xf7, InstType, from); } -static void _g3_EmitOp( G3Type InstType, const xIndirect64orLess& from ) +static void _g3_EmitOp(G3Type InstType, const xIndirect64orLess &from) { - xOpWrite( from.GetPrefix16(), from.Is8BitOp() ? 0xf6 : 0xf7, InstType, from ); + xOpWrite(from.GetPrefix16(), from.Is8BitOp() ? 0xf6 : 0xf7, InstType, from); } -void xImpl_Group3::operator()( const xRegisterInt& from ) const { _g3_EmitOp( InstType, from ); } -void xImpl_Group3::operator()( const xIndirect64orLess& from ) const { _g3_EmitOp( InstType, from ); } +void xImpl_Group3::operator()(const xRegisterInt &from) const { _g3_EmitOp(InstType, from); } +void xImpl_Group3::operator()(const xIndirect64orLess &from) const { _g3_EmitOp(InstType, from); } -void xImpl_iDiv::operator()( const xRegisterInt& from ) const { _g3_EmitOp( G3Type_iDIV, from ); } -void xImpl_iDiv::operator()( const xIndirect64orLess& from ) const { _g3_EmitOp( G3Type_iDIV, from ); } +void xImpl_iDiv::operator()(const xRegisterInt &from) const { _g3_EmitOp(G3Type_iDIV, from); } +void xImpl_iDiv::operator()(const xIndirect64orLess &from) const { _g3_EmitOp(G3Type_iDIV, from); } -template< typename SrcType > -static void _imul_ImmStyle( const xRegisterInt& param1, const SrcType& param2, int imm ) +template +static void _imul_ImmStyle(const xRegisterInt ¶m1, const SrcType ¶m2, int imm) { - pxAssert( param1.GetOperandSize() == param2.GetOperandSize() ); + pxAssert(param1.GetOperandSize() == param2.GetOperandSize()); - xOpWrite0F( param1.GetPrefix16(), is_s8( imm ) ? 0x6b : 0x69, param1, param2 ); + xOpWrite0F(param1.GetPrefix16(), is_s8(imm) ? 0x6b : 0x69, param1, param2); - if( is_s8( imm ) ) - xWrite8( (u8)imm ); - else - param1.xWriteImm( imm ); + if (is_s8(imm)) + xWrite8((u8)imm); + else + param1.xWriteImm(imm); } -void xImpl_iMul::operator()( const xRegisterInt& from ) const { _g3_EmitOp( G3Type_iMUL, from ); } -void xImpl_iMul::operator()( const xIndirect64orLess& from ) const { _g3_EmitOp( G3Type_iMUL, from ); } +void xImpl_iMul::operator()(const xRegisterInt &from) const { _g3_EmitOp(G3Type_iMUL, from); } +void xImpl_iMul::operator()(const xIndirect64orLess &from) const { _g3_EmitOp(G3Type_iMUL, from); } -void xImpl_iMul::operator()( const xRegister32& to, const xRegister32& from ) const { xOpWrite0F( 0xaf, to, from ); } -void xImpl_iMul::operator()( const xRegister32& to, const xIndirectVoid& src ) const { xOpWrite0F( 0xaf, to, src ); } -void xImpl_iMul::operator()( const xRegister16& to, const xRegister16& from ) const { xOpWrite0F( 0x66, 0xaf, to, from ); } -void xImpl_iMul::operator()( const xRegister16& to, const xIndirectVoid& src ) const { xOpWrite0F( 0x66, 0xaf, to, src ); } +void xImpl_iMul::operator()(const xRegister32 &to, const xRegister32 &from) const { xOpWrite0F(0xaf, to, from); } +void xImpl_iMul::operator()(const xRegister32 &to, const xIndirectVoid &src) const { xOpWrite0F(0xaf, to, src); } +void xImpl_iMul::operator()(const xRegister16 &to, const xRegister16 &from) const { xOpWrite0F(0x66, 0xaf, to, from); } +void xImpl_iMul::operator()(const xRegister16 &to, const xIndirectVoid &src) const { xOpWrite0F(0x66, 0xaf, to, src); } -void xImpl_iMul::operator()( const xRegister32& to, const xRegister32& from, s32 imm ) const{ _imul_ImmStyle( to, from, imm ); } -void xImpl_iMul::operator()( const xRegister32& to, const xIndirectVoid& from, s32 imm ) const { _imul_ImmStyle( to, from, imm ); } -void xImpl_iMul::operator()( const xRegister16& to, const xRegister16& from, s16 imm ) const{ _imul_ImmStyle( to, from, imm ); } -void xImpl_iMul::operator()( const xRegister16& to, const xIndirectVoid& from, s16 imm ) const { _imul_ImmStyle( to, from, imm ); } +void xImpl_iMul::operator()(const xRegister32 &to, const xRegister32 &from, s32 imm) const { _imul_ImmStyle(to, from, imm); } +void xImpl_iMul::operator()(const xRegister32 &to, const xIndirectVoid &from, s32 imm) const { _imul_ImmStyle(to, from, imm); } +void xImpl_iMul::operator()(const xRegister16 &to, const xRegister16 &from, s16 imm) const { _imul_ImmStyle(to, from, imm); } +void xImpl_iMul::operator()(const xRegister16 &to, const xIndirectVoid &from, s16 imm) const { _imul_ImmStyle(to, from, imm); } -const xImpl_Group3 xNOT = { G3Type_NOT }; -const xImpl_Group3 xNEG = { G3Type_NEG }; -const xImpl_Group3 xUMUL = { G3Type_MUL }; -const xImpl_Group3 xUDIV = { G3Type_DIV }; +const xImpl_Group3 xNOT = {G3Type_NOT}; +const xImpl_Group3 xNEG = {G3Type_NEG}; +const xImpl_Group3 xUMUL = {G3Type_MUL}; +const xImpl_Group3 xUDIV = {G3Type_DIV}; -const xImpl_iDiv xDIV = { { 0x00, 0x5e }, { 0x66, 0x5e }, { 0xf3, 0x5e }, { 0xf2, 0x5e } }; -const xImpl_iMul xMUL = { { 0x00, 0x59 }, { 0x66, 0x59 }, { 0xf3, 0x59 }, { 0xf2, 0x59 } }; +const xImpl_iDiv xDIV = {{0x00, 0x5e}, {0x66, 0x5e}, {0xf3, 0x5e}, {0xf2, 0x5e}}; +const xImpl_iMul xMUL = {{0x00, 0x59}, {0x66, 0x59}, {0xf3, 0x59}, {0xf2, 0x59}}; // ===================================================================================================== // Group 8 Instructions // ===================================================================================================== -void xImpl_Group8::operator()( const xRegister16or32or64& bitbase, const xRegister16or32or64& bitoffset ) const { - pxAssert( bitbase->GetOperandSize() == bitoffset->GetOperandSize() ); - xOpWrite0F( bitbase->GetPrefix16(), 0xa3 | (InstType << 3), bitbase, bitoffset ); -} -void xImpl_Group8::operator()( const xIndirect64& bitbase, u8 bitoffset ) const { xOpWrite0F( 0xba, InstType, bitbase, bitoffset ); } -void xImpl_Group8::operator()( const xIndirect32& bitbase, u8 bitoffset ) const { xOpWrite0F( 0xba, InstType, bitbase, bitoffset ); } -void xImpl_Group8::operator()( const xIndirect16& bitbase, u8 bitoffset ) const { xOpWrite0F( 0x66, 0xba, InstType, bitbase, bitoffset ); } - -void xImpl_Group8::operator()( const xRegister16or32or64& bitbase, u8 bitoffset ) const +void xImpl_Group8::operator()(const xRegister16or32or64 &bitbase, const xRegister16or32or64 &bitoffset) const { - xOpWrite0F( bitbase->GetPrefix16(), 0xba, InstType, bitbase, bitoffset ); + pxAssert(bitbase->GetOperandSize() == bitoffset->GetOperandSize()); + xOpWrite0F(bitbase->GetPrefix16(), 0xa3 | (InstType << 3), bitbase, bitoffset); } +void xImpl_Group8::operator()(const xIndirect64 &bitbase, u8 bitoffset) const { xOpWrite0F(0xba, InstType, bitbase, bitoffset); } +void xImpl_Group8::operator()(const xIndirect32 &bitbase, u8 bitoffset) const { xOpWrite0F(0xba, InstType, bitbase, bitoffset); } +void xImpl_Group8::operator()(const xIndirect16 &bitbase, u8 bitoffset) const { xOpWrite0F(0x66, 0xba, InstType, bitbase, bitoffset); } -void xImpl_Group8::operator()( const xIndirectVoid& bitbase, const xRegister16or32or64& bitoffset ) const +void xImpl_Group8::operator()(const xRegister16or32or64 &bitbase, u8 bitoffset) const { - xOpWrite0F( bitoffset->GetPrefix16(), 0xa3 | (InstType << 3), bitoffset, bitbase ); + xOpWrite0F(bitbase->GetPrefix16(), 0xba, InstType, bitbase, bitoffset); } -const xImpl_Group8 xBT = { G8Type_BT }; -const xImpl_Group8 xBTR = { G8Type_BTR }; -const xImpl_Group8 xBTS = { G8Type_BTS }; -const xImpl_Group8 xBTC = { G8Type_BTC }; +void xImpl_Group8::operator()(const xIndirectVoid &bitbase, const xRegister16or32or64 &bitoffset) const +{ + xOpWrite0F(bitoffset->GetPrefix16(), 0xa3 | (InstType << 3), bitoffset, bitbase); +} + +const xImpl_Group8 xBT = {G8Type_BT}; +const xImpl_Group8 xBTR = {G8Type_BTR}; +const xImpl_Group8 xBTS = {G8Type_BTS}; +const xImpl_Group8 xBTC = {G8Type_BTC}; -} // End namespace x86Emitter - +} // End namespace x86Emitter diff --git a/common/src/x86emitter/jmp.cpp b/common/src/x86emitter/jmp.cpp index 6dc6526f17..0bc8021b6e 100644 --- a/common/src/x86emitter/jmp.cpp +++ b/common/src/x86emitter/jmp.cpp @@ -31,72 +31,72 @@ #include "PrecompiledHeader.h" #include "internal.h" -namespace x86Emitter { +namespace x86Emitter +{ -void xImpl_JmpCall::operator()( const xRegisterInt& absreg ) const { xOpWrite( 0, 0xff, isJmp ? 4 : 2, absreg ); } -void xImpl_JmpCall::operator()( const xIndirect64orLess& src ) const { xOpWrite( 0, 0xff, isJmp ? 4 : 2, src ); } +void xImpl_JmpCall::operator()(const xRegisterInt &absreg) const { xOpWrite(0, 0xff, isJmp ? 4 : 2, absreg); } +void xImpl_JmpCall::operator()(const xIndirect64orLess &src) const { xOpWrite(0, 0xff, isJmp ? 4 : 2, src); } -const xImpl_JmpCall xJMP = { true }; -const xImpl_JmpCall xCALL = { false }; +const xImpl_JmpCall xJMP = {true}; +const xImpl_JmpCall xCALL = {false}; -const xImpl_FastCall xFastCall = { }; +const xImpl_FastCall xFastCall = {}; void xSmartJump::SetTarget() { - u8* target = xGetPtr(); - if( m_baseptr == NULL ) return; + u8 *target = xGetPtr(); + if (m_baseptr == NULL) + return; - xSetPtr( m_baseptr ); - u8* const saveme = m_baseptr + GetMaxInstructionSize(); - xJccKnownTarget( m_cc, target, true ); + xSetPtr(m_baseptr); + u8 *const saveme = m_baseptr + GetMaxInstructionSize(); + xJccKnownTarget(m_cc, target, true); - // Copy recompiled data inward if the jump instruction didn't fill the - // alloted buffer (means that we optimized things to a j8!) + // Copy recompiled data inward if the jump instruction didn't fill the + // alloted buffer (means that we optimized things to a j8!) - const int spacer = (sptr)saveme - (sptr)xGetPtr(); - if( spacer != 0 ) - { - u8* destpos = xGetPtr(); - const int copylen = (sptr)target - (sptr)saveme; + const int spacer = (sptr)saveme - (sptr)xGetPtr(); + if (spacer != 0) { + u8 *destpos = xGetPtr(); + const int copylen = (sptr)target - (sptr)saveme; - memcpy( destpos, saveme, copylen ); - xSetPtr( target - spacer ); - } + memcpy(destpos, saveme, copylen); + xSetPtr(target - spacer); + } } xSmartJump::~xSmartJump() { - SetTarget(); - m_baseptr = NULL; // just in case (sometimes helps in debugging too) + SetTarget(); + m_baseptr = NULL; // just in case (sometimes helps in debugging too) } // ------------------------------------------------------------------------ // Emits a 32 bit jump, and returns a pointer to the 32 bit displacement. // (displacements should be assigned relative to the end of the jump instruction, // or in other words *(retval+1) ) -__emitinline s32* xJcc32( JccComparisonType comparison, s32 displacement ) +__emitinline s32 *xJcc32(JccComparisonType comparison, s32 displacement) { - if( comparison == Jcc_Unconditional ) - xWrite8( 0xe9 ); - else - { - xWrite8( 0x0f ); - xWrite8( 0x80 | comparison ); - } - xWrite( displacement ); + if (comparison == Jcc_Unconditional) + xWrite8(0xe9); + else { + xWrite8(0x0f); + xWrite8(0x80 | comparison); + } + xWrite(displacement); - return ((s32*)xGetPtr()) - 1; + return ((s32 *)xGetPtr()) - 1; } // ------------------------------------------------------------------------ // Emits a 32 bit jump, and returns a pointer to the 8 bit displacement. // (displacements should be assigned relative to the end of the jump instruction, // or in other words *(retval+1) ) -__emitinline s8* xJcc8( JccComparisonType comparison, s8 displacement ) +__emitinline s8 *xJcc8(JccComparisonType comparison, s8 displacement) { - xWrite8( (comparison == Jcc_Unconditional) ? 0xeb : (0x70 | comparison) ); - xWrite( displacement ); - return (s8*)xGetPtr() - 1; + xWrite8((comparison == Jcc_Unconditional) ? 0xeb : (0x70 | comparison)); + xWrite(displacement); + return (s8 *)xGetPtr() - 1; } // ------------------------------------------------------------------------ @@ -106,93 +106,86 @@ __emitinline s8* xJcc8( JccComparisonType comparison, s8 displacement ) // slideForward - used internally by xSmartJump to indicate that the jump target is going // to slide forward in the event of an 8 bit displacement. // -__emitinline void xJccKnownTarget( JccComparisonType comparison, const void* target, bool slideForward ) +__emitinline void xJccKnownTarget(JccComparisonType comparison, const void *target, bool slideForward) { - // Calculate the potential j8 displacement first, assuming an instruction length of 2: - sptr displacement8 = (sptr)target - (sptr)(xGetPtr() + 2); + // Calculate the potential j8 displacement first, assuming an instruction length of 2: + sptr displacement8 = (sptr)target - (sptr)(xGetPtr() + 2); - const int slideVal = slideForward ? ((comparison == Jcc_Unconditional) ? 3 : 4) : 0; - displacement8 -= slideVal; + const int slideVal = slideForward ? ((comparison == Jcc_Unconditional) ? 3 : 4) : 0; + displacement8 -= slideVal; - if( slideForward ) - { - pxAssertDev( displacement8 >= 0, "Used slideForward on a backward jump; nothing to slide!" ); - } + if (slideForward) { + pxAssertDev(displacement8 >= 0, "Used slideForward on a backward jump; nothing to slide!"); + } - if( is_s8( displacement8 ) ) - xJcc8( comparison, displacement8 ); - else - { - // Perform a 32 bit jump instead. :( - s32* bah = xJcc32( comparison ); - sptr distance = (sptr)target - (sptr)xGetPtr(); + if (is_s8(displacement8)) + xJcc8(comparison, displacement8); + else { + // Perform a 32 bit jump instead. :( + s32 *bah = xJcc32(comparison); + sptr distance = (sptr)target - (sptr)xGetPtr(); #ifdef __x86_64__ - // This assert won't physically happen on x86 targets - pxAssertDev(distance >= -0x80000000LL && distance < 0x80000000LL, "Jump target is too far away, needs an indirect register"); + // This assert won't physically happen on x86 targets + pxAssertDev(distance >= -0x80000000LL && distance < 0x80000000LL, "Jump target is too far away, needs an indirect register"); #endif - *bah = (s32)distance; - } + *bah = (s32)distance; + } } // Low-level jump instruction! Specify a comparison type and a target in void* form, and // a jump (either 8 or 32 bit) is generated. -__emitinline void xJcc( JccComparisonType comparison, const void* target ) +__emitinline void xJcc(JccComparisonType comparison, const void *target) { - xJccKnownTarget( comparison, target, false ); + xJccKnownTarget(comparison, target, false); } -xForwardJumpBase::xForwardJumpBase( uint opsize, JccComparisonType cctype ) +xForwardJumpBase::xForwardJumpBase(uint opsize, JccComparisonType cctype) { - pxAssert( opsize == 1 || opsize == 4 ); - pxAssertDev( cctype != Jcc_Unknown, "Invalid ForwardJump conditional type." ); + pxAssert(opsize == 1 || opsize == 4); + pxAssertDev(cctype != Jcc_Unknown, "Invalid ForwardJump conditional type."); - BasePtr = (s8*)xGetPtr() + - ((opsize == 1) ? 2 : // j8's are always 2 bytes. - ((cctype==Jcc_Unconditional) ? 5 : 6 )); // j32's are either 5 or 6 bytes + BasePtr = (s8 *)xGetPtr() + + ((opsize == 1) ? 2 : // j8's are always 2 bytes. + ((cctype == Jcc_Unconditional) ? 5 : 6)); // j32's are either 5 or 6 bytes - if( opsize == 1 ) - xWrite8( (cctype == Jcc_Unconditional) ? 0xeb : (0x70 | cctype) ); - else - { - if( cctype == Jcc_Unconditional ) - xWrite8( 0xe9 ); - else - { - xWrite8( 0x0f ); - xWrite8( 0x80 | cctype ); - } - } + if (opsize == 1) + xWrite8((cctype == Jcc_Unconditional) ? 0xeb : (0x70 | cctype)); + else { + if (cctype == Jcc_Unconditional) + xWrite8(0xe9); + else { + xWrite8(0x0f); + xWrite8(0x80 | cctype); + } + } - xAdvancePtr( opsize ); + xAdvancePtr(opsize); } -void xForwardJumpBase::_setTarget( uint opsize ) const +void xForwardJumpBase::_setTarget(uint opsize) const { - pxAssertDev( BasePtr != NULL, "" ); + pxAssertDev(BasePtr != NULL, ""); - sptr displacement = (sptr)xGetPtr() - (sptr)BasePtr; - if( opsize == 1 ) - { - pxAssertDev( is_s8( displacement ), "Emitter Error: Invalid short jump displacement." ); - BasePtr[-1] = (s8)displacement; - } - else - { - // full displacement, no sanity checks needed :D - ((s32*)BasePtr)[-1] = displacement; - } + sptr displacement = (sptr)xGetPtr() - (sptr)BasePtr; + if (opsize == 1) { + pxAssertDev(is_s8(displacement), "Emitter Error: Invalid short jump displacement."); + BasePtr[-1] = (s8)displacement; + } else { + // full displacement, no sanity checks needed :D + ((s32 *)BasePtr)[-1] = displacement; + } } // returns the inverted conditional type for this Jcc condition. Ie, JNS will become JS. -__fi JccComparisonType xInvertCond( JccComparisonType src ) +__fi JccComparisonType xInvertCond(JccComparisonType src) { - pxAssert( src != Jcc_Unknown ); - if( Jcc_Unconditional == src ) return Jcc_Unconditional; + pxAssert(src != Jcc_Unknown); + if (Jcc_Unconditional == src) + return Jcc_Unconditional; - // x86 conditionals are clever! To invert conditional types, just invert the lower bit: - return (JccComparisonType)((int)src ^ 1); + // x86 conditionals are clever! To invert conditional types, just invert the lower bit: + return (JccComparisonType)((int)src ^ 1); } - } diff --git a/common/src/x86emitter/legacy.cpp b/common/src/x86emitter/legacy.cpp index 1bd5c4e859..146b2f3fe6 100644 --- a/common/src/x86emitter/legacy.cpp +++ b/common/src/x86emitter/legacy.cpp @@ -28,26 +28,26 @@ #include "PrecompiledHeader.h" #include "legacy_internal.h" -emitterT void ModRM( uint mod, uint reg, uint rm ) +emitterT void ModRM(uint mod, uint reg, uint rm) { - // Note: Following assertions are for legacy support only. - // The new emitter performs these sanity checks during operand construction, so these - // assertions can probably be removed once all legacy emitter code has been removed. - pxAssert( mod < 4 ); - pxAssert( reg < 8 ); - pxAssert( rm < 8 ); - xWrite8( (mod << 6) | (reg << 3) | rm ); + // Note: Following assertions are for legacy support only. + // The new emitter performs these sanity checks during operand construction, so these + // assertions can probably be removed once all legacy emitter code has been removed. + pxAssert(mod < 4); + pxAssert(reg < 8); + pxAssert(rm < 8); + xWrite8((mod << 6) | (reg << 3) | rm); } -emitterT void SibSB( uint ss, uint index, uint base ) +emitterT void SibSB(uint ss, uint index, uint base) { - // Note: Following asserts are for legacy support only. - // The new emitter performs these sanity checks during operand construction, so these - // assertions can probably be removed once all legacy emitter code has been removed. - pxAssert( ss < 4 ); - pxAssert( index < 8 ); - pxAssert( base < 8 ); - xWrite8( (ss << 6) | (index << 3) | base ); + // Note: Following asserts are for legacy support only. + // The new emitter performs these sanity checks during operand construction, so these + // assertions can probably be removed once all legacy emitter code has been removed. + pxAssert(ss < 4); + pxAssert(index < 8); + pxAssert(base < 8); + xWrite8((ss << 6) | (index << 3) | base); } using namespace x86Emitter; @@ -58,33 +58,33 @@ using namespace x86Emitter; ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// -emitterT u8* J8Rel( int cc, int to ) +emitterT u8 *J8Rel(int cc, int to) { - xWrite8( cc ); - xWrite8( to ); - return (u8*)(x86Ptr - 1); + xWrite8(cc); + xWrite8(to); + return (u8 *)(x86Ptr - 1); } -emitterT u16* J16Rel( int cc, u32 to ) +emitterT u16 *J16Rel(int cc, u32 to) { - xWrite16( 0x0F66 ); - xWrite8( cc ); - xWrite16( to ); - return (u16*)( x86Ptr - 2 ); + xWrite16(0x0F66); + xWrite8(cc); + xWrite16(to); + return (u16 *)(x86Ptr - 2); } -emitterT u32* J32Rel( int cc, u32 to ) +emitterT u32 *J32Rel(int cc, u32 to) { - xWrite8( 0x0F ); - xWrite8( cc ); - xWrite32( to ); - return (u32*)( x86Ptr - 4 ); + xWrite8(0x0F); + xWrite8(cc); + xWrite32(to); + return (u32 *)(x86Ptr - 4); } //////////////////////////////////////////////////// -emitterT void x86SetPtr( u8* ptr ) +emitterT void x86SetPtr(u8 *ptr) { - x86Ptr = ptr; + x86Ptr = ptr; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -93,55 +93,57 @@ emitterT void x86SetPtr( u8* ptr ) // I don't auto-inline these because of the console logging in case of error, which tends // to cause quite a bit of code bloat. // -void x86SetJ8( u8* j8 ) +void x86SetJ8(u8 *j8) { - u32 jump = ( x86Ptr - j8 ) - 1; + u32 jump = (x86Ptr - j8) - 1; - if ( jump > 0x7f ) { - Console.Error( "j8 greater than 0x7f!!" ); - assert(0); - } - *j8 = (u8)jump; + if (jump > 0x7f) { + Console.Error("j8 greater than 0x7f!!"); + assert(0); + } + *j8 = (u8)jump; } -void x86SetJ8A( u8* j8 ) +void x86SetJ8A(u8 *j8) { - u32 jump = ( x86Ptr - j8 ) - 1; + u32 jump = (x86Ptr - j8) - 1; - if ( jump > 0x7f ) { - Console.Error( "j8 greater than 0x7f!!" ); - assert(0); - } + if (jump > 0x7f) { + Console.Error("j8 greater than 0x7f!!"); + assert(0); + } - if( ((uptr)x86Ptr&0xf) > 4 ) { + if (((uptr)x86Ptr & 0xf) > 4) { - uptr newjump = jump + 16-((uptr)x86Ptr&0xf); + uptr newjump = jump + 16 - ((uptr)x86Ptr & 0xf); - if( newjump <= 0x7f ) { - jump = newjump; - while((uptr)x86Ptr&0xf) *x86Ptr++ = 0x90; - } - } - *j8 = (u8)jump; + if (newjump <= 0x7f) { + jump = newjump; + while ((uptr)x86Ptr & 0xf) + *x86Ptr++ = 0x90; + } + } + *j8 = (u8)jump; } //////////////////////////////////////////////////// -emitterT void x86SetJ32( u32* j32 ) +emitterT void x86SetJ32(u32 *j32) { - *j32 = ( x86Ptr - (u8*)j32 ) - 4; + *j32 = (x86Ptr - (u8 *)j32) - 4; } -emitterT void x86SetJ32A( u32* j32 ) +emitterT void x86SetJ32A(u32 *j32) { - while((uptr)x86Ptr&0xf) *x86Ptr++ = 0x90; - x86SetJ32(j32); + while ((uptr)x86Ptr & 0xf) + *x86Ptr++ = 0x90; + x86SetJ32(j32); } //////////////////////////////////////////////////// -emitterT void x86Align( int bytes ) +emitterT void x86Align(int bytes) { - // forward align - x86Ptr = (u8*)( ( (uptr)x86Ptr + bytes - 1) & ~( bytes - 1 ) ); + // forward align + x86Ptr = (u8 *)(((uptr)x86Ptr + bytes - 1) & ~(bytes - 1)); } /********************/ @@ -153,259 +155,262 @@ emitterT void x86Align( int bytes ) //////////////////////////////////// /* jmp rel8 */ -emitterT u8* JMP8( u8 to ) +emitterT u8 *JMP8(u8 to) { - xWrite8( 0xEB ); - xWrite8( to ); - return x86Ptr - 1; + xWrite8(0xEB); + xWrite8(to); + return x86Ptr - 1; } /* jmp rel32 */ -emitterT u32* JMP32( uptr to ) +emitterT u32 *JMP32(uptr to) { - assert( (sptr)to <= 0x7fffffff && (sptr)to >= -0x7fffffff ); - xWrite8( 0xE9 ); - xWrite32( to ); - return (u32*)(x86Ptr - 4 ); + assert((sptr)to <= 0x7fffffff && (sptr)to >= -0x7fffffff); + xWrite8(0xE9); + xWrite32(to); + return (u32 *)(x86Ptr - 4); } /* jp rel8 */ -emitterT u8* JP8( u8 to ) { - return J8Rel( 0x7A, to ); +emitterT u8 *JP8(u8 to) +{ + return J8Rel(0x7A, to); } /* jnp rel8 */ -emitterT u8* JNP8( u8 to ) { - return J8Rel( 0x7B, to ); +emitterT u8 *JNP8(u8 to) +{ + return J8Rel(0x7B, to); } /* je rel8 */ -emitterT u8* JE8( u8 to ) { - return J8Rel( 0x74, to ); +emitterT u8 *JE8(u8 to) +{ + return J8Rel(0x74, to); } /* jz rel8 */ -emitterT u8* JZ8( u8 to ) +emitterT u8 *JZ8(u8 to) { - return J8Rel( 0x74, to ); + return J8Rel(0x74, to); } /* js rel8 */ -emitterT u8* JS8( u8 to ) +emitterT u8 *JS8(u8 to) { - return J8Rel( 0x78, to ); + return J8Rel(0x78, to); } /* jns rel8 */ -emitterT u8* JNS8( u8 to ) +emitterT u8 *JNS8(u8 to) { - return J8Rel( 0x79, to ); + return J8Rel(0x79, to); } /* jg rel8 */ -emitterT u8* JG8( u8 to ) +emitterT u8 *JG8(u8 to) { - return J8Rel( 0x7F, to ); + return J8Rel(0x7F, to); } /* jge rel8 */ -emitterT u8* JGE8( u8 to ) +emitterT u8 *JGE8(u8 to) { - return J8Rel( 0x7D, to ); + return J8Rel(0x7D, to); } /* jl rel8 */ -emitterT u8* JL8( u8 to ) +emitterT u8 *JL8(u8 to) { - return J8Rel( 0x7C, to ); + return J8Rel(0x7C, to); } /* ja rel8 */ -emitterT u8* JA8( u8 to ) +emitterT u8 *JA8(u8 to) { - return J8Rel( 0x77, to ); + return J8Rel(0x77, to); } -emitterT u8* JAE8( u8 to ) +emitterT u8 *JAE8(u8 to) { - return J8Rel( 0x73, to ); + return J8Rel(0x73, to); } /* jb rel8 */ -emitterT u8* JB8( u8 to ) +emitterT u8 *JB8(u8 to) { - return J8Rel( 0x72, to ); + return J8Rel(0x72, to); } /* jbe rel8 */ -emitterT u8* JBE8( u8 to ) +emitterT u8 *JBE8(u8 to) { - return J8Rel( 0x76, to ); + return J8Rel(0x76, to); } /* jle rel8 */ -emitterT u8* JLE8( u8 to ) +emitterT u8 *JLE8(u8 to) { - return J8Rel( 0x7E, to ); + return J8Rel(0x7E, to); } /* jne rel8 */ -emitterT u8* JNE8( u8 to ) +emitterT u8 *JNE8(u8 to) { - return J8Rel( 0x75, to ); + return J8Rel(0x75, to); } /* jnz rel8 */ -emitterT u8* JNZ8( u8 to ) +emitterT u8 *JNZ8(u8 to) { - return J8Rel( 0x75, to ); + return J8Rel(0x75, to); } /* jng rel8 */ -emitterT u8* JNG8( u8 to ) +emitterT u8 *JNG8(u8 to) { - return J8Rel( 0x7E, to ); + return J8Rel(0x7E, to); } /* jnge rel8 */ -emitterT u8* JNGE8( u8 to ) +emitterT u8 *JNGE8(u8 to) { - return J8Rel( 0x7C, to ); + return J8Rel(0x7C, to); } /* jnl rel8 */ -emitterT u8* JNL8( u8 to ) +emitterT u8 *JNL8(u8 to) { - return J8Rel( 0x7D, to ); + return J8Rel(0x7D, to); } /* jnle rel8 */ -emitterT u8* JNLE8( u8 to ) +emitterT u8 *JNLE8(u8 to) { - return J8Rel( 0x7F, to ); + return J8Rel(0x7F, to); } /* jo rel8 */ -emitterT u8* JO8( u8 to ) +emitterT u8 *JO8(u8 to) { - return J8Rel( 0x70, to ); + return J8Rel(0x70, to); } /* jno rel8 */ -emitterT u8* JNO8( u8 to ) +emitterT u8 *JNO8(u8 to) { - return J8Rel( 0x71, to ); + return J8Rel(0x71, to); } // jb rel32 -emitterT u32* JB32( u32 to ) +emitterT u32 *JB32(u32 to) { - return J32Rel( 0x82, to ); + return J32Rel(0x82, to); } /* je rel32 */ -emitterT u32* JE32( u32 to ) +emitterT u32 *JE32(u32 to) { - return J32Rel( 0x84, to ); + return J32Rel(0x84, to); } /* jz rel32 */ -emitterT u32* JZ32( u32 to ) +emitterT u32 *JZ32(u32 to) { - return J32Rel( 0x84, to ); + return J32Rel(0x84, to); } /* js rel32 */ -emitterT u32* JS32( u32 to ) +emitterT u32 *JS32(u32 to) { - return J32Rel( 0x88, to ); + return J32Rel(0x88, to); } /* jns rel32 */ -emitterT u32* JNS32( u32 to ) +emitterT u32 *JNS32(u32 to) { - return J32Rel( 0x89, to ); + return J32Rel(0x89, to); } /* jg rel32 */ -emitterT u32* JG32( u32 to ) +emitterT u32 *JG32(u32 to) { - return J32Rel( 0x8F, to ); + return J32Rel(0x8F, to); } /* jge rel32 */ -emitterT u32* JGE32( u32 to ) +emitterT u32 *JGE32(u32 to) { - return J32Rel( 0x8D, to ); + return J32Rel(0x8D, to); } /* jl rel32 */ -emitterT u32* JL32( u32 to ) +emitterT u32 *JL32(u32 to) { - return J32Rel( 0x8C, to ); + return J32Rel(0x8C, to); } /* jle rel32 */ -emitterT u32* JLE32( u32 to ) +emitterT u32 *JLE32(u32 to) { - return J32Rel( 0x8E, to ); + return J32Rel(0x8E, to); } /* ja rel32 */ -emitterT u32* JA32( u32 to ) +emitterT u32 *JA32(u32 to) { - return J32Rel( 0x87, to ); + return J32Rel(0x87, to); } /* jae rel32 */ -emitterT u32* JAE32( u32 to ) +emitterT u32 *JAE32(u32 to) { - return J32Rel( 0x83, to ); + return J32Rel(0x83, to); } /* jne rel32 */ -emitterT u32* JNE32( u32 to ) +emitterT u32 *JNE32(u32 to) { - return J32Rel( 0x85, to ); + return J32Rel(0x85, to); } /* jnz rel32 */ -emitterT u32* JNZ32( u32 to ) +emitterT u32 *JNZ32(u32 to) { - return J32Rel( 0x85, to ); + return J32Rel(0x85, to); } /* jng rel32 */ -emitterT u32* JNG32( u32 to ) +emitterT u32 *JNG32(u32 to) { - return J32Rel( 0x8E, to ); + return J32Rel(0x8E, to); } /* jnge rel32 */ -emitterT u32* JNGE32( u32 to ) +emitterT u32 *JNGE32(u32 to) { - return J32Rel( 0x8C, to ); + return J32Rel(0x8C, to); } /* jnl rel32 */ -emitterT u32* JNL32( u32 to ) +emitterT u32 *JNL32(u32 to) { - return J32Rel( 0x8D, to ); + return J32Rel(0x8D, to); } /* jnle rel32 */ -emitterT u32* JNLE32( u32 to ) +emitterT u32 *JNLE32(u32 to) { - return J32Rel( 0x8F, to ); + return J32Rel(0x8F, to); } /* jo rel32 */ -emitterT u32* JO32( u32 to ) +emitterT u32 *JO32(u32 to) { - return J32Rel( 0x80, to ); + return J32Rel(0x80, to); } /* jno rel32 */ -emitterT u32* JNO32( u32 to ) +emitterT u32 *JNO32(u32 to) { - return J32Rel( 0x81, to ); + return J32Rel(0x81, to); } diff --git a/common/src/x86emitter/legacy_sse.cpp b/common/src/x86emitter/legacy_sse.cpp index 8bca3200a6..315df9c6d4 100644 --- a/common/src/x86emitter/legacy_sse.cpp +++ b/common/src/x86emitter/legacy_sse.cpp @@ -22,12 +22,12 @@ using namespace x86Emitter; // Begin SSE-Only Part! // ------------------------------------------------------------------------ -#define DEFINE_LEGACY_SSSD_OPCODE( mod ) \ - emitterT void SSE_##mod##SS_XMM_to_XMM( x86SSERegType to, x86SSERegType from ) { x##mod.SS( xRegisterSSE(to), xRegisterSSE(from) ); } \ - emitterT void SSE2_##mod##SD_XMM_to_XMM( x86SSERegType to, x86SSERegType from ) { x##mod.SD( xRegisterSSE(to), xRegisterSSE(from) ); } +#define DEFINE_LEGACY_SSSD_OPCODE(mod) \ + emitterT void SSE_##mod##SS_XMM_to_XMM(x86SSERegType to, x86SSERegType from) { x##mod.SS(xRegisterSSE(to), xRegisterSSE(from)); } \ + emitterT void SSE2_##mod##SD_XMM_to_XMM(x86SSERegType to, x86SSERegType from) { x##mod.SD(xRegisterSSE(to), xRegisterSSE(from)); } -DEFINE_LEGACY_SSSD_OPCODE( SUB ) -DEFINE_LEGACY_SSSD_OPCODE( ADD ) +DEFINE_LEGACY_SSSD_OPCODE(SUB) +DEFINE_LEGACY_SSSD_OPCODE(ADD) -DEFINE_LEGACY_SSSD_OPCODE( MIN ) -DEFINE_LEGACY_SSSD_OPCODE( MAX ) +DEFINE_LEGACY_SSSD_OPCODE(MIN) +DEFINE_LEGACY_SSSD_OPCODE(MAX) diff --git a/common/src/x86emitter/movs.cpp b/common/src/x86emitter/movs.cpp index 4637137ecd..acab765be1 100644 --- a/common/src/x86emitter/movs.cpp +++ b/common/src/x86emitter/movs.cpp @@ -32,82 +32,77 @@ #include "internal.h" #include "implement/helpers.h" -namespace x86Emitter { - -void _xMovRtoR( const xRegisterInt& to, const xRegisterInt& from ) +namespace x86Emitter { - pxAssert( to.GetOperandSize() == from.GetOperandSize() ); - if( to == from ) return; // ignore redundant MOVs. +void _xMovRtoR(const xRegisterInt &to, const xRegisterInt &from) +{ + pxAssert(to.GetOperandSize() == from.GetOperandSize()); - xOpWrite( from.GetPrefix16(), from.Is8BitOp() ? 0x88 : 0x89, from, to ); + if (to == from) + return; // ignore redundant MOVs. + + xOpWrite(from.GetPrefix16(), from.Is8BitOp() ? 0x88 : 0x89, from, to); } -void xImpl_Mov::operator()( const xRegisterInt& to, const xRegisterInt& from ) const +void xImpl_Mov::operator()(const xRegisterInt &to, const xRegisterInt &from) const { - // FIXME WTF? - _xMovRtoR(to, from); + // FIXME WTF? + _xMovRtoR(to, from); } -void xImpl_Mov::operator()( const xIndirectVoid& dest, const xRegisterInt& from ) const +void xImpl_Mov::operator()(const xIndirectVoid &dest, const xRegisterInt &from) const { - // mov eax has a special from when writing directly to a DISP32 address - // (sans any register index/base registers). + // mov eax has a special from when writing directly to a DISP32 address + // (sans any register index/base registers). - if( from.IsAccumulator() && dest.Index.IsEmpty() && dest.Base.IsEmpty() ) - { - // FIXME: in 64 bits, it could be 8B whereas Displacement is limited to 4B normally + if (from.IsAccumulator() && dest.Index.IsEmpty() && dest.Base.IsEmpty()) { +// FIXME: in 64 bits, it could be 8B whereas Displacement is limited to 4B normally #ifdef __x86_64__ - pxAssert(0); + pxAssert(0); #endif - xOpAccWrite( from.GetPrefix16(), from.Is8BitOp() ? 0xa2 : 0xa3, from.Id, dest ); - xWrite32( dest.Displacement ); - } - else - { - xOpWrite( from.GetPrefix16(), from.Is8BitOp() ? 0x88 : 0x89, from.Id, dest ); - } + xOpAccWrite(from.GetPrefix16(), from.Is8BitOp() ? 0xa2 : 0xa3, from.Id, dest); + xWrite32(dest.Displacement); + } else { + xOpWrite(from.GetPrefix16(), from.Is8BitOp() ? 0x88 : 0x89, from.Id, dest); + } } -void xImpl_Mov::operator()( const xRegisterInt& to, const xIndirectVoid& src ) const +void xImpl_Mov::operator()(const xRegisterInt &to, const xIndirectVoid &src) const { - // mov eax has a special from when reading directly from a DISP32 address - // (sans any register index/base registers). + // mov eax has a special from when reading directly from a DISP32 address + // (sans any register index/base registers). - if( to.IsAccumulator() && src.Index.IsEmpty() && src.Base.IsEmpty() ) - { - // FIXME: in 64 bits, it could be 8B whereas Displacement is limited to 4B normally + if (to.IsAccumulator() && src.Index.IsEmpty() && src.Base.IsEmpty()) { +// FIXME: in 64 bits, it could be 8B whereas Displacement is limited to 4B normally #ifdef __x86_64__ - pxAssert(0); + pxAssert(0); #endif - xOpAccWrite( to.GetPrefix16(), to.Is8BitOp() ? 0xa0 : 0xa1, to, src ); - xWrite32( src.Displacement ); - } - else - { - xOpWrite( to.GetPrefix16(), to.Is8BitOp() ? 0x8a : 0x8b, to, src ); - } + xOpAccWrite(to.GetPrefix16(), to.Is8BitOp() ? 0xa0 : 0xa1, to, src); + xWrite32(src.Displacement); + } else { + xOpWrite(to.GetPrefix16(), to.Is8BitOp() ? 0x8a : 0x8b, to, src); + } } -void xImpl_Mov::operator()( const xIndirect64orLess& dest, int imm ) const +void xImpl_Mov::operator()(const xIndirect64orLess &dest, int imm) const { - xOpWrite( dest.GetPrefix16(), dest.Is8BitOp() ? 0xc6 : 0xc7, 0, dest ); - dest.xWriteImm( imm ); + xOpWrite(dest.GetPrefix16(), dest.Is8BitOp() ? 0xc6 : 0xc7, 0, dest); + dest.xWriteImm(imm); } // preserve_flags - set to true to disable optimizations which could alter the state of // the flags (namely replacing mov reg,0 with xor). -void xImpl_Mov::operator()( const xRegisterInt& to, int imm, bool preserve_flags ) const +void xImpl_Mov::operator()(const xRegisterInt &to, int imm, bool preserve_flags) const { - if( !preserve_flags && (imm == 0) ) - _g1_EmitOp( G1Type_XOR, to, to ); - else - { - // Note: MOV does not have (reg16/32,imm8) forms. - u8 opcode = (to.Is8BitOp() ? 0xb0 : 0xb8) | to.Id; - xOpAccWrite( to.GetPrefix16(), opcode, 0, to); - to.xWriteImm( imm ); - } + if (!preserve_flags && (imm == 0)) + _g1_EmitOp(G1Type_XOR, to, to); + else { + // Note: MOV does not have (reg16/32,imm8) forms. + u8 opcode = (to.Is8BitOp() ? 0xb0 : 0xb8) | to.Id; + xOpAccWrite(to.GetPrefix16(), opcode, 0, to); + to.xWriteImm(imm); + } } const xImpl_Mov xMOV; @@ -116,7 +111,7 @@ const xImpl_Mov xMOV; // CMOVcc // -------------------------------------------------------------------------------------- -#define ccSane() pxAssertDev( ccType >= 0 && ccType <= 0x0f, "Invalid comparison type specifier." ) +#define ccSane() pxAssertDev(ccType >= 0 && ccType <= 0x0f, "Invalid comparison type specifier.") // Macro useful for trapping unwanted use of EBP. //#define EbpAssert() pxAssert( to != ebp ) @@ -124,54 +119,62 @@ const xImpl_Mov xMOV; -void xImpl_CMov::operator()( const xRegister16or32or64& to, const xRegister16or32or64& from ) const { - pxAssert( to->GetOperandSize() == from->GetOperandSize() ); - ccSane(); - xOpWrite0F( to->GetPrefix16(), 0x40 | ccType, to, from ); +void xImpl_CMov::operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from) const +{ + pxAssert(to->GetOperandSize() == from->GetOperandSize()); + ccSane(); + xOpWrite0F(to->GetPrefix16(), 0x40 | ccType, to, from); } -void xImpl_CMov::operator()( const xRegister16or32or64& to, const xIndirectVoid& sibsrc ) const { - ccSane(); - xOpWrite0F( to->GetPrefix16(), 0x40 | ccType, to, sibsrc ); +void xImpl_CMov::operator()(const xRegister16or32or64 &to, const xIndirectVoid &sibsrc) const +{ + ccSane(); + xOpWrite0F(to->GetPrefix16(), 0x40 | ccType, to, sibsrc); } //void xImpl_CMov::operator()( const xDirectOrIndirect32& to, const xDirectOrIndirect32& from ) const { ccSane(); _DoI_helpermess( *this, to, from ); } //void xImpl_CMov::operator()( const xDirectOrIndirect16& to, const xDirectOrIndirect16& from ) const { ccSane(); _DoI_helpermess( *this, to, from ); } -void xImpl_Set::operator()( const xRegister8& to ) const { ccSane(); xOpWrite0F( 0x90 | ccType, 0, to ); } -void xImpl_Set::operator()( const xIndirect8& dest ) const { ccSane(); xOpWrite0F( 0x90 | ccType, 0, dest ); } +void xImpl_Set::operator()(const xRegister8 &to) const +{ + ccSane(); + xOpWrite0F(0x90 | ccType, 0, to); +} +void xImpl_Set::operator()(const xIndirect8 &dest) const +{ + ccSane(); + xOpWrite0F(0x90 | ccType, 0, dest); +} //void xImpl_Set::operator()( const xDirectOrIndirect8& dest ) const { ccSane(); _DoI_helpermess( *this, dest ); } -void xImpl_MovExtend::operator()( const xRegister16or32or64& to, const xRegister8& from ) const +void xImpl_MovExtend::operator()(const xRegister16or32or64 &to, const xRegister8 &from) const { - EbpAssert(); - xOpWrite0F( - ( to->GetOperandSize() == 2 ) ? 0x66 : 0, - SignExtend ? 0xbe : 0xb6, - to, from - ); + EbpAssert(); + xOpWrite0F( + (to->GetOperandSize() == 2) ? 0x66 : 0, + SignExtend ? 0xbe : 0xb6, + to, from); } -void xImpl_MovExtend::operator()( const xRegister16or32or64& to, const xIndirect8& sibsrc ) const +void xImpl_MovExtend::operator()(const xRegister16or32or64 &to, const xIndirect8 &sibsrc) const { - EbpAssert(); - xOpWrite0F( - ( to->GetOperandSize() == 2 ) ? 0x66 : 0, - SignExtend ? 0xbe : 0xb6, - to, sibsrc - ); + EbpAssert(); + xOpWrite0F( + (to->GetOperandSize() == 2) ? 0x66 : 0, + SignExtend ? 0xbe : 0xb6, + to, sibsrc); } -void xImpl_MovExtend::operator()( const xRegister32or64& to, const xRegister16& from ) const +void xImpl_MovExtend::operator()(const xRegister32or64 &to, const xRegister16 &from) const { - EbpAssert(); - xOpWrite0F( SignExtend ? 0xbf : 0xb7, to, from ); + EbpAssert(); + xOpWrite0F(SignExtend ? 0xbf : 0xb7, to, from); } -void xImpl_MovExtend::operator()( const xRegister32or64& to, const xIndirect16& sibsrc ) const +void xImpl_MovExtend::operator()(const xRegister32or64 &to, const xIndirect16 &sibsrc) const { - EbpAssert(); - xOpWrite0F( SignExtend ? 0xbf : 0xb7, to, sibsrc ); + EbpAssert(); + xOpWrite0F(SignExtend ? 0xbf : 0xb7, to, sibsrc); } #if 0 @@ -188,58 +191,58 @@ void xImpl_MovExtend::operator()( const xRegister16or32& to, const xDirectOrIndi } #endif -const xImpl_MovExtend xMOVSX = { true }; -const xImpl_MovExtend xMOVZX = { false }; +const xImpl_MovExtend xMOVSX = {true}; +const xImpl_MovExtend xMOVZX = {false}; -const xImpl_CMov xCMOVA = { Jcc_Above }; -const xImpl_CMov xCMOVAE = { Jcc_AboveOrEqual }; -const xImpl_CMov xCMOVB = { Jcc_Below }; -const xImpl_CMov xCMOVBE = { Jcc_BelowOrEqual }; +const xImpl_CMov xCMOVA = {Jcc_Above}; +const xImpl_CMov xCMOVAE = {Jcc_AboveOrEqual}; +const xImpl_CMov xCMOVB = {Jcc_Below}; +const xImpl_CMov xCMOVBE = {Jcc_BelowOrEqual}; -const xImpl_CMov xCMOVG = { Jcc_Greater }; -const xImpl_CMov xCMOVGE = { Jcc_GreaterOrEqual }; -const xImpl_CMov xCMOVL = { Jcc_Less }; -const xImpl_CMov xCMOVLE = { Jcc_LessOrEqual }; +const xImpl_CMov xCMOVG = {Jcc_Greater}; +const xImpl_CMov xCMOVGE = {Jcc_GreaterOrEqual}; +const xImpl_CMov xCMOVL = {Jcc_Less}; +const xImpl_CMov xCMOVLE = {Jcc_LessOrEqual}; -const xImpl_CMov xCMOVZ = { Jcc_Zero }; -const xImpl_CMov xCMOVE = { Jcc_Equal }; -const xImpl_CMov xCMOVNZ = { Jcc_NotZero }; -const xImpl_CMov xCMOVNE = { Jcc_NotEqual }; +const xImpl_CMov xCMOVZ = {Jcc_Zero}; +const xImpl_CMov xCMOVE = {Jcc_Equal}; +const xImpl_CMov xCMOVNZ = {Jcc_NotZero}; +const xImpl_CMov xCMOVNE = {Jcc_NotEqual}; -const xImpl_CMov xCMOVO = { Jcc_Overflow }; -const xImpl_CMov xCMOVNO = { Jcc_NotOverflow }; -const xImpl_CMov xCMOVC = { Jcc_Carry }; -const xImpl_CMov xCMOVNC = { Jcc_NotCarry }; +const xImpl_CMov xCMOVO = {Jcc_Overflow}; +const xImpl_CMov xCMOVNO = {Jcc_NotOverflow}; +const xImpl_CMov xCMOVC = {Jcc_Carry}; +const xImpl_CMov xCMOVNC = {Jcc_NotCarry}; -const xImpl_CMov xCMOVS = { Jcc_Signed }; -const xImpl_CMov xCMOVNS = { Jcc_Unsigned }; -const xImpl_CMov xCMOVPE = { Jcc_ParityEven }; -const xImpl_CMov xCMOVPO = { Jcc_ParityOdd }; +const xImpl_CMov xCMOVS = {Jcc_Signed}; +const xImpl_CMov xCMOVNS = {Jcc_Unsigned}; +const xImpl_CMov xCMOVPE = {Jcc_ParityEven}; +const xImpl_CMov xCMOVPO = {Jcc_ParityOdd}; -const xImpl_Set xSETA = { Jcc_Above }; -const xImpl_Set xSETAE = { Jcc_AboveOrEqual }; -const xImpl_Set xSETB = { Jcc_Below }; -const xImpl_Set xSETBE = { Jcc_BelowOrEqual }; +const xImpl_Set xSETA = {Jcc_Above}; +const xImpl_Set xSETAE = {Jcc_AboveOrEqual}; +const xImpl_Set xSETB = {Jcc_Below}; +const xImpl_Set xSETBE = {Jcc_BelowOrEqual}; -const xImpl_Set xSETG = { Jcc_Greater }; -const xImpl_Set xSETGE = { Jcc_GreaterOrEqual }; -const xImpl_Set xSETL = { Jcc_Less }; -const xImpl_Set xSETLE = { Jcc_LessOrEqual }; +const xImpl_Set xSETG = {Jcc_Greater}; +const xImpl_Set xSETGE = {Jcc_GreaterOrEqual}; +const xImpl_Set xSETL = {Jcc_Less}; +const xImpl_Set xSETLE = {Jcc_LessOrEqual}; -const xImpl_Set xSETZ = { Jcc_Zero }; -const xImpl_Set xSETE = { Jcc_Equal }; -const xImpl_Set xSETNZ = { Jcc_NotZero }; -const xImpl_Set xSETNE = { Jcc_NotEqual }; +const xImpl_Set xSETZ = {Jcc_Zero}; +const xImpl_Set xSETE = {Jcc_Equal}; +const xImpl_Set xSETNZ = {Jcc_NotZero}; +const xImpl_Set xSETNE = {Jcc_NotEqual}; -const xImpl_Set xSETO = { Jcc_Overflow }; -const xImpl_Set xSETNO = { Jcc_NotOverflow }; -const xImpl_Set xSETC = { Jcc_Carry }; -const xImpl_Set xSETNC = { Jcc_NotCarry }; +const xImpl_Set xSETO = {Jcc_Overflow}; +const xImpl_Set xSETNO = {Jcc_NotOverflow}; +const xImpl_Set xSETC = {Jcc_Carry}; +const xImpl_Set xSETNC = {Jcc_NotCarry}; -const xImpl_Set xSETS = { Jcc_Signed }; -const xImpl_Set xSETNS = { Jcc_Unsigned }; -const xImpl_Set xSETPE = { Jcc_ParityEven }; -const xImpl_Set xSETPO = { Jcc_ParityOdd }; +const xImpl_Set xSETS = {Jcc_Signed}; +const xImpl_Set xSETNS = {Jcc_Unsigned}; +const xImpl_Set xSETPE = {Jcc_ParityEven}; +const xImpl_Set xSETPO = {Jcc_ParityOdd}; -} // end namespace x86Emitter +} // end namespace x86Emitter diff --git a/common/src/x86emitter/simd.cpp b/common/src/x86emitter/simd.cpp index a15d581353..71e2a8d713 100644 --- a/common/src/x86emitter/simd.cpp +++ b/common/src/x86emitter/simd.cpp @@ -20,66 +20,71 @@ // Mask of valid bit fields for the target CPU. Typically this is either 0xFFFF (SSE2 // or better) or 0xFFBF (SSE1 and earlier). Code can ensure a safe/valid MXCSR by // AND'ing this mask against an MXCSR prior to LDMXCSR. -SSE_MXCSR MXCSR_Mask; +SSE_MXCSR MXCSR_Mask; -const wxChar* EnumToString( SSE_RoundMode sse ) +const wxChar *EnumToString(SSE_RoundMode sse) { - switch( sse ) - { - case SSEround_Nearest: return L"Nearest"; - case SSEround_NegInf: return L"NegativeInfinity"; - case SSEround_PosInf: return L"PositiveInfinity"; - case SSEround_Chop: return L"Chop"; - default: return L"Invalid"; - } + switch (sse) { + case SSEround_Nearest: + return L"Nearest"; + case SSEround_NegInf: + return L"NegativeInfinity"; + case SSEround_PosInf: + return L"PositiveInfinity"; + case SSEround_Chop: + return L"Chop"; + default: + return L"Invalid"; + } - return L"Invalid"; + return L"Invalid"; } SSE_RoundMode SSE_MXCSR::GetRoundMode() const { - return (SSE_RoundMode)RoundingControl; + return (SSE_RoundMode)RoundingControl; } -SSE_MXCSR& SSE_MXCSR::SetRoundMode( SSE_RoundMode mode ) +SSE_MXCSR &SSE_MXCSR::SetRoundMode(SSE_RoundMode mode) { - pxAssert( (uint)mode < 4 ); - RoundingControl = (u32)mode; - return *this; + pxAssert((uint)mode < 4); + RoundingControl = (u32)mode; + return *this; } -SSE_MXCSR& SSE_MXCSR::ClearExceptionFlags() +SSE_MXCSR &SSE_MXCSR::ClearExceptionFlags() { - bitmask &= ~0x3f; - return *this; + bitmask &= ~0x3f; + return *this; } -SSE_MXCSR& SSE_MXCSR::EnableExceptions() +SSE_MXCSR &SSE_MXCSR::EnableExceptions() { - bitmask &= ~(0x3f << 7); - return *this; + bitmask &= ~(0x3f << 7); + return *this; } -SSE_MXCSR& SSE_MXCSR::DisableExceptions() +SSE_MXCSR &SSE_MXCSR::DisableExceptions() { - bitmask |= 0x3f << 7; - return *this; + bitmask |= 0x3f << 7; + return *this; } // Applies the reserve bits mask for the current running cpu, as fetched from the CPU // during CPU init/detection. -SSE_MXCSR& SSE_MXCSR::ApplyReserveMask() +SSE_MXCSR &SSE_MXCSR::ApplyReserveMask() { - bitmask &= MXCSR_Mask.bitmask; - return *this; + bitmask &= MXCSR_Mask.bitmask; + return *this; } SSE_MXCSR::operator x86Emitter::xIndirect32() const { - return x86Emitter::ptr32[&bitmask]; + return x86Emitter::ptr32[&bitmask]; } -namespace x86Emitter { +namespace x86Emitter +{ // ------------------------------------------------------------------------ // SimdPrefix - If the lower byte of the opcode is 0x38 or 0x3a, then the opcode is @@ -88,48 +93,43 @@ namespace x86Emitter { // Non-zero upper bytes, when the lower byte is not the 0x38 or 0x3a prefix, will // generate an assertion. // -__emitinline void SimdPrefix( u8 prefix, u16 opcode ) +__emitinline void SimdPrefix(u8 prefix, u16 opcode) { #ifdef __x86_64__ - pxAssertMsg(prefix == 0, "REX prefix must be just before the opcode"); + pxAssertMsg(prefix == 0, "REX prefix must be just before the opcode"); #endif - const bool is16BitOpcode = ((opcode & 0xff) == 0x38) || ((opcode & 0xff) == 0x3a); + const bool is16BitOpcode = ((opcode & 0xff) == 0x38) || ((opcode & 0xff) == 0x3a); - // If the lower byte is not a valid prefix and the upper byte is non-zero it - // means we made a mistake! - if( !is16BitOpcode ) pxAssert( (opcode >> 8) == 0 ); + // If the lower byte is not a valid prefix and the upper byte is non-zero it + // means we made a mistake! + if (!is16BitOpcode) + pxAssert((opcode >> 8) == 0); - if( prefix != 0 ) - { - if( is16BitOpcode ) - xWrite32( (opcode<<16) | 0x0f00 | prefix ); - else - { - xWrite16( 0x0f00 | prefix ); - xWrite8( opcode ); - } - } - else - { - if( is16BitOpcode ) - { - xWrite8( 0x0f ); - xWrite16( opcode ); - } - else - xWrite16( (opcode<<8) | 0x0f ); - } + if (prefix != 0) { + if (is16BitOpcode) + xWrite32((opcode << 16) | 0x0f00 | prefix); + else { + xWrite16(0x0f00 | prefix); + xWrite8(opcode); + } + } else { + if (is16BitOpcode) { + xWrite8(0x0f); + xWrite16(opcode); + } else + xWrite16((opcode << 8) | 0x0f); + } } -const xImplSimd_DestRegEither xPAND = { 0x66,0xdb }; -const xImplSimd_DestRegEither xPANDN = { 0x66,0xdf }; -const xImplSimd_DestRegEither xPOR = { 0x66,0xeb }; -const xImplSimd_DestRegEither xPXOR = { 0x66,0xef }; +const xImplSimd_DestRegEither xPAND = {0x66, 0xdb}; +const xImplSimd_DestRegEither xPANDN = {0x66, 0xdf}; +const xImplSimd_DestRegEither xPOR = {0x66, 0xeb}; +const xImplSimd_DestRegEither xPXOR = {0x66, 0xef}; // [SSE-4.1] Performs a bitwise AND of dest against src, and sets the ZF flag // only if all bits in the result are 0. PTEST also sets the CF flag according // to the following condition: (xmm2/m128 AND NOT xmm1) == 0; -const xImplSimd_DestRegSSE xPTEST = { 0x66,0x1738 }; +const xImplSimd_DestRegSSE xPTEST = {0x66, 0x1738}; // ===================================================================================================== // SSE Conversion Operations, as looney as they are. @@ -138,514 +138,515 @@ const xImplSimd_DestRegSSE xPTEST = { 0x66,0x1738 }; // nature of the functions. (so if a function expects an m32, you must use (u32*) or ptr32[]). // -__fi void xCVTDQ2PD( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf3, 0xe6 ); } -__fi void xCVTDQ2PD( const xRegisterSSE& to, const xIndirect64& from ) { OpWriteSSE( 0xf3, 0xe6 ); } -__fi void xCVTDQ2PS( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0x00, 0x5b ); } -__fi void xCVTDQ2PS( const xRegisterSSE& to, const xIndirect128& from ) { OpWriteSSE( 0x00, 0x5b ); } +__fi void xCVTDQ2PD(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0xf3, 0xe6); } +__fi void xCVTDQ2PD(const xRegisterSSE &to, const xIndirect64 &from) { OpWriteSSE(0xf3, 0xe6); } +__fi void xCVTDQ2PS(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0x00, 0x5b); } +__fi void xCVTDQ2PS(const xRegisterSSE &to, const xIndirect128 &from) { OpWriteSSE(0x00, 0x5b); } -__fi void xCVTPD2DQ( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf2, 0xe6 ); } -__fi void xCVTPD2DQ( const xRegisterSSE& to, const xIndirect128& from ) { OpWriteSSE( 0xf2, 0xe6 ); } -__fi void xCVTPD2PS( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0x66, 0x5a ); } -__fi void xCVTPD2PS( const xRegisterSSE& to, const xIndirect128& from ) { OpWriteSSE( 0x66, 0x5a ); } +__fi void xCVTPD2DQ(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0xf2, 0xe6); } +__fi void xCVTPD2DQ(const xRegisterSSE &to, const xIndirect128 &from) { OpWriteSSE(0xf2, 0xe6); } +__fi void xCVTPD2PS(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0x66, 0x5a); } +__fi void xCVTPD2PS(const xRegisterSSE &to, const xIndirect128 &from) { OpWriteSSE(0x66, 0x5a); } -__fi void xCVTPI2PD( const xRegisterSSE& to, const xIndirect64& from ) { OpWriteSSE( 0x66, 0x2a ); } -__fi void xCVTPI2PS( const xRegisterSSE& to, const xIndirect64& from ) { OpWriteSSE( 0x00, 0x2a ); } +__fi void xCVTPI2PD(const xRegisterSSE &to, const xIndirect64 &from) { OpWriteSSE(0x66, 0x2a); } +__fi void xCVTPI2PS(const xRegisterSSE &to, const xIndirect64 &from) { OpWriteSSE(0x00, 0x2a); } -__fi void xCVTPS2DQ( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0x66, 0x5b ); } -__fi void xCVTPS2DQ( const xRegisterSSE& to, const xIndirect128& from ) { OpWriteSSE( 0x66, 0x5b ); } -__fi void xCVTPS2PD( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0x00, 0x5a ); } -__fi void xCVTPS2PD( const xRegisterSSE& to, const xIndirect64& from ) { OpWriteSSE( 0x00, 0x5a ); } +__fi void xCVTPS2DQ(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0x66, 0x5b); } +__fi void xCVTPS2DQ(const xRegisterSSE &to, const xIndirect128 &from) { OpWriteSSE(0x66, 0x5b); } +__fi void xCVTPS2PD(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0x00, 0x5a); } +__fi void xCVTPS2PD(const xRegisterSSE &to, const xIndirect64 &from) { OpWriteSSE(0x00, 0x5a); } -__fi void xCVTSD2SI( const xRegister32or64& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf2, 0x2d ); } -__fi void xCVTSD2SI( const xRegister32or64& to, const xIndirect64& from ) { OpWriteSSE( 0xf2, 0x2d ); } -__fi void xCVTSD2SS( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf2, 0x5a ); } -__fi void xCVTSD2SS( const xRegisterSSE& to, const xIndirect64& from ) { OpWriteSSE( 0xf2, 0x5a ); } -__fi void xCVTSI2SS( const xRegisterSSE& to, const xRegister32or64& from ) { OpWriteSSE( 0xf3, 0x2a ); } -__fi void xCVTSI2SS( const xRegisterSSE& to, const xIndirect32& from ) { OpWriteSSE( 0xf3, 0x2a ); } +__fi void xCVTSD2SI(const xRegister32or64 &to, const xRegisterSSE &from) { OpWriteSSE(0xf2, 0x2d); } +__fi void xCVTSD2SI(const xRegister32or64 &to, const xIndirect64 &from) { OpWriteSSE(0xf2, 0x2d); } +__fi void xCVTSD2SS(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0xf2, 0x5a); } +__fi void xCVTSD2SS(const xRegisterSSE &to, const xIndirect64 &from) { OpWriteSSE(0xf2, 0x5a); } +__fi void xCVTSI2SS(const xRegisterSSE &to, const xRegister32or64 &from) { OpWriteSSE(0xf3, 0x2a); } +__fi void xCVTSI2SS(const xRegisterSSE &to, const xIndirect32 &from) { OpWriteSSE(0xf3, 0x2a); } -__fi void xCVTSS2SD( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf3, 0x5a ); } -__fi void xCVTSS2SD( const xRegisterSSE& to, const xIndirect32& from ) { OpWriteSSE( 0xf3, 0x5a ); } -__fi void xCVTSS2SI( const xRegister32or64& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf3, 0x2d ); } -__fi void xCVTSS2SI( const xRegister32or64& to, const xIndirect32& from ) { OpWriteSSE( 0xf3, 0x2d ); } +__fi void xCVTSS2SD(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0xf3, 0x5a); } +__fi void xCVTSS2SD(const xRegisterSSE &to, const xIndirect32 &from) { OpWriteSSE(0xf3, 0x5a); } +__fi void xCVTSS2SI(const xRegister32or64 &to, const xRegisterSSE &from) { OpWriteSSE(0xf3, 0x2d); } +__fi void xCVTSS2SI(const xRegister32or64 &to, const xIndirect32 &from) { OpWriteSSE(0xf3, 0x2d); } -__fi void xCVTTPD2DQ( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0x66, 0xe6 ); } -__fi void xCVTTPD2DQ( const xRegisterSSE& to, const xIndirect128& from ) { OpWriteSSE( 0x66, 0xe6 ); } -__fi void xCVTTPS2DQ( const xRegisterSSE& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf3, 0x5b ); } -__fi void xCVTTPS2DQ( const xRegisterSSE& to, const xIndirect128& from ) { OpWriteSSE( 0xf3, 0x5b ); } +__fi void xCVTTPD2DQ(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0x66, 0xe6); } +__fi void xCVTTPD2DQ(const xRegisterSSE &to, const xIndirect128 &from) { OpWriteSSE(0x66, 0xe6); } +__fi void xCVTTPS2DQ(const xRegisterSSE &to, const xRegisterSSE &from) { OpWriteSSE(0xf3, 0x5b); } +__fi void xCVTTPS2DQ(const xRegisterSSE &to, const xIndirect128 &from) { OpWriteSSE(0xf3, 0x5b); } -__fi void xCVTTSD2SI( const xRegister32or64& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf2, 0x2c ); } -__fi void xCVTTSD2SI( const xRegister32or64& to, const xIndirect64& from ) { OpWriteSSE( 0xf2, 0x2c ); } -__fi void xCVTTSS2SI( const xRegister32or64& to, const xRegisterSSE& from ) { OpWriteSSE( 0xf3, 0x2c ); } -__fi void xCVTTSS2SI( const xRegister32or64& to, const xIndirect32& from ) { OpWriteSSE( 0xf3, 0x2c ); } +__fi void xCVTTSD2SI(const xRegister32or64 &to, const xRegisterSSE &from) { OpWriteSSE(0xf2, 0x2c); } +__fi void xCVTTSD2SI(const xRegister32or64 &to, const xIndirect64 &from) { OpWriteSSE(0xf2, 0x2c); } +__fi void xCVTTSS2SI(const xRegister32or64 &to, const xRegisterSSE &from) { OpWriteSSE(0xf3, 0x2c); } +__fi void xCVTTSS2SI(const xRegister32or64 &to, const xIndirect32 &from) { OpWriteSSE(0xf3, 0x2c); } // ------------------------------------------------------------------------ -void xImplSimd_DestRegSSE::operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( Prefix, Opcode ); } -void xImplSimd_DestRegSSE::operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const { OpWriteSSE( Prefix, Opcode ); } +void xImplSimd_DestRegSSE::operator()(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(Prefix, Opcode); } +void xImplSimd_DestRegSSE::operator()(const xRegisterSSE &to, const xIndirectVoid &from) const { OpWriteSSE(Prefix, Opcode); } -void xImplSimd_DestRegImmSSE::operator()( const xRegisterSSE& to, const xRegisterSSE& from, u8 imm ) const { xOpWrite0F( Prefix, Opcode, to, from, imm ); } -void xImplSimd_DestRegImmSSE::operator()( const xRegisterSSE& to, const xIndirectVoid& from, u8 imm ) const { xOpWrite0F( Prefix, Opcode, to, from, imm ); } +void xImplSimd_DestRegImmSSE::operator()(const xRegisterSSE &to, const xRegisterSSE &from, u8 imm) const { xOpWrite0F(Prefix, Opcode, to, from, imm); } +void xImplSimd_DestRegImmSSE::operator()(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm) const { xOpWrite0F(Prefix, Opcode, to, from, imm); } -void xImplSimd_DestRegEither::operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( Prefix, Opcode ); } -void xImplSimd_DestRegEither::operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const { OpWriteSSE( Prefix, Opcode ); } +void xImplSimd_DestRegEither::operator()(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(Prefix, Opcode); } +void xImplSimd_DestRegEither::operator()(const xRegisterSSE &to, const xIndirectVoid &from) const { OpWriteSSE(Prefix, Opcode); } -void xImplSimd_DestSSE_CmpImm::operator()( const xRegisterSSE& to, const xRegisterSSE& from, SSE2_ComparisonType imm ) const { xOpWrite0F( Prefix, Opcode, to, from, imm ); } -void xImplSimd_DestSSE_CmpImm::operator()( const xRegisterSSE& to, const xIndirectVoid& from, SSE2_ComparisonType imm ) const { xOpWrite0F( Prefix, Opcode, to, from, imm ); } +void xImplSimd_DestSSE_CmpImm::operator()(const xRegisterSSE &to, const xRegisterSSE &from, SSE2_ComparisonType imm) const { xOpWrite0F(Prefix, Opcode, to, from, imm); } +void xImplSimd_DestSSE_CmpImm::operator()(const xRegisterSSE &to, const xIndirectVoid &from, SSE2_ComparisonType imm) const { xOpWrite0F(Prefix, Opcode, to, from, imm); } // ===================================================================================================== // SIMD Arithmetic Instructions // ===================================================================================================== -void _SimdShiftHelper::operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( Prefix, Opcode ); } -void _SimdShiftHelper::operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const { OpWriteSSE( Prefix, Opcode ); } +void _SimdShiftHelper::operator()(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(Prefix, Opcode); } +void _SimdShiftHelper::operator()(const xRegisterSSE &to, const xIndirectVoid &from) const { OpWriteSSE(Prefix, Opcode); } -void _SimdShiftHelper::operator()( const xRegisterSSE& to, u8 imm8 ) const +void _SimdShiftHelper::operator()(const xRegisterSSE &to, u8 imm8) const { - xOpWrite0F( 0x66, OpcodeImm, (int)Modcode, to ); - xWrite8( imm8 ); + xOpWrite0F(0x66, OpcodeImm, (int)Modcode, to); + xWrite8(imm8); } -void xImplSimd_Shift::DQ( const xRegisterSSE& to, u8 imm8 ) const +void xImplSimd_Shift::DQ(const xRegisterSSE &to, u8 imm8) const { - xOpWrite0F( 0x66, 0x73, (int)Q.Modcode+1, to, imm8 ); + xOpWrite0F(0x66, 0x73, (int)Q.Modcode + 1, to, imm8); } const xImplSimd_ShiftWithoutQ xPSRA = -{ - { 0x66, 0xe1, 0x71, 4 }, // W - { 0x66, 0xe2, 0x72, 4 } // D + { + {0x66, 0xe1, 0x71, 4}, // W + {0x66, 0xe2, 0x72, 4} // D }; const xImplSimd_Shift xPSRL = -{ - { 0x66, 0xd1, 0x71, 2 }, // W - { 0x66, 0xd2, 0x72, 2 }, // D - { 0x66, 0xd3, 0x73, 2 }, // Q + { + {0x66, 0xd1, 0x71, 2}, // W + {0x66, 0xd2, 0x72, 2}, // D + {0x66, 0xd3, 0x73, 2}, // Q }; const xImplSimd_Shift xPSLL = -{ - { 0x66, 0xf1, 0x71, 6 }, // W - { 0x66, 0xf2, 0x72, 6 }, // D - { 0x66, 0xf3, 0x73, 6 }, // Q + { + {0x66, 0xf1, 0x71, 6}, // W + {0x66, 0xf2, 0x72, 6}, // D + {0x66, 0xf3, 0x73, 6}, // Q }; const xImplSimd_AddSub xPADD = -{ - { 0x66, 0xdc+0x20 }, // B - { 0x66, 0xdc+0x21 }, // W - { 0x66, 0xdc+0x22 }, // D - { 0x66, 0xd4 }, // Q + { + {0x66, 0xdc + 0x20}, // B + {0x66, 0xdc + 0x21}, // W + {0x66, 0xdc + 0x22}, // D + {0x66, 0xd4}, // Q - { 0x66, 0xdc+0x10 }, // SB - { 0x66, 0xdc+0x11 }, // SW - { 0x66, 0xdc }, // USB - { 0x66, 0xdc+1 }, // USW + {0x66, 0xdc + 0x10}, // SB + {0x66, 0xdc + 0x11}, // SW + {0x66, 0xdc}, // USB + {0x66, 0xdc + 1}, // USW }; const xImplSimd_AddSub xPSUB = -{ - { 0x66, 0xd8+0x20 }, // B - { 0x66, 0xd8+0x21 }, // W - { 0x66, 0xd8+0x22 }, // D - { 0x66, 0xfb }, // Q + { + {0x66, 0xd8 + 0x20}, // B + {0x66, 0xd8 + 0x21}, // W + {0x66, 0xd8 + 0x22}, // D + {0x66, 0xfb}, // Q - { 0x66, 0xd8+0x10 }, // SB - { 0x66, 0xd8+0x11 }, // SW - { 0x66, 0xd8 }, // USB - { 0x66, 0xd8+1 }, // USW + {0x66, 0xd8 + 0x10}, // SB + {0x66, 0xd8 + 0x11}, // SW + {0x66, 0xd8}, // USB + {0x66, 0xd8 + 1}, // USW }; const xImplSimd_PMul xPMUL = -{ - { 0x66, 0xd5 }, // LW - { 0x66, 0xe5 }, // HW - { 0x66, 0xe4 }, // HUW - { 0x66, 0xf4 }, // UDQ + { + {0x66, 0xd5}, // LW + {0x66, 0xe5}, // HW + {0x66, 0xe4}, // HUW + {0x66, 0xf4}, // UDQ - { 0x66, 0x0b38 }, // HRSW - { 0x66, 0x4038 }, // LD - { 0x66, 0x2838 }, // DQ + {0x66, 0x0b38}, // HRSW + {0x66, 0x4038}, // LD + {0x66, 0x2838}, // DQ }; const xImplSimd_rSqrt xRSQRT = -{ - { 0x00, 0x52 }, // PS - { 0xf3, 0x52 } // SS + { + {0x00, 0x52}, // PS + {0xf3, 0x52} // SS }; const xImplSimd_rSqrt xRCP = -{ - { 0x00, 0x53 }, // PS - { 0xf3, 0x53 } // SS + { + {0x00, 0x53}, // PS + {0xf3, 0x53} // SS }; const xImplSimd_Sqrt xSQRT = -{ - { 0x00, 0x51 }, // PS - { 0xf3, 0x51 }, // SS - { 0xf2, 0x51 } // SS + { + {0x00, 0x51}, // PS + {0xf3, 0x51}, // SS + {0xf2, 0x51} // SS }; const xImplSimd_AndNot xANDN = -{ - { 0x00, 0x55 }, // PS - { 0x66, 0x55 } // PD + { + {0x00, 0x55}, // PS + {0x66, 0x55} // PD }; const xImplSimd_PAbsolute xPABS = -{ - { 0x66, 0x1c38 }, // B - { 0x66, 0x1d38 }, // W - { 0x66, 0x1e38 } // D + { + {0x66, 0x1c38}, // B + {0x66, 0x1d38}, // W + {0x66, 0x1e38} // D }; const xImplSimd_PSign xPSIGN = -{ - { 0x66, 0x0838 }, // B - { 0x66, 0x0938 }, // W - { 0x66, 0x0a38 }, // D + { + {0x66, 0x0838}, // B + {0x66, 0x0938}, // W + {0x66, 0x0a38}, // D }; const xImplSimd_PMultAdd xPMADD = -{ - { 0x66, 0xf5 }, // WD - { 0x66, 0xf438 }, // UBSW + { + {0x66, 0xf5}, // WD + {0x66, 0xf438}, // UBSW }; const xImplSimd_HorizAdd xHADD = -{ - { 0xf2, 0x7c }, // PS - { 0x66, 0x7c }, // PD + { + {0xf2, 0x7c}, // PS + {0x66, 0x7c}, // PD }; const xImplSimd_DotProduct xDP = -{ - { 0x66,0x403a }, // PS - { 0x66,0x413a }, // PD + { + {0x66, 0x403a}, // PS + {0x66, 0x413a}, // PD }; const xImplSimd_Round xROUND = -{ - { 0x66,0x083a }, // PS - { 0x66,0x093a }, // PD - { 0x66,0x0a3a }, // SS - { 0x66,0x0b3a }, // SD + { + {0x66, 0x083a}, // PS + {0x66, 0x093a}, // PD + {0x66, 0x0a3a}, // SS + {0x66, 0x0b3a}, // SD }; // ===================================================================================================== // SIMD Comparison Instructions // ===================================================================================================== -void xImplSimd_Compare::PS( const xRegisterSSE& to, const xRegisterSSE& from ) const { xOpWrite0F( 0x00, 0xc2, to, from, (u8)CType ); } -void xImplSimd_Compare::PS( const xRegisterSSE& to, const xIndirectVoid& from ) const { xOpWrite0F( 0x00, 0xc2, to, from, (u8)CType ); } +void xImplSimd_Compare::PS(const xRegisterSSE &to, const xRegisterSSE &from) const { xOpWrite0F(0x00, 0xc2, to, from, (u8)CType); } +void xImplSimd_Compare::PS(const xRegisterSSE &to, const xIndirectVoid &from) const { xOpWrite0F(0x00, 0xc2, to, from, (u8)CType); } -void xImplSimd_Compare::PD( const xRegisterSSE& to, const xRegisterSSE& from ) const { xOpWrite0F( 0x66, 0xc2, to, from, (u8)CType ); } -void xImplSimd_Compare::PD( const xRegisterSSE& to, const xIndirectVoid& from ) const { xOpWrite0F( 0x66, 0xc2, to, from, (u8)CType ); } +void xImplSimd_Compare::PD(const xRegisterSSE &to, const xRegisterSSE &from) const { xOpWrite0F(0x66, 0xc2, to, from, (u8)CType); } +void xImplSimd_Compare::PD(const xRegisterSSE &to, const xIndirectVoid &from) const { xOpWrite0F(0x66, 0xc2, to, from, (u8)CType); } -void xImplSimd_Compare::SS( const xRegisterSSE& to, const xRegisterSSE& from ) const { xOpWrite0F( 0xf3, 0xc2, to, from, (u8)CType ); } -void xImplSimd_Compare::SS( const xRegisterSSE& to, const xIndirectVoid& from ) const { xOpWrite0F( 0xf3, 0xc2, to, from, (u8)CType ); } +void xImplSimd_Compare::SS(const xRegisterSSE &to, const xRegisterSSE &from) const { xOpWrite0F(0xf3, 0xc2, to, from, (u8)CType); } +void xImplSimd_Compare::SS(const xRegisterSSE &to, const xIndirectVoid &from) const { xOpWrite0F(0xf3, 0xc2, to, from, (u8)CType); } -void xImplSimd_Compare::SD( const xRegisterSSE& to, const xRegisterSSE& from ) const { xOpWrite0F( 0xf2, 0xc2, to, from, (u8)CType ); } -void xImplSimd_Compare::SD( const xRegisterSSE& to, const xIndirectVoid& from ) const { xOpWrite0F( 0xf2, 0xc2, to, from, (u8)CType ); } +void xImplSimd_Compare::SD(const xRegisterSSE &to, const xRegisterSSE &from) const { xOpWrite0F(0xf2, 0xc2, to, from, (u8)CType); } +void xImplSimd_Compare::SD(const xRegisterSSE &to, const xIndirectVoid &from) const { xOpWrite0F(0xf2, 0xc2, to, from, (u8)CType); } const xImplSimd_MinMax xMIN = -{ - { 0x00, 0x5d }, // PS - { 0x66, 0x5d }, // PD - { 0xf3, 0x5d }, // SS - { 0xf2, 0x5d }, // SD + { + {0x00, 0x5d}, // PS + {0x66, 0x5d}, // PD + {0xf3, 0x5d}, // SS + {0xf2, 0x5d}, // SD }; const xImplSimd_MinMax xMAX = -{ - { 0x00, 0x5f }, // PS - { 0x66, 0x5f }, // PD - { 0xf3, 0x5f }, // SS - { 0xf2, 0x5f }, // SD + { + {0x00, 0x5f}, // PS + {0x66, 0x5f}, // PD + {0xf3, 0x5f}, // SS + {0xf2, 0x5f}, // SD }; // [TODO] : Merge this into the xCMP class, so that they are notation as: xCMP.EQ -const xImplSimd_Compare xCMPEQ = { SSE2_Equal }; -const xImplSimd_Compare xCMPLT = { SSE2_Less }; -const xImplSimd_Compare xCMPLE = { SSE2_LessOrEqual }; -const xImplSimd_Compare xCMPUNORD = { SSE2_LessOrEqual }; -const xImplSimd_Compare xCMPNE = { SSE2_NotEqual }; -const xImplSimd_Compare xCMPNLT = { SSE2_NotLess }; -const xImplSimd_Compare xCMPNLE = { SSE2_NotLessOrEqual }; -const xImplSimd_Compare xCMPORD = { SSE2_Ordered }; +const xImplSimd_Compare xCMPEQ = {SSE2_Equal}; +const xImplSimd_Compare xCMPLT = {SSE2_Less}; +const xImplSimd_Compare xCMPLE = {SSE2_LessOrEqual}; +const xImplSimd_Compare xCMPUNORD = {SSE2_LessOrEqual}; +const xImplSimd_Compare xCMPNE = {SSE2_NotEqual}; +const xImplSimd_Compare xCMPNLT = {SSE2_NotLess}; +const xImplSimd_Compare xCMPNLE = {SSE2_NotLessOrEqual}; +const xImplSimd_Compare xCMPORD = {SSE2_Ordered}; const xImplSimd_COMI xCOMI = -{ - { 0x00, 0x2f }, // SS - { 0x66, 0x2f }, // SD + { + {0x00, 0x2f}, // SS + {0x66, 0x2f}, // SD }; const xImplSimd_COMI xUCOMI = -{ - { 0x00, 0x2e }, // SS - { 0x66, 0x2e }, // SD + { + {0x00, 0x2e}, // SS + {0x66, 0x2e}, // SD }; const xImplSimd_PCompare xPCMP = -{ - { 0x66, 0x74 }, // EQB - { 0x66, 0x75 }, // EQW - { 0x66, 0x76 }, // EQD + { + {0x66, 0x74}, // EQB + {0x66, 0x75}, // EQW + {0x66, 0x76}, // EQD - { 0x66, 0x64 }, // GTB - { 0x66, 0x65 }, // GTW - { 0x66, 0x66 }, // GTD + {0x66, 0x64}, // GTB + {0x66, 0x65}, // GTW + {0x66, 0x66}, // GTD }; const xImplSimd_PMinMax xPMIN = -{ - { 0x66, 0xda }, // UB - { 0x66, 0xea }, // SW - { 0x66, 0x3838 }, // SB - { 0x66, 0x3938 }, // SD + { + {0x66, 0xda}, // UB + {0x66, 0xea}, // SW + {0x66, 0x3838}, // SB + {0x66, 0x3938}, // SD - { 0x66, 0x3a38 }, // UW - { 0x66, 0x3b38 }, // UD + {0x66, 0x3a38}, // UW + {0x66, 0x3b38}, // UD }; const xImplSimd_PMinMax xPMAX = -{ - { 0x66, 0xde }, // UB - { 0x66, 0xee }, // SW - { 0x66, 0x3c38 }, // SB - { 0x66, 0x3d38 }, // SD + { + {0x66, 0xde}, // UB + {0x66, 0xee}, // SW + {0x66, 0x3c38}, // SB + {0x66, 0x3d38}, // SD - { 0x66, 0x3e38 }, // UW - { 0x66, 0x3f38 }, // UD + {0x66, 0x3e38}, // UW + {0x66, 0x3f38}, // UD }; // ===================================================================================================== // SIMD Shuffle/Pack (Shuffle puck?) // ===================================================================================================== -__fi void xImplSimd_Shuffle::_selector_assertion_check( u8 selector ) const +__fi void xImplSimd_Shuffle::_selector_assertion_check(u8 selector) const { - pxAssertMsg( (selector & ~3) == 0, - "Invalid immediate operand on SSE Shuffle: Upper 6 bits of the SSE Shuffle-PD Selector are reserved and must be zero." - ); + pxAssertMsg((selector & ~3) == 0, + "Invalid immediate operand on SSE Shuffle: Upper 6 bits of the SSE Shuffle-PD Selector are reserved and must be zero."); } -void xImplSimd_Shuffle::PS( const xRegisterSSE& to, const xRegisterSSE& from, u8 selector ) const +void xImplSimd_Shuffle::PS(const xRegisterSSE &to, const xRegisterSSE &from, u8 selector) const { - xOpWrite0F( 0xc6, to, from, selector ); + xOpWrite0F(0xc6, to, from, selector); } -void xImplSimd_Shuffle::PS( const xRegisterSSE& to, const xIndirectVoid& from, u8 selector ) const +void xImplSimd_Shuffle::PS(const xRegisterSSE &to, const xIndirectVoid &from, u8 selector) const { - xOpWrite0F( 0xc6, to, from, selector ); + xOpWrite0F(0xc6, to, from, selector); } -void xImplSimd_Shuffle::PD( const xRegisterSSE& to, const xRegisterSSE& from, u8 selector ) const +void xImplSimd_Shuffle::PD(const xRegisterSSE &to, const xRegisterSSE &from, u8 selector) const { - _selector_assertion_check( selector ); - xOpWrite0F( 0x66, 0xc6, to, from, selector & 0x3 ); + _selector_assertion_check(selector); + xOpWrite0F(0x66, 0xc6, to, from, selector & 0x3); } -void xImplSimd_Shuffle::PD( const xRegisterSSE& to, const xIndirectVoid& from, u8 selector ) const +void xImplSimd_Shuffle::PD(const xRegisterSSE &to, const xIndirectVoid &from, u8 selector) const { - _selector_assertion_check( selector ); - xOpWrite0F( 0x66, 0xc6, to, from, selector & 0x3 ); + _selector_assertion_check(selector); + xOpWrite0F(0x66, 0xc6, to, from, selector & 0x3); } -void xImplSimd_InsertExtractHelper::operator()( const xRegisterSSE& to, const xRegister32& from, u8 imm8 ) const +void xImplSimd_InsertExtractHelper::operator()(const xRegisterSSE &to, const xRegister32 &from, u8 imm8) const { - xOpWrite0F( 0x66, Opcode, to, from, imm8 ); + xOpWrite0F(0x66, Opcode, to, from, imm8); } -void xImplSimd_InsertExtractHelper::operator()( const xRegisterSSE& to, const xIndirectVoid& from, u8 imm8 ) const +void xImplSimd_InsertExtractHelper::operator()(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm8) const { - xOpWrite0F( 0x66, Opcode, to, from, imm8 ); + xOpWrite0F(0x66, Opcode, to, from, imm8); } -void xImplSimd_PInsert::W( const xRegisterSSE& to, const xRegister32& from, u8 imm8 ) const { xOpWrite0F( 0x66, 0xc4, to, from, imm8 ); } -void xImplSimd_PInsert::W( const xRegisterSSE& to, const xIndirectVoid& from, u8 imm8 ) const { xOpWrite0F( 0x66, 0xc4, to, from, imm8 ); } +void xImplSimd_PInsert::W(const xRegisterSSE &to, const xRegister32 &from, u8 imm8) const { xOpWrite0F(0x66, 0xc4, to, from, imm8); } +void xImplSimd_PInsert::W(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm8) const { xOpWrite0F(0x66, 0xc4, to, from, imm8); } -void SimdImpl_PExtract::W( const xRegister32& to, const xRegisterSSE& from, u8 imm8 ) const { xOpWrite0F( 0x66, 0xc5, to, from, imm8 ); } -void SimdImpl_PExtract::W( const xIndirectVoid& dest, const xRegisterSSE& from, u8 imm8 ) const { xOpWrite0F( 0x66, 0x153a, from, dest, imm8 ); } +void SimdImpl_PExtract::W(const xRegister32 &to, const xRegisterSSE &from, u8 imm8) const { xOpWrite0F(0x66, 0xc5, to, from, imm8); } +void SimdImpl_PExtract::W(const xIndirectVoid &dest, const xRegisterSSE &from, u8 imm8) const { xOpWrite0F(0x66, 0x153a, from, dest, imm8); } -const xImplSimd_Shuffle xSHUF = { }; +const xImplSimd_Shuffle xSHUF = {}; const xImplSimd_PShuffle xPSHUF = -{ - { 0x66, 0x70 }, // D - { 0xf2, 0x70 }, // LW - { 0xf3, 0x70 }, // HW + { + {0x66, 0x70}, // D + {0xf2, 0x70}, // LW + {0xf3, 0x70}, // HW - { 0x66, 0x0038 }, // B + {0x66, 0x0038}, // B }; const SimdImpl_PUnpack xPUNPCK = -{ - { 0x66, 0x60 }, // LBW - { 0x66, 0x61 }, // LWD - { 0x66, 0x62 }, // LDQ - { 0x66, 0x6c }, // LQDQ + { + {0x66, 0x60}, // LBW + {0x66, 0x61}, // LWD + {0x66, 0x62}, // LDQ + {0x66, 0x6c}, // LQDQ - { 0x66, 0x68 }, // HBW - { 0x66, 0x69 }, // HWD - { 0x66, 0x6a }, // HDQ - { 0x66, 0x6d }, // HQDQ + {0x66, 0x68}, // HBW + {0x66, 0x69}, // HWD + {0x66, 0x6a}, // HDQ + {0x66, 0x6d}, // HQDQ }; const SimdImpl_Pack xPACK = -{ - { 0x66, 0x63 }, // SSWB - { 0x66, 0x6b }, // SSDW - { 0x66, 0x67 }, // USWB - { 0x66, 0x2b38 }, // USDW + { + {0x66, 0x63}, // SSWB + {0x66, 0x6b}, // SSDW + {0x66, 0x67}, // USWB + {0x66, 0x2b38}, // USDW }; const xImplSimd_Unpack xUNPCK = -{ - { 0x00, 0x15 }, // HPS - { 0x66, 0x15 }, // HPD - { 0x00, 0x14 }, // LPS - { 0x66, 0x14 }, // LPD + { + {0x00, 0x15}, // HPS + {0x66, 0x15}, // HPD + {0x00, 0x14}, // LPS + {0x66, 0x14}, // LPD }; const xImplSimd_PInsert xPINSR = -{ - { 0x203a }, // B - { 0x223a }, // D + { + {0x203a}, // B + {0x223a}, // D }; const SimdImpl_PExtract xPEXTR = -{ - { 0x143a }, // B - { 0x163a }, // D + { + {0x143a}, // B + {0x163a}, // D }; // ===================================================================================================== // SIMD Move And Blend Instructions // ===================================================================================================== -void xImplSimd_MovHL::PS( const xRegisterSSE& to, const xIndirectVoid& from ) const { xOpWrite0F( Opcode, to, from ); } -void xImplSimd_MovHL::PS( const xIndirectVoid& to, const xRegisterSSE& from ) const { xOpWrite0F( Opcode+1, from, to ); } +void xImplSimd_MovHL::PS(const xRegisterSSE &to, const xIndirectVoid &from) const { xOpWrite0F(Opcode, to, from); } +void xImplSimd_MovHL::PS(const xIndirectVoid &to, const xRegisterSSE &from) const { xOpWrite0F(Opcode + 1, from, to); } -void xImplSimd_MovHL::PD( const xRegisterSSE& to, const xIndirectVoid& from ) const { xOpWrite0F( 0x66, Opcode, to, from ); } -void xImplSimd_MovHL::PD( const xIndirectVoid& to, const xRegisterSSE& from ) const { xOpWrite0F( 0x66, Opcode+1, from, to ); } +void xImplSimd_MovHL::PD(const xRegisterSSE &to, const xIndirectVoid &from) const { xOpWrite0F(0x66, Opcode, to, from); } +void xImplSimd_MovHL::PD(const xIndirectVoid &to, const xRegisterSSE &from) const { xOpWrite0F(0x66, Opcode + 1, from, to); } -void xImplSimd_MovHL_RtoR::PS( const xRegisterSSE& to, const xRegisterSSE& from ) const { xOpWrite0F( Opcode, to, from ); } -void xImplSimd_MovHL_RtoR::PD( const xRegisterSSE& to, const xRegisterSSE& from ) const { xOpWrite0F( 0x66, Opcode, to, from ); } +void xImplSimd_MovHL_RtoR::PS(const xRegisterSSE &to, const xRegisterSSE &from) const { xOpWrite0F(Opcode, to, from); } +void xImplSimd_MovHL_RtoR::PD(const xRegisterSSE &to, const xRegisterSSE &from) const { xOpWrite0F(0x66, Opcode, to, from); } -static const u16 MovPS_OpAligned = 0x28; // Aligned [aps] form -static const u16 MovPS_OpUnaligned = 0x10; // unaligned [ups] form +static const u16 MovPS_OpAligned = 0x28; // Aligned [aps] form +static const u16 MovPS_OpUnaligned = 0x10; // unaligned [ups] form -void xImplSimd_MoveSSE::operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const +void xImplSimd_MoveSSE::operator()(const xRegisterSSE &to, const xRegisterSSE &from) const { - if( to != from ) xOpWrite0F( Prefix, MovPS_OpAligned, to, from ); + if (to != from) + xOpWrite0F(Prefix, MovPS_OpAligned, to, from); } -void xImplSimd_MoveSSE::operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const +void xImplSimd_MoveSSE::operator()(const xRegisterSSE &to, const xIndirectVoid &from) const { - // ModSib form is aligned if it's displacement-only and the displacement is aligned: - bool isReallyAligned = isAligned || ( ((from.Displacement & 0x0f) == 0) && from.Index.IsEmpty() && from.Base.IsEmpty() ); + // ModSib form is aligned if it's displacement-only and the displacement is aligned: + bool isReallyAligned = isAligned || (((from.Displacement & 0x0f) == 0) && from.Index.IsEmpty() && from.Base.IsEmpty()); - xOpWrite0F( Prefix, isReallyAligned ? MovPS_OpAligned : MovPS_OpUnaligned, to, from ); + xOpWrite0F(Prefix, isReallyAligned ? MovPS_OpAligned : MovPS_OpUnaligned, to, from); } -void xImplSimd_MoveSSE::operator()( const xIndirectVoid& to, const xRegisterSSE& from ) const +void xImplSimd_MoveSSE::operator()(const xIndirectVoid &to, const xRegisterSSE &from) const { - // ModSib form is aligned if it's displacement-only and the displacement is aligned: - bool isReallyAligned = isAligned || ( (to.Displacement & 0x0f) == 0 && to.Index.IsEmpty() && to.Base.IsEmpty() ); - xOpWrite0F( Prefix, isReallyAligned ? MovPS_OpAligned+1 : MovPS_OpUnaligned+1, from, to ); + // ModSib form is aligned if it's displacement-only and the displacement is aligned: + bool isReallyAligned = isAligned || ((to.Displacement & 0x0f) == 0 && to.Index.IsEmpty() && to.Base.IsEmpty()); + xOpWrite0F(Prefix, isReallyAligned ? MovPS_OpAligned + 1 : MovPS_OpUnaligned + 1, from, to); } -static const u8 MovDQ_PrefixAligned = 0x66; // Aligned [dqa] form -static const u8 MovDQ_PrefixUnaligned = 0xf3; // unaligned [dqu] form +static const u8 MovDQ_PrefixAligned = 0x66; // Aligned [dqa] form +static const u8 MovDQ_PrefixUnaligned = 0xf3; // unaligned [dqu] form -void xImplSimd_MoveDQ::operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const +void xImplSimd_MoveDQ::operator()(const xRegisterSSE &to, const xRegisterSSE &from) const { - if( to != from ) xOpWrite0F( MovDQ_PrefixAligned, 0x6f, to, from ); + if (to != from) + xOpWrite0F(MovDQ_PrefixAligned, 0x6f, to, from); } -void xImplSimd_MoveDQ::operator()( const xRegisterSSE& to, const xIndirectVoid& from ) const +void xImplSimd_MoveDQ::operator()(const xRegisterSSE &to, const xIndirectVoid &from) const { - // ModSib form is aligned if it's displacement-only and the displacement is aligned: - bool isReallyAligned = isAligned || ( (from.Displacement & 0x0f) == 0 && from.Index.IsEmpty() && from.Base.IsEmpty() ); - xOpWrite0F( isReallyAligned ? MovDQ_PrefixAligned : MovDQ_PrefixUnaligned, 0x6f, to, from ); + // ModSib form is aligned if it's displacement-only and the displacement is aligned: + bool isReallyAligned = isAligned || ((from.Displacement & 0x0f) == 0 && from.Index.IsEmpty() && from.Base.IsEmpty()); + xOpWrite0F(isReallyAligned ? MovDQ_PrefixAligned : MovDQ_PrefixUnaligned, 0x6f, to, from); } -void xImplSimd_MoveDQ::operator()( const xIndirectVoid& to, const xRegisterSSE& from ) const +void xImplSimd_MoveDQ::operator()(const xIndirectVoid &to, const xRegisterSSE &from) const { - // ModSib form is aligned if it's displacement-only and the displacement is aligned: - bool isReallyAligned = isAligned || ( (to.Displacement & 0x0f) == 0 && to.Index.IsEmpty() && to.Base.IsEmpty() ); + // ModSib form is aligned if it's displacement-only and the displacement is aligned: + bool isReallyAligned = isAligned || ((to.Displacement & 0x0f) == 0 && to.Index.IsEmpty() && to.Base.IsEmpty()); - // use opcode 0x7f : alternate ModRM encoding (reverse src/dst) - xOpWrite0F( isReallyAligned ? MovDQ_PrefixAligned : MovDQ_PrefixUnaligned, 0x7f, from, to ); + // use opcode 0x7f : alternate ModRM encoding (reverse src/dst) + xOpWrite0F(isReallyAligned ? MovDQ_PrefixAligned : MovDQ_PrefixUnaligned, 0x7f, from, to); } -void xImplSimd_PMove::BW( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( 0x66, OpcodeBase ); } -void xImplSimd_PMove::BW( const xRegisterSSE& to, const xIndirect64& from ) const { OpWriteSSE( 0x66, OpcodeBase ); } +void xImplSimd_PMove::BW(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(0x66, OpcodeBase); } +void xImplSimd_PMove::BW(const xRegisterSSE &to, const xIndirect64 &from) const { OpWriteSSE(0x66, OpcodeBase); } -void xImplSimd_PMove::BD( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x100 ); } -void xImplSimd_PMove::BD( const xRegisterSSE& to, const xIndirect32& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x100 ); } +void xImplSimd_PMove::BD(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(0x66, OpcodeBase + 0x100); } +void xImplSimd_PMove::BD(const xRegisterSSE &to, const xIndirect32 &from) const { OpWriteSSE(0x66, OpcodeBase + 0x100); } -void xImplSimd_PMove::BQ( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x200 ); } -void xImplSimd_PMove::BQ( const xRegisterSSE& to, const xIndirect16& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x200 ); } +void xImplSimd_PMove::BQ(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(0x66, OpcodeBase + 0x200); } +void xImplSimd_PMove::BQ(const xRegisterSSE &to, const xIndirect16 &from) const { OpWriteSSE(0x66, OpcodeBase + 0x200); } -void xImplSimd_PMove::WD( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x300 ); } -void xImplSimd_PMove::WD( const xRegisterSSE& to, const xIndirect64& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x300 ); } +void xImplSimd_PMove::WD(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(0x66, OpcodeBase + 0x300); } +void xImplSimd_PMove::WD(const xRegisterSSE &to, const xIndirect64 &from) const { OpWriteSSE(0x66, OpcodeBase + 0x300); } -void xImplSimd_PMove::WQ( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x400 ); } -void xImplSimd_PMove::WQ( const xRegisterSSE& to, const xIndirect32& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x400 ); } +void xImplSimd_PMove::WQ(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(0x66, OpcodeBase + 0x400); } +void xImplSimd_PMove::WQ(const xRegisterSSE &to, const xIndirect32 &from) const { OpWriteSSE(0x66, OpcodeBase + 0x400); } -void xImplSimd_PMove::DQ( const xRegisterSSE& to, const xRegisterSSE& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x500 ); } -void xImplSimd_PMove::DQ( const xRegisterSSE& to, const xIndirect64& from ) const { OpWriteSSE( 0x66, OpcodeBase+0x500 ); } +void xImplSimd_PMove::DQ(const xRegisterSSE &to, const xRegisterSSE &from) const { OpWriteSSE(0x66, OpcodeBase + 0x500); } +void xImplSimd_PMove::DQ(const xRegisterSSE &to, const xIndirect64 &from) const { OpWriteSSE(0x66, OpcodeBase + 0x500); } -const xImplSimd_MoveSSE xMOVAPS = { 0x00, true }; -const xImplSimd_MoveSSE xMOVUPS = { 0x00, false }; +const xImplSimd_MoveSSE xMOVAPS = {0x00, true}; +const xImplSimd_MoveSSE xMOVUPS = {0x00, false}; #ifdef ALWAYS_USE_MOVAPS - const xImplSimd_MoveSSE xMOVDQA = { 0x00, true }; - const xImplSimd_MoveSSE xMOVAPD = { 0x00, true }; +const xImplSimd_MoveSSE xMOVDQA = {0x00, true}; +const xImplSimd_MoveSSE xMOVAPD = {0x00, true}; - const xImplSimd_MoveSSE xMOVDQU = { 0x00, false }; - const xImplSimd_MoveSSE xMOVUPD = { 0x00, false }; +const xImplSimd_MoveSSE xMOVDQU = {0x00, false}; +const xImplSimd_MoveSSE xMOVUPD = {0x00, false}; #else - const xImplSimd_MoveDQ xMOVDQA = { 0x66, true }; - const xImplSimd_MoveSSE xMOVAPD = { 0x66, true }; +const xImplSimd_MoveDQ xMOVDQA = {0x66, true}; +const xImplSimd_MoveSSE xMOVAPD = {0x66, true}; - const xImplSimd_MoveDQ xMOVDQU = { 0xf3, false }; - const xImplSimd_MoveSSE xMOVUPD = { 0x66, false }; +const xImplSimd_MoveDQ xMOVDQU = {0xf3, false}; +const xImplSimd_MoveSSE xMOVUPD = {0x66, false}; #endif -const xImplSimd_MovHL xMOVH = { 0x16 }; -const xImplSimd_MovHL xMOVL = { 0x12 }; +const xImplSimd_MovHL xMOVH = {0x16}; +const xImplSimd_MovHL xMOVL = {0x12}; -const xImplSimd_MovHL_RtoR xMOVLH = { 0x16 }; -const xImplSimd_MovHL_RtoR xMOVHL = { 0x12 }; +const xImplSimd_MovHL_RtoR xMOVLH = {0x16}; +const xImplSimd_MovHL_RtoR xMOVHL = {0x12}; const xImplSimd_Blend xBLEND = -{ - { 0x66, 0x0c3a }, // PS - { 0x66, 0x0d3a }, // PD - { 0x66, 0x1438 }, // VPS - { 0x66, 0x1538 }, // VPD + { + {0x66, 0x0c3a}, // PS + {0x66, 0x0d3a}, // PD + {0x66, 0x1438}, // VPS + {0x66, 0x1538}, // VPD }; -const xImplSimd_PMove xPMOVSX = { 0x2038 }; -const xImplSimd_PMove xPMOVZX = { 0x3038 }; +const xImplSimd_PMove xPMOVSX = {0x2038}; +const xImplSimd_PMove xPMOVZX = {0x3038}; // [SSE-3] -const xImplSimd_DestRegSSE xMOVSLDUP = { 0xf3,0x12 }; +const xImplSimd_DestRegSSE xMOVSLDUP = {0xf3, 0x12}; // [SSE-3] -const xImplSimd_DestRegSSE xMOVSHDUP = { 0xf3,0x16 }; +const xImplSimd_DestRegSSE xMOVSHDUP = {0xf3, 0x16}; ////////////////////////////////////////////////////////////////////////////////////////// // MMX Mov Instructions (MOVD, MOVQ, MOVSS). @@ -658,63 +659,67 @@ const xImplSimd_DestRegSSE xMOVSHDUP = { 0xf3,0x16 }; // * MOVD has valid forms for MMX and XMM registers. // -__fi void xMOVDZX( const xRegisterSSE& to, const xRegister32or64& from ) { xOpWrite0F( 0x66, 0x6e, to, from ); } -__fi void xMOVDZX( const xRegisterSSE& to, const xIndirectVoid& src ) { xOpWrite0F( 0x66, 0x6e, to, src ); } +__fi void xMOVDZX(const xRegisterSSE &to, const xRegister32or64 &from) { xOpWrite0F(0x66, 0x6e, to, from); } +__fi void xMOVDZX(const xRegisterSSE &to, const xIndirectVoid &src) { xOpWrite0F(0x66, 0x6e, to, src); } -__fi void xMOVD( const xRegister32or64& to, const xRegisterSSE& from ) { xOpWrite0F( 0x66, 0x7e, from, to ); } -__fi void xMOVD( const xIndirectVoid& dest, const xRegisterSSE& from ) { xOpWrite0F( 0x66, 0x7e, from, dest ); } +__fi void xMOVD(const xRegister32or64 &to, const xRegisterSSE &from) { xOpWrite0F(0x66, 0x7e, from, to); } +__fi void xMOVD(const xIndirectVoid &dest, const xRegisterSSE &from) { xOpWrite0F(0x66, 0x7e, from, dest); } // Moves from XMM to XMM, with the *upper 64 bits* of the destination register // being cleared to zero. -__fi void xMOVQZX( const xRegisterSSE& to, const xRegisterSSE& from ) { xOpWrite0F( 0xf3, 0x7e, to, from ); } +__fi void xMOVQZX(const xRegisterSSE &to, const xRegisterSSE &from) { xOpWrite0F(0xf3, 0x7e, to, from); } // Moves from XMM to XMM, with the *upper 64 bits* of the destination register // being cleared to zero. -__fi void xMOVQZX( const xRegisterSSE& to, const xIndirectVoid& src ) { xOpWrite0F( 0xf3, 0x7e, to, src ); } +__fi void xMOVQZX(const xRegisterSSE &to, const xIndirectVoid &src) { xOpWrite0F(0xf3, 0x7e, to, src); } // Moves from XMM to XMM, with the *upper 64 bits* of the destination register // being cleared to zero. -__fi void xMOVQZX( const xRegisterSSE& to, const void* src ) { xOpWrite0F( 0xf3, 0x7e, to, src ); } +__fi void xMOVQZX(const xRegisterSSE &to, const void *src) { xOpWrite0F(0xf3, 0x7e, to, src); } // Moves lower quad of XMM to ptr64 (no bits are cleared) -__fi void xMOVQ( const xIndirectVoid& dest, const xRegisterSSE& from ) { xOpWrite0F( 0x66, 0xd6, from, dest ); } +__fi void xMOVQ(const xIndirectVoid &dest, const xRegisterSSE &from) { xOpWrite0F(0x66, 0xd6, from, dest); } ////////////////////////////////////////////////////////////////////////////////////////// // -#define IMPLEMENT_xMOVS( ssd, prefix ) \ - __fi void xMOV##ssd( const xRegisterSSE& to, const xRegisterSSE& from ) { if( to != from ) xOpWrite0F( prefix, 0x10, to, from ); } \ - __fi void xMOV##ssd##ZX( const xRegisterSSE& to, const xIndirectVoid& from ) { xOpWrite0F( prefix, 0x10, to, from ); } \ - __fi void xMOV##ssd( const xIndirectVoid& to, const xRegisterSSE& from ) { xOpWrite0F( prefix, 0x11, from, to ); } +#define IMPLEMENT_xMOVS(ssd, prefix) \ + __fi void xMOV##ssd(const xRegisterSSE &to, const xRegisterSSE &from) \ + { \ + if (to != from) \ + xOpWrite0F(prefix, 0x10, to, from); \ + } \ + __fi void xMOV##ssd##ZX(const xRegisterSSE &to, const xIndirectVoid &from) { xOpWrite0F(prefix, 0x10, to, from); } \ + __fi void xMOV##ssd(const xIndirectVoid &to, const xRegisterSSE &from) { xOpWrite0F(prefix, 0x11, from, to); } -IMPLEMENT_xMOVS( SS, 0xf3 ) -IMPLEMENT_xMOVS( SD, 0xf2 ) +IMPLEMENT_xMOVS(SS, 0xf3) + IMPLEMENT_xMOVS(SD, 0xf2) -////////////////////////////////////////////////////////////////////////////////////////// -// Non-temporal movs only support a register as a target (ie, load form only, no stores) -// + ////////////////////////////////////////////////////////////////////////////////////////// + // Non-temporal movs only support a register as a target (ie, load form only, no stores) + // -__fi void xMOVNTDQA( const xRegisterSSE& to, const xIndirectVoid& from ) + __fi void xMOVNTDQA(const xRegisterSSE &to, const xIndirectVoid &from) { - xOpWrite0F( 0x66, 0x2a38, to.Id, from); + xOpWrite0F(0x66, 0x2a38, to.Id, from); } -__fi void xMOVNTDQA( const xIndirectVoid& to, const xRegisterSSE& from ) { xOpWrite0F( 0x66, 0xe7, from, to ); } +__fi void xMOVNTDQA(const xIndirectVoid &to, const xRegisterSSE &from) { xOpWrite0F(0x66, 0xe7, from, to); } -__fi void xMOVNTPD( const xIndirectVoid& to, const xRegisterSSE& from ) { xOpWrite0F( 0x66, 0x2b, from, to ); } -__fi void xMOVNTPS( const xIndirectVoid& to, const xRegisterSSE& from ) { xOpWrite0F( 0x2b, from, to ); } +__fi void xMOVNTPD(const xIndirectVoid &to, const xRegisterSSE &from) { xOpWrite0F(0x66, 0x2b, from, to); } +__fi void xMOVNTPS(const xIndirectVoid &to, const xRegisterSSE &from) { xOpWrite0F(0x2b, from, to); } // ------------------------------------------------------------------------ -__fi void xMOVMSKPS( const xRegister32or64& to, const xRegisterSSE& from) { xOpWrite0F( 0x50, to, from ); } -__fi void xMOVMSKPD( const xRegister32or64& to, const xRegisterSSE& from) { xOpWrite0F( 0x66, 0x50, to, from, true ); } +__fi void xMOVMSKPS(const xRegister32or64 &to, const xRegisterSSE &from) { xOpWrite0F(0x50, to, from); } +__fi void xMOVMSKPD(const xRegister32or64 &to, const xRegisterSSE &from) { xOpWrite0F(0x66, 0x50, to, from, true); } // xMASKMOV: // Selectively write bytes from mm1/xmm1 to memory location using the byte mask in mm2/xmm2. // The default memory location is specified by DS:EDI. The most significant bit in each byte // of the mask operand determines whether the corresponding byte in the source operand is // written to the corresponding byte location in memory. -__fi void xMASKMOV( const xRegisterSSE& to, const xRegisterSSE& from ) { xOpWrite0F( 0x66, 0xf7, to, from ); } +__fi void xMASKMOV(const xRegisterSSE &to, const xRegisterSSE &from) { xOpWrite0F(0x66, 0xf7, to, from); } // xPMOVMSKB: // Creates a mask made up of the most significant bit of each byte of the source @@ -724,13 +729,13 @@ __fi void xMASKMOV( const xRegisterSSE& to, const xRegisterSSE& from ) { xOpWri // When operating on a 64-bit (MMX) source, the byte mask is 8 bits; when operating on // 128-bit (SSE) source, the byte mask is 16-bits. // -__fi void xPMOVMSKB( const xRegister32or64& to, const xRegisterSSE& from ) { xOpWrite0F( 0x66, 0xd7, to, from ); } +__fi void xPMOVMSKB(const xRegister32or64 &to, const xRegisterSSE &from) { xOpWrite0F(0x66, 0xd7, to, from); } // [sSSE-3] Concatenates dest and source operands into an intermediate composite, // shifts the composite at byte granularity to the right by a constant immediate, // and extracts the right-aligned result into the destination. // -__fi void xPALIGNR( const xRegisterSSE& to, const xRegisterSSE& from, u8 imm8 ) { xOpWrite0F( 0x66, 0x0f3a, to, from, imm8 ); } +__fi void xPALIGNR(const xRegisterSSE &to, const xRegisterSSE &from, u8 imm8) { xOpWrite0F(0x66, 0x0f3a, to, from, imm8); } // -------------------------------------------------------------------------------------- @@ -752,15 +757,15 @@ __fi void xPALIGNR( const xRegisterSSE& to, const xRegisterSSE& from, u8 imm8 ) // * ZMASK: Each bit of Imm8[3:0] selects a dword element in dest to be written // with 0.0 if set to 1. // -__emitinline void xINSERTPS( const xRegisterSSE& to, const xRegisterSSE& from, u8 imm8 ) { xOpWrite0F( 0x66, 0x213a, to, from, imm8 ); } -__emitinline void xINSERTPS( const xRegisterSSE& to, const xIndirect32& from, u8 imm8 ) { xOpWrite0F( 0x66, 0x213a, to, from, imm8 ); } +__emitinline void xINSERTPS(const xRegisterSSE &to, const xRegisterSSE &from, u8 imm8) { xOpWrite0F(0x66, 0x213a, to, from, imm8); } +__emitinline void xINSERTPS(const xRegisterSSE &to, const xIndirect32 &from, u8 imm8) { xOpWrite0F(0x66, 0x213a, to, from, imm8); } // [SSE-4.1] Extract a single-precision floating-point value from src at an offset // determined by imm8[1-0]*32. The extracted single precision floating-point value // is stored into the low 32-bits of dest (or at a 32-bit memory pointer). // -__emitinline void xEXTRACTPS( const xRegister32or64& to, const xRegisterSSE& from, u8 imm8 ) { xOpWrite0F( 0x66, 0x173a, to, from, imm8 ); } -__emitinline void xEXTRACTPS( const xIndirect32& dest, const xRegisterSSE& from, u8 imm8 ) { xOpWrite0F( 0x66, 0x173a, from, dest, imm8 ); } +__emitinline void xEXTRACTPS(const xRegister32or64 &to, const xRegisterSSE &from, u8 imm8) { xOpWrite0F(0x66, 0x173a, to, from, imm8); } +__emitinline void xEXTRACTPS(const xIndirect32 &dest, const xRegisterSSE &from, u8 imm8) { xOpWrite0F(0x66, 0x173a, from, dest, imm8); } // ===================================================================================================== @@ -769,29 +774,28 @@ __emitinline void xEXTRACTPS( const xIndirect32& dest, const xRegisterSSE& from, // Store Streaming SIMD Extension Control/Status to Mem32. -__emitinline void xSTMXCSR( const xIndirect32& dest ) +__emitinline void xSTMXCSR(const xIndirect32 &dest) { - xOpWrite0F( 0, 0xae, 3, dest ); + xOpWrite0F(0, 0xae, 3, dest); } // Load Streaming SIMD Extension Control/Status from Mem32. -__emitinline void xLDMXCSR( const xIndirect32& src ) +__emitinline void xLDMXCSR(const xIndirect32 &src) { - xOpWrite0F( 0, 0xae, 2, src ); + xOpWrite0F(0, 0xae, 2, src); } // Save x87 FPU, MMX Technology, and SSE State to buffer // Target buffer must be at least 512 bytes in length to hold the result. -__emitinline void xFXSAVE( const xIndirectVoid& dest ) +__emitinline void xFXSAVE(const xIndirectVoid &dest) { - xOpWrite0F( 0, 0xae, 0, dest ); + xOpWrite0F(0, 0xae, 0, dest); } // Restore x87 FPU, MMX , XMM, and MXCSR State. // Source buffer should be 512 bytes in length. -__emitinline void xFXRSTOR( const xIndirectVoid& src ) +__emitinline void xFXRSTOR(const xIndirectVoid &src) { - xOpWrite0F( 0, 0xae, 1, src ); + xOpWrite0F(0, 0xae, 1, src); } - } diff --git a/common/src/x86emitter/x86emitter.cpp b/common/src/x86emitter/x86emitter.cpp index e8a85a576f..078cdda27a 100644 --- a/common/src/x86emitter/x86emitter.cpp +++ b/common/src/x86emitter/x86emitter.cpp @@ -61,152 +61,159 @@ // -__tls_emit u8* x86Ptr; -__tls_emit XMMSSEType g_xmmtypes[iREGCNT_XMM] = { XMMT_INT }; +__tls_emit u8 *x86Ptr; +__tls_emit XMMSSEType g_xmmtypes[iREGCNT_XMM] = {XMMT_INT}; -namespace x86Emitter { - -template void xWrite( u8 val ); -template void xWrite( u16 val ); -template void xWrite( u32 val ); -template void xWrite( u64 val ); -template void xWrite( u128 val ); - -__fi void xWrite8( u8 val ) +namespace x86Emitter { - xWrite( val ); + +template void xWrite(u8 val); +template void xWrite(u16 val); +template void xWrite(u32 val); +template void xWrite(u64 val); +template void xWrite(u128 val); + +__fi void xWrite8(u8 val) +{ + xWrite(val); } -__fi void xWrite16( u16 val ) +__fi void xWrite16(u16 val) { - xWrite( val ); + xWrite(val); } -__fi void xWrite32( u32 val ) +__fi void xWrite32(u32 val) { - xWrite( val ); + xWrite(val); } -__fi void xWrite64( u64 val ) +__fi void xWrite64(u64 val) { - xWrite( val ); + xWrite(val); } // Empty initializers are due to frivolously pointless GCC errors (it demands the // objects be initialized even though they have no actual variable members). -const xAddressIndexer ptr = { }; -const xAddressIndexer ptr128 = { }; -const xAddressIndexer ptr64 = { }; -const xAddressIndexer ptr32 = { }; -const xAddressIndexer ptr16 = { }; -const xAddressIndexer ptr8 = { }; +const xAddressIndexer ptr = {}; +const xAddressIndexer ptr128 = {}; +const xAddressIndexer ptr64 = {}; +const xAddressIndexer ptr32 = {}; +const xAddressIndexer ptr16 = {}; +const xAddressIndexer ptr8 = {}; // ------------------------------------------------------------------------ -const xRegisterEmpty xEmptyReg = { }; +const xRegisterEmpty xEmptyReg = {}; + +// clang-format off const xRegisterSSE - xmm0( 0 ), xmm1( 1 ), - xmm2( 2 ), xmm3( 3 ), - xmm4( 4 ), xmm5( 5 ), - xmm6( 6 ), xmm7( 7 ), - xmm8( 8 ), xmm9( 9 ), - xmm10( 10 ), xmm11( 11 ), - xmm12( 12 ), xmm13( 13 ), - xmm14( 14 ), xmm15( 15 ); + xmm0(0), xmm1(1), + xmm2(2), xmm3(3), + xmm4(4), xmm5(5), + xmm6(6), xmm7(7), + xmm8(8), xmm9(9), + xmm10(10), xmm11(11), + xmm12(12), xmm13(13), + xmm14(14), xmm15(15); const xAddressReg - rax( 0 ), rbx( 3 ), - rcx( 1 ), rdx( 2 ), - rsp( 4 ), rbp( 5 ), - rsi( 6 ), rdi( 7 ), - r8( 8 ) , r9( 9 ) , - r10( 10 ), r11( 11 ), - r12( 12 ), r13( 13 ), - r14( 14 ), r15( 15 ); + rax(0), rbx(3), + rcx(1), rdx(2), + rsp(4), rbp(5), + rsi(6), rdi(7), + r8(8), r9(9), + r10(10), r11(11), + r12(12), r13(13), + r14(14), r15(15); const xAddressReg - eax( 0 ), ebx( 3 ), - ecx( 1 ), edx( 2 ), - esp( 4 ), ebp( 5 ), - esi( 6 ), edi( 7 ); + eax(0), ebx(3), + ecx(1), edx(2), + esp(4), ebp(5), + esi(6), edi(7); const xRegister16 - ax( 0 ), bx( 3 ), - cx( 1 ), dx( 2 ), - sp( 4 ), bp( 5 ), - si( 6 ), di( 7 ); + ax(0), bx(3), + cx(1), dx(2), + sp(4), bp(5), + si(6), di(7); const xRegister8 - al( 0 ), - dl( 2 ), bl( 3 ), - ah( 4 ), ch( 5 ), - dh( 6 ), bh( 7 ); + al(0), + dl(2), bl(3), + ah(4), ch(5), + dh(6), bh(7); + +// clang-format on const xRegisterCL cl; const char *const x86_regnames_gpr8[] = -{ - "al", "cl", "dl", "bl", - "ah", "ch", "dh", "bh", - "b8", "b9", "b10", "b11", - "b12", "b13", "b14", "b15" -}; + { + "al", "cl", "dl", "bl", + "ah", "ch", "dh", "bh", + "b8", "b9", "b10", "b11", + "b12", "b13", "b14", "b15"}; const char *const x86_regnames_gpr16[] = -{ - "ax", "cx", "dx", "bx", - "sp", "bp", "si", "di", - "h8", "h9", "h10", "h11", - "h12", "h13", "h14", "h15" -}; + { + "ax", "cx", "dx", "bx", + "sp", "bp", "si", "di", + "h8", "h9", "h10", "h11", + "h12", "h13", "h14", "h15"}; const char *const x86_regnames_gpr32[] = -{ - "eax", "ecx", "edx", "ebx", - "esp", "ebp", "esi", "edi", - "e8", "e9", "e10", "e11", - "e12", "e13", "e14", "e15" -}; + { + "eax", "ecx", "edx", "ebx", + "esp", "ebp", "esi", "edi", + "e8", "e9", "e10", "e11", + "e12", "e13", "e14", "e15"}; const char *const x86_regnames_gpr64[] = -{ - "rax", "rcx", "rdx", "rbx", - "rsp", "rbp", "rsi", "rdi", - "r8" , "r9" , "r10", "r11", - "r12", "r13", "r14", "r15" -}; + { + "rax", "rcx", "rdx", "rbx", + "rsp", "rbp", "rsi", "rdi", + "r8", "r9", "r10", "r11", + "r12", "r13", "r14", "r15"}; const char *const x86_regnames_sse[] = + { + "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm6", "xmm7", + "xmm8", "xmm9", "xmm10", "xmm11", + "xmm12", "xmm13", "xmm14", "xmm15"}; + +const char *xRegisterBase::GetName() { - "xmm0", "xmm1", "xmm2", "xmm3", - "xmm4", "xmm5", "xmm6", "xmm7", - "xmm8", "xmm9", "xmm10", "xmm11", - "xmm12", "xmm13", "xmm14", "xmm15" -}; + if (Id == xRegId_Invalid) + return "invalid"; + if (Id == xRegId_Empty) + return "empty"; -const char* xRegisterBase::GetName() -{ - if( Id == xRegId_Invalid ) return "invalid"; - if( Id == xRegId_Empty ) return "empty"; + // bad error? Return a "big" error string. Might break formatting of register tables + // but that's the least of your worries if you see this baby. + if (Id >= (int)iREGCNT_GPR || Id < 0) + return "!Register index out of range!"; - // bad error? Return a "big" error string. Might break formatting of register tables - // but that's the least of your worries if you see this baby. - if( Id >= (int)iREGCNT_GPR || Id < 0 ) return "!Register index out of range!"; - - switch( GetOperandSize() ) - { - case 1: return x86_regnames_gpr8[ Id ]; - case 2: return x86_regnames_gpr16[ Id ]; - case 4: return x86_regnames_gpr32[ Id ]; + switch (GetOperandSize()) { + case 1: + return x86_regnames_gpr8[Id]; + case 2: + return x86_regnames_gpr16[Id]; + case 4: + return x86_regnames_gpr32[Id]; #ifdef __x86_64__ - case 8: return x86_regnames_gpr64[ Id ]; + case 8: + return x86_regnames_gpr64[Id]; #endif - case 16: return x86_regnames_sse[ Id ]; - } + case 16: + return x86_regnames_sse[Id]; + } - return "oops?"; + return "oops?"; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -233,48 +240,51 @@ const char* xRegisterBase::GetName() // (btw, I know this isn't a critical performance item by any means, but it's // annoying simply because it *should* be an easy thing to optimize) -static __fi void ModRM( uint mod, uint reg, uint rm ) +static __fi void ModRM(uint mod, uint reg, uint rm) { - xWrite8( (mod << 6) | (reg << 3) | rm ); + xWrite8((mod << 6) | (reg << 3) | rm); } -static __fi void SibSB( u32 ss, u32 index, u32 base ) +static __fi void SibSB(u32 ss, u32 index, u32 base) { - xWrite8( (ss << 6) | (index << 3) | base ); + xWrite8((ss << 6) | (index << 3) | base); } -void EmitSibMagic( uint regfield, const void* address ) +void EmitSibMagic(uint regfield, const void *address) { - ModRM( 0, regfield, ModRm_UseDisp32 ); + ModRM(0, regfield, ModRm_UseDisp32); - // SIB encoding only supports 32bit offsets, even on x86_64 - // We must make sure that the displacement is within the 32bit range - // Else we will fail out in a spectacular fashion - sptr displacement = (sptr)address; + // SIB encoding only supports 32bit offsets, even on x86_64 + // We must make sure that the displacement is within the 32bit range + // Else we will fail out in a spectacular fashion + sptr displacement = (sptr)address; #ifdef __x86_64__ - pxAssertDev(displacement >= -0x80000000LL && displacement < 0x80000000LL, "SIB target is too far away, needs an indirect register"); + pxAssertDev(displacement >= -0x80000000LL && displacement < 0x80000000LL, "SIB target is too far away, needs an indirect register"); #endif - xWrite( (s32)displacement ); + xWrite((s32)displacement); } ////////////////////////////////////////////////////////////////////////////////////////// // returns TRUE if this instruction requires SIB to be encoded, or FALSE if the // instruction ca be encoded as ModRm alone. -static __fi bool NeedsSibMagic( const xIndirectVoid& info ) +static __fi bool NeedsSibMagic(const xIndirectVoid &info) { - // no registers? no sibs! - // (xIndirectVoid::Reduce always places a register in Index, and optionally leaves - // Base empty if only register is specified) - if( info.Index.IsEmpty() ) return false; + // no registers? no sibs! + // (xIndirectVoid::Reduce always places a register in Index, and optionally leaves + // Base empty if only register is specified) + if (info.Index.IsEmpty()) + return false; - // A scaled register needs a SIB - if( info.Scale != 0 ) return true; + // A scaled register needs a SIB + if (info.Scale != 0) + return true; - // two registers needs a SIB - if( !info.Base.IsEmpty() ) return true; + // two registers needs a SIB + if (!info.Base.IsEmpty()) + return true; - return false; + return false; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -283,156 +293,146 @@ static __fi bool NeedsSibMagic( const xIndirectVoid& info ) // regfield - register field to be written to the ModRm. This is either a register specifier // or an opcode extension. In either case, the instruction determines the value for us. // -void EmitSibMagic( uint regfield, const xIndirectVoid& info ) +void EmitSibMagic(uint regfield, const xIndirectVoid &info) { - // 3 bits also on x86_64 (so max is 8) - // We might need to mask it on x86_64 - pxAssertDev( regfield < 8, "Invalid x86 register identifier." ); - int displacement_size = (info.Displacement == 0) ? 0 : - ( ( info.IsByteSizeDisp() ) ? 1 : 2 ); + // 3 bits also on x86_64 (so max is 8) + // We might need to mask it on x86_64 + pxAssertDev(regfield < 8, "Invalid x86 register identifier."); + int displacement_size = (info.Displacement == 0) ? 0 : + ((info.IsByteSizeDisp()) ? 1 : 2); - pxAssert(!info.Base.IsEmpty() || !info.Index.IsEmpty() || displacement_size == 2); + pxAssert(!info.Base.IsEmpty() || !info.Index.IsEmpty() || displacement_size == 2); - if( !NeedsSibMagic( info ) ) - { - // Use ModRm-only encoding, with the rm field holding an index/base register, if - // one has been specified. If neither register is specified then use Disp32 form, - // which is encoded as "EBP w/o displacement" (which is why EBP must always be - // encoded *with* a displacement of 0, if it would otherwise not have one). + if (!NeedsSibMagic(info)) { + // Use ModRm-only encoding, with the rm field holding an index/base register, if + // one has been specified. If neither register is specified then use Disp32 form, + // which is encoded as "EBP w/o displacement" (which is why EBP must always be + // encoded *with* a displacement of 0, if it would otherwise not have one). - if( info.Index.IsEmpty() ) - { - EmitSibMagic( regfield, (void*)info.Displacement ); - return; - } - else - { - if( info.Index == ebp && displacement_size == 0 ) - displacement_size = 1; // forces [ebp] to be encoded as [ebp+0]! + if (info.Index.IsEmpty()) { + EmitSibMagic(regfield, (void *)info.Displacement); + return; + } else { + if (info.Index == ebp && displacement_size == 0) + displacement_size = 1; // forces [ebp] to be encoded as [ebp+0]! - ModRM( displacement_size, regfield, info.Index.Id ); - } - } - else - { - // In order to encode "just" index*scale (and no base), we have to encode - // it as a special [index*scale + displacement] form, which is done by - // specifying EBP as the base register and setting the displacement field - // to zero. (same as ModRm w/o SIB form above, basically, except the - // ModRm_UseDisp flag is specified in the SIB instead of the ModRM field). + ModRM(displacement_size, regfield, info.Index.Id); + } + } else { + // In order to encode "just" index*scale (and no base), we have to encode + // it as a special [index*scale + displacement] form, which is done by + // specifying EBP as the base register and setting the displacement field + // to zero. (same as ModRm w/o SIB form above, basically, except the + // ModRm_UseDisp flag is specified in the SIB instead of the ModRM field). - if( info.Base.IsEmpty() ) - { - ModRM( 0, regfield, ModRm_UseSib ); - SibSB( info.Scale, info.Index.Id, ModRm_UseDisp32 ); - xWrite( info.Displacement ); - return; - } - else - { - if( info.Base == ebp && displacement_size == 0 ) - displacement_size = 1; // forces [ebp] to be encoded as [ebp+0]! + if (info.Base.IsEmpty()) { + ModRM(0, regfield, ModRm_UseSib); + SibSB(info.Scale, info.Index.Id, ModRm_UseDisp32); + xWrite(info.Displacement); + return; + } else { + if (info.Base == ebp && displacement_size == 0) + displacement_size = 1; // forces [ebp] to be encoded as [ebp+0]! - ModRM( displacement_size, regfield, ModRm_UseSib ); - SibSB( info.Scale, info.Index.Id, info.Base.Id ); - } - } + ModRM(displacement_size, regfield, ModRm_UseSib); + SibSB(info.Scale, info.Index.Id, info.Base.Id); + } + } - if( displacement_size != 0 ) - { - if( displacement_size == 1 ) - xWrite( info.Displacement ); - else - xWrite( info.Displacement ); - } + if (displacement_size != 0) { + if (displacement_size == 1) + xWrite(info.Displacement); + else + xWrite(info.Displacement); + } } // Writes a ModRM byte for "Direct" register access forms, which is used for all // instructions taking a form of [reg,reg]. -void EmitSibMagic( uint reg1, const xRegisterBase& reg2 ) +void EmitSibMagic(uint reg1, const xRegisterBase ®2) { - xWrite8( (Mod_Direct << 6) | (reg1 << 3) | reg2.Id ); + xWrite8((Mod_Direct << 6) | (reg1 << 3) | reg2.Id); } -void EmitSibMagic( const xRegisterBase& reg1, const xRegisterBase& reg2 ) +void EmitSibMagic(const xRegisterBase ®1, const xRegisterBase ®2) { - xWrite8( (Mod_Direct << 6) | (reg1.Id << 3) | reg2.Id ); + xWrite8((Mod_Direct << 6) | (reg1.Id << 3) | reg2.Id); } -void EmitSibMagic( const xRegisterBase& reg1, const void* src ) +void EmitSibMagic(const xRegisterBase ®1, const void *src) { - EmitSibMagic( reg1.Id, src ); + EmitSibMagic(reg1.Id, src); } -void EmitSibMagic( const xRegisterBase& reg1, const xIndirectVoid& sib ) +void EmitSibMagic(const xRegisterBase ®1, const xIndirectVoid &sib) { - EmitSibMagic( reg1.Id, sib ); + EmitSibMagic(reg1.Id, sib); } ////////////////////////////////////////////////////////////////////////////////////////// __emitinline static void EmitRex(bool w, bool r, bool x, bool b) { #ifdef __x86_64__ - u8 rex = 0x40 | (w << 3) | (r << 2) | (x << 1) | b; - if (rex != 0x40) - xWrite8(rex); + u8 rex = 0x40 | (w << 3) | (r << 2) | (x << 1) | b; + if (rex != 0x40) + xWrite8(rex); #endif } -void EmitRex( uint regfield, const void* address ) +void EmitRex(uint regfield, const void *address) { - pxAssert(0); - bool w = false; - bool r = false; - bool x = false; - bool b = false; - EmitRex(w, r, x, b); + pxAssert(0); + bool w = false; + bool r = false; + bool x = false; + bool b = false; + EmitRex(w, r, x, b); } -void EmitRex( uint regfield, const xIndirectVoid& info ) +void EmitRex(uint regfield, const xIndirectVoid &info) { - bool w = info.Base.IsWide(); - bool r = false; - bool x = false; - bool b = info.IsExtended(); - EmitRex(w, r, x, b); + bool w = info.Base.IsWide(); + bool r = false; + bool x = false; + bool b = info.IsExtended(); + EmitRex(w, r, x, b); } -void EmitRex( uint reg1, const xRegisterBase& reg2 ) +void EmitRex(uint reg1, const xRegisterBase ®2) { - bool w = reg2.IsWide(); - bool r = false; - bool x = false; - bool b = reg2.IsExtended(); - EmitRex(w, r, x, b); + bool w = reg2.IsWide(); + bool r = false; + bool x = false; + bool b = reg2.IsExtended(); + EmitRex(w, r, x, b); } -void EmitRex( const xRegisterBase& reg1, const xRegisterBase& reg2 ) +void EmitRex(const xRegisterBase ®1, const xRegisterBase ®2) { - bool w = reg1.IsWide(); - bool r = reg1.IsExtended(); - bool x = false; - bool b = reg2.IsExtended(); - EmitRex(w, r, x, b); + bool w = reg1.IsWide(); + bool r = reg1.IsExtended(); + bool x = false; + bool b = reg2.IsExtended(); + EmitRex(w, r, x, b); } -void EmitRex( const xRegisterBase& reg1, const void* src ) +void EmitRex(const xRegisterBase ®1, const void *src) { - pxAssert(0); //see fixme - bool w = reg1.IsWide(); - bool r = reg1.IsExtended(); - bool x = false; - bool b = false; // FIXME src.IsExtended(); - EmitRex(w, r, x, b); + pxAssert(0); //see fixme + bool w = reg1.IsWide(); + bool r = reg1.IsExtended(); + bool x = false; + bool b = false; // FIXME src.IsExtended(); + EmitRex(w, r, x, b); } -void EmitRex( const xRegisterBase& reg1, const xIndirectVoid& sib ) +void EmitRex(const xRegisterBase ®1, const xIndirectVoid &sib) { - bool w = reg1.IsWide(); - bool r = reg1.IsExtended(); - bool x = sib.Index.IsExtended(); - bool b = sib.Base.IsExtended(); - EmitRex(w, r, x, b); + bool w = reg1.IsWide(); + bool r = reg1.IsExtended(); + bool x = sib.Index.IsExtended(); + bool b = sib.Base.IsExtended(); + EmitRex(w, r, x, b); } @@ -443,23 +443,23 @@ void EmitRex( const xRegisterBase& reg1, const xIndirectVoid& sib ) // Assigns the current emitter buffer target address. // This is provided instead of using x86Ptr directly, since we may in the future find // a need to change the storage class system for the x86Ptr 'under the hood.' -__emitinline void xSetPtr( void* ptr ) +__emitinline void xSetPtr(void *ptr) { - x86Ptr = (u8*)ptr; + x86Ptr = (u8 *)ptr; } // Retrieves the current emitter buffer target address. // This is provided instead of using x86Ptr directly, since we may in the future find // a need to change the storage class system for the x86Ptr 'under the hood.' -__emitinline u8* xGetPtr() +__emitinline u8 *xGetPtr() { - return x86Ptr; + return x86Ptr; } -__emitinline void xAlignPtr( uint bytes ) +__emitinline void xAlignPtr(uint bytes) { - // forward align - x86Ptr = (u8*)( ( (uptr)x86Ptr + bytes - 1) & ~(bytes - 1) ); + // forward align + x86Ptr = (u8 *)(((uptr)x86Ptr + bytes - 1) & ~(bytes - 1)); } // Performs best-case alignment for the target CPU, for use prior to starting a new @@ -468,81 +468,78 @@ __emitinline void xAlignPtr( uint bytes ) // a loss). __emitinline void xAlignCallTarget() { - // Core2/i7 CPUs prefer unaligned addresses. Checking for SSSE3 is a decent filter. - // (also align in debug modes for disasm convenience) + // Core2/i7 CPUs prefer unaligned addresses. Checking for SSSE3 is a decent filter. + // (also align in debug modes for disasm convenience) - if( IsDebugBuild || !x86caps.hasSupplementalStreamingSIMD3Extensions ) - { - // - P4's and earlier prefer 16 byte alignment. - // - AMD Athlons and Phenoms prefer 8 byte alignment, but I don't have an easy - // heuristic for it yet. - // - AMD Phenom IIs are unknown (either prefer 8 byte, or unaligned). + if (IsDebugBuild || !x86caps.hasSupplementalStreamingSIMD3Extensions) { + // - P4's and earlier prefer 16 byte alignment. + // - AMD Athlons and Phenoms prefer 8 byte alignment, but I don't have an easy + // heuristic for it yet. + // - AMD Phenom IIs are unknown (either prefer 8 byte, or unaligned). - xAlignPtr( 16 ); - } + xAlignPtr(16); + } } -__emitinline u8* xGetAlignedCallTarget() +__emitinline u8 *xGetAlignedCallTarget() { - xAlignCallTarget(); - return x86Ptr; + xAlignCallTarget(); + return x86Ptr; } -__emitinline void xAdvancePtr( uint bytes ) +__emitinline void xAdvancePtr(uint bytes) { - if( IsDevBuild ) - { - // common debugger courtesy: advance with INT3 as filler. - for( uint i=0; i( src.Displacement ); - else - xWrite( src.Displacement ); - } + if (displacement_size != 0) { + if (displacement_size == 1) + xWrite(src.Displacement); + else + xWrite(src.Displacement); + } } -__emitinline void xLEA( xRegister64 to, const xIndirectVoid& src, bool preserve_flags ) +__emitinline void xLEA(xRegister64 to, const xIndirectVoid &src, bool preserve_flags) { - EmitLeaMagic( to, src, preserve_flags ); + EmitLeaMagic(to, src, preserve_flags); } -__emitinline void xLEA( xRegister32 to, const xIndirectVoid& src, bool preserve_flags ) +__emitinline void xLEA(xRegister32 to, const xIndirectVoid &src, bool preserve_flags) { - EmitLeaMagic( to, src, preserve_flags ); + EmitLeaMagic(to, src, preserve_flags); } -__emitinline void xLEA( xRegister16 to, const xIndirectVoid& src, bool preserve_flags ) +__emitinline void xLEA(xRegister16 to, const xIndirectVoid &src, bool preserve_flags) { - xWrite8( 0x66 ); - EmitLeaMagic( to, src, preserve_flags ); + xWrite8(0x66); + EmitLeaMagic(to, src, preserve_flags); } // ===================================================================================================== // TEST / INC / DEC // ===================================================================================================== -void xImpl_Test::operator()( const xRegisterInt& to, const xRegisterInt& from ) const +void xImpl_Test::operator()(const xRegisterInt &to, const xRegisterInt &from) const { - pxAssert( to.GetOperandSize() == from.GetOperandSize() ); - xOpWrite( to.GetPrefix16(), to.Is8BitOp() ? 0x84 : 0x85, from, to ); + pxAssert(to.GetOperandSize() == from.GetOperandSize()); + xOpWrite(to.GetPrefix16(), to.Is8BitOp() ? 0x84 : 0x85, from, to); } -void xImpl_Test::operator()( const xIndirect64orLess& dest, int imm ) const +void xImpl_Test::operator()(const xIndirect64orLess &dest, int imm) const { - xOpWrite( dest.GetPrefix16(), dest.Is8BitOp() ? 0xf6 : 0xf7, 0, dest ); - dest.xWriteImm( imm ); + xOpWrite(dest.GetPrefix16(), dest.Is8BitOp() ? 0xf6 : 0xf7, 0, dest); + dest.xWriteImm(imm); } -void xImpl_Test::operator()( const xRegisterInt& to, int imm ) const +void xImpl_Test::operator()(const xRegisterInt &to, int imm) const { - if( to.IsAccumulator() ) { - xOpAccWrite( to.GetPrefix16(), to.Is8BitOp() ? 0xa8 : 0xa9, 0, to ); - } else { - xOpWrite( to.GetPrefix16(), to.Is8BitOp() ? 0xf6 : 0xf7, 0, to ); - } - to.xWriteImm( imm ); + if (to.IsAccumulator()) { + xOpAccWrite(to.GetPrefix16(), to.Is8BitOp() ? 0xa8 : 0xa9, 0, to); + } else { + xOpWrite(to.GetPrefix16(), to.Is8BitOp() ? 0xf6 : 0xf7, 0, to); + } + to.xWriteImm(imm); } -void xImpl_BitScan::operator()( const xRegister16or32or64& to, const xRegister16or32or64& from ) const { - pxAssert( to->GetOperandSize() == from->GetOperandSize() ); - xOpWrite0F( from->GetPrefix16(), Opcode, to, from ); -} -void xImpl_BitScan::operator()( const xRegister16or32or64& to, const xIndirectVoid& sibsrc ) const +void xImpl_BitScan::operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from) const { - xOpWrite0F( to->GetPrefix16(), Opcode, to, sibsrc ); + pxAssert(to->GetOperandSize() == from->GetOperandSize()); + xOpWrite0F(from->GetPrefix16(), Opcode, to, from); +} +void xImpl_BitScan::operator()(const xRegister16or32or64 &to, const xIndirectVoid &sibsrc) const +{ + xOpWrite0F(to->GetPrefix16(), Opcode, to, sibsrc); } -void xImpl_IncDec::operator()( const xRegisterInt& to ) const +void xImpl_IncDec::operator()(const xRegisterInt &to) const { - if( to.Is8BitOp() ) - { - u8 regfield = isDec ? 1 : 0; - xOpWrite( to.GetPrefix16(), 0xfe, regfield, to); - } - else - { + if (to.Is8BitOp()) { + u8 regfield = isDec ? 1 : 0; + xOpWrite(to.GetPrefix16(), 0xfe, regfield, to); + } else { #ifdef __x86_64__ - pxAssertMsg(0, "Single Byte INC/DEC aren't valid in 64 bits." - "You need to use the ModR/M form (FF/0 FF/1 opcodes)"); + pxAssertMsg(0, "Single Byte INC/DEC aren't valid in 64 bits." + "You need to use the ModR/M form (FF/0 FF/1 opcodes)"); #endif - to.prefix16(); - xWrite8( (isDec ? 0x48 : 0x40) | to.Id ); - } + to.prefix16(); + xWrite8((isDec ? 0x48 : 0x40) | to.Id); + } } -void xImpl_IncDec::operator()( const xIndirect64orLess& to ) const +void xImpl_IncDec::operator()(const xIndirect64orLess &to) const { - to.prefix16(); - xWrite8( to.Is8BitOp() ? 0xfe : 0xff ); - EmitSibMagic( isDec ? 1 : 0, to ); + to.prefix16(); + xWrite8(to.Is8BitOp() ? 0xfe : 0xff); + EmitSibMagic(isDec ? 1 : 0, to); } -void xImpl_DwordShift::operator()( const xRegister16or32or64& to, const xRegister16or32or64& from, const xRegisterCL& /* clreg */ ) const { - pxAssert( to->GetOperandSize() == from->GetOperandSize() ); - xOpWrite0F( from->GetPrefix16(), OpcodeBase+1, to, from ); -} - -void xImpl_DwordShift::operator()( const xRegister16or32or64& to, const xRegister16or32or64& from, u8 shiftcnt ) const +void xImpl_DwordShift::operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from, const xRegisterCL & /* clreg */) const { - pxAssert( to->GetOperandSize() == from->GetOperandSize() ); - if( shiftcnt != 0 ) - xOpWrite0F( from->GetPrefix16(), OpcodeBase, to, from, shiftcnt ); + pxAssert(to->GetOperandSize() == from->GetOperandSize()); + xOpWrite0F(from->GetPrefix16(), OpcodeBase + 1, to, from); } -void xImpl_DwordShift::operator()( const xIndirectVoid& dest, const xRegister16or32or64& from, const xRegisterCL& /* clreg */ ) const +void xImpl_DwordShift::operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from, u8 shiftcnt) const { - xOpWrite0F( from->GetPrefix16(), OpcodeBase + 1, from, dest ); + pxAssert(to->GetOperandSize() == from->GetOperandSize()); + if (shiftcnt != 0) + xOpWrite0F(from->GetPrefix16(), OpcodeBase, to, from, shiftcnt); } -void xImpl_DwordShift::operator()( const xIndirectVoid& dest, const xRegister16or32or64& from, u8 shiftcnt ) const +void xImpl_DwordShift::operator()(const xIndirectVoid &dest, const xRegister16or32or64 &from, const xRegisterCL & /* clreg */) const { - if( shiftcnt != 0 ) - xOpWrite0F( from->GetPrefix16(), OpcodeBase, from, dest, shiftcnt ); + xOpWrite0F(from->GetPrefix16(), OpcodeBase + 1, from, dest); } -const xImpl_Test xTEST = { }; +void xImpl_DwordShift::operator()(const xIndirectVoid &dest, const xRegister16or32or64 &from, u8 shiftcnt) const +{ + if (shiftcnt != 0) + xOpWrite0F(from->GetPrefix16(), OpcodeBase, from, dest, shiftcnt); +} -const xImpl_BitScan xBSF = { 0xbc }; -const xImpl_BitScan xBSR = { 0xbd }; +const xImpl_Test xTEST = {}; -const xImpl_IncDec xINC = { false }; -const xImpl_IncDec xDEC = { true }; +const xImpl_BitScan xBSF = {0xbc}; +const xImpl_BitScan xBSR = {0xbd}; -const xImpl_DwordShift xSHLD = { 0xa4 }; -const xImpl_DwordShift xSHRD = { 0xac }; +const xImpl_IncDec xINC = {false}; +const xImpl_IncDec xDEC = {true}; + +const xImpl_DwordShift xSHLD = {0xa4}; +const xImpl_DwordShift xSHRD = {0xac}; ////////////////////////////////////////////////////////////////////////////////////////// // Push / Pop Emitters @@ -1006,77 +975,80 @@ const xImpl_DwordShift xSHRD = { 0xac }; // Note: pushad/popad implementations are intentionally left out. The instructions are // invalid in x64, and are super slow on x32. Use multiple Push/Pop instructions instead. -__emitinline void xPOP( const xIndirectVoid& from ) +__emitinline void xPOP(const xIndirectVoid &from) { - xWrite8( 0x8f ); - EmitSibMagic( 0, from ); + xWrite8(0x8f); + EmitSibMagic(0, from); } -__emitinline void xPUSH( const xIndirectVoid& from ) +__emitinline void xPUSH(const xIndirectVoid &from) { - xWrite8( 0xff ); - EmitSibMagic( 6, from ); + xWrite8(0xff); + EmitSibMagic(6, from); } -__fi void xPOP( xRegister32or64 from ) { xWrite8( 0x58 | from->Id ); } +__fi void xPOP(xRegister32or64 from) { xWrite8(0x58 | from->Id); } -__fi void xPUSH( u32 imm ) { xWrite8( 0x68 ); xWrite32( imm ); } -__fi void xPUSH( xRegister32or64 from ) { xWrite8( 0x50 | from->Id ); } +__fi void xPUSH(u32 imm) +{ + xWrite8(0x68); + xWrite32(imm); +} +__fi void xPUSH(xRegister32or64 from) { xWrite8(0x50 | from->Id); } // pushes the EFLAGS register onto the stack -__fi void xPUSHFD() { xWrite8( 0x9C ); } +__fi void xPUSHFD() { xWrite8(0x9C); } // pops the EFLAGS register from the stack -__fi void xPOPFD() { xWrite8( 0x9D ); } +__fi void xPOPFD() { xWrite8(0x9D); } ////////////////////////////////////////////////////////////////////////////////////////// // -__fi void xLEAVE() { xWrite8( 0xC9 ); } -__fi void xRET() { xWrite8( 0xC3 ); } -__fi void xCBW() { xWrite16( 0x9866 ); } -__fi void xCWD() { xWrite8( 0x98 ); } -__fi void xCDQ() { xWrite8( 0x99 ); } -__fi void xCWDE() { xWrite8( 0x98 ); } +__fi void xLEAVE() { xWrite8(0xC9); } +__fi void xRET() { xWrite8(0xC3); } +__fi void xCBW() { xWrite16(0x9866); } +__fi void xCWD() { xWrite8(0x98); } +__fi void xCDQ() { xWrite8(0x99); } +__fi void xCWDE() { xWrite8(0x98); } -__fi void xLAHF() { xWrite8( 0x9f ); } -__fi void xSAHF() { xWrite8( 0x9e ); } +__fi void xLAHF() { xWrite8(0x9f); } +__fi void xSAHF() { xWrite8(0x9e); } -__fi void xSTC() { xWrite8( 0xF9 ); } -__fi void xCLC() { xWrite8( 0xF8 ); } +__fi void xSTC() { xWrite8(0xF9); } +__fi void xCLC() { xWrite8(0xF8); } // NOP 1-byte -__fi void xNOP() { xWrite8(0x90); } +__fi void xNOP() { xWrite8(0x90); } -__fi void xINT( u8 imm ) +__fi void xINT(u8 imm) { - if (imm == 3) - xWrite8(0xcc); - else - { - xWrite8(0xcd); - xWrite8(imm); - } + if (imm == 3) + xWrite8(0xcc); + else { + xWrite8(0xcd); + xWrite8(imm); + } } -__fi void xINTO() { xWrite8(0xce); } +__fi void xINTO() { xWrite8(0xce); } -__emitinline void xBSWAP( const xRegister32or64& to ) +__emitinline void xBSWAP(const xRegister32or64 &to) { - xWrite8( 0x0F ); - xWrite8( 0xC8 | to->Id ); + xWrite8(0x0F); + xWrite8(0xC8 | to->Id); } -static __aligned16 u64 xmm_data[iREGCNT_XMM*2]; +static __aligned16 u64 xmm_data[iREGCNT_XMM * 2]; -__emitinline void xStoreReg( const xRegisterSSE& src ) +__emitinline void xStoreReg(const xRegisterSSE &src) { - xMOVDQA( ptr[&xmm_data[src.Id*2]], src ); + xMOVDQA(ptr[&xmm_data[src.Id * 2]], src); } -__emitinline void xRestoreReg( const xRegisterSSE& dest ) +__emitinline void xRestoreReg(const xRegisterSSE &dest) { - xMOVDQA( dest, ptr[&xmm_data[dest.Id*2]] ); + xMOVDQA(dest, ptr[&xmm_data[dest.Id * 2]]); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1101,91 +1073,91 @@ __emitinline void xRestoreReg( const xRegisterSSE& dest ) xScopedStackFrame::xScopedStackFrame(bool base_frame, bool save_base_pointer, int offset) { - m_base_frame = base_frame; - m_save_base_pointer = save_base_pointer; - m_offset = offset; + m_base_frame = base_frame; + m_save_base_pointer = save_base_pointer; + m_offset = offset; #ifdef __x86_64__ - m_offset += 8; // Call stores the return address (4 bytes) + m_offset += 8; // Call stores the return address (4 bytes) - // Note rbp can surely be optimized in 64 bits - if (m_base_frame) { - xPUSH( rbp ); - xMOV( rbp, rsp ); - m_offset += 8; - } else if (m_save_base_pointer) { - xPUSH( rbp ); - m_offset += 8; - } + // Note rbp can surely be optimized in 64 bits + if (m_base_frame) { + xPUSH(rbp); + xMOV(rbp, rsp); + m_offset += 8; + } else if (m_save_base_pointer) { + xPUSH(rbp); + m_offset += 8; + } - xPUSH( rbx ); - xPUSH( r12 ); - xPUSH( r13 ); - xPUSH( r14 ); - xPUSH( r15 ); - m_offset += 40; + xPUSH(rbx); + xPUSH(r12); + xPUSH(r13); + xPUSH(r14); + xPUSH(r15); + m_offset += 40; #else - m_offset += 4; // Call stores the return address (4 bytes) + m_offset += 4; // Call stores the return address (4 bytes) - // Create a new frame - if (m_base_frame) { - xPUSH( ebp ); - xMOV( ebp, esp ); - m_offset += 4; - } else if (m_save_base_pointer) { - xPUSH( ebp ); - m_offset += 4; - } + // Create a new frame + if (m_base_frame) { + xPUSH(ebp); + xMOV(ebp, esp); + m_offset += 4; + } else if (m_save_base_pointer) { + xPUSH(ebp); + m_offset += 4; + } - // Save the register context - xPUSH( edi ); - xPUSH( esi ); - xPUSH( ebx ); - m_offset += 12; + // Save the register context + xPUSH(edi); + xPUSH(esi); + xPUSH(ebx); + m_offset += 12; #endif - ALIGN_STACK(-(16 - m_offset % 16)); + ALIGN_STACK(-(16 - m_offset % 16)); } xScopedStackFrame::~xScopedStackFrame() { - ALIGN_STACK(16 - m_offset % 16); + ALIGN_STACK(16 - m_offset % 16); #ifdef __x86_64__ - // Restore the register context - xPOP( r15 ); - xPOP( r14 ); - xPOP( r13 ); - xPOP( r12 ); - xPOP( rbx ); + // Restore the register context + xPOP(r15); + xPOP(r14); + xPOP(r13); + xPOP(r12); + xPOP(rbx); - // Destroy the frame - if (m_base_frame) { - xLEAVE(); - } else if (m_save_base_pointer) { - xPOP( rbp ); - } + // Destroy the frame + if (m_base_frame) { + xLEAVE(); + } else if (m_save_base_pointer) { + xPOP(rbp); + } #else - // Restore the register context - xPOP( ebx ); - xPOP( esi ); - xPOP( edi ); + // Restore the register context + xPOP(ebx); + xPOP(esi); + xPOP(edi); - // Destroy the frame - if (m_base_frame) { - xLEAVE(); - } else if (m_save_base_pointer) { - xPOP( ebp ); - } + // Destroy the frame + if (m_base_frame) { + xLEAVE(); + } else if (m_save_base_pointer) { + xPOP(ebp); + } #endif } -} // End namespace x86Emitter +} // End namespace x86Emitter diff --git a/linux_various/check_format.sh b/linux_various/check_format.sh index f32cf1e3d6..1c5ebf5fbd 100755 --- a/linux_various/check_format.sh +++ b/linux_various/check_format.sh @@ -45,7 +45,6 @@ fi # get updates and blacklist directories that don't use yet the clang-format syntax files=`git diff --name-only --diff-filter=ACMRT $diff_range -- $PWD | \ grep "\.\(c\|h\|inl\|cpp\|hpp\)$" | \ - grep -v "${1}common/" | \ grep -v "${1}pcsx2/" | \ grep -v "${1}plugins/CDVDisoEFP/" | \ grep -v "${1}plugins/CDVDlinuz/" | \ diff --git a/linux_various/pre-commit b/linux_various/pre-commit index ec15a85818..8564bdb137 100755 --- a/linux_various/pre-commit +++ b/linux_various/pre-commit @@ -28,7 +28,7 @@ PARSE_EXTS=true # file types to parse. Only effective when PARSE_EXTS is true. FILE_EXTS=".c .h .cpp .hpp .inl" -ALLOWED_ROOT_DIR="./plugins/USBnull ./plugins/SPU2null ./plugins/FWnull ./plugins/dev9null ./plugins/GSnull ./plugins/CDVDnull ./plugins/PadNull ./plugins/LilyPad/ ./plugins/onepad/ ./plugins/spu2-x/" +ALLOWED_ROOT_DIR="./plugins/USBnull ./plugins/SPU2null ./plugins/FWnull ./plugins/dev9null ./plugins/GSnull ./plugins/CDVDnull ./plugins/PadNull ./plugins/LilyPad/ ./plugins/onepad/ ./plugins/spu2-x/ ./common" ################################################################## # There should be no need to change anything below this line.