Merge pull request #1659 from PCSX2/greg/clang-format-common

reformat main common directory
This commit is contained in:
Gregory Hainaut 2016-11-14 11:37:53 +01:00 committed by GitHub
commit 259521ec3e
137 changed files with 15017 additions and 14373 deletions

View File

@ -71,12 +71,14 @@
#define KEYPRESS 1 #define KEYPRESS 1
#define KEYRELEASE 2 #define KEYRELEASE 2
typedef struct { typedef struct
{
int size; int size;
s8 *data; s8 *data;
} freezeData; } freezeData;
typedef struct _keyEvent { typedef struct _keyEvent
{
u32 key; u32 key;
u32 evt; u32 evt;
} keyEvent; } keyEvent;
@ -103,15 +105,15 @@ typedef struct _keyEvent {
#define PS2E_GS_VERSION 0x0006 #define PS2E_GS_VERSION 0x0006
#define PS2E_PAD_VERSION 0x0002 // -=[ OBSOLETE ]=- #define PS2E_PAD_VERSION 0x0002 // -=[ OBSOLETE ]=-
#ifdef ENABLE_NEW_IOPDMA_SPU2 #ifdef ENABLE_NEW_IOPDMA_SPU2
# define PS2E_SPU2_VERSION 0x0006 #define PS2E_SPU2_VERSION 0x0006
#else #else
# define PS2E_SPU2_VERSION 0x0005 #define PS2E_SPU2_VERSION 0x0005
#endif #endif
#define PS2E_CDVD_VERSION 0x0005 #define PS2E_CDVD_VERSION 0x0005
#ifdef ENABLE_NEW_IOPDMA_DEV9 #ifdef ENABLE_NEW_IOPDMA_DEV9
# define PS2E_DEV9_VERSION 0x0004 #define PS2E_DEV9_VERSION 0x0004
#else #else
# define PS2E_DEV9_VERSION 0x0003 #define PS2E_DEV9_VERSION 0x0003
#endif #endif
#define PS2E_USB_VERSION 0x0003 #define PS2E_USB_VERSION 0x0003
#define PS2E_FW_VERSION 0x0002 #define PS2E_FW_VERSION 0x0002
@ -124,7 +126,7 @@ extern "C" {
u32 CALLBACK PS2EgetLibType(void); u32 CALLBACK PS2EgetLibType(void);
u32 CALLBACK PS2EgetLibVersion2(u32 type); u32 CALLBACK PS2EgetLibVersion2(u32 type);
char* CALLBACK PS2EgetLibName(void); char *CALLBACK PS2EgetLibName(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -139,7 +141,7 @@ char* CALLBACK PS2EgetLibName(void);
*/ */
// for 64bit compilers // for 64bit compilers
typedef char __keyEvent_Size__[(sizeof(keyEvent) == 8)?1:-1]; typedef char __keyEvent_Size__[(sizeof(keyEvent) == 8) ? 1 : -1];
// plugin types // plugin types
#define SIO_TYPE_PAD 0x00000001 #define SIO_TYPE_PAD 0x00000001
@ -147,11 +149,12 @@ typedef char __keyEvent_Size__[(sizeof(keyEvent) == 8)?1:-1];
#define SIO_TYPE_RM 0x00000040 #define SIO_TYPE_RM 0x00000040
#define SIO_TYPE_MC 0x00000100 #define SIO_TYPE_MC 0x00000100
typedef int (CALLBACK * SIOchangeSlotCB)(int slot); typedef int(CALLBACK *SIOchangeSlotCB)(int slot);
typedef struct _cdvdSubQ { typedef struct _cdvdSubQ
u8 ctrl:4; // control and mode bits {
u8 mode:4; // control and mode bits u8 ctrl : 4; // control and mode bits
u8 mode : 4; // control and mode bits
u8 trackNum; // current track number (1 to 99) u8 trackNum; // current track number (1 to 99)
u8 trackIndex; // current index within track (0 to 99) u8 trackIndex; // current index within track (0 to 99)
u8 trackM; // current minute location on the disc (BCD encoded) u8 trackM; // current minute location on the disc (BCD encoded)
@ -163,12 +166,14 @@ typedef struct _cdvdSubQ {
u8 discF; // current frame offset from first track (BCD encoded) u8 discF; // current frame offset from first track (BCD encoded)
} cdvdSubQ; } cdvdSubQ;
typedef struct _cdvdTD { // NOT bcd coded typedef struct _cdvdTD
{ // NOT bcd coded
u32 lsn; u32 lsn;
u8 type; u8 type;
} cdvdTD; } cdvdTD;
typedef struct _cdvdTN { typedef struct _cdvdTN
{
u8 strack; //number of the first track (usually 1) u8 strack; //number of the first track (usually 1)
u8 etrack; //number of the last track u8 etrack; //number of the last track
} cdvdTN; } cdvdTN;
@ -215,7 +220,8 @@ typedef int (*DEV9handler)(void);
typedef void (*USBcallback)(int cycles); typedef void (*USBcallback)(int cycles);
typedef int (*USBhandler)(void); typedef int (*USBhandler)(void);
typedef struct _GSdriverInfo { typedef struct _GSdriverInfo
{
char name[8]; char name[8];
void *common; void *common;
} GSdriverInfo; } GSdriverInfo;
@ -236,15 +242,15 @@ s32 CALLBACK GSinit();
s32 CALLBACK GSopen(void *pDsp, const char *Title, int multithread); s32 CALLBACK GSopen(void *pDsp, const char *Title, int multithread);
void CALLBACK GSclose(); void CALLBACK GSclose();
void CALLBACK GSshutdown(); void CALLBACK GSshutdown();
void CALLBACK GSsetSettingsDir( const char* dir ); void CALLBACK GSsetSettingsDir(const char *dir);
void CALLBACK GSsetLogDir( const char* dir ); void CALLBACK GSsetLogDir(const char *dir);
void CALLBACK GSvsync(int field); void CALLBACK GSvsync(int field);
void CALLBACK GSgifTransfer(const u32 *pMem, u32 addr); void CALLBACK GSgifTransfer(const u32 *pMem, u32 addr);
void CALLBACK GSgifTransfer1(u32 *pMem, u32 addr); void CALLBACK GSgifTransfer1(u32 *pMem, u32 addr);
void CALLBACK GSgifTransfer2(u32 *pMem, u32 size); void CALLBACK GSgifTransfer2(u32 *pMem, u32 size);
void CALLBACK GSgifTransfer3(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 GSgifSoftReset(u32 mask);
void CALLBACK GSreadFIFO(u64 *mem); void CALLBACK GSreadFIFO(u64 *mem);
void CALLBACK GSinitReadFIFO(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 // GSkeyEvent gets called when there is a keyEvent from the PAD plugin
void CALLBACK GSkeyEvent(keyEvent *ev); 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 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 GSirqCallback(void (*callback)());
void CALLBACK GSprintf(int timeout, char *fmt, ...); void CALLBACK GSprintf(int timeout, char *fmt, ...);
void CALLBACK GSsetBaseMem(void*); void CALLBACK GSsetBaseMem(void *);
void CALLBACK GSsetGameCRC(int crc, int gameoptions); 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 // controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done
@ -269,12 +275,12 @@ void CALLBACK GSsetFrameSkip(int frameskip);
// if start is 1, starts recording spu2 data, else stops // if start is 1, starts recording spu2 data, else stops
// returns a non zero value if successful // returns a non zero value if successful
// for now, pData is not used // for now, pData is not used
int CALLBACK GSsetupRecording(int start, void* pData); int CALLBACK GSsetupRecording(int start, void *pData);
void CALLBACK GSreset(); void CALLBACK GSreset();
//deprecated: GSgetTitleInfo was used in PCSX2 but no plugin supported it prior to r4070: //deprecated: GSgetTitleInfo was used in PCSX2 but no plugin supported it prior to r4070:
//void CALLBACK GSgetTitleInfo( char dest[128] ); //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); void CALLBACK GSwriteCSR(u32 value);
s32 CALLBACK GSfreeze(int mode, freezeData *data); s32 CALLBACK GSfreeze(int mode, freezeData *data);
void CALLBACK GSconfigure(); void CALLBACK GSconfigure();
@ -295,11 +301,11 @@ s32 CALLBACK PADinit(u32 flags);
s32 CALLBACK PADopen(void *pDsp); s32 CALLBACK PADopen(void *pDsp);
void CALLBACK PADclose(); void CALLBACK PADclose();
void CALLBACK PADshutdown(); void CALLBACK PADshutdown();
void CALLBACK PADsetSettingsDir( const char* dir ); void CALLBACK PADsetSettingsDir(const char *dir);
void CALLBACK PADsetLogDir( const char* dir ); void CALLBACK PADsetLogDir(const char *dir);
// PADkeyEvent is called every vsync (return NULL if no event) // PADkeyEvent is called every vsync (return NULL if no event)
keyEvent* CALLBACK PADkeyEvent(); keyEvent *CALLBACK PADkeyEvent();
u8 CALLBACK PADstartPoll(int pad); u8 CALLBACK PADstartPoll(int pad);
u8 CALLBACK PADpoll(u8 value); u8 CALLBACK PADpoll(u8 value);
// returns: 1 if supported pad1 // returns: 1 if supported pad1
@ -342,16 +348,16 @@ s32 CALLBACK SPU2init();
s32 CALLBACK SPU2open(void *pDsp); s32 CALLBACK SPU2open(void *pDsp);
void CALLBACK SPU2close(); void CALLBACK SPU2close();
void CALLBACK SPU2shutdown(); void CALLBACK SPU2shutdown();
void CALLBACK SPU2setSettingsDir( const char* dir ); void CALLBACK SPU2setSettingsDir(const char *dir);
void CALLBACK SPU2setLogDir( const char* dir ); void CALLBACK SPU2setLogDir(const char *dir);
void CALLBACK SPU2reset(); void CALLBACK SPU2reset();
void CALLBACK SPU2write(u32 mem, u16 value); void CALLBACK SPU2write(u32 mem, u16 value);
u16 CALLBACK SPU2read(u32 mem); u16 CALLBACK SPU2read(u32 mem);
#ifdef ENABLE_NEW_IOPDMA_SPU2 #ifdef ENABLE_NEW_IOPDMA_SPU2
s32 CALLBACK SPU2dmaRead(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); s32 CALLBACK SPU2dmaWrite(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed);
void CALLBACK SPU2dmaInterrupt(s32 channel); void CALLBACK SPU2dmaInterrupt(s32 channel);
// dma irq callbacks not needed anymore, they are handled by the dmac // 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 SPU2readDMA4Mem(u16 *pMem, int size);
void CALLBACK SPU2writeDMA4Mem(u16 *pMem, int size); void CALLBACK SPU2writeDMA4Mem(u16 *pMem, int size);
void CALLBACK SPU2interruptDMA4(); void CALLBACK SPU2interruptDMA4();
void CALLBACK SPU2readDMA7Mem(u16* pMem, int size); void CALLBACK SPU2readDMA7Mem(u16 *pMem, int size);
void CALLBACK SPU2writeDMA7Mem(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 // all addresses passed by dma will be pointers to the array starting at baseaddr
@ -370,18 +376,18 @@ void CALLBACK SPU2setDMABaseAddr(uptr baseaddr);
void CALLBACK SPU2interruptDMA7(); void CALLBACK SPU2interruptDMA7();
u32 CALLBACK SPU2ReadMemAddr(int core); 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 #endif
// extended funcs // extended funcs
// if start is 1, starts recording spu2 data, else stops // if start is 1, starts recording spu2 data, else stops
// returns a non zero value if successful // returns a non zero value if successful
// for now, pData is not used // 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 SPU2setTimeStretcher(short int enable);
void CALLBACK SPU2async(u32 cycles); void CALLBACK SPU2async(u32 cycles);
@ -401,21 +407,21 @@ s32 CALLBACK SPU2test();
// basic funcs // basic funcs
s32 CALLBACK CDVDinit(); s32 CALLBACK CDVDinit();
s32 CALLBACK CDVDopen(const char* pTitleFilename); s32 CALLBACK CDVDopen(const char *pTitleFilename);
void CALLBACK CDVDclose(); void CALLBACK CDVDclose();
void CALLBACK CDVDshutdown(); void CALLBACK CDVDshutdown();
void CALLBACK CDVDsetSettingsDir( const char* dir ); void CALLBACK CDVDsetSettingsDir(const char *dir);
void CALLBACK CDVDsetLogDir( 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) // 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 CDVDreadSubQ(u32 lsn, cdvdSubQ *subq); //read subq from disc (only cds have subq data)
s32 CALLBACK CDVDgetTN(cdvdTN *Buffer); //disk information s32 CALLBACK CDVDgetTN(cdvdTN *Buffer); //disk information
s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type 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 CDVDgetTOC(void *toc); //gets ps2 style toc from disc
s32 CALLBACK CDVDgetDiskType(); //CDVD_TYPE_xxxx s32 CALLBACK CDVDgetDiskType(); //CDVD_TYPE_xxxx
s32 CALLBACK CDVDgetTrayStatus(); //CDVD_TRAY_xxxx s32 CALLBACK CDVDgetTrayStatus(); //CDVD_TRAY_xxxx
s32 CALLBACK CDVDctrlTrayOpen(); //open disc tray s32 CALLBACK CDVDctrlTrayOpen(); //open disc tray
@ -431,13 +437,13 @@ void CALLBACK CDVDnewDiskCB(void (*callback)());
// new funcs // new funcs
// read a track directly // read a track directly
s32 CALLBACK CDVDreadSector(u8* buffer, s32 lsn, int mode); s32 CALLBACK CDVDreadSector(u8 *buffer, s32 lsn, int mode);
// improved getBuffer // improved getBuffer
s32 CALLBACK CDVDgetBuffer2(u8* buffer); s32 CALLBACK CDVDgetBuffer2(u8 *buffer);
// tool function // tool function
s32 CALLBACK CDVDgetDualInfo(s32* dualType, u32* _layer1start); s32 CALLBACK CDVDgetDualInfo(s32 *dualType, u32 *_layer1start);
#endif #endif
@ -455,8 +461,8 @@ s32 CALLBACK DEV9init();
s32 CALLBACK DEV9open(void *pDsp); s32 CALLBACK DEV9open(void *pDsp);
void CALLBACK DEV9close(); void CALLBACK DEV9close();
void CALLBACK DEV9shutdown(); void CALLBACK DEV9shutdown();
void CALLBACK DEV9setSettingsDir( const char* dir ); void CALLBACK DEV9setSettingsDir(const char *dir);
void CALLBACK DEV9setLogDir( const char* dir ); void CALLBACK DEV9setLogDir(const char *dir);
u8 CALLBACK DEV9read8(u32 addr); u8 CALLBACK DEV9read8(u32 addr);
u16 CALLBACK DEV9read16(u32 addr); u16 CALLBACK DEV9read16(u32 addr);
@ -465,8 +471,8 @@ void CALLBACK DEV9write8(u32 addr, u8 value);
void CALLBACK DEV9write16(u32 addr, u16 value); void CALLBACK DEV9write16(u32 addr, u16 value);
void CALLBACK DEV9write32(u32 addr, u32 value); void CALLBACK DEV9write32(u32 addr, u32 value);
#ifdef ENABLE_NEW_IOPDMA_DEV9 #ifdef ENABLE_NEW_IOPDMA_DEV9
s32 CALLBACK DEV9dmaRead(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); s32 CALLBACK DEV9dmaWrite(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed);
void CALLBACK DEV9dmaInterrupt(s32 channel); void CALLBACK DEV9dmaInterrupt(s32 channel);
#else #else
void CALLBACK DEV9readDMA8Mem(u32 *pMem, int size); void CALLBACK DEV9readDMA8Mem(u32 *pMem, int size);
@ -498,8 +504,8 @@ s32 CALLBACK USBinit();
s32 CALLBACK USBopen(void *pDsp); s32 CALLBACK USBopen(void *pDsp);
void CALLBACK USBclose(); void CALLBACK USBclose();
void CALLBACK USBshutdown(); void CALLBACK USBshutdown();
void CALLBACK USBsetSettingsDir( const char* dir ); void CALLBACK USBsetSettingsDir(const char *dir);
void CALLBACK USBsetLogDir( const char* dir ); void CALLBACK USBsetLogDir(const char *dir);
u8 CALLBACK USBread8(u32 addr); u8 CALLBACK USBread8(u32 addr);
u16 CALLBACK USBread16(u32 addr); u16 CALLBACK USBread16(u32 addr);
@ -537,8 +543,8 @@ s32 CALLBACK FWinit();
s32 CALLBACK FWopen(void *pDsp); s32 CALLBACK FWopen(void *pDsp);
void CALLBACK FWclose(); void CALLBACK FWclose();
void CALLBACK FWshutdown(); void CALLBACK FWshutdown();
void CALLBACK FWsetSettingsDir( const char* dir ); void CALLBACK FWsetSettingsDir(const char *dir);
void CALLBACK FWsetLogDir( 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 FWwrite32(u32 addr, u32 value);
@ -555,168 +561,168 @@ s32 CALLBACK FWtest();
// might be useful for emulators // might be useful for emulators
#ifdef PLUGINtypedefs #ifdef PLUGINtypedefs
typedef u32 (CALLBACK* _PS2EgetLibType)(void); typedef u32(CALLBACK *_PS2EgetLibType)(void);
typedef u32 (CALLBACK* _PS2EgetLibVersion2)(u32 type); typedef u32(CALLBACK *_PS2EgetLibVersion2)(u32 type);
typedef char*(CALLBACK* _PS2EgetLibName)(void); 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 // GS
// NOTE: GSreadFIFOX/GSwriteCSR functions CANNOT use XMM/MMX regs // NOTE: GSreadFIFOX/GSwriteCSR functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones // 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 *_GSopen)(void *pDsp, const char *Title, int multithread);
typedef s32 (CALLBACK* _GSopen2)( void *pDsp, u32 flags ); typedef s32(CALLBACK *_GSopen2)(void *pDsp, u32 flags);
typedef void (CALLBACK* _GSvsync)(int field); typedef void(CALLBACK *_GSvsync)(int field);
typedef void (CALLBACK* _GSgifTransfer)(const u32 *pMem, u32 size); typedef void(CALLBACK *_GSgifTransfer)(const u32 *pMem, u32 size);
typedef void (CALLBACK* _GSgifTransfer1)(u32 *pMem, u32 addr); typedef void(CALLBACK *_GSgifTransfer1)(u32 *pMem, u32 addr);
typedef void (CALLBACK* _GSgifTransfer2)(u32 *pMem, u32 size); typedef void(CALLBACK *_GSgifTransfer2)(u32 *pMem, u32 size);
typedef void (CALLBACK* _GSgifTransfer3)(u32 *pMem, u32 size); typedef void(CALLBACK *_GSgifTransfer3)(u32 *pMem, u32 size);
typedef void (CALLBACK* _GSgifSoftReset)(u32 mask); typedef void(CALLBACK *_GSgifSoftReset)(u32 mask);
typedef void (CALLBACK* _GSreadFIFO)(u64 *pMem); typedef void(CALLBACK *_GSreadFIFO)(u64 *pMem);
typedef void (CALLBACK* _GSreadFIFO2)(u64 *pMem, int qwc); typedef void(CALLBACK *_GSreadFIFO2)(u64 *pMem, int qwc);
typedef void (CALLBACK* _GSinitReadFIFO)(u64 *pMem); typedef void(CALLBACK *_GSinitReadFIFO)(u64 *pMem);
typedef void (CALLBACK* _GSinitReadFIFO2)(u64 *pMem, int qwc); typedef void(CALLBACK *_GSinitReadFIFO2)(u64 *pMem, int qwc);
typedef void (CALLBACK* _GSchangeSaveState)(int, const char* filename); typedef void(CALLBACK *_GSchangeSaveState)(int, const char *filename);
typedef void (CALLBACK* _GSgetTitleInfo2)(char* dest, size_t length); typedef void(CALLBACK *_GSgetTitleInfo2)(char *dest, size_t length);
typedef void (CALLBACK* _GSirqCallback)(void (*callback)()); typedef void(CALLBACK *_GSirqCallback)(void (*callback)());
typedef void (CALLBACK* _GSprintf)(int timeout, char *fmt, ...); typedef void(CALLBACK *_GSprintf)(int timeout, char *fmt, ...);
typedef void (CALLBACK* _GSsetBaseMem)(void*); typedef void(CALLBACK *_GSsetBaseMem)(void *);
typedef void (CALLBACK* _GSsetGameCRC)(int, int); typedef void(CALLBACK *_GSsetGameCRC)(int, int);
typedef void (CALLBACK* _GSsetFrameSkip)(int frameskip); typedef void(CALLBACK *_GSsetFrameSkip)(int frameskip);
typedef void (CALLBACK* _GSsetFrameLimit)(int limit); typedef void(CALLBACK *_GSsetFrameLimit)(int limit);
typedef void (CALLBACK* _GSsetVsync)(int enabled); typedef void(CALLBACK *_GSsetVsync)(int enabled);
typedef void (CALLBACK* _GSsetExclusive)(int isExclusive); typedef void(CALLBACK *_GSsetExclusive)(int isExclusive);
typedef int (CALLBACK* _GSsetupRecording)(int, void*); typedef int(CALLBACK *_GSsetupRecording)(int, void *);
typedef void (CALLBACK* _GSreset)(); typedef void(CALLBACK *_GSreset)();
typedef void (CALLBACK* _GSwriteCSR)(u32 value); typedef void(CALLBACK *_GSwriteCSR)(u32 value);
typedef void (CALLBACK* _GSmakeSnapshot)(const char *path); typedef void(CALLBACK *_GSmakeSnapshot)(const char *path);
typedef void (CALLBACK* _GSmakeSnapshot2)(const char *path, int*, int); typedef void(CALLBACK *_GSmakeSnapshot2)(const char *path, int *, int);
// PAD // PAD
typedef s32 (CALLBACK* _PADinit)(u32 flags); typedef s32(CALLBACK *_PADinit)(u32 flags);
typedef s32 (CALLBACK* _PADopen)(void *pDsp); typedef s32(CALLBACK *_PADopen)(void *pDsp);
typedef u8 (CALLBACK* _PADstartPoll)(int pad); typedef u8(CALLBACK *_PADstartPoll)(int pad);
typedef u8 (CALLBACK* _PADpoll)(u8 value); typedef u8(CALLBACK *_PADpoll)(u8 value);
typedef u32 (CALLBACK* _PADquery)(int pad); typedef u32(CALLBACK *_PADquery)(int pad);
typedef void (CALLBACK* _PADupdate)(int pad); typedef void(CALLBACK *_PADupdate)(int pad);
typedef keyEvent* (CALLBACK* _PADkeyEvent)(); typedef keyEvent *(CALLBACK *_PADkeyEvent)();
typedef void (CALLBACK* _PADgsDriverInfo)(GSdriverInfo *info); typedef void(CALLBACK *_PADgsDriverInfo)(GSdriverInfo *info);
typedef s32 (CALLBACK* _PADsetSlot)(u8 port, u8 slot); typedef s32(CALLBACK *_PADsetSlot)(u8 port, u8 slot);
typedef s32 (CALLBACK* _PADqueryMtap)(u8 port); typedef s32(CALLBACK *_PADqueryMtap)(u8 port);
typedef void (CALLBACK* _PADWriteEvent)(keyEvent &evt); typedef void(CALLBACK *_PADWriteEvent)(keyEvent &evt);
// SPU2 // SPU2
typedef s32 (CALLBACK* _SPU2open)(void *pDsp); typedef s32(CALLBACK *_SPU2open)(void *pDsp);
typedef void (CALLBACK* _SPU2reset)(); typedef void(CALLBACK *_SPU2reset)();
typedef void (CALLBACK* _SPU2write)(u32 mem, u16 value); typedef void(CALLBACK *_SPU2write)(u32 mem, u16 value);
typedef u16 (CALLBACK* _SPU2read)(u32 mem); typedef u16(CALLBACK *_SPU2read)(u32 mem);
#ifdef ENABLE_NEW_IOPDMA_SPU2 #ifdef ENABLE_NEW_IOPDMA_SPU2
typedef s32 (CALLBACK* _SPU2dmaRead)(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); 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 s32(CALLBACK *_SPU2dmaWrite)(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed);
typedef void (CALLBACK* _SPU2dmaInterrupt)(s32 channel); typedef void(CALLBACK *_SPU2dmaInterrupt)(s32 channel);
// dma irq callbacks not needed anymore, they are handled by the dmac // 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 #else
typedef void (CALLBACK* _SPU2readDMA4Mem)(u16 *pMem, int size); typedef void(CALLBACK *_SPU2readDMA4Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2writeDMA4Mem)(u16 *pMem, int size); typedef void(CALLBACK *_SPU2writeDMA4Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2interruptDMA4)(); typedef void(CALLBACK *_SPU2interruptDMA4)();
typedef void (CALLBACK* _SPU2readDMA7Mem)(u16 *pMem, int size); typedef void(CALLBACK *_SPU2readDMA7Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2writeDMA7Mem)(u16 *pMem, int size); typedef void(CALLBACK *_SPU2writeDMA7Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2setDMABaseAddr)(uptr baseaddr); typedef void(CALLBACK *_SPU2setDMABaseAddr)(uptr baseaddr);
typedef void (CALLBACK* _SPU2interruptDMA7)(); typedef void(CALLBACK *_SPU2interruptDMA7)();
typedef void (CALLBACK* _SPU2irqCallback)(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)()); typedef void(CALLBACK *_SPU2irqCallback)(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)());
typedef u32 (CALLBACK* _SPU2ReadMemAddr)(int core); typedef u32(CALLBACK *_SPU2ReadMemAddr)(int core);
typedef void (CALLBACK* _SPU2WriteMemAddr)(int core,u32 value); typedef void(CALLBACK *_SPU2WriteMemAddr)(int core, u32 value);
#endif #endif
typedef int (CALLBACK* _SPU2setupRecording)(int, void*); typedef int(CALLBACK *_SPU2setupRecording)(int, void *);
typedef void (CALLBACK* _SPU2setClockPtr)(u32*ptr); typedef void(CALLBACK *_SPU2setClockPtr)(u32 *ptr);
typedef void (CALLBACK* _SPU2setTimeStretcher)(short int enable); typedef void(CALLBACK *_SPU2setTimeStretcher)(short int enable);
typedef void (CALLBACK* _SPU2async)(u32 cycles); typedef void(CALLBACK *_SPU2async)(u32 cycles);
// CDVD // CDVD
// NOTE: The read/write functions CANNOT use XMM/MMX regs // NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones // 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. // Initiates an asynchronous track read operation.
// Returns -1 on error (invalid track) // Returns -1 on error (invalid track)
// Returns 0 on success. // 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 // *OBSOLETE* returns a pointer to the buffer, or NULL if data hasn't finished
// loading yet. // loading yet.
typedef u8* (CALLBACK* _CDVDgetBuffer)(); typedef u8 *(CALLBACK *_CDVDgetBuffer)();
// Copies loaded data to the target buffer. // Copies loaded data to the target buffer.
// Returns -2 if the asynchronous read is still pending. // Returns -2 if the asynchronous read is still pending.
// Returns -1 if the asyncronous read failed. // Returns -1 if the asyncronous read failed.
// Returns 0 on success. // 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 *_CDVDreadSubQ)(u32 lsn, cdvdSubQ *subq);
typedef s32 (CALLBACK* _CDVDgetTN)(cdvdTN *Buffer); typedef s32(CALLBACK *_CDVDgetTN)(cdvdTN *Buffer);
typedef s32 (CALLBACK* _CDVDgetTD)(u8 Track, cdvdTD *Buffer); typedef s32(CALLBACK *_CDVDgetTD)(u8 Track, cdvdTD *Buffer);
typedef s32 (CALLBACK* _CDVDgetTOC)(void* toc); typedef s32(CALLBACK *_CDVDgetTOC)(void *toc);
typedef s32 (CALLBACK* _CDVDgetDiskType)(); typedef s32(CALLBACK *_CDVDgetDiskType)();
typedef s32 (CALLBACK* _CDVDgetTrayStatus)(); typedef s32(CALLBACK *_CDVDgetTrayStatus)();
typedef s32 (CALLBACK* _CDVDctrlTrayOpen)(); typedef s32(CALLBACK *_CDVDctrlTrayOpen)();
typedef s32 (CALLBACK* _CDVDctrlTrayClose)(); typedef s32(CALLBACK *_CDVDctrlTrayClose)();
typedef s32 (CALLBACK* _CDVDreadSector)(u8* buffer, u32 lsn, int mode); typedef s32(CALLBACK *_CDVDreadSector)(u8 *buffer, u32 lsn, int mode);
typedef s32 (CALLBACK* _CDVDgetDualInfo)(s32* dualType, u32* _layer1start); typedef s32(CALLBACK *_CDVDgetDualInfo)(s32 *dualType, u32 *_layer1start);
typedef void (CALLBACK* _CDVDnewDiskCB)(void (*callback)()); typedef void(CALLBACK *_CDVDnewDiskCB)(void (*callback)());
// DEV9 // DEV9
// NOTE: The read/write functions CANNOT use XMM/MMX regs // NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones // If you want to use them, need to save and restore current ones
typedef s32 (CALLBACK* _DEV9open)(void *pDsp); typedef s32(CALLBACK *_DEV9open)(void *pDsp);
typedef u8 (CALLBACK* _DEV9read8)(u32 mem); typedef u8(CALLBACK *_DEV9read8)(u32 mem);
typedef u16 (CALLBACK* _DEV9read16)(u32 mem); typedef u16(CALLBACK *_DEV9read16)(u32 mem);
typedef u32 (CALLBACK* _DEV9read32)(u32 mem); typedef u32(CALLBACK *_DEV9read32)(u32 mem);
typedef void (CALLBACK* _DEV9write8)(u32 mem, u8 value); typedef void(CALLBACK *_DEV9write8)(u32 mem, u8 value);
typedef void (CALLBACK* _DEV9write16)(u32 mem, u16 value); typedef void(CALLBACK *_DEV9write16)(u32 mem, u16 value);
typedef void (CALLBACK* _DEV9write32)(u32 mem, u32 value); typedef void(CALLBACK *_DEV9write32)(u32 mem, u32 value);
#ifdef ENABLE_NEW_IOPDMA_DEV9 #ifdef ENABLE_NEW_IOPDMA_DEV9
typedef s32 (CALLBACK* _DEV9dmaRead)(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed); 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 s32(CALLBACK *_DEV9dmaWrite)(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed);
typedef void (CALLBACK* _DEV9dmaInterrupt)(s32 channel); typedef void(CALLBACK *_DEV9dmaInterrupt)(s32 channel);
#else #else
typedef void (CALLBACK* _DEV9readDMA8Mem)(u32 *pMem, int size); typedef void(CALLBACK *_DEV9readDMA8Mem)(u32 *pMem, int size);
typedef void (CALLBACK* _DEV9writeDMA8Mem)(u32 *pMem, int size); typedef void(CALLBACK *_DEV9writeDMA8Mem)(u32 *pMem, int size);
#endif #endif
typedef void (CALLBACK* _DEV9irqCallback)(DEV9callback callback); typedef void(CALLBACK *_DEV9irqCallback)(DEV9callback callback);
typedef DEV9handler (CALLBACK* _DEV9irqHandler)(void); typedef DEV9handler(CALLBACK *_DEV9irqHandler)(void);
typedef void (CALLBACK* _DEV9async)(u32 cycles); typedef void(CALLBACK *_DEV9async)(u32 cycles);
// USB // USB
// NOTE: The read/write functions CANNOT use XMM/MMX regs // NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones // If you want to use them, need to save and restore current ones
typedef s32 (CALLBACK* _USBopen)(void *pDsp); typedef s32(CALLBACK *_USBopen)(void *pDsp);
typedef u8 (CALLBACK* _USBread8)(u32 mem); typedef u8(CALLBACK *_USBread8)(u32 mem);
typedef u16 (CALLBACK* _USBread16)(u32 mem); typedef u16(CALLBACK *_USBread16)(u32 mem);
typedef u32 (CALLBACK* _USBread32)(u32 mem); typedef u32(CALLBACK *_USBread32)(u32 mem);
typedef void (CALLBACK* _USBwrite8)(u32 mem, u8 value); typedef void(CALLBACK *_USBwrite8)(u32 mem, u8 value);
typedef void (CALLBACK* _USBwrite16)(u32 mem, u16 value); typedef void(CALLBACK *_USBwrite16)(u32 mem, u16 value);
typedef void (CALLBACK* _USBwrite32)(u32 mem, u32 value); typedef void(CALLBACK *_USBwrite32)(u32 mem, u32 value);
typedef void (CALLBACK* _USBasync)(u32 cycles); typedef void(CALLBACK *_USBasync)(u32 cycles);
typedef void (CALLBACK* _USBirqCallback)(USBcallback callback); typedef void(CALLBACK *_USBirqCallback)(USBcallback callback);
typedef USBhandler (CALLBACK* _USBirqHandler)(void); typedef USBhandler(CALLBACK *_USBirqHandler)(void);
typedef void (CALLBACK* _USBsetRAM)(void *mem); typedef void(CALLBACK *_USBsetRAM)(void *mem);
//FW //FW
typedef s32 (CALLBACK* _FWopen)(void *pDsp); typedef s32(CALLBACK *_FWopen)(void *pDsp);
typedef u32 (CALLBACK* _FWread32)(u32 mem); typedef u32(CALLBACK *_FWread32)(u32 mem);
typedef void (CALLBACK* _FWwrite32)(u32 mem, u32 value); typedef void(CALLBACK *_FWwrite32)(u32 mem, u32 value);
typedef void (CALLBACK* _FWirqCallback)(void (*callback)()); typedef void(CALLBACK *_FWirqCallback)(void (*callback)());
#endif #endif
#ifdef PLUGINfuncs #ifdef PLUGINfuncs

View File

@ -55,8 +55,7 @@ static void __forceinline PluginNullConfigure(std::wstring desc, s32 &log);
static void __forceinline PluginNullAbout(const wchar_t *aboutText); static void __forceinline PluginNullAbout(const wchar_t *aboutText);
#endif #endif
enum FileMode enum FileMode {
{
READ_FILE = 0, READ_FILE = 0,
WRITE_FILE WRITE_FILE
}; };
@ -70,8 +69,7 @@ struct PluginLog
{ {
LogFile = fopen(logname.c_str(), "w"); LogFile = fopen(logname.c_str(), "w");
if (LogFile) if (LogFile) {
{
setvbuf(LogFile, NULL, _IONBF, 0); setvbuf(LogFile, NULL, _IONBF, 0);
return true; return true;
} }
@ -90,11 +88,14 @@ struct PluginLog
{ {
va_list list; va_list list;
if (LogFile == NULL) return; if (LogFile == NULL)
return;
va_start(list, fmt); va_start(list, fmt);
if (WriteToFile) vfprintf(LogFile, fmt, list); if (WriteToFile)
if (WriteToConsole) vfprintf(stdout, fmt, list); vfprintf(LogFile, fmt, list);
if (WriteToConsole)
vfprintf(stdout, fmt, list);
va_end(list); va_end(list);
} }
@ -102,15 +103,20 @@ struct PluginLog
{ {
va_list list; va_list list;
if (LogFile == NULL) return; if (LogFile == NULL)
return;
va_start(list, fmt); va_start(list, fmt);
if (WriteToFile) vfprintf(LogFile, fmt, list); if (WriteToFile)
if (WriteToConsole) vfprintf(stdout, fmt, list); vfprintf(LogFile, fmt, list);
if (WriteToConsole)
vfprintf(stdout, fmt, list);
va_end(list); va_end(list);
if (WriteToFile) fprintf(LogFile, "\n"); if (WriteToFile)
if (WriteToConsole) fprintf(stdout, "\n"); fprintf(LogFile, "\n");
if (WriteToConsole)
fprintf(stdout, "\n");
} }
#if !defined(_MSC_VER) || !defined(UNICODE) #if !defined(_MSC_VER) || !defined(UNICODE)
@ -119,7 +125,8 @@ struct PluginLog
va_list list; va_list list;
char buf[256]; char buf[256];
if (LogFile == NULL) return; if (LogFile == NULL)
return;
va_start(list, fmt); va_start(list, fmt);
vsprintf(buf, fmt, list); vsprintf(buf, fmt, list);
@ -133,7 +140,8 @@ struct PluginLog
va_list list; va_list list;
wchar_t buf[256]; wchar_t buf[256];
if (LogFile == NULL) return; if (LogFile == NULL)
return;
va_start(list, fmt); va_start(list, fmt);
vswprintf(buf, 256, fmt, list); vswprintf(buf, 256, fmt, list);
@ -151,16 +159,14 @@ struct PluginConf
bool Open(std::string name, FileMode mode = READ_FILE) bool Open(std::string name, FileMode mode = READ_FILE)
{ {
if (mode == READ_FILE) if (mode == READ_FILE) {
{
ConfFile = fopen(name.c_str(), "r"); ConfFile = fopen(name.c_str(), "r");
} } else {
else
{
ConfFile = fopen(name.c_str(), "w"); ConfFile = fopen(name.c_str(), "w");
} }
if (ConfFile == NULL) return false; if (ConfFile == NULL)
return false;
return true; return true;
} }
@ -173,7 +179,7 @@ struct PluginConf
} }
} }
int ReadInt(const std::string& item, int defval) int ReadInt(const std::string &item, int defval)
{ {
int value = defval; int value = defval;
std::string buf = item + " = %d\n"; std::string buf = item + " = %d\n";
@ -189,7 +195,8 @@ struct PluginConf
{ {
std::string buf = item + " = %d\n"; 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); vsprintf(msg, fmt, list);
va_end(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; GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL, dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO, GTK_MESSAGE_INFO,
GTK_BUTTONS_OK, GTK_BUTTONS_OK,
"%s", msg); "%s", msg);
gtk_dialog_run (GTK_DIALOG (dialog)); gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy (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); log = gtk_toggle_button_get_active(check);
} }
@ -227,7 +235,7 @@ static void __forceinline PluginNullConfigure(std::string desc, int &log)
/* Create the widgets */ /* Create the widgets */
dialog = gtk_dialog_new(); 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"); check_box = gtk_check_button_new_with_label("Logging");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), (log != 0)); 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); g_signal_connect(check_box, "toggled", G_CALLBACK(set_logging), &log);
/* Add all our widgets, and show everything we've added to the dialog. */ /* 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))), 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))), check_box);
gtk_dialog_add_button(GTK_DIALOG(dialog), "Ok", 0); 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_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy (dialog); gtk_widget_destroy(dialog);
} }
static void __forceinline PluginNullAbout(const char *aboutText) static void __forceinline PluginNullAbout(const char *aboutText)
@ -265,7 +273,8 @@ static void SysMessage(const char *fmt, ...)
vsprintf(msg, fmt, list); vsprintf(msg, fmt, list);
va_end(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? // TODO OSX can we use WX MessageBox here or should Cocoa MessageBox used?
} }
@ -305,10 +314,10 @@ static void __forceinline SysMessage(const char *fmt, ...)
{ {
va_list list; va_list list;
char tmp[512]; char tmp[512];
va_start(list,fmt); va_start(list, fmt);
vsprintf(tmp,fmt,list); vsprintf(tmp, fmt, list);
va_end(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) static void __forceinline PluginNullConfigure(std::string desc, s32 &log)
@ -351,15 +360,15 @@ static void __forceinline PluginNullAbout(const wchar_t *aboutText)
#endif #endif
#define ENTRY_POINT \ #define ENTRY_POINT \
HINSTANCE hInst; \ HINSTANCE hInst; \
\ \
BOOL APIENTRY DllMain(HANDLE hModule, /* DLL INIT*/ \ BOOL APIENTRY DllMain(HANDLE hModule, /* DLL INIT*/ \
DWORD dwReason, \ DWORD dwReason, \
LPVOID lpReserved) \ LPVOID lpReserved) \
{ \ { \
hInst = (HINSTANCE)hModule; \ hInst = (HINSTANCE)hModule; \
return TRUE; /* very quick :)*/ \ return TRUE; /* very quick :)*/ \
} }
#endif #endif
#endif // PS2EEXT_H_INCLUDED #endif // PS2EEXT_H_INCLUDED

View File

@ -13,7 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
// This file is just for backwards compatibility. // This file is just for backwards compatibility.
#ifndef __PS2ETYPES_H__ #ifndef __PS2ETYPES_H__
#define __PS2ETYPES_H__ #define __PS2ETYPES_H__

View File

@ -35,61 +35,68 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#define EXPORT_C(type) extern "C" type CALLBACK #define EXPORT_C(type) extern "C" type CALLBACK
#else #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 #endif
EXPORT_C(u32) PS2EgetLibType(void); EXPORT_C(u32)
EXPORT_C(u32) PS2EgetLibVersion2(u32 type); PS2EgetLibType(void);
EXPORT_C(char*) PS2EgetLibName(void); EXPORT_C(u32)
PS2EgetLibVersion2(u32 type);
EXPORT_C(char *)
PS2EgetLibName(void);
// Extended functions. // Extended functions.
// allows the plugin to see the whole configuration when started up. // 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. // 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 // Alternately, this function serves the same purpose, but would work for emulators outside
// of pcsx2. // of pcsx2.
EXPORT_C_(void) PS2EpassIniPath(const char *path); EXPORT_C_(void)
PS2EpassIniPath(const char *path);
// PS2EgetLibType returns (may be OR'd) // PS2EgetLibType returns (may be OR'd)
enum { enum {
PS2E_LT_GS = 0x01, PS2E_LT_GS = 0x01,
PS2E_LT_PAD = 0x02, // -=[ OBSOLETE ]=- PS2E_LT_PAD = 0x02, // -=[ OBSOLETE ]=-
PS2E_LT_SPU2 = 0x04, PS2E_LT_SPU2 = 0x04,
PS2E_LT_CDVD = 0x08, PS2E_LT_CDVD = 0x08,
PS2E_LT_DEV9 = 0x10, PS2E_LT_DEV9 = 0x10,
PS2E_LT_USB = 0x20, PS2E_LT_USB = 0x20,
PS2E_LT_FW = 0x40, PS2E_LT_FW = 0x40,
PS2E_LT_SIO = 0x80 PS2E_LT_SIO = 0x80
} PluginLibType; } PluginLibType;
// PS2EgetLibVersion2 (high 16 bits) // PS2EgetLibVersion2 (high 16 bits)
enum { enum {
PS2E_GS_VERSION = 0x0006, PS2E_GS_VERSION = 0x0006,
PS2E_PAD_VERSION = 0x0002, // -=[ OBSOLETE ]=- PS2E_PAD_VERSION = 0x0002, // -=[ OBSOLETE ]=-
PS2E_SPU2_VERSION = 0x0005, PS2E_SPU2_VERSION = 0x0005,
PS2E_CDVD_VERSION = 0x0005, PS2E_CDVD_VERSION = 0x0005,
PS2E_DEV9_VERSION = 0x0003, PS2E_DEV9_VERSION = 0x0003,
PS2E_USB_VERSION = 0x0003, PS2E_USB_VERSION = 0x0003,
PS2E_FW_VERSION = 0x0002, PS2E_FW_VERSION = 0x0002,
PS2E_SIO_VERSION = 0x0001 PS2E_SIO_VERSION = 0x0001
} PluginLibVersion; } PluginLibVersion;
// freeze modes: // freeze modes:
enum { enum {
FREEZE_LOAD = 0, FREEZE_LOAD = 0,
FREEZE_SAVE = 1, FREEZE_SAVE = 1,
FREEZE_SIZE = 2 FREEZE_SIZE = 2
} FreezeModes; } FreezeModes;
typedef struct _GSdriverInfo { typedef struct _GSdriverInfo
{
char name[8]; char name[8];
void *common; void *common;
} GSdriverInfo; } GSdriverInfo;
#ifdef _MSC_VER #ifdef _MSC_VER
typedef struct _winInfo { // unsupported values must be set to zero typedef struct _winInfo
{ // unsupported values must be set to zero
HWND hWnd; HWND hWnd;
HMENU hMenu; HMENU hMenu;
HWND hStatusWnd; HWND hStatusWnd;

View File

@ -26,9 +26,9 @@
// make sure __POSIX__ is defined for all systems where we assume POSIX // make sure __POSIX__ is defined for all systems where we assume POSIX
// compliance // compliance
#if defined(__linux__) || defined(__APPLE__) || defined(__unix__) || defined(__CYGWIN__) || defined(__LINUX__) #if defined(__linux__) || defined(__APPLE__) || defined(__unix__) || defined(__CYGWIN__) || defined(__LINUX__)
# if !defined(__POSIX__) #if !defined(__POSIX__)
# define __POSIX__ 1 #define __POSIX__ 1
# endif #endif
#endif #endif
#include "Pcsx2Types.h" #include "Pcsx2Types.h"
@ -39,7 +39,7 @@
// Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with // Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with
// that as well. >_< // that as well. >_<
#ifndef ArraySize #ifndef ArraySize
# define ArraySize(x) (sizeof(x)/sizeof((x)[0])) #define ArraySize(x) (sizeof(x) / sizeof((x)[0]))
#endif #endif
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -51,51 +51,51 @@
// some tight loops it will likely make debug builds unusably slow. // some tight loops it will likely make debug builds unusably slow.
// //
#ifdef __cplusplus #ifdef __cplusplus
# ifdef PCSX2_DEVBUILD #ifdef PCSX2_DEVBUILD
static const bool IsDevBuild = true; 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
#else #else
static const bool IsDevBuild = false;
# 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 #endif
#ifdef PCSX2_DEBUG #ifdef PCSX2_DEBUG
# define pxDebugCode(code) code static const bool IsDebugBuild = true;
#else #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 #endif
#ifdef PCSX2_DEVBUILD #ifdef PCSX2_DEVBUILD
# define pxDevelCode(code) code #define pxDevelCode(code) code
#else #else
# define pxDevelCode(code) #define pxDevelCode(code)
#endif #endif
#if defined(PCSX2_DEBUG) || defined(PCSX2_DEVBUILD) #if defined(PCSX2_DEBUG) || defined(PCSX2_DEVBUILD)
# define pxReleaseCode(code) #define pxReleaseCode(code)
# define pxNonReleaseCode(code) code #define pxNonReleaseCode(code) code
#else #else
# define pxReleaseCode(code) code #define pxReleaseCode(code) code
# define pxNonReleaseCode(code) #define pxNonReleaseCode(code)
#endif #endif
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -154,27 +154,27 @@ static const int __pagesize = PCSX2_PAGESIZE;
// This is the 2005/earlier compatible packing define, which must be used in conjunction // This is the 2005/earlier compatible packing define, which must be used in conjunction
// with #ifdef _MSC_VER/#pragma pack() directives (ugly). // with #ifdef _MSC_VER/#pragma pack() directives (ugly).
# define __packed #define __packed
# define __aligned(alig) __declspec(align(alig)) #define __aligned(alig) __declspec(align(alig))
# define __aligned16 __declspec(align(16)) #define __aligned16 __declspec(align(16))
# define __aligned32 __declspec(align(32)) #define __aligned32 __declspec(align(32))
# define __pagealigned __declspec(align(PCSX2_PAGESIZE)) #define __pagealigned __declspec(align(PCSX2_PAGESIZE))
// Deprecated; use __align instead. // Deprecated; use __align instead.
# define PCSX2_ALIGNED(alig,x) __declspec(align(alig)) x #define PCSX2_ALIGNED(alig, x) __declspec(align(alig)) x
# define PCSX2_ALIGNED_EXTERN(alig,x) extern __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(x) __declspec(align(16)) x
# define PCSX2_ALIGNED16_EXTERN(x) extern __declspec(align(16)) x #define PCSX2_ALIGNED16_EXTERN(x) extern __declspec(align(16)) x
# define __noinline __declspec(noinline) #define __noinline __declspec(noinline)
# define __threadlocal __declspec(thread) #define __threadlocal __declspec(thread)
// Don't know if there are Visual C++ equivalents of these. // Don't know if there are Visual C++ equivalents of these.
# define likely(x) (!!(x)) #define likely(x) (!!(x))
# define unlikely(x) (!!(x)) #define unlikely(x) (!!(x))
# define CALLBACK __stdcall #define CALLBACK __stdcall
#else #else
@ -183,42 +183,42 @@ static const int __pagesize = PCSX2_PAGESIZE;
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
#ifndef __packed #ifndef __packed
# define __packed __attribute__((packed)) #define __packed __attribute__((packed))
#endif #endif
#ifndef __aligned #ifndef __aligned
# define __aligned(alig) __attribute__((aligned(alig))) #define __aligned(alig) __attribute__((aligned(alig)))
#endif #endif
# define __aligned16 __attribute__((aligned(16))) #define __aligned16 __attribute__((aligned(16)))
# define __aligned32 __attribute__((aligned(32))) #define __aligned32 __attribute__((aligned(32)))
# define __pagealigned __attribute__((aligned(PCSX2_PAGESIZE))) #define __pagealigned __attribute__((aligned(PCSX2_PAGESIZE)))
// Deprecated; use __align instead. // Deprecated; use __align instead.
# define PCSX2_ALIGNED(alig,x) x __attribute((aligned(alig))) #define PCSX2_ALIGNED(alig, x) x __attribute((aligned(alig)))
# define PCSX2_ALIGNED16(x) x __attribute((aligned(16))) #define PCSX2_ALIGNED16(x) x __attribute((aligned(16)))
# define PCSX2_ALIGNED_EXTERN(alig,x) extern x __attribute((aligned(alig))) #define PCSX2_ALIGNED_EXTERN(alig, x) extern x __attribute((aligned(alig)))
# define PCSX2_ALIGNED16_EXTERN(x) extern x __attribute((aligned(16))) #define PCSX2_ALIGNED16_EXTERN(x) extern x __attribute((aligned(16)))
# define __assume(cond) ((void)0) // GCC has no equivalent for __assume #define __assume(cond) ((void)0) // GCC has no equivalent for __assume
# define CALLBACK __attribute__((stdcall)) #define CALLBACK __attribute__((stdcall))
// Inlining note: GCC needs ((unused)) attributes defined on inlined functions to suppress // 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 // 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 >_<) // happens *by design* like all the friggen time >_<)
#ifndef __fastcall #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 #endif
# define _inline __inline__ __attribute__((unused))
# ifdef NDEBUG
# define __forceinline __attribute__((always_inline,unused))
# else
# define __forceinline __attribute__((unused))
# endif
#ifndef __noinline #ifndef __noinline
# define __noinline __attribute__((noinline)) #define __noinline __attribute__((noinline))
#endif #endif
# define __threadlocal __thread #define __threadlocal __thread
# define likely(x) __builtin_expect(!!(x), 1) #define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0) #define unlikely(x) __builtin_expect(!!(x), 0)
#endif #endif
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -233,9 +233,9 @@ static const int __pagesize = PCSX2_PAGESIZE;
// environment. // environment.
// //
#ifdef PCSX2_DEVBUILD #ifdef PCSX2_DEVBUILD
# define __releaseinline #define __releaseinline
#else #else
# define __releaseinline __forceinline #define __releaseinline __forceinline
#endif #endif
#define __ri __releaseinline #define __ri __releaseinline

View File

@ -24,9 +24,9 @@
// depend on these types will not be usable (they will yield linker errors). // depend on these types will not be usable (they will yield linker errors).
#ifdef __cplusplus #ifdef __cplusplus
class wxString; class wxString;
class FastFormatAscii; class FastFormatAscii;
class FastFormatUnicode; class FastFormatUnicode;
#endif #endif
@ -77,7 +77,7 @@ union u128
u8 _u8[16]; u8 _u8[16];
// Explicit conversion from u64. Zero-extends the source through 128 bits. // Explicit conversion from u64. Zero-extends the source through 128 bits.
static u128 From64( u64 src ) static u128 From64(u64 src)
{ {
u128 retval; u128 retval;
retval.lo = src; retval.lo = src;
@ -86,7 +86,7 @@ union u128
} }
// Explicit conversion from u32. Zero-extends the source through 128 bits. // Explicit conversion from u32. Zero-extends the source through 128 bits.
static u128 From32( u32 src ) static u128 From32(u32 src)
{ {
u128 retval; u128 retval;
retval._u32[0] = src; retval._u32[0] = src;
@ -99,12 +99,12 @@ union u128
operator u16() const { return _u16[0]; } operator u16() const { return _u16[0]; }
operator u8() const { return _u8[0]; } operator u8() const { return _u8[0]; }
bool operator==( const u128& right ) const bool operator==(const u128 &right) const
{ {
return (lo == right.lo) && (hi == right.hi); return (lo == right.lo) && (hi == right.hi);
} }
bool operator!=( const u128& right ) const bool operator!=(const u128 &right) const
{ {
return (lo != right.lo) || (hi != right.hi); return (lo != right.lo) || (hi != right.hi);
} }
@ -116,9 +116,9 @@ union u128
wxString ToString64() const; wxString ToString64() const;
wxString ToString8() const; wxString ToString8() const;
void WriteTo( FastFormatAscii& dest ) const; void WriteTo(FastFormatAscii &dest) const;
void WriteTo8( FastFormatAscii& dest ) const; void WriteTo8(FastFormatAscii &dest) const;
void WriteTo64( FastFormatAscii& dest ) const; void WriteTo64(FastFormatAscii &dest) const;
}; };
struct s128 struct s128
@ -127,16 +127,16 @@ struct s128
s64 hi; s64 hi;
// explicit conversion from s64, with sign extension. // explicit conversion from s64, with sign extension.
static s128 From64( s64 src ) static s128 From64(s64 src)
{ {
s128 retval = { src, (src < 0) ? -1 : 0 }; s128 retval = {src, (src < 0) ? -1 : 0};
return retval; return retval;
} }
// explicit conversion from s32, with sign extension. // explicit conversion from s32, with sign extension.
static s128 From64( s32 src ) static s128 From64(s32 src)
{ {
s128 retval = { src, (src < 0) ? -1 : 0 }; s128 retval = {src, (src < 0) ? -1 : 0};
return retval; return retval;
} }
@ -144,12 +144,12 @@ struct s128
operator u16() const { return (s16)lo; } operator u16() const { return (s16)lo; }
operator u8() const { return (s8)lo; } operator u8() const { return (s8)lo; }
bool operator==( const s128& right ) const bool operator==(const s128 &right) const
{ {
return (lo == right.lo) && (hi == right.hi); return (lo == right.lo) && (hi == right.hi);
} }
bool operator!=( const s128& right ) const bool operator!=(const s128 &right) const
{ {
return (lo != right.lo) || (hi != right.hi); return (lo != right.lo) || (hi != right.hi);
} }

View File

@ -107,7 +107,7 @@
#ifndef BOOL #ifndef BOOL
typedef int BOOL; typedef int BOOL;
#endif #endif
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -122,15 +122,15 @@
// on its HWND define that could be useful, and well it's probably good practice to use // on its HWND define that could be useful, and well it's probably good practice to use
// platform available defines when they exist. // platform available defines when they exist.
// //
#if defined( _WX_DEFS_H_ ) #if defined(_WX_DEFS_H_)
typedef WXWidget PS2E_HWND; typedef WXWidget PS2E_HWND;
#elif defined( _WINDEF_ ) #elif defined(_WINDEF_)
// For Windows let's use HWND, since it has some type strictness applied to it. // For Windows let's use HWND, since it has some type strictness applied to it.
typedef HWND PS2E_HWND; typedef HWND PS2E_HWND;
#else #else
// Unsupported platform... use void* as a best guess. Should work fine for almost // Unsupported platform... use void* as a best guess. Should work fine for almost
// any GUI platform, and certainly works for any currently supported one. // any GUI platform, and certainly works for any currently supported one.
typedef void* PS2E_HWND; typedef void *PS2E_HWND;
#endif #endif
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -144,20 +144,20 @@
// pointer type. // pointer type.
// //
#ifndef PS2E_THISPTR #ifndef PS2E_THISPTR
# define PS2E_THISPTR struct _PS2E_ComponentAPI* #define PS2E_THISPTR struct _PS2E_ComponentAPI *
#else #else
// Ensure the user's defined PS2E_THISPTR retains the correct signature for our // Ensure the user's defined PS2E_THISPTR retains the correct signature for our
// plugin API. // plugin API.
static_assert( sizeof(PS2E_THISPTR) == sizeof(void*), "Incorrect signature for PS2E_THISPTR" ); static_assert(sizeof(PS2E_THISPTR) == sizeof(void *), "Incorrect signature for PS2E_THISPTR");
#endif #endif
// PS2E_LIB_THISPTR - (library scope version of PS2E_THISPTR) // PS2E_LIB_THISPTR - (library scope version of PS2E_THISPTR)
#ifndef PS2E_LIB_THISPTR #ifndef PS2E_LIB_THISPTR
# define PS2E_LIB_THISPTR void* #define PS2E_LIB_THISPTR void *
#else #else
// Ensure the user's defined PS2E_THISPTR retains the correct signature for our // Ensure the user's defined PS2E_THISPTR retains the correct signature for our
// plugin API. // plugin API.
static_assert( sizeof(PS2E_LIB_THISPTR) == sizeof(void*), "Incorrect signature for PS2E_LIB_THISPTR" ); static_assert(sizeof(PS2E_LIB_THISPTR) == sizeof(void *), "Incorrect signature for PS2E_LIB_THISPTR");
#endif #endif
// Use fastcall by default, since under most circumstances the object-model approach of the // Use fastcall by default, since under most circumstances the object-model approach of the
@ -174,8 +174,7 @@ extern "C" {
// Plugin Type / Version Enumerations // Plugin Type / Version Enumerations
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
enum PS2E_ComponentTypes enum PS2E_ComponentTypes {
{
PS2E_TYPE_GS = 0, PS2E_TYPE_GS = 0,
PS2E_TYPE_PAD, PS2E_TYPE_PAD,
PS2E_TYPE_SPU2, PS2E_TYPE_SPU2,
@ -187,8 +186,7 @@ enum PS2E_ComponentTypes
PS2E_TYPE_Mcd, PS2E_TYPE_Mcd,
}; };
enum PluginLibVersion enum PluginLibVersion {
{
PS2E_VER_GS = 0x1000, PS2E_VER_GS = 0x1000,
PS2E_VER_PAD = 0x1000, PS2E_VER_PAD = 0x1000,
PS2E_VER_SPU2 = 0x1000, PS2E_VER_SPU2 = 0x1000,
@ -199,8 +197,7 @@ enum PluginLibVersion
PS2E_VER_SIO = 0x1000 PS2E_VER_SIO = 0x1000
}; };
enum OSDIconTypes enum OSDIconTypes {
{
OSD_Icon_None = 0, OSD_Icon_None = 0,
OSD_Icon_Error, OSD_Icon_Error,
OSD_Icon_Notice, // An exclamation point maybe? OSD_Icon_Notice, // An exclamation point maybe?
@ -215,17 +212,16 @@ enum OSDIconTypes
OSD_Icon_ReserveEnd = 0x1000 OSD_Icon_ReserveEnd = 0x1000
}; };
enum PS2E_MenuItemStyle enum PS2E_MenuItemStyle {
{
MenuType_Normal = 0, MenuType_Normal = 0,
MenuType_Checked, MenuType_Checked,
MenuType_Radio, MenuType_Radio,
MenuType_Separator MenuType_Separator
}; };
typedef void* PS2E_MenuHandle; typedef void *PS2E_MenuHandle;
typedef void* PS2E_MenuItemHandle; typedef void *PS2E_MenuItemHandle;
typedef void PS2E_CALLBACK PS2E_OnMenuItemClicked( PS2E_THISPTR* thisptr, void* userptr ); typedef void PS2E_CALLBACK PS2E_OnMenuItemClicked(PS2E_THISPTR *thisptr, void *userptr);
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// PS2E_ConsoleWriterAPI // PS2E_ConsoleWriterAPI
@ -250,18 +246,18 @@ typedef void PS2E_CALLBACK PS2E_OnMenuItemClicked( PS2E_THISPTR* thisptr, void*
typedef struct _PS2E_ConsoleWriterAPI typedef struct _PS2E_ConsoleWriterAPI
{ {
// Writes text to console; no newline is appended. // Writes text to console; no newline is appended.
void (PS2E_CALLBACK* Write)( const char* fmt, ... ); void(PS2E_CALLBACK *Write)(const char *fmt, ...);
// Appends an automatic newline to the specified formatted output. // Appends an automatic newline to the specified formatted output.
void (PS2E_CALLBACK* WriteLn)( const char* fmt, ... ); void(PS2E_CALLBACK *WriteLn)(const char *fmt, ...);
// This function always appends a newline. // This function always appends a newline.
void (PS2E_CALLBACK* Error)( const char* fmt, ... ); void(PS2E_CALLBACK *Error)(const char *fmt, ...);
// This function always appends a newline. // This function always appends a newline.
void (PS2E_CALLBACK* Warning)( const char* fmt, ... ); void(PS2E_CALLBACK *Warning)(const char *fmt, ...);
void* reserved[4]; void *reserved[4];
} PS2E_ConsoleWriterAPI; } PS2E_ConsoleWriterAPI;
@ -279,18 +275,18 @@ typedef struct _PS2E_ConsoleWriterAPI
typedef struct _PS2E_ConsoleWriterWideAPI typedef struct _PS2E_ConsoleWriterWideAPI
{ {
// Writes text to console; no newline is appended. // Writes text to console; no newline is appended.
void (PS2E_CALLBACK* Write)( const wchar_t* fmt, ... ); void(PS2E_CALLBACK *Write)(const wchar_t *fmt, ...);
// Appends an automatic newline to the specified formatted output. // Appends an automatic newline to the specified formatted output.
void (PS2E_CALLBACK* WriteLn)( const wchar_t* fmt, ... ); void(PS2E_CALLBACK *WriteLn)(const wchar_t *fmt, ...);
// This function always appends a newline. // This function always appends a newline.
void (PS2E_CALLBACK* Error)( const wchar_t* fmt, ... ); void(PS2E_CALLBACK *Error)(const wchar_t *fmt, ...);
// This function always appends a newline. // This function always appends a newline.
void (PS2E_CALLBACK* Warning)( const wchar_t* fmt, ... ); void(PS2E_CALLBACK *Warning)(const wchar_t *fmt, ...);
void* reserved[4]; void *reserved[4];
} PS2E_ConsoleWriterWideAPI; } PS2E_ConsoleWriterWideAPI;
@ -307,7 +303,7 @@ typedef struct _PS2E_Image
{ {
u32 width; u32 width;
u32 height; u32 height;
u8* data; // RGBA data. top to bottom. u8 *data; // RGBA data. top to bottom.
} PS2E_Image; } PS2E_Image;
@ -316,13 +312,13 @@ typedef struct _PS2E_Image
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
typedef struct _PS2E_MenuItemInfo typedef struct _PS2E_MenuItemInfo
{ {
const char* LabelText; const char *LabelText;
const char* HelpText; const char *HelpText;
// Optional image displayed with the menu option. The emulator may not support // 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 // this option, or may choose to ignore or resize the image if the size parameters
// are outside a valid threshold. // are outside a valid threshold.
const PS2E_Image* Image; const PS2E_Image *Image;
// Specifies the style of the menu, either Normal, Checked, Radio, or Separator. // 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 // This option is overridden if the SubMenu field is non-NULL (in such case the
@ -343,11 +339,11 @@ typedef struct _PS2E_MenuItemInfo
BOOL Enabled; BOOL Enabled;
// Optional user data pointer (or typecast integer value) // Optional user data pointer (or typecast integer value)
void* UserPtr; void *UserPtr;
// Callback issued when the menu is clicked/activated. If NULL, the menu will be // Callback issued when the menu is clicked/activated. If NULL, the menu will be
// disabled (grayed). // disabled (grayed).
PS2E_OnMenuItemClicked* OnClicked; PS2E_OnMenuItemClicked *OnClicked;
} PS2E_MenuItemInfo; } PS2E_MenuItemInfo;
@ -358,27 +354,27 @@ typedef struct _PS2E_MenuItemAPI
{ {
// Allocates a new MenuItem and returns its handle. The returned item can be added to any // Allocates a new MenuItem and returns its handle. The returned item can be added to any
// menu. // menu.
PS2E_MenuItemHandle (PS2E_CALLBACK* MenuItem_Create)( PS2E_THISPTR thisptr ); PS2E_MenuItemHandle(PS2E_CALLBACK *MenuItem_Create)(PS2E_THISPTR thisptr);
// Deletes the menu item and frees allocated resources. The menu item will be removed from // 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 // whatever menu it is attached to. If the menu item has a SubMenu, the SubMenu is not
// deleted. // deleted.
void (PS2E_CALLBACK* MenuItem_Delete)( PS2E_MenuItemHandle mitem ); void(PS2E_CALLBACK *MenuItem_Delete)(PS2E_MenuItemHandle mitem);
// (Re-)Assigns all properties for a menu. Assignment generally takes effect immediately. // (Re-)Assigns all properties for a menu. Assignment generally takes effect immediately.
void (PS2E_CALLBACK* MenuItem_SetEverything)( PS2E_MenuItemHandle mitem, const PS2E_MenuItemInfo* info ); void(PS2E_CALLBACK *MenuItem_SetEverything)(PS2E_MenuItemHandle mitem, const PS2E_MenuItemInfo *info);
// Sets the text label of a menu item. // Sets the text label of a menu item.
void (PS2E_CALLBACK* MenuItem_SetText)( PS2E_MenuItemHandle mitem, const char* text ); 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 // 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 // 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. // interface does not have a context for help text.
void (PS2E_CALLBACK* MenuItem_SetHelpText)( PS2E_MenuItemHandle mitem, const char* helptxt ); void(PS2E_CALLBACK *MenuItem_SetHelpText)(PS2E_MenuItemHandle mitem, const char *helptxt);
// Gives the menu item an accompanying image (orientation of the image may depend // Gives the menu item an accompanying image (orientation of the image may depend
// on the operating system platform). // on the operating system platform).
void (PS2E_CALLBACK* MenuItem_SetImage)( PS2E_MenuItemHandle mitem, const PS2E_Image* image ); 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 // Gives the menu item an accompanying image (orientation of the image may depend
// on the operating system platform). // on the operating system platform).
@ -386,7 +382,8 @@ typedef struct _PS2E_MenuItemAPI
// Returns: // Returns:
// TRUE if the image was loaded successfully, or FALSE if the image was not found, // 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). // 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 ); 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 // 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 // the operating system platform). Image is loaded from memory using a memory stream
@ -395,33 +392,35 @@ typedef struct _PS2E_MenuItemAPI
// Returns: // Returns:
// TRUE if the image was loaded successfully, or FALSE if the image data is invalid // TRUE if the image was loaded successfully, or FALSE if the image data is invalid
// (not a PNG, or data corrupted). // (not a PNG, or data corrupted).
BOOL (PS2E_CALLBACK* MenuItem_SetImagePng_FromMemory)( PS2E_MenuItemHandle mitem, const u8* data ); BOOL(PS2E_CALLBACK *MenuItem_SetImagePng_FromMemory)
(PS2E_MenuItemHandle mitem, const u8 *data);
// Assigns the menu item's style. // Assigns the menu item's style.
void (PS2E_CALLBACK* MenuItem_SetStyle)( PS2E_MenuItemHandle mitem, PS2E_MenuItemStyle 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 // 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 // specific menu items. The value can be any integer typecast if you don't actually
// need more than an integers worth of data. // need more than an integers worth of data.
void (PS2E_CALLBACK* MenuItem_SetUserData)( PS2E_MenuItemHandle mitem, void* dataptr ); 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 // 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 // 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 // ignored. Passing NULL into this function will clear the submenu and return the
// menu item to whatever its current Style attribute is set to. // menu item to whatever its current Style attribute is set to.
void (PS2E_CALLBACK* MenuItem_SetSubMenu)( PS2E_MenuItemHandle mitem, PS2E_MenuHandle submenu ); void(PS2E_CALLBACK *MenuItem_SetSubMenu)(PS2E_MenuItemHandle mitem, PS2E_MenuHandle submenu);
// Assigns the callback function for this menu (important!). If passed NULL, the menu // Assigns the callback function for this menu (important!). If passed NULL, the menu
// item will be automatically disabled (grayed out) by the emulator. // item will be automatically disabled (grayed out) by the emulator.
void (PS2E_CALLBACK* MenuItem_SetCallback)( PS2E_MenuItemHandle mitem, PS2E_OnMenuItemClicked* onClickedCallback ); 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. // 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 ); void(PS2E_CALLBACK *MenuItem_Enable)(PS2E_MenuItemHandle mitem, BOOL enable);
// Returns the current enable status of the specified menu item. // Returns the current enable status of the specified menu item.
BOOL (PS2E_CALLBACK* MenuItem_IsEnabled)( PS2E_MenuItemHandle mitem ); BOOL(PS2E_CALLBACK *MenuItem_IsEnabled)
(PS2E_MenuItemHandle mitem);
void* reserved[4]; void *reserved[4];
} PS2E_MenuItemAPI; } PS2E_MenuItemAPI;
@ -456,8 +455,8 @@ typedef struct _PS2E_SessionInfo
{ {
PS2E_HWND window; PS2E_HWND window;
u32* CycleEE; // current EE cycle count u32 *CycleEE; // current EE cycle count
u32* CycleIOP; // current IOP 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
@ -493,7 +492,7 @@ typedef struct _PS2E_EmulatorInfo
// Brief name of the emulator (ex: "PCSX2") [required] // Brief name of the emulator (ex: "PCSX2") [required]
// Depending on the design of the emulator, this string may optionally include version // 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. // information, however that is not recommended since it can inhibit backward support.
const char* EmuName; const char *EmuName;
// Version information. All fields besides the emulator's name are optional. // Version information. All fields besides the emulator's name are optional.
PS2E_VersionInfo EmuVersion; PS2E_VersionInfo EmuVersion;
@ -526,7 +525,8 @@ typedef struct _PS2E_EmulatorInfo
// Returns: // Returns:
// 0 - Value was retrieved successfully. // 0 - Value was retrieved successfully.
// 1 - Unknown value. Contents of dest are unchanged. // 1 - Unknown value. Contents of dest are unchanged.
BOOL (PS2E_CALLBACK* GetInt)( const char* name, int* dest ); BOOL(PS2E_CALLBACK *GetInt)
(const char *name, int *dest);
// GetBoolean // GetBoolean
// Assigns *dest either 1 (true) or 0 (false). Note to Emulators: Returning any non- // Assigns *dest either 1 (true) or 0 (false). Note to Emulators: Returning any non-
@ -536,7 +536,8 @@ typedef struct _PS2E_EmulatorInfo
// Returns: // Returns:
// 0 - Value was retrieved successfully. // 0 - Value was retrieved successfully.
// 1 - Unknown value. Contents of dest are unchanged. // 1 - Unknown value. Contents of dest are unchanged.
BOOL (PS2E_CALLBACK* GetBoolean)( const char* name, BOOL* result ); BOOL(PS2E_CALLBACK *GetBoolean)
(const char *name, BOOL *result);
// GetString // GetString
// Copies an ASCII-Z string into the dest pointer, to max length allowed. The result // Copies an ASCII-Z string into the dest pointer, to max length allowed. The result
@ -546,7 +547,8 @@ typedef struct _PS2E_EmulatorInfo
// Returns: // Returns:
// 0 - Value was retrieved successfully. // 0 - Value was retrieved successfully.
// 1 - Unknown value. Contents of dest are unchanged. // 1 - Unknown value. Contents of dest are unchanged.
BOOL (PS2E_CALLBACK* GetString)( const char* name, char* dest, int maxlen ); BOOL(PS2E_CALLBACK *GetString)
(const char *name, char *dest, int maxlen);
// GetStringAlloc // GetStringAlloc
// Provides an alternative to GetString, that can retrieve strings of arbitrary length. // Provides an alternative to GetString, that can retrieve strings of arbitrary length.
@ -556,7 +558,7 @@ typedef struct _PS2E_EmulatorInfo
// It is then the responsibility of the plugin to free the allocated pointer when it // It is then the responsibility of the plugin to free the allocated pointer when it
// is done with it. // is done with it.
// //
char* (PS2E_CALLBACK* GetStringAlloc)( const char* name, void* (PS2E_CALLBACK *allocator)(int size) ); char *(PS2E_CALLBACK *GetStringAlloc)(const char *name, void *(PS2E_CALLBACK *allocator)(int size));
// OSD_WriteLn // OSD_WriteLn
// This function allows the plugin to post messages to the emulator's On-Screen Display. // This function allows the plugin to post messages to the emulator's On-Screen Display.
@ -578,30 +580,30 @@ typedef struct _PS2E_EmulatorInfo
// //
// msg - string message displayed to the user. // msg - string message displayed to the user.
// //
void (PS2E_CALLBACK* OSD_WriteLn)( int icon, const char* msg ); 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 // 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 // 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. // 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 ); PS2E_MenuHandle(PS2E_CALLBACK *Menu_Create)(PS2E_THISPTR thisptr);
// Deletes the specified menu and frees its allocated memory resources. NULL pointers are // 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 // 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 // do not explicitly delete your plugin's menu resources, the emulator will do automatic
// cleanup after the plugin's instance is freed. // cleanup after the plugin's instance is freed.
void (PS2E_CALLBACK* Menu_Delete)( PS2E_MenuHandle handle ); 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 // 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 // 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 // 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. // multiple menus, you will need to create multiple instances of the item.
void (PS2E_CALLBACK* Menu_AddItem)( PS2E_MenuHandle menu, PS2E_MenuItemHandle mitem ); void(PS2E_CALLBACK *Menu_AddItem)(PS2E_MenuHandle menu, PS2E_MenuItemHandle mitem);
// Interface for creating menu items and modifying their properties. // Interface for creating menu items and modifying their properties.
PS2E_MenuItemAPI MenuItem; PS2E_MenuItemAPI MenuItem;
@ -617,7 +619,7 @@ typedef struct _PS2E_EmulatorInfo
// side before using this interface. See PS2E_ConsoleWriterWideAPI comments for more info. // side before using this interface. See PS2E_ConsoleWriterWideAPI comments for more info.
PS2E_ConsoleWriterWideAPI ConsoleW; PS2E_ConsoleWriterWideAPI ConsoleW;
void* reserved2[8]; void *reserved2[8];
} PS2E_EmulatorInfo; } PS2E_EmulatorInfo;
@ -630,7 +632,7 @@ typedef struct _PS2E_EmulatorInfo
typedef struct _PS2E_FreezeData typedef struct _PS2E_FreezeData
{ {
u32 Size; // size of the data being frozen or thawed. This value is allowed to be changed by Freeze(). 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) void *Data; // pointer to the data target (freeze) or source (thaw)
} PS2E_FreezeData; } PS2E_FreezeData;
@ -661,7 +663,7 @@ typedef struct _PS2E_ComponentAPI
// Threading: EmuOpen is called from the GUI thread. All other emulation threads are // 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). // 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 ); void(PS2E_CALLBACK *EmuOpen)(PS2E_THISPTR thisptr, const PS2E_SessionInfo *session);
// EmuClose // EmuClose
// This function is called by the emulator prior to stopping emulation. The window // This function is called by the emulator prior to stopping emulation. The window
@ -671,7 +673,7 @@ typedef struct _PS2E_ComponentAPI
// Threading: EmuClose is called from the GUI thread. All other emulation threads are // 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). // guaranteed to be suspended or closed at the time of this call (no locks required).
// //
void (PS2E_CALLBACK* EmuClose)( PS2E_THISPTR thisptr ); void(PS2E_CALLBACK *EmuClose)(PS2E_THISPTR thisptr);
// CalcFreezeSize // CalcFreezeSize
// This function should calculate and return the amount of memory needed for the plugin // This function should calculate and return the amount of memory needed for the plugin
@ -685,7 +687,7 @@ typedef struct _PS2E_ComponentAPI
// May be called from any thread (GUI, Emu, GS, Unknown, etc). // May be called from any thread (GUI, Emu, GS, Unknown, etc).
// All Emulation threads are halted at a PS2 logical vsync-end event. // All Emulation threads are halted at a PS2 logical vsync-end event.
// No locking is necessary. // No locking is necessary.
u32 (PS2E_CALLBACK* CalcFreezeSize)( PS2E_THISPTR thisptr ); u32(PS2E_CALLBACK *CalcFreezeSize)(PS2E_THISPTR thisptr);
// Freeze // Freeze
// This function should make a complete copy of the plugin's emulation state into the // This function should make a complete copy of the plugin's emulation state into the
@ -700,7 +702,7 @@ typedef struct _PS2E_ComponentAPI
// May be called from any thread (GUI, Emu, GS, Unknown, etc). // May be called from any thread (GUI, Emu, GS, Unknown, etc).
// All Emulation threads are halted at a PS2 logical vsync-end event. // All Emulation threads are halted at a PS2 logical vsync-end event.
// No locking is necessary. // No locking is necessary.
void (PS2E_CALLBACK* Freeze)( PS2E_THISPTR thisptr, PS2E_FreezeData* dest ); void(PS2E_CALLBACK *Freeze)(PS2E_THISPTR thisptr, PS2E_FreezeData *dest);
// Thaw // Thaw
// Plugin should restore a complete emulation state from the given FreezeData. The // Plugin should restore a complete emulation state from the given FreezeData. The
@ -711,7 +713,7 @@ typedef struct _PS2E_ComponentAPI
// May be called from any thread (GUI, Emu, GS, Unknown, etc). // May be called from any thread (GUI, Emu, GS, Unknown, etc).
// All Emulation threads are halted at a PS2 logical vsync-end event. // All Emulation threads are halted at a PS2 logical vsync-end event.
// No locking is necessary. // No locking is necessary.
void (PS2E_CALLBACK* Thaw)( PS2E_THISPTR thisptr, const PS2E_FreezeData* src ); void(PS2E_CALLBACK *Thaw)(PS2E_THISPTR thisptr, const PS2E_FreezeData *src);
// Configure // Configure
// The plugin should open a modal dialog box with plugin-specific settings and prop- // The plugin should open a modal dialog box with plugin-specific settings and prop-
@ -730,7 +732,7 @@ typedef struct _PS2E_ComponentAPI
// Thread Safety: // Thread Safety:
// Always called from the GUI thread, with emulation in a halted state (no locks // Always called from the GUI thread, with emulation in a halted state (no locks
// needed). // needed).
void (PS2E_CALLBACK* Configure)( PS2E_THISPTR thisptr ); void(PS2E_CALLBACK *Configure)(PS2E_THISPTR thisptr);
// GetLastError // GetLastError
// This is an optional method with allows the emulator to retrieve extended formatted // This is an optional method with allows the emulator to retrieve extended formatted
@ -754,10 +756,10 @@ typedef struct _PS2E_ComponentAPI
// * Interlocking: Instance. All calls from the emu are fully interlocked against // * Interlocking: Instance. All calls from the emu are fully interlocked against
// the plugin instance. // the plugin instance.
// //
void (PS2E_CALLBACK* GetLastError)( PS2E_THISPTR thisptr, char* const* msg_diag, wchar_t* const* msg_user ); 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. // Reserved area at the end of the structure, for future API expansion.
void* reserved[8]; void *reserved[8];
} PS2E_ComponentAPI; } PS2E_ComponentAPI;
@ -791,7 +793,7 @@ typedef struct _PS2E_LibraryAPI
// //
// This function may be called multiple times by the emulator, so it should accommodate // 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. // for such if it performs heap allocations or other initialization procedures.
const char* (PS2E_CALLBACK* GetName)(); const char *(PS2E_CALLBACK *GetName)();
// GetVersion // GetVersion
// This function returns name and version information for the requested PS2 component. // This function returns name and version information for the requested PS2 component.
@ -812,7 +814,7 @@ typedef struct _PS2E_LibraryAPI
// component - indicates the ps2 component plugin to be versioned. If the plugin // component - indicates the ps2 component plugin to be versioned. If the plugin
// does not support the requested component, the function should return NULL. // does not support the requested component, the function should return NULL.
// //
const PS2E_VersionInfo* (PS2E_CALLBACK* GetVersion)( u32 component ); const PS2E_VersionInfo *(PS2E_CALLBACK *GetVersion)(u32 component);
// Test // Test
// Called by the plugin enumerator to check the hardware availability of the specified // Called by the plugin enumerator to check the hardware availability of the specified
@ -824,7 +826,8 @@ typedef struct _PS2E_LibraryAPI
// have provisions in its interface to allow for the forced disabling of extended CPU cap- // have provisions in its interface to allow for the forced disabling of extended CPU cap-
// abilities, for testing purposes. // abilities, for testing purposes.
// //
BOOL (PS2E_CALLBACK* Test)( u32 component, const PS2E_EmulatorInfo* xinfo ); BOOL(PS2E_CALLBACK *Test)
(u32 component, const PS2E_EmulatorInfo *xinfo);
// NewComponentInstance // NewComponentInstance
// The emulator calls this function to fetch the API for the requested component. // The emulator calls this function to fetch the API for the requested component.
@ -851,12 +854,13 @@ typedef struct _PS2E_LibraryAPI
// Plugins may optionally prepare more detailed information on why the plugin failed // Plugins may optionally prepare more detailed information on why the plugin failed
// it's availability test which the emu can request via GetLastError. // it's availability test which the emu can request via GetLastError.
// //
PS2E_THISPTR (PS2E_CALLBACK* NewComponentInstance)( u32 component ); PS2E_THISPTR(PS2E_CALLBACK *NewComponentInstance)
(u32 component);
// DeleteComponentInstance // DeleteComponentInstance
// Called by the emulator when the plugin component is to be shutdown. The component API // Called by the emulator when the plugin component is to be shutdown. The component API
// instance pointer can be safely deleted here. // instance pointer can be safely deleted here.
void (PS2E_CALLBACK* DeleteComponentInstance)( PS2E_THISPTR instance ); void(PS2E_CALLBACK *DeleteComponentInstance)(PS2E_THISPTR instance);
// SetSettingsFolder // SetSettingsFolder
// Callback is passed an ASCII-Z string representing the folder where the emulator's // Callback is passed an ASCII-Z string representing the folder where the emulator's
@ -868,7 +872,7 @@ typedef struct _PS2E_LibraryAPI
// emulation state, shutdown plugins, and restart everything anew from the new settings // emulation state, shutdown plugins, and restart everything anew from the new settings
// in such an event as a dynamic change of the settings folder. // in such an event as a dynamic change of the settings folder.
// //
void (PS2E_CALLBACK* SetSettingsFolder)( const char* folder ); void(PS2E_CALLBACK *SetSettingsFolder)(const char *folder);
// SetLogFolder // SetLogFolder
// This callback may be issued at any time. It is the responsibility of the plugin // This callback may be issued at any time. It is the responsibility of the plugin
@ -879,12 +883,12 @@ typedef struct _PS2E_LibraryAPI
// This function is always called from the GUI thread. All emulation threads are // This function is always called from the GUI thread. All emulation threads are
// suspended during the call, so no locking is required. // suspended during the call, so no locking is required.
// //
void (PS2E_CALLBACK* SetLogFolder)( const char* folder ); void(PS2E_CALLBACK *SetLogFolder)(const char *folder);
// Reserved area at the end of the structure, for future API expansion. This area // 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 // 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. // defined functions here will recognize the functions as not supported by the plugin.
void* reserved[12]; void *reserved[12];
} PS2E_LibraryAPI; } PS2E_LibraryAPI;
@ -911,7 +915,7 @@ typedef struct _PS2E_ComponentAPI_GS
// This function may be called from either GUI thread or GS thread. Emulators calling // 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 // it from non-GS threads must ensure mutex locking with TakeSnapshot (meaning the
// plugin should be free to disregard threading concerns). // plugin should be free to disregard threading concerns).
void (PS2E_CALLBACK* GsSetSnapshotsFolder)( PS2E_THISPTR thisptr, const char* folder ); void(PS2E_CALLBACK *GsSetSnapshotsFolder)(PS2E_THISPTR thisptr, const char *folder);
// TakeSnapshot // TakeSnapshot
// The GS plugin is to save the current frame into the given target image. This // The GS plugin is to save the current frame into the given target image. This
@ -920,7 +924,8 @@ typedef struct _PS2E_ComponentAPI_GS
// //
// Returns TRUE if the snapshot succeeded, or FALSE if it failed (contents of dest // Returns TRUE if the snapshot succeeded, or FALSE if it failed (contents of dest
// are considered indeterminate and will be ignored by the emu). // are considered indeterminate and will be ignored by the emu).
BOOL (PS2E_CALLBACK* GsTakeSnapshot)( PS2E_THISPTR thisptr, PS2E_Image* dest ); BOOL(PS2E_CALLBACK *GsTakeSnapshot)
(PS2E_THISPTR thisptr, PS2E_Image *dest);
// OSD_QueueMessage // OSD_QueueMessage
// Queues a message to the GS for display to the user. The GS can print the message // Queues a message to the GS for display to the user. The GS can print the message
@ -937,7 +942,7 @@ typedef struct _PS2E_ComponentAPI_GS
// timeout - Suggested timeout period, in milliseconds. This is a hint and need // timeout - Suggested timeout period, in milliseconds. This is a hint and need
// not be strictly adhered to by the GS. // not be strictly adhered to by the GS.
// //
void (PS2E_CALLBACK* OSD_QueueMessage)( PS2E_THISPTR thisptr, const char* msg, int timeout ); void(PS2E_CALLBACK *OSD_QueueMessage)(PS2E_THISPTR thisptr, const char *msg, int timeout);
// OSD_IconStatus // OSD_IconStatus
// Sets the visibility status of an icon. Icon placement can be determined by the GS, // Sets the visibility status of an icon. Icon placement can be determined by the GS,
@ -949,7 +954,7 @@ typedef struct _PS2E_ComponentAPI_GS
// alpha - 0.0 is hdden, 1.0 is visible. Other alpha values may be used as either // 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 // transparency or as a scrolling factor (ie, to scroll the icon in and out of view, in
// any way the GS plugin sees fit). // any way the GS plugin sees fit).
void (PS2E_CALLBACK* OSD_IconStatus)( PS2E_THISPTR thisptr, OSDIconTypes iconId, float alpha ); void(PS2E_CALLBACK *OSD_IconStatus)(PS2E_THISPTR thisptr, OSDIconTypes iconId, float alpha);
// GSvsync // GSvsync
// //
@ -958,7 +963,8 @@ typedef struct _PS2E_ComponentAPI_GS
// (if any critical errors accumulated during GStransferTags or GStransferImage, they // (if any critical errors accumulated during GStransferTags or GStransferImage, they
// should also be handled here by returning FALSE) // should also be handled here by returning FALSE)
// //
BOOL (PS2E_CALLBACK* GsVsync)(int field); BOOL(PS2E_CALLBACK *GsVsync)
(int field);
// GSwriteRegs // GSwriteRegs
// Sends a GIFtag and associated register data. This is the main transfer method for all // Sends a GIFtag and associated register data. This is the main transfer method for all
@ -980,7 +986,7 @@ typedef struct _PS2E_ComponentAPI_GS
// //
// nloop - number of loops of register data. Valid range is 1->32767 (upper 17 // nloop - number of loops of register data. Valid range is 1->32767 (upper 17
// bits are always zero). This value will never be zero. // bits are always zero). This value will never be zero.
void (PS2E_CALLBACK* GsWriteRegs)(const u128 *pMem, int regcnt, int nloop); void(PS2E_CALLBACK *GsWriteRegs)(const u128 *pMem, int regcnt, int nloop);
// GSwritePrim // GSwritePrim
// Starts a new prim by sending the specified value to the PRIM register. The emulator // Starts a new prim by sending the specified value to the PRIM register. The emulator
@ -990,7 +996,7 @@ typedef struct _PS2E_ComponentAPI_GS
// Parameters: // Parameters:
// primData - value to write to the PRIM register. Only the bottom 10 bits are // primData - value to write to the PRIM register. Only the bottom 10 bits are
// valid. Upper bits are always zero. // valid. Upper bits are always zero.
void (PS2E_CALLBACK* GsWritePrim)(int primData); void(PS2E_CALLBACK *GsWritePrim)(int primData);
// GSwriteImage // GSwriteImage
// Uploads new image data. Data uploaded may be in any number of partial chunks, for // Uploads new image data. Data uploaded may be in any number of partial chunks, for
@ -1000,16 +1006,16 @@ typedef struct _PS2E_ComponentAPI_GS
// larger texture buffer, or for games to modify several portions of a single large // 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 // buffer, by using mid-transfer writes to TRXPOS and TRXDIR (TRXPOS writes only become
// effective once TRXDIR has been written). // effective once TRXDIR has been written).
void (PS2E_CALLBACK* GsWriteImage)(const u128 *pMem, int qwc_cnt); void(PS2E_CALLBACK *GsWriteImage)(const u128 *pMem, int qwc_cnt);
// GSreadImage // GSreadImage
// This special callback is for implementing the Read mode direction of the GIFpath. // 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 // 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 // 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. // and the GS must not write more than that.
void (PS2E_CALLBACK* GsReadImage)(u128 *pMem, int qwc_cnt); void(PS2E_CALLBACK *GsReadImage)(u128 *pMem, int qwc_cnt);
void* reserved[8]; void *reserved[8];
} PS2E_ComponentAPI_GS; } PS2E_ComponentAPI_GS;
@ -1047,7 +1053,8 @@ typedef struct _PS2E_ComponentAPI_Mcd
// Returns: // Returns:
// False if the card is not available, or True if it is available. // False if the card is not available, or True if it is available.
// //
BOOL (PS2E_CALLBACK* McdIsPresent)( PS2E_THISPTR thisptr, uint port, uint slot ); BOOL(PS2E_CALLBACK *McdIsPresent)
(PS2E_THISPTR thisptr, uint port, uint slot);
// McdGetSectorSize (can be NULL) // McdGetSectorSize (can be NULL)
// Requests memorycard formatting information from the Mcd provider. See the description of // Requests memorycard formatting information from the Mcd provider. See the description of
@ -1057,7 +1064,7 @@ typedef struct _PS2E_ComponentAPI_Mcd
// Returns: // Returns:
// Assigned values for memorycard sector size and sector count in 'outways.' // 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 ); void(PS2E_CALLBACK *McdGetSizeInfo)(PS2E_THISPTR thisptr, uint port, uint slot, PS2E_McdSizeInfo *outways);
// McdIsPSX // McdIsPSX
// Checks if the memorycard is a PSX one from the Mcd provider. // Checks if the memorycard is a PSX one from the Mcd provider.
@ -1065,7 +1072,7 @@ typedef struct _PS2E_ComponentAPI_Mcd
// Returns: // Returns:
// False: PS2, True: PSX // False: PS2, True: PSX
// //
bool (PS2E_CALLBACK* McdIsPSX)( PS2E_THISPTR thisptr, uint port, uint slot ); bool(PS2E_CALLBACK *McdIsPSX)(PS2E_THISPTR thisptr, uint port, uint slot);
// McdRead // McdRead
// Requests that a block of data be loaded from the memorycard into the specified dest // Requests that a block of data be loaded from the memorycard into the specified dest
@ -1077,7 +1084,8 @@ typedef struct _PS2E_ComponentAPI_Mcd
// False on failure, and True on success. Emulator may use GetLastError to retrieve additional // False on failure, and True on success. Emulator may use GetLastError to retrieve additional
// information for logging or displaying to the user. // 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 ); BOOL(PS2E_CALLBACK *McdRead)
(PS2E_THISPTR thisptr, uint port, uint slot, u8 *dest, u32 adr, int size);
// McdSave // McdSave
// Saves the provided block of data to the memorycard at the specified seek address. // Saves the provided block of data to the memorycard at the specified seek address.
@ -1088,7 +1096,8 @@ typedef struct _PS2E_ComponentAPI_Mcd
// False on failure, and True on success. Emulator may use GetLastError to retrieve additional // False on failure, and True on success. Emulator may use GetLastError to retrieve additional
// information for logging or displaying to the user. // 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 ); BOOL(PS2E_CALLBACK *McdSave)
(PS2E_THISPTR thisptr, uint port, uint slot, const u8 *src, u32 adr, int size);
// McdEraseBlock // McdEraseBlock
// Saves "cleared" data to the memorycard at the specified seek address. Cleared data // Saves "cleared" data to the memorycard at the specified seek address. Cleared data
@ -1100,18 +1109,19 @@ typedef struct _PS2E_ComponentAPI_Mcd
// False on failure, and True on success. Emulator may use GetLastError to retrieve additional // False on failure, and True on success. Emulator may use GetLastError to retrieve additional
// information for logging or displaying to the user. // information for logging or displaying to the user.
// //
BOOL (PS2E_CALLBACK* McdEraseBlock)( PS2E_THISPTR thisptr, uint port, uint slot, u32 adr ); 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 // McdNextFrame
// Inform the memory card that a frame of emulation time has passed. // 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. // 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 ); 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; } PS2E_ComponentAPI_Mcd;
@ -1120,14 +1130,12 @@ typedef struct _PS2E_ComponentAPI_Mcd
// KeyEvent type enumerations // KeyEvent type enumerations
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
enum PS2E_KeyEventTypes enum PS2E_KeyEventTypes {
{
PS2E_KEY_UP = 0, PS2E_KEY_UP = 0,
PS2E_KEY_DOWN PS2E_KEY_DOWN
}; };
enum PS2E_KeyModifiers enum PS2E_KeyModifiers {
{
PS2E_SHIFT = 1, PS2E_SHIFT = 1,
PS2E_CONTROL = 2, PS2E_CONTROL = 2,
PS2E_ALT = 4 PS2E_ALT = 4
@ -1176,7 +1184,8 @@ typedef struct _PS2E_ComponentAPI_Pad
// Returns: // Returns:
// False if the card/pad is not available, or True if it is available. // 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 ); BOOL(PS2E_CALLBACK *PadIsPresent)
(PS2E_THISPTR thisptr, uint port, uint slot);
// PadStartPoll // PadStartPoll
// Called by the emulator to start polling the specified pad. // Called by the emulator to start polling the specified pad.
@ -1188,7 +1197,7 @@ typedef struct _PS2E_ComponentAPI_Pad
// Called from the EEcore thread. The emulator performs no locking of its own, so // Called from the EEcore thread. The emulator performs no locking of its own, so
// calls to this may occur concurrently with calls to PadUpdate. // calls to this may occur concurrently with calls to PadUpdate.
// //
u8 (PS2E_CALLBACK* PadStartPoll)( PS2E_THISPTR thisptr, uint port, uint slot ); u8(PS2E_CALLBACK *PadStartPoll)(PS2E_THISPTR thisptr, uint port, uint slot);
// PadPoll // PadPoll
// Continues polling the specified pad, sending the given value. // Continues polling the specified pad, sending the given value.
@ -1200,7 +1209,7 @@ typedef struct _PS2E_ComponentAPI_Pad
// Called from the EEcore thread. The emulator performs no locking of its own, so // Called from the EEcore thread. The emulator performs no locking of its own, so
// calls to this may occur concurrently with calls to PadUpdate. // calls to this may occur concurrently with calls to PadUpdate.
// //
u8 (PS2E_CALLBACK* PadPoll)( PS2E_THISPTR thisptr, u8 value ); u8(PS2E_CALLBACK *PadPoll)(PS2E_THISPTR thisptr, u8 value);
// PadKeyEvent // PadKeyEvent
// Called by the emulator in the gui thread to check for keys being pressed or released. // Called by the emulator in the gui thread to check for keys being pressed or released.
@ -1213,7 +1222,7 @@ typedef struct _PS2E_ComponentAPI_Pad
// May be called from any thread. The emulator performs no locking of its own, so // 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. // calls to this may occur concurrently with calls to PadUpdate.
// //
PS2E_KeyEvent* (PS2E_CALLBACK* PadGetKeyEvent)( PS2E_THISPTR thisptr ); PS2E_KeyEvent *(PS2E_CALLBACK *PadGetKeyEvent)(PS2E_THISPTR thisptr);
// PadUpdate // PadUpdate
// This callback is issued from the thread that owns the GSwindow, at roughly 50/60hz, // This callback is issued from the thread that owns the GSwindow, at roughly 50/60hz,
@ -1225,9 +1234,9 @@ typedef struct _PS2E_ComponentAPI_Pad
// or an MTGS thread). The emulator performs no locking of its own, so calls to this // 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. // may occur concurrently with calls to PadKeyEvent and PadPoll.
// //
void (PS2E_CALLBACK* PadUpdate)( PS2E_THISPTR thisptr ); void(PS2E_CALLBACK *PadUpdate)(PS2E_THISPTR thisptr);
void* reserved[8]; void *reserved[8];
} PS2E_ComponentAPI_Pad; } PS2E_ComponentAPI_Pad;
@ -1260,7 +1269,7 @@ typedef struct _PS2E_ComponentAPI_Pad
// * Affinity: Called only from the Main/GUI thread. // * Affinity: Called only from the Main/GUI thread.
// * Interlocking: Full interlocking garaunteed. // * 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 // 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 // msg_user - optional translated user message, which is displayed as a popup to explain
// to the user why the plugin failed to initialize. // 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);
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////

View File

@ -31,10 +31,9 @@ class Pcsx2AppTraits : public wxGUIAppTraits
public: public:
virtual ~Pcsx2AppTraits() {} virtual ~Pcsx2AppTraits() {}
wxMessageOutput* CreateMessageOutput(); wxMessageOutput *CreateMessageOutput();
#ifdef wxUSE_STDPATHS #ifdef wxUSE_STDPATHS
wxStandardPaths& GetStandardPaths(); wxStandardPaths &GetStandardPaths();
#endif #endif
}; };

View File

@ -17,14 +17,14 @@
#ifndef __pxFUNCTION__ #ifndef __pxFUNCTION__
#if defined(__GNUG__) #if defined(__GNUG__)
# define __pxFUNCTION__ __PRETTY_FUNCTION__ #define __pxFUNCTION__ __PRETTY_FUNCTION__
#else #else
# define __pxFUNCTION__ __FUNCTION__ #define __pxFUNCTION__ __FUNCTION__
#endif #endif
#endif #endif
#ifndef wxNullChar #ifndef wxNullChar
# define wxNullChar ((wxChar*)NULL) #define wxNullChar ((wxChar *)NULL)
#endif #endif
// FnChar_t - function name char type; typedef'd in case it ever changes between compilers // 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 struct DiagnosticOrigin
{ {
const wxChar* srcfile; const wxChar *srcfile;
const FnChar_t* function; const FnChar_t *function;
const wxChar* condition; const wxChar *condition;
int line; int line;
DiagnosticOrigin( const wxChar *_file, int _line, const FnChar_t *_func, const wxChar* _cond = NULL ) DiagnosticOrigin(const wxChar *_file, int _line, const FnChar_t *_func, const wxChar *_cond = NULL)
: srcfile( _file ) : srcfile(_file)
, function( _func ) , function(_func)
, condition( _cond ) , condition(_cond)
, line( _line ) , 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 // Returns ture if the assertion is to trap into the debugger, or false if execution
// of the program should continue unimpeded. // 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 pxAssertImpl_LogIt;
extern pxDoAssertFnType* pxDoAssert; extern pxDoAssertFnType *pxDoAssert;
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// pxAssert / pxAssertDev // 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 // 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); // builds. To have code optimized, explicitly use pxAssume(false) or pxAssumeDev(false,msg);
#define pxDiagSpot DiagnosticOrigin( __TFILE__, __LINE__, __pxFUNCTION__ ) #define pxDiagSpot DiagnosticOrigin(__TFILE__, __LINE__, __pxFUNCTION__)
#define pxAssertSpot(cond) DiagnosticOrigin( __TFILE__, __LINE__, __pxFUNCTION__, _T(#cond) ) #define pxAssertSpot(cond) DiagnosticOrigin(__TFILE__, __LINE__, __pxFUNCTION__, _T(#cond))
// pxAssertRel -> // pxAssertRel ->
// Special release-mode assertion. Limited use since stack traces in release mode builds // 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 // (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. // 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 pxAssertRel(cond, msg) ((likely(cond)) || (pxOnAssert(pxAssertSpot(cond), msg), false))
#define pxAssumeRel(cond, msg) ((void) ( (!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 pxFailRel(msg) pxAssertRel(false, msg)
#if defined(PCSX2_DEBUG) #if defined(PCSX2_DEBUG)
# define pxAssertMsg(cond, msg) pxAssertRel(cond, msg) #define pxAssertMsg(cond, msg) pxAssertRel(cond, msg)
# define pxAssertDev(cond, msg) pxAssertMsg(cond, msg) #define pxAssertDev(cond, msg) pxAssertMsg(cond, msg)
# define pxAssumeMsg(cond, msg) pxAssumeRel(cond, msg) #define pxAssumeMsg(cond, msg) pxAssumeRel(cond, msg)
# define pxAssumeDev(cond, msg) pxAssumeRel(cond, msg) #define pxAssumeDev(cond, msg) pxAssumeRel(cond, msg)
# define pxFail(msg) pxAssertMsg(false, msg) #define pxFail(msg) pxAssertMsg(false, msg)
# define pxFailDev(msg) pxAssertDev(false, msg) #define pxFailDev(msg) pxAssertDev(false, msg)
#elif defined(PCSX2_DEVBUILD) #elif defined(PCSX2_DEVBUILD)
// Devel builds now will give you a release-mode assertion dialog window if any of the // Devel builds now will give you a release-mode assertion dialog window if any of the
// following macro's 'cond' field is false. // following macro's 'cond' field is false.
// Note: Only use pxAssume/Msg/Dev if you know what you're doing, __assume is supposed // 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 // to be used as an optimization hint, yet many devs have been using psAssume
// thinking its the same as an assertion. // thinking its the same as an assertion.
// __assume(0) is also very dangerous because it is a special case of __assume() which // __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 // tells the compiler that the code path is not reachable, and it can cause unpredictable
// results if the code path can be reached. // results if the code path can be reached.
// i.e. if (1) { __assume(0); something(); } // i.e. if (1) { __assume(0); something(); }
// In the above example, something() may never be called. // 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 // __assume(0)'s real use is in optimizing stuff such as "default:" cases on a switch
// statement. See jNO_DEFAULT // statement. See jNO_DEFAULT
# define pxAssertMsg(cond, msg) pxAssertRel(cond, msg) #define pxAssertMsg(cond, msg) pxAssertRel(cond, msg)
# define pxAssertDev(cond, msg) pxAssertRel(cond, msg) #define pxAssertDev(cond, msg) pxAssertRel(cond, msg)
# define pxAssumeMsg(cond, msg) pxAssumeRel(cond, msg) //(__assume(cond)) #define pxAssumeMsg(cond, msg) pxAssumeRel(cond, msg) //(__assume(cond))
# define pxAssumeDev(cond, msg) pxAssumeRel(cond, msg) #define pxAssumeDev(cond, msg) pxAssumeRel(cond, msg)
# define pxFail(msg) pxAssertDev(false, msg) #define pxFail(msg) pxAssertDev(false, msg)
# define pxFailDev(msg) pxAssertDev(false, msg) #define pxFailDev(msg) pxAssertDev(false, msg)
#else #else
// Release Builds just use __assume as an optimization, and return the conditional // Release Builds just use __assume as an optimization, and return the conditional
// as a result (which is optimized to nil if unused). // as a result (which is optimized to nil if unused).
# define pxAssertMsg(cond, msg) (likely(cond)) #define pxAssertMsg(cond, msg) (likely(cond))
# define pxAssertDev(cond, msg) (likely(cond)) #define pxAssertDev(cond, msg) (likely(cond))
# define pxAssumeMsg(cond, msg) (__assume(cond)) #define pxAssumeMsg(cond, msg) (__assume(cond))
# define pxAssumeDev(cond, msg) (__assume(cond)) #define pxAssumeDev(cond, msg) (__assume(cond))
# define pxFail(msg) do{} while(0) #define pxFail(msg) \
# define pxFailDev(msg) do{} while(0) do { \
} while (0)
#define pxFailDev(msg) \
do { \
} while (0)
#endif #endif
#define pxAssert(cond) pxAssertMsg(cond, wxNullChar) #define pxAssert(cond) pxAssertMsg(cond, wxNullChar)
#define pxAssume(cond) pxAssumeMsg(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. // 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 // For stricter checking in Devel builds as well as debug builds (but possibly slower), use
// IndexBoundsCheckDev. // IndexBoundsCheckDev.
#define IndexBoundsCheck( objname, idx, sze ) pxAssertMsg( (uint)(idx) < (uint)(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) ) ) 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), \ #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) ) ) 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), \ #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) ) ) 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), \ #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) ) ) 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 wxChar *msg = NULL);
extern void pxOnAssert( const DiagnosticOrigin& origin, const char* msg ); 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 wxString &msg);
extern void pxOnAssert( const DiagnosticOrigin& origin, const FastFormatUnicode& msg); extern void pxOnAssert(const DiagnosticOrigin &origin, const FastFormatUnicode &msg);
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// jNO_DEFAULT -- disables the default case in a switch, which improves switch optimization // 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. // * In debug/devel builds the default case will cause an assertion.
// //
#ifndef jNO_DEFAULT #ifndef jNO_DEFAULT
# define jNO_DEFAULT \ #define jNO_DEFAULT \
default: \ default: { \
{ \ pxAssumeDev(0, "Incorrect usage of jNO_DEFAULT detected (default case is not unreachable!)"); \
pxAssumeDev( 0, "Incorrect usage of jNO_DEFAULT detected (default case is not unreachable!)" ); \
break; \ break; \
} }
#endif #endif

View File

@ -22,16 +22,16 @@ class CheckedStaticBox : public wxPanelWithHelpers
typedef wxPanelWithHelpers _parent; typedef wxPanelWithHelpers _parent;
public: public:
wxBoxSizer& ThisSizer; // Boxsizer which holds all child items. wxBoxSizer &ThisSizer; // Boxsizer which holds all child items.
wxCheckBox& ThisToggle; // toggle which can enable/disable all child controls wxCheckBox &ThisToggle; // toggle which can enable/disable all child controls
public: public:
CheckedStaticBox( wxWindow* parent, int orientation, const wxString& title=wxEmptyString ); CheckedStaticBox(wxWindow *parent, int orientation, const wxString &title = wxEmptyString);
void SetValue( bool val ); void SetValue(bool val);
bool GetValue() const; bool GetValue() const;
bool Enable( bool enable = true ); bool Enable(bool enable = true);
public: public:
virtual void MainToggle_Click( wxCommandEvent& evt ); virtual void MainToggle_Click(wxCommandEvent &evt);
}; };

View File

@ -17,8 +17,7 @@
#include "StringHelpers.h" #include "StringHelpers.h"
enum ConsoleColors enum ConsoleColors {
{
Color_Current = -1, Color_Current = -1,
Color_Default = 0, Color_Default = 0,
@ -73,28 +72,28 @@ struct IConsoleWriter
{ {
// A direct console write, without tabbing or newlines. Useful to devs who want to do quick // 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. // logging of various junk; but should *not* be used in production code due.
void (__concall *WriteRaw)( const wxString& fmt ); void(__concall *WriteRaw)(const wxString &fmt);
// WriteLn implementation for internal use only. Bypasses tabbing, prefixing, and other // WriteLn implementation for internal use only. Bypasses tabbing, prefixing, and other
// formatting. // formatting.
void (__concall *DoWriteLn)( const wxString& fmt ); void(__concall *DoWriteLn)(const wxString &fmt);
// SetColor implementation for internal use only. // SetColor implementation for internal use only.
void (__concall *DoSetColor)( ConsoleColors color ); void(__concall *DoSetColor)(ConsoleColors color);
// Special implementation of DoWrite that's pretty much for MSVC use only. // 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. // All implementations should map to DoWrite, except Stdio which should map to Null.
// (This avoids circular/recursive stdio output) // (This avoids circular/recursive stdio output)
void (__concall *DoWriteFromStdout)( const wxString& fmt ); void(__concall *DoWriteFromStdout)(const wxString &fmt);
void (__concall *Newline)(); void(__concall *Newline)();
void (__concall *SetTitle)( const wxString& title ); void(__concall *SetTitle)(const wxString &title);
// internal value for indentation of individual lines. Use the Indent() member to invoke. // internal value for indentation of individual lines. Use the Indent() member to invoke.
int _imm_indentation; int _imm_indentation;
// For internal use only. // For internal use only.
wxString _addIndentation( const wxString& src, int glob_indent ) const; wxString _addIndentation(const wxString &src, int glob_indent) const;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Public members; call these to print stuff to console! // Public members; call these to print stuff to console!
@ -103,28 +102,28 @@ struct IConsoleWriter
// disable logs at compile time using the "0&&action" macro trick. // disable logs at compile time using the "0&&action" macro trick.
ConsoleColors GetColor() const; ConsoleColors GetColor() const;
const IConsoleWriter& SetColor( ConsoleColors color ) const; const IConsoleWriter &SetColor(ConsoleColors color) const;
const IConsoleWriter& ClearColor() const; const IConsoleWriter &ClearColor() const;
const IConsoleWriter& SetIndent( int tabcount=1 ) 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 FormatV(const char *fmt, va_list args) const;
bool WriteLn( ConsoleColors color, const char* fmt, ... ) const; bool WriteLn(ConsoleColors color, const char *fmt, ...) const;
bool WriteLn( const char* fmt, ... ) const; bool WriteLn(const char *fmt, ...) const;
bool Error( const char* fmt, ... ) const; bool Error(const char *fmt, ...) const;
bool Warning( const char* fmt, ... ) const; bool Warning(const char *fmt, ...) const;
bool FormatV( const wxChar* fmt, va_list args ) const; bool FormatV(const wxChar *fmt, va_list args) const;
bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const; bool WriteLn(ConsoleColors color, const wxChar *fmt, ...) const;
bool WriteLn( const wxChar* fmt, ... ) const; bool WriteLn(const wxChar *fmt, ...) const;
bool Error( const wxChar* fmt, ... ) const; bool Error(const wxChar *fmt, ...) const;
bool Warning( const wxChar* fmt, ... ) const; bool Warning(const wxChar *fmt, ...) const;
bool WriteLn( ConsoleColors color, const wxString fmt, ... ) const; bool WriteLn(ConsoleColors color, const wxString fmt, ...) const;
bool WriteLn( const wxString fmt, ... ) const; bool WriteLn(const wxString fmt, ...) const;
bool Error( const wxString fmt, ... ) const; bool Error(const wxString fmt, ...) const;
bool Warning( const wxString fmt, ... ) const; bool Warning(const wxString fmt, ...) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -134,37 +133,37 @@ struct IConsoleWriter
// //
struct NullConsoleWriter struct NullConsoleWriter
{ {
void WriteRaw( const wxString& fmt ) {} void WriteRaw(const wxString &fmt) {}
void DoWriteLn( const wxString& fmt ) {} void DoWriteLn(const wxString &fmt) {}
void DoSetColor( ConsoleColors color ) {} void DoSetColor(ConsoleColors color) {}
void DoWriteFromStdout( const wxString& fmt ) {} void DoWriteFromStdout(const wxString &fmt) {}
void Newline() {} void Newline() {}
void SetTitle( const wxString& title ) {} void SetTitle(const wxString &title) {}
ConsoleColors GetColor() const { return Color_Current; } ConsoleColors GetColor() const { return Color_Current; }
const NullConsoleWriter& SetColor( ConsoleColors color ) const { return *this; } const NullConsoleWriter &SetColor(ConsoleColors color) const { return *this; }
const NullConsoleWriter& ClearColor() const { return *this; } const NullConsoleWriter &ClearColor() const { return *this; }
const NullConsoleWriter& SetIndent( int tabcount=1 ) 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 FormatV(const char *fmt, va_list args) const { return false; }
bool WriteLn( ConsoleColors color, const char* fmt, ... ) const { return false; } bool WriteLn(ConsoleColors color, const char *fmt, ...) const { return false; }
bool WriteLn( const char* fmt, ... ) const { return false; } bool WriteLn(const char *fmt, ...) const { return false; }
bool Error( const char* fmt, ... ) const { return false; } bool Error(const char *fmt, ...) const { return false; }
bool Warning( 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 FormatV(const wxChar *fmt, va_list args) const { return false; }
bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const { return false; } bool WriteLn(ConsoleColors color, const wxChar *fmt, ...) const { return false; }
bool WriteLn( const wxChar* fmt, ... ) const { return false; } bool WriteLn(const wxChar *fmt, ...) const { return false; }
bool Error( const wxChar* fmt, ... ) const { return false; } bool Error(const wxChar *fmt, ...) const { return false; }
bool Warning( 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(ConsoleColors color, const wxString fmt, ...) const { return false; }
bool WriteLn( const wxString fmt, ... ) const { return false; } bool WriteLn(const wxString fmt, ...) const { return false; }
bool Error( const wxString fmt, ... ) const { return false; } bool Error(const wxString fmt, ...) const { return false; }
bool Warning( const wxString fmt, ... ) const { return false; } bool Warning(const wxString fmt, ...) const { return false; }
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -180,7 +179,7 @@ struct NullConsoleWriter
// //
class ConsoleIndentScope class ConsoleIndentScope
{ {
DeclareNoncopyableObject( ConsoleIndentScope ); DeclareNoncopyableObject(ConsoleIndentScope);
protected: protected:
int m_amount; int m_amount;
@ -189,7 +188,7 @@ protected:
public: public:
// Constructor: The specified number of tabs will be appended to the current indentation // 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. // setting. The tabs will be unrolled when the object leaves scope or is destroyed.
ConsoleIndentScope( int tabs=1 ); ConsoleIndentScope(int tabs = 1);
virtual ~ConsoleIndentScope() throw(); virtual ~ConsoleIndentScope() throw();
void EnterScope(); void EnterScope();
void LeaveScope(); void LeaveScope();
@ -200,7 +199,7 @@ public:
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class ConsoleColorScope class ConsoleColorScope
{ {
DeclareNoncopyableObject( ConsoleColorScope ); DeclareNoncopyableObject(ConsoleColorScope);
protected: protected:
ConsoleColors m_newcolor; ConsoleColors m_newcolor;
@ -208,7 +207,7 @@ protected:
bool m_IsScoped; bool m_IsScoped;
public: public:
ConsoleColorScope( ConsoleColors newcolor ); ConsoleColorScope(ConsoleColors newcolor);
virtual ~ConsoleColorScope() throw(); virtual ~ConsoleColorScope() throw();
void EnterScope(); void EnterScope();
void LeaveScope(); void LeaveScope();
@ -221,14 +220,14 @@ public:
// //
class ConsoleAttrScope class ConsoleAttrScope
{ {
DeclareNoncopyableObject( ConsoleAttrScope ); DeclareNoncopyableObject(ConsoleAttrScope);
protected: protected:
ConsoleColors m_old_color; ConsoleColors m_old_color;
int m_tabsize; int m_tabsize;
public: public:
ConsoleAttrScope( ConsoleColors newcolor, int indent=0 ); ConsoleAttrScope(ConsoleColors newcolor, int indent = 0);
virtual ~ConsoleAttrScope() throw(); virtual ~ConsoleAttrScope() throw();
}; };
@ -237,7 +236,7 @@ extern IConsoleWriter Console;
#if defined(__unix__) #if defined(__unix__)
extern void Console_SetStdout(FILE *fp); extern void Console_SetStdout(FILE *fp);
#endif #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_Null;
extern const IConsoleWriter ConsoleWriter_Stdout; extern const IConsoleWriter ConsoleWriter_Stdout;
@ -249,14 +248,14 @@ extern IConsoleWriter DevConWriter;
extern bool DevConWriterEnabled; extern bool DevConWriterEnabled;
#ifdef PCSX2_DEVBUILD #ifdef PCSX2_DEVBUILD
# define DevCon DevConWriter #define DevCon DevConWriter
#else #else
# define DevCon DevConWriterEnabled && DevConWriter #define DevCon DevConWriterEnabled &&DevConWriter
#endif #endif
#ifdef PCSX2_DEBUG #ifdef PCSX2_DEBUG
extern IConsoleWriter DbgConWriter; extern IConsoleWriter DbgConWriter;
# define DbgCon DbgConWriter #define DbgCon DbgConWriter
#else #else
# define DbgCon 0&&NullCon #define DbgCon 0 && NullCon
#endif #endif

View File

@ -24,19 +24,19 @@
#define wxsFormat wxString::Format #define wxsFormat wxString::Format
#ifdef PCSX2_DEBUG #ifdef PCSX2_DEBUG
# define tryDEBUG try #define tryDEBUG try
# define catchDEBUG(clause) catch(clause) #define catchDEBUG(clause) catch (clause)
#else #else
# define tryDEBUG if(true) #define tryDEBUG if (true)
# define catchDEBUG(clause) if(false) #define catchDEBUG(clause) if (false)
#endif #endif
#if defined(PCSX2_DEVBUILD) || defined(PCSX2_DEBUG) #if defined(PCSX2_DEVBUILD) || defined(PCSX2_DEBUG)
# define tryDEVEL try #define tryDEVEL try
# define catchDEVEL catch(clause) #define catchDEVEL catch (clause)
#else #else
# define tryDEBUG if(true) #define tryDEBUG if (true)
# define catchDEBUG(clause) if(false) #define catchDEBUG(clause) if (false)
#endif #endif
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -61,24 +61,48 @@
// method is not implemented! You must implement it yourself if you want to use it: // method is not implemented! You must implement it yourself if you want to use it:
// EnumToString(value); // EnumToString(value);
// //
#define ImplementEnumOperators( enumName ) \ #define ImplementEnumOperators(enumName) \
static __fi enumName& operator++ ( enumName& src ) { src = (enumName)((int)src+1); return src; } \ static __fi enumName &operator++(enumName &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; } \ src = (enumName)((int)src + 1); \
static __fi enumName operator-- ( enumName& src, int ) { enumName orig = src; src = (enumName)((int)src-1); return orig; } \ 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 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 ) { \ static __fi bool EnumIsValid(enumName id) \
return ((int)id >= enumName##_FIRST) && ((int)id < enumName##_COUNT); } \ { \
static __fi void EnumAssert( enumName id ) { \ return ((int)id >= enumName##_FIRST) && ((int)id < enumName##_COUNT); \
pxAssert( EnumIsValid(id) ); } \ } \
static __fi void EnumAssert(enumName id) \
{ \
pxAssert(EnumIsValid(id)); \
} \
\ \
extern const wxChar* EnumToString( enumName id ) extern const wxChar *EnumToString(enumName id)
class pxEnumEnd_t { }; class pxEnumEnd_t
{
};
static const pxEnumEnd_t pxEnumEnd = {}; static const pxEnumEnd_t pxEnumEnd = {};
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -105,10 +129,10 @@ static const pxEnumEnd_t pxEnumEnd = {};
// of wx dependencies though, and has a nicer typeset. :) // of wx dependencies though, and has a nicer typeset. :)
// //
#ifndef DeclareNoncopyableObject #ifndef DeclareNoncopyableObject
# define DeclareNoncopyableObject(classname) \ #define DeclareNoncopyableObject(classname) \
private: \ private: \
explicit classname(const classname&); \ explicit classname(const classname &); \
classname& operator=(const classname&) classname &operator=(const classname &)
#endif #endif
@ -120,10 +144,10 @@ static const pxEnumEnd_t pxEnumEnd = {};
class ScopedBool class ScopedBool
{ {
protected: protected:
bool* m_boolme; bool *m_boolme;
public: public:
ScopedBool(bool& boolme) ScopedBool(bool &boolme)
{ {
boolme = true; boolme = true;
m_boolme = &boolme; m_boolme = &boolme;
@ -149,15 +173,15 @@ public:
#define WXINTL_NO_GETTEXT_MACRO #define WXINTL_NO_GETTEXT_MACRO
#ifndef _ #ifndef _
# define _(s) pxGetTranslation(_T(s)) #define _(s) pxGetTranslation(_T(s))
#endif #endif
#ifndef _t #ifndef _t
# define _t(s) pxGetTranslation(_T(s)) #define _t(s) pxGetTranslation(_T(s))
#endif #endif
#ifndef _d #ifndef _d
# define _d(s) pxGetTranslation(_T(s)) #define _d(s) pxGetTranslation(_T(s))
#endif #endif
// pxL / pxLt / pxDt -- macros provided for tagging translation strings, without actually running // pxL / pxLt / pxDt -- macros provided for tagging translation strings, without actually running
@ -167,15 +191,15 @@ public:
// debug/devel specific translations. // debug/devel specific translations.
// //
#ifndef pxL #ifndef pxL
# define pxL(a) wxT(a) #define pxL(a) wxT(a)
#endif #endif
#ifndef pxLt #ifndef pxLt
# define pxLt(a) wxT(a) #define pxLt(a) wxT(a)
#endif #endif
#ifndef pxDt #ifndef pxDt
# define pxDt(a) wxT(a) #define pxDt(a) wxT(a)
#endif #endif
@ -228,21 +252,21 @@ static const s64 _4gb = _1gb * 4;
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// pxE(msg) and pxEt(msg) [macros] => now same as _/_t/_d // 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). // 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). // 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 pxExpandMsg(const wxChar *englishContent);
extern const wxChar* __fastcall pxGetTranslation( const wxChar* message ); extern const wxChar *__fastcall pxGetTranslation(const wxChar *message);
extern bool pxIsEnglish( int id ); extern bool pxIsEnglish(int id);
extern wxString fromUTF8( const char* src ); extern wxString fromUTF8(const char *src);
extern wxString fromAscii( const char* src ); extern wxString fromAscii(const char *src);
#include "Utilities/Assertions.h" #include "Utilities/Assertions.h"

View File

@ -25,8 +25,8 @@
class IEmbeddedImage class IEmbeddedImage
{ {
public: public:
virtual const wxImage& Get()=0; virtual const wxImage &Get() = 0;
virtual wxImage Scale( int width, int height )=0; virtual wxImage Scale(int width, int height) = 0;
}; };
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -38,7 +38,7 @@ public:
// Note: Get() only loads the image once. All subsequent calls to Get will use the // Note: Get() only loads the image once. All subsequent calls to Get will use the
// previously loaded image data. // previously loaded image data.
// //
template< typename ImageType > template <typename ImageType>
class EmbeddedImage : public IEmbeddedImage class EmbeddedImage : public IEmbeddedImage
{ {
protected: protected:
@ -52,20 +52,19 @@ protected:
// //
void _loadImage() void _loadImage()
{ {
if( !m_Image.Ok() ) if (!m_Image.Ok()) {
{ wxMemoryInputStream joe(ImageType::Data, ImageType::Length);
wxMemoryInputStream joe( ImageType::Data, ImageType::Length ); m_Image.LoadFile(joe, ImageType::GetFormat());
m_Image.LoadFile( joe, ImageType::GetFormat() );
if( m_ResampleTo.IsFullySpecified() && ( m_ResampleTo.GetWidth() != m_Image.GetWidth() || m_ResampleTo.GetHeight() != m_Image.GetHeight() ) ) 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 ); m_Image.Rescale(m_ResampleTo.GetWidth(), m_ResampleTo.GetHeight(), wxIMAGE_QUALITY_HIGH);
} }
} }
public: public:
EmbeddedImage() : EmbeddedImage()
m_Image() : m_Image()
, m_ResampleTo( wxDefaultSize ) , m_ResampleTo(wxDefaultSize)
{ {
} }
@ -78,9 +77,9 @@ public:
// sampling images (basically resembles a pixel resize). ResampleBox produces much cleaner // sampling images (basically resembles a pixel resize). ResampleBox produces much cleaner
// results. // results.
// //
EmbeddedImage( int newWidth, int newHeight ) : EmbeddedImage(int newWidth, int newHeight)
m_Image() : m_Image()
, m_ResampleTo( newWidth, newHeight ) , m_ResampleTo(newWidth, newHeight)
{ {
} }
@ -91,7 +90,7 @@ public:
// and only happens when the image is actually fetched. Simply creating an instance // and only happens when the image is actually fetched. Simply creating an instance
// of an EmbeddedImage object uses no excess memory nor cpu overhead. :) // of an EmbeddedImage object uses no excess memory nor cpu overhead. :)
// //
const wxImage& Get() const wxImage &Get()
{ {
_loadImage(); _loadImage();
return m_Image; return m_Image;
@ -100,7 +99,7 @@ public:
wxIcon GetIcon() wxIcon GetIcon()
{ {
wxIcon retval; wxIcon retval;
retval.CopyFromBitmap( Get() ); retval.CopyFromBitmap(Get());
return retval; return retval;
} }
@ -109,14 +108,13 @@ public:
// is left unmodified). // is left unmodified).
// //
wxImage Scale( int width, int height ) wxImage Scale(int width, int height)
{ {
_loadImage(); _loadImage();
// Not strictly necessary - wxWidgets does the dimensions check anyway. // Not strictly necessary - wxWidgets does the dimensions check anyway.
if( width != m_Image.GetWidth() || height != m_Image.GetHeight() ) if (width != m_Image.GetWidth() || height != m_Image.GetHeight())
return m_Image.Scale( width, height, wxIMAGE_QUALITY_HIGH ); return m_Image.Scale(width, height, wxIMAGE_QUALITY_HIGH);
else else
return m_Image; return m_Image;
} }
}; };

View File

@ -22,12 +22,12 @@
// EventSource< template EvtType > // EventSource< template EvtType >
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
template< typename ListenerType > template <typename ListenerType>
class EventSource class EventSource
{ {
public: public:
typedef typename ListenerType::EvtParams EvtParams; typedef typename ListenerType::EvtParams EvtParams;
typedef typename std::list< ListenerType* > ListenerList; typedef typename std::list<ListenerType *> ListenerList;
typedef typename ListenerList::iterator ListenerIterator; typedef typename ListenerList::iterator ListenerIterator;
protected: protected:
@ -51,27 +51,29 @@ public:
virtual ~EventSource() throw() {} virtual ~EventSource() throw() {}
virtual ListenerIterator Add( ListenerType& listener ); virtual ListenerIterator Add(ListenerType &listener);
virtual void Remove( ListenerType& listener ); virtual void Remove(ListenerType &listener);
virtual void Remove( const ListenerIterator& listenerHandle ); virtual void Remove(const ListenerIterator &listenerHandle);
void Add( ListenerType* listener ) void Add(ListenerType *listener)
{ {
if( listener == NULL ) return; if (listener == NULL)
Add( *listener ); return;
Add(*listener);
} }
void Remove( ListenerType* listener ) void Remove(ListenerType *listener)
{ {
if( listener == NULL ) return; if (listener == NULL)
Remove( *listener ); return;
Remove(*listener);
} }
void Dispatch( const EvtParams& params ); void Dispatch(const EvtParams &params);
protected: protected:
virtual ListenerIterator _AddFast_without_lock( ListenerType& listener ); virtual ListenerIterator _AddFast_without_lock(ListenerType &listener);
virtual void _DispatchRaw( ListenerIterator iter, const ListenerIterator& iend, const EvtParams& params ); virtual void _DispatchRaw(ListenerIterator iter, const ListenerIterator &iend, const EvtParams &params);
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -80,7 +82,7 @@ protected:
// This class is used as a base interface for EventListeners. It allows the listeners to do // 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. // customized dispatching of several event types into "user friendly" function overrides.
// //
template< typename EvtParams > template <typename EvtParams>
class IEventDispatcher class IEventDispatcher
{ {
protected: protected:
@ -88,5 +90,5 @@ protected:
public: public:
virtual ~IEventDispatcher() throw() {} virtual ~IEventDispatcher() throw() {}
virtual void DispatchEvent( const EvtParams& params )=0; virtual void DispatchEvent(const EvtParams &params) = 0;
}; };

View File

@ -19,88 +19,80 @@
using Threading::ScopedLock; using Threading::ScopedLock;
template< typename ListenerType > template <typename ListenerType>
typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::Add( ListenerType& listener ) typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::Add(ListenerType &listener)
{ {
ScopedLock locker( m_listeners_lock ); ScopedLock locker(m_listeners_lock);
// Check for duplicates before adding the event. // Check for duplicates before adding the event.
if( IsDebugBuild ) if (IsDebugBuild) {
{
ListenerIterator iter = m_listeners.begin(); ListenerIterator iter = m_listeners.begin();
while( iter != m_listeners.end() ) while (iter != m_listeners.end()) {
{ if ((*iter) == &listener)
if( (*iter) == &listener ) return iter; return iter;
++iter; ++iter;
} }
} }
return _AddFast_without_lock( listener ); return _AddFast_without_lock(listener);
} }
template< typename ListenerType > template <typename ListenerType>
void EventSource<ListenerType>::Remove( ListenerType& listener ) void EventSource<ListenerType>::Remove(ListenerType &listener)
{ {
ScopedLock locker( m_listeners_lock ); ScopedLock locker(m_listeners_lock);
m_cache_valid = false; m_cache_valid = false;
m_listeners.remove( &listener ); m_listeners.remove(&listener);
} }
template< typename ListenerType > template <typename ListenerType>
void EventSource<ListenerType>::Remove( const ListenerIterator& listenerHandle ) void EventSource<ListenerType>::Remove(const ListenerIterator &listenerHandle)
{ {
ScopedLock locker( m_listeners_lock ); ScopedLock locker(m_listeners_lock);
m_cache_valid = false; m_cache_valid = false;
m_listeners.erase( listenerHandle ); m_listeners.erase(listenerHandle);
} }
template< typename ListenerType > template <typename ListenerType>
typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::_AddFast_without_lock( ListenerType& listener ) typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::_AddFast_without_lock(ListenerType &listener)
{ {
m_cache_valid = false; m_cache_valid = false;
m_listeners.push_front( &listener ); m_listeners.push_front(&listener);
return m_listeners.begin(); return m_listeners.begin();
} }
template< typename ListenerType > template <typename ListenerType>
__fi void EventSource<ListenerType>::_DispatchRaw( ListenerIterator iter, const ListenerIterator& iend, const EvtParams& evtparams ) __fi void EventSource<ListenerType>::_DispatchRaw(ListenerIterator iter, const ListenerIterator &iend, const EvtParams &evtparams)
{ {
while( iter != iend ) while (iter != iend) {
{
try { try {
(*iter)->DispatchEvent( evtparams ); (*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( Exception::RuntimeError& ex ) } catch (BaseException &ex) {
{ if (IsDevBuild) {
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(); ex.DiagMsg() = L"Non-runtime BaseException thrown from event listener .. " + ex.DiagMsg();
throw; throw;
} }
Console.Error( L"Ignoring non-runtime BaseException thrown from event listener: " + ex.FormatDiagnosticMessage() ); Console.Error(L"Ignoring non-runtime BaseException thrown from event listener: " + ex.FormatDiagnosticMessage());
} }
++iter; ++iter;
} }
} }
template< typename ListenerType > template <typename ListenerType>
void EventSource<ListenerType>::Dispatch( const EvtParams& evtparams ) void EventSource<ListenerType>::Dispatch(const EvtParams &evtparams)
{ {
if( !m_cache_valid ) if (!m_cache_valid) {
{
m_cache_copy = m_listeners; m_cache_copy = m_listeners;
m_cache_valid = true; m_cache_valid = true;
} }
if( m_cache_copy.empty() ) return; if (m_cache_copy.empty())
_DispatchRaw( m_cache_copy.begin(), m_cache_copy.end(), evtparams ); return;
_DispatchRaw(m_cache_copy.begin(), m_cache_copy.end(), evtparams);
} }

View File

@ -30,71 +30,72 @@ void pxTrap();
// friendly error log in their wake. // friendly error log in their wake.
// //
// Note: Console can also fire an Exception::OutOfMemory // Note: Console can also fire an Exception::OutOfMemory
#define __DESTRUCTOR_CATCHALL( funcname ) \ #define __DESTRUCTOR_CATCHALL(funcname) \
catch( BaseException& ex ) \ catch (BaseException & ex) \
{ \ { \
try { \ try { \
Console.Error( "Unhandled BaseException in %s (ignored!):", funcname ); \ Console.Error("Unhandled BaseException in %s (ignored!):", funcname); \
Console.Error( ex.FormatDiagnosticMessage() ); \ Console.Error(ex.FormatDiagnosticMessage()); \
} catch (...) { \ } catch (...) { \
fprintf(stderr, "ERROR: (out of memory?)\n"); \ fprintf(stderr, "ERROR: (out of memory?)\n"); \
} \ } \
} \ } \
catch( std::exception& ex ) \ catch (std::exception & ex) \
{ \ { \
try { \ try { \
Console.Error( "Unhandled std::exception in %s (ignored!):", funcname ); \ Console.Error("Unhandled std::exception in %s (ignored!):", funcname); \
Console.Error( ex.what() ); \ Console.Error(ex.what()); \
} catch (...) { \ } catch (...) { \
fprintf(stderr, "ERROR: (out of memory?)\n"); \ fprintf(stderr, "ERROR: (out of memory?)\n"); \
} \ } \
} \ } \
catch(...) { \ catch (...) \
{ \
/* Unreachable code */ \ /* Unreachable code */ \
} }
#define DESTRUCTOR_CATCHALL __DESTRUCTOR_CATCHALL( __pxFUNCTION__ ) #define DESTRUCTOR_CATCHALL __DESTRUCTOR_CATCHALL(__pxFUNCTION__)
namespace Exception namespace Exception
{ {
int MakeNewType(); int MakeNewType();
BaseException* FromErrno( const wxString& streamname, int errcode ); BaseException *FromErrno(const wxString &streamname, int errcode);
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// BaseException // BaseException
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// std::exception sucks, and isn't entirely cross-platform reliable in its implementation, // 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 // 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. // 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. // Note, this class is "abstract" which means you shouldn't use it directly like, ever.
// Use Exception::RuntimeError instead for generic exceptions. // Use Exception::RuntimeError instead for generic exceptions.
// //
// Because exceptions are the (only!) really useful example of multiple inheritance, // Because exceptions are the (only!) really useful example of multiple inheritance,
// this class has only a trivial constructor, and must be manually initialized using // 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 // 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. // is, by design, a lot of fail, especially when class initializers are mixed in.
// //
// [TODO] : Add an InnerException component, and Clone() facility. // [TODO] : Add an InnerException component, and Clone() facility.
// //
class BaseException class BaseException
{ {
protected: protected:
wxString m_message_diag; // (untranslated) a "detailed" message of what disastrous thing has occurred! 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! wxString m_message_user; // (translated) a "detailed" message of what disastrous thing has occurred!
public: public:
virtual ~BaseException() throw()=0; // the =0; syntax forces this class into "abstract" mode. virtual ~BaseException() throw() = 0; // the =0; syntax forces this class into "abstract" mode.
const wxString& DiagMsg() const { return m_message_diag; } const wxString &DiagMsg() const { return m_message_diag; }
const wxString& UserMsg() const { return m_message_user; } const wxString &UserMsg() const { return m_message_user; }
wxString& DiagMsg() { return m_message_diag; } wxString &DiagMsg() { return m_message_diag; }
wxString& UserMsg() { return m_message_user; } wxString &UserMsg() { return m_message_user; }
BaseException& SetBothMsgs( const wxChar* msg_diag ); BaseException &SetBothMsgs(const wxChar *msg_diag);
BaseException& SetDiagMsg( const wxString& msg_diag ); BaseException &SetDiagMsg(const wxString &msg_diag);
BaseException& SetUserMsg( const wxString& msg_user ); BaseException &SetUserMsg(const wxString &msg_user);
// Returns a message suitable for diagnostic / logging purposes. // Returns a message suitable for diagnostic / logging purposes.
// This message is always in English, and includes a full stack trace. // This message is always in English, and includes a full stack trace.
@ -104,38 +105,38 @@ namespace Exception
// This message is usually meant for display in a user popup or such. // This message is usually meant for display in a user popup or such.
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
virtual void Rethrow() const=0; virtual void Rethrow() const = 0;
virtual BaseException* Clone() const=0; virtual BaseException *Clone() const = 0;
}; };
typedef std::unique_ptr<BaseException> ScopedExcept; typedef std::unique_ptr<BaseException> ScopedExcept;
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// Ps2Generic Exception // Ps2Generic Exception
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// This class is used as a base exception for things tossed by PS2 cpus (EE, IOP, etc). // 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 // Implementation note: does not derive from BaseException, so that we can use different
// catch block hierarchies to handle them (if needed). // catch block hierarchies to handle them (if needed).
// //
// Translation Note: Currently these exceptions are never translated. English/diagnostic // Translation Note: Currently these exceptions are never translated. English/diagnostic
// format only. :) // format only. :)
// //
class Ps2Generic class Ps2Generic
{ {
protected: protected:
wxString m_message; // a "detailed" message of what disastrous thing has occurred! wxString m_message; // a "detailed" message of what disastrous thing has occurred!
public: public:
virtual ~Ps2Generic() throw() {} virtual ~Ps2Generic() throw() {}
virtual u32 GetPc() const=0; virtual u32 GetPc() const = 0;
virtual bool IsDelaySlot() const=0; virtual bool IsDelaySlot() const = 0;
virtual wxString& Message() { return m_message; } virtual wxString &Message() { return m_message; }
virtual void Rethrow() const=0; virtual void Rethrow() const = 0;
virtual Ps2Generic* Clone() const=0; virtual Ps2Generic *Clone() const = 0;
}; };
// Some helper macros for defining the standard constructors of internationalized constructors // Some helper macros for defining the standard constructors of internationalized constructors
// Parameters: // Parameters:
@ -151,58 +152,71 @@ namespace Exception
// //
// (update: web searches indicate it's MSVC specific -- happens in 2008, not sure about 2010). // (update: web searches indicate it's MSVC specific -- happens in 2008, not sure about 2010).
// //
#define DEFINE_EXCEPTION_COPYTORS( classname, parent ) \ #define DEFINE_EXCEPTION_COPYTORS(classname, parent) \
private: \ private: \
typedef parent _parent; \ typedef parent _parent; \
\
public: \ public: \
virtual ~classname() throw() {} \ virtual ~classname() throw() {} \
virtual void Rethrow() const { throw *this; } \ virtual void Rethrow() const { throw * this; } \
virtual classname* Clone() const { return new classname( *this ); } virtual classname *Clone() const { return new classname(*this); }
#define DEFINE_EXCEPTION_MESSAGES( classname ) \ #define DEFINE_EXCEPTION_MESSAGES(classname) \
public: \ public: \
classname& SetBothMsgs( const wxChar* msg_diag ) { BaseException::SetBothMsgs(msg_diag); return *this; } \ classname &SetBothMsgs(const wxChar *msg_diag) \
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; } 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 DEFINE_RUNTIME_EXCEPTION(classname, parent, message) \
DEFINE_EXCEPTION_COPYTORS( classname, parent ) \ DEFINE_EXCEPTION_COPYTORS(classname, parent) \
classname() { SetDiagMsg(message); } \ classname() { SetDiagMsg(message); } \
DEFINE_EXCEPTION_MESSAGES( classname ) DEFINE_EXCEPTION_MESSAGES(classname)
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// RuntimeError - Generalized Exceptions with Recoverable Traits! // RuntimeError - Generalized Exceptions with Recoverable Traits!
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
class RuntimeError : public BaseException class RuntimeError : public BaseException
{ {
DEFINE_EXCEPTION_COPYTORS( RuntimeError, BaseException ) DEFINE_EXCEPTION_COPYTORS(RuntimeError, BaseException)
DEFINE_EXCEPTION_MESSAGES( RuntimeError ) DEFINE_EXCEPTION_MESSAGES(RuntimeError)
public: public:
bool IsSilent; bool IsSilent;
RuntimeError() { IsSilent = false; } RuntimeError() { IsSilent = false; }
RuntimeError( const std::runtime_error& ex, const wxString& prefix=wxEmptyString ); RuntimeError(const std::runtime_error &ex, const wxString &prefix = wxEmptyString);
RuntimeError( const std::exception& ex, const wxString& prefix=wxEmptyString ); RuntimeError(const std::exception &ex, const wxString &prefix = wxEmptyString);
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// CancelAppEvent - Exception for canceling an event in a non-verbose fashion // CancelAppEvent - Exception for canceling an event in a non-verbose fashion
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// Typically the PCSX2 interface issues popup dialogs for runtime errors. This exception // 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 // instead issues a "silent" cancelation that is handled by the app gracefully (generates
// log, and resumes messages queue processing). // log, and resumes messages queue processing).
// //
// I chose to have this exception derive from RuntimeError, since if one is thrown from outside // 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. // an App message loop we'll still want it to be handled in a reasonably graceful manner.
class CancelEvent : public RuntimeError class CancelEvent : public RuntimeError
{ {
DEFINE_RUNTIME_EXCEPTION( CancelEvent, RuntimeError, pxLt("No reason given.") ) DEFINE_RUNTIME_EXCEPTION(CancelEvent, RuntimeError, pxLt("No reason given."))
public: public:
explicit CancelEvent( const wxString& logmsg ) explicit CancelEvent(const wxString &logmsg)
{ {
m_message_diag = logmsg; m_message_diag = logmsg;
// overridden message formatters only use the diagnostic version... // overridden message formatters only use the diagnostic version...
@ -210,158 +224,167 @@ public: \
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
}; };
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// OutOfMemory // OutOfMemory
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// This exception has a custom-formatted Diagnostic string. The parameter give when constructing // 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 // 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." // output. The default diagnostic message is "Out of memory exception, while allocating the %s."
// where %s is filled in with the block name. // where %s is filled in with the block name.
// //
// The user string is not custom-formatted, and should contain *NO* %s tags. // The user string is not custom-formatted, and should contain *NO* %s tags.
// //
class OutOfMemory : public RuntimeError class OutOfMemory : public RuntimeError
{ {
DEFINE_RUNTIME_EXCEPTION( OutOfMemory, RuntimeError, wxEmptyString ) DEFINE_RUNTIME_EXCEPTION(OutOfMemory, RuntimeError, wxEmptyString)
public: public:
wxString AllocDescription; wxString AllocDescription;
public: public:
OutOfMemory( const wxString& allocdesc ); OutOfMemory(const wxString &allocdesc);
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
}; };
class ParseError : public RuntimeError class ParseError : public RuntimeError
{ {
DEFINE_RUNTIME_EXCEPTION( ParseError, RuntimeError, pxL("Parse error") ); DEFINE_RUNTIME_EXCEPTION(ParseError, RuntimeError, pxL("Parse error"));
}; };
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// Hardware/OS Exceptions: // Hardware/OS Exceptions:
// HardwareDeficiency / VirtualMemoryMapConflict // HardwareDeficiency / VirtualMemoryMapConflict
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// This exception is a specific type of OutOfMemory error that isn't "really" an out of // 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 // 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. // we'd really like to have access to.
class VirtualMemoryMapConflict : public OutOfMemory class VirtualMemoryMapConflict : public OutOfMemory
{ {
DEFINE_RUNTIME_EXCEPTION( VirtualMemoryMapConflict, OutOfMemory, wxEmptyString ) DEFINE_RUNTIME_EXCEPTION(VirtualMemoryMapConflict, OutOfMemory, wxEmptyString)
VirtualMemoryMapConflict( const wxString& allocdesc ); VirtualMemoryMapConflict(const wxString &allocdesc);
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
}; };
class HardwareDeficiency : public RuntimeError class HardwareDeficiency : public RuntimeError
{ {
public: public:
DEFINE_RUNTIME_EXCEPTION( HardwareDeficiency, RuntimeError, pxL("Your machine's hardware is incapable of running PCSX2. Sorry dood.") ); DEFINE_RUNTIME_EXCEPTION(HardwareDeficiency, RuntimeError, pxL("Your machine's hardware is incapable of running PCSX2. Sorry dood."));
}; };
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// Streaming (file) Exceptions: // Streaming (file) Exceptions:
// Stream / BadStream / CannotCreateStream / FileNotFound / AccessDenied / EndOfStream // Stream / BadStream / CannotCreateStream / FileNotFound / AccessDenied / EndOfStream
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
#define DEFINE_STREAM_EXCEPTION_ACCESSORS( classname ) \ #define DEFINE_STREAM_EXCEPTION_ACCESSORS(classname) \
virtual classname& SetStreamName( const wxString& name ) { StreamName = name; return *this; } \ virtual classname &SetStreamName(const wxString &name) \
virtual classname& SetStreamName( const char* name ) { StreamName = fromUTF8(name); return *this; } { \
StreamName = name; \
return *this; \
} \
virtual classname &SetStreamName(const char *name) \
{ \
StreamName = fromUTF8(name); \
return *this; \
}
#define DEFINE_STREAM_EXCEPTION( classname, parent ) \ #define DEFINE_STREAM_EXCEPTION(classname, parent) \
DEFINE_RUNTIME_EXCEPTION( classname, parent, wxEmptyString ) \ DEFINE_RUNTIME_EXCEPTION(classname, parent, wxEmptyString) \
classname( const wxString& filename ) { \ classname(const wxString &filename) \
{ \
StreamName = filename; \ StreamName = filename; \
} \ } \
DEFINE_STREAM_EXCEPTION_ACCESSORS( classname ) DEFINE_STREAM_EXCEPTION_ACCESSORS(classname)
// A generic base error class for bad streams -- corrupted data, sudden closures, loss of // 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 // connection, or anything else that would indicate a failure to open a stream or read the
// data after the stream was successfully opened. // data after the stream was successfully opened.
// //
class BadStream : public RuntimeError class BadStream : public RuntimeError
{ {
DEFINE_STREAM_EXCEPTION( BadStream, RuntimeError ) DEFINE_STREAM_EXCEPTION(BadStream, RuntimeError)
public: public:
wxString StreamName; // name of the stream (if applicable) wxString StreamName; // name of the stream (if applicable)
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
protected: protected:
void _formatDiagMsg( FastFormatUnicode& dest ) const; void _formatDiagMsg(FastFormatUnicode &dest) const;
void _formatUserMsg( FastFormatUnicode& dest ) const; void _formatUserMsg(FastFormatUnicode &dest) const;
}; };
// A generic exception for odd-ball stream creation errors. // A generic exception for odd-ball stream creation errors.
// //
class CannotCreateStream : public BadStream class CannotCreateStream : public BadStream
{ {
DEFINE_STREAM_EXCEPTION( CannotCreateStream, BadStream ) DEFINE_STREAM_EXCEPTION(CannotCreateStream, BadStream)
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
}; };
// Exception thrown when an attempt to open a non-existent file is made. // Exception thrown when an attempt to open a non-existent file is made.
// (this exception can also mean file permissions are invalid) // (this exception can also mean file permissions are invalid)
// //
class FileNotFound : public CannotCreateStream class FileNotFound : public CannotCreateStream
{ {
public: public:
DEFINE_STREAM_EXCEPTION( FileNotFound, CannotCreateStream ) DEFINE_STREAM_EXCEPTION(FileNotFound, CannotCreateStream)
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
}; };
class AccessDenied : public CannotCreateStream class AccessDenied : public CannotCreateStream
{ {
public: public:
DEFINE_STREAM_EXCEPTION( AccessDenied, CannotCreateStream ) DEFINE_STREAM_EXCEPTION(AccessDenied, CannotCreateStream)
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
}; };
// EndOfStream can be used either as an error, or used just as a shortcut for manual // EndOfStream can be used either as an error, or used just as a shortcut for manual
// feof checks. // feof checks.
// //
class EndOfStream : public BadStream class EndOfStream : public BadStream
{ {
public: public:
DEFINE_STREAM_EXCEPTION( EndOfStream, BadStream ) DEFINE_STREAM_EXCEPTION(EndOfStream, BadStream)
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
}; };
#ifdef __WXMSW__ #ifdef __WXMSW__
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// Exception::WinApiError // Exception::WinApiError
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class WinApiError : public RuntimeError class WinApiError : public RuntimeError
{ {
DEFINE_EXCEPTION_COPYTORS( WinApiError, RuntimeError ) DEFINE_EXCEPTION_COPYTORS(WinApiError, RuntimeError)
DEFINE_EXCEPTION_MESSAGES( WinApiError ) DEFINE_EXCEPTION_MESSAGES(WinApiError)
public: public:
int ErrorId; int ErrorId;
public: public:
WinApiError(); WinApiError();
wxString GetMsgFromWindows() const; wxString GetMsgFromWindows() const;
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
}; };
#endif #endif
} }

View File

@ -17,58 +17,58 @@
#include "Dependencies.h" #include "Dependencies.h"
template< int Precision > template <int Precision>
struct FixedInt struct FixedInt
{ {
s32 Raw; s32 Raw;
FixedInt(); FixedInt();
FixedInt( int signedval ); FixedInt(int signedval);
FixedInt( double doubval ); FixedInt(double doubval);
FixedInt( float floval ); FixedInt(float floval);
bool operator ==( const FixedInt<Precision>& right ) const { return Raw == right.Raw; } bool operator==(const FixedInt<Precision> &right) const { return Raw == right.Raw; }
bool operator !=( const FixedInt<Precision>& right ) const { return Raw != right.Raw; } bool operator!=(const FixedInt<Precision> &right) const { return Raw != right.Raw; }
bool operator>( const FixedInt<Precision>& right ) const { return Raw > right.Raw; }; bool operator>(const FixedInt<Precision> &right) const { return Raw > right.Raw; };
bool operator>=( const FixedInt<Precision>& right ) const { return Raw >= right.Raw; }; bool operator>=(const FixedInt<Precision> &right) const { return Raw >= right.Raw; };
bool operator<( const FixedInt<Precision>& right ) const { return Raw < right.Raw; }; bool operator<(const FixedInt<Precision> &right) const { return Raw < right.Raw; };
bool operator<=( const FixedInt<Precision>& right ) const { return Raw <= right.Raw; }; bool operator<=(const FixedInt<Precision> &right) const { return Raw <= right.Raw; };
FixedInt<Precision> operator+( const FixedInt<Precision>& right ) const; FixedInt<Precision> operator+(const FixedInt<Precision> &right) const;
FixedInt<Precision> operator-( const FixedInt<Precision>& right ) const; FixedInt<Precision> operator-(const FixedInt<Precision> &right) const;
FixedInt<Precision>& operator+=( const FixedInt<Precision>& right ); FixedInt<Precision> &operator+=(const FixedInt<Precision> &right);
FixedInt<Precision>& operator-=( const FixedInt<Precision>& right ); FixedInt<Precision> &operator-=(const FixedInt<Precision> &right);
FixedInt<Precision>& ConfineTo( const FixedInt<Precision>& low, const FixedInt<Precision>& high ); FixedInt<Precision> &ConfineTo(const FixedInt<Precision> &low, const FixedInt<Precision> &high);
FixedInt<Precision> operator*( const FixedInt<Precision>& right ) const; FixedInt<Precision> operator*(const FixedInt<Precision> &right) const;
FixedInt<Precision> operator/( const FixedInt<Precision>& right ) const; FixedInt<Precision> operator/(const FixedInt<Precision> &right) const;
FixedInt<Precision>& operator*=( const FixedInt<Precision>& right ); FixedInt<Precision> &operator*=(const FixedInt<Precision> &right);
FixedInt<Precision>& operator/=( const FixedInt<Precision>& right ); FixedInt<Precision> &operator/=(const FixedInt<Precision> &right);
static bool OverflowCheck( int signedval ); static bool OverflowCheck(int signedval);
static bool OverflowCheck( double signedval ); static bool OverflowCheck(double signedval);
int GetWhole() const; int GetWhole() const;
int GetFraction() const; int GetFraction() const;
FixedInt<Precision>& SetRaw( s32 rawsrc ); FixedInt<Precision> &SetRaw(s32 rawsrc);
FixedInt<Precision>& Round(); FixedInt<Precision> &Round();
FixedInt<Precision>& SetWhole( s32 wholepart ); FixedInt<Precision> &SetWhole(s32 wholepart);
FixedInt<Precision>& SetFraction( u32 fracpart ); FixedInt<Precision> &SetFraction(u32 fracpart);
wxString ToString() const; wxString ToString() const;
wxString ToString( int fracDigits ) const; wxString ToString(int fracDigits) const;
double ToDouble() const; double ToDouble() const;
float ToFloat() const; float ToFloat() const;
int ToIntTruncated() const; int ToIntTruncated() const;
int ToIntRounded() const; int ToIntRounded() const;
static bool TryFromString( FixedInt<Precision>& dest, const wxString& parseFrom ); static bool TryFromString(FixedInt<Precision> &dest, const wxString &parseFrom);
static FixedInt<Precision> FromString( const wxString& parseFrom, const FixedInt<Precision>& defval ); static FixedInt<Precision> FromString(const wxString &parseFrom, const FixedInt<Precision> &defval);
static FixedInt<Precision> FromString( const wxString parseFrom ); static FixedInt<Precision> FromString(const wxString parseFrom);
}; };
typedef FixedInt<256> Fixed256; typedef FixedInt<256> Fixed256;

View File

@ -18,223 +18,234 @@
#include "FixedPointTypes.h" #include "FixedPointTypes.h"
#include <cmath> // for pow! #include <cmath> // for pow!
template< int Precision > template <int Precision>
FixedInt<Precision>::FixedInt() FixedInt<Precision>::FixedInt()
{ {
Raw = 0; Raw = 0;
} }
template< int Precision > template <int Precision>
FixedInt<Precision>::FixedInt( int signedval ) FixedInt<Precision>::FixedInt(int signedval)
{ {
Raw = signedval * Precision; Raw = signedval * Precision;
} }
template< int Precision > template <int Precision>
FixedInt<Precision>::FixedInt( double doubval ) FixedInt<Precision>::FixedInt(double doubval)
{ {
Raw = lround(doubval * (double)Precision); Raw = lround(doubval * (double)Precision);
} }
template< int Precision > template <int Precision>
FixedInt<Precision>::FixedInt( float floval ) FixedInt<Precision>::FixedInt(float floval)
{ {
Raw = lroundf(floval * (float)Precision); Raw = lroundf(floval * (float)Precision);
} }
template< int Precision > template <int Precision>
FixedInt<Precision> FixedInt<Precision>::operator+( const FixedInt<Precision>& right ) const FixedInt<Precision> FixedInt<Precision>::operator+(const FixedInt<Precision> &right) const
{ {
return FixedInt<Precision>().SetRaw( Raw + right.Raw ); return FixedInt<Precision>().SetRaw(Raw + right.Raw);
} }
template< int Precision > template <int Precision>
FixedInt<Precision> FixedInt<Precision>::operator-( const FixedInt<Precision>& right ) const FixedInt<Precision> FixedInt<Precision>::operator-(const FixedInt<Precision> &right) const
{ {
return FixedInt<Precision>().SetRaw( Raw + right.Raw ); return FixedInt<Precision>().SetRaw(Raw + right.Raw);
} }
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::operator+=( const FixedInt<Precision>& right ) FixedInt<Precision> &FixedInt<Precision>::operator+=(const FixedInt<Precision> &right)
{ {
return SetRaw( Raw + right.Raw ); return SetRaw(Raw + right.Raw);
} }
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::operator-=( const FixedInt<Precision>& right ) FixedInt<Precision> &FixedInt<Precision>::operator-=(const FixedInt<Precision> &right)
{ {
return SetRaw( Raw + right.Raw ); return SetRaw(Raw + right.Raw);
} }
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::ConfineTo( const FixedInt<Precision>& low, const FixedInt<Precision>& high ) FixedInt<Precision> &FixedInt<Precision>::ConfineTo(const FixedInt<Precision> &low, const FixedInt<Precision> &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 // Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math
// you'll need to use the Raw values directly. // you'll need to use the Raw values directly.
template< int Precision > template <int Precision>
FixedInt<Precision> FixedInt<Precision>::operator*( const FixedInt<Precision>& right ) const FixedInt<Precision> FixedInt<Precision>::operator*(const FixedInt<Precision> &right) const
{ {
s64 mulres = (s64)Raw * right.Raw; s64 mulres = (s64)Raw * right.Raw;
return FixedInt<Precision>().SetRaw( (s32)(mulres / Precision) ); return FixedInt<Precision>().SetRaw((s32)(mulres / Precision));
} }
// Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math // Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math
// you'll need to use the Raw values directly. // you'll need to use the Raw values directly.
template< int Precision > template <int Precision>
FixedInt<Precision> FixedInt<Precision>::operator/( const FixedInt<Precision>& right ) const FixedInt<Precision> FixedInt<Precision>::operator/(const FixedInt<Precision> &right) const
{ {
s64 divres = Raw * Precision; s64 divres = Raw * Precision;
return FixedInt<Precision>().SetRaw( (s32)(divres / right.Raw) ); return FixedInt<Precision>().SetRaw((s32)(divres / right.Raw));
} }
// Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math // Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math
// you'll need to use the Raw values directly. // you'll need to use the Raw values directly.
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::operator*=( const FixedInt<Precision>& right ) FixedInt<Precision> &FixedInt<Precision>::operator*=(const FixedInt<Precision> &right)
{ {
s64 mulres = (s64)Raw * right.Raw; s64 mulres = (s64)Raw * right.Raw;
return SetRaw( (s32)(mulres / Precision) ); return SetRaw((s32)(mulres / Precision));
} }
// Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math // Uses 64 bit internally to avoid overflows. For more precise/optimized 32 bit math
// you'll need to use the Raw values directly. // you'll need to use the Raw values directly.
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::operator/=( const FixedInt<Precision>& right ) FixedInt<Precision> &FixedInt<Precision>::operator/=(const FixedInt<Precision> &right)
{ {
s64 divres = Raw * Precision; s64 divres = Raw * Precision;
return SetRaw( (s32)(divres / right.Raw) ); return SetRaw((s32)(divres / right.Raw));
} }
// returns TRUE if the value overflows the legal integer range of this container. // returns TRUE if the value overflows the legal integer range of this container.
template< int Precision > template <int Precision>
bool FixedInt<Precision>::OverflowCheck( int signedval ) bool FixedInt<Precision>::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. // returns TRUE if the value overflows the legal integer range of this container.
template< int Precision > template <int Precision>
bool FixedInt<Precision>::OverflowCheck( double signedval ) bool FixedInt<Precision>::OverflowCheck(double signedval)
{ {
return ( signedval >= (INT_MAX / Precision) ); return (signedval >= (INT_MAX / Precision));
} }
template< int Precision > int FixedInt<Precision>::GetWhole() const { return Raw / Precision; } template <int Precision>
template< int Precision > int FixedInt<Precision>::GetFraction() const { return Raw % Precision; } int FixedInt<Precision>::GetWhole() const
{
return Raw / Precision;
}
template <int Precision>
int FixedInt<Precision>::GetFraction() const
{
return Raw % Precision;
}
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::SetRaw( s32 rawsrc ) FixedInt<Precision> &FixedInt<Precision>::SetRaw(s32 rawsrc)
{ {
Raw = rawsrc; Raw = rawsrc;
return *this; return *this;
} }
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::Round() FixedInt<Precision> &FixedInt<Precision>::Round()
{ {
Raw = ToIntRounded(); Raw = ToIntRounded();
return *this; return *this;
} }
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::SetWhole( s32 wholepart ) FixedInt<Precision> &FixedInt<Precision>::SetWhole(s32 wholepart)
{ {
pxAssert( wholepart < (INT_MAX / Precision) ); pxAssert(wholepart < (INT_MAX / Precision));
Raw = GetFraction() + (wholepart * Precision); Raw = GetFraction() + (wholepart * Precision);
return *this; return *this;
} }
template< int Precision > template <int Precision>
FixedInt<Precision>& FixedInt<Precision>::SetFraction( u32 fracpart ) FixedInt<Precision> &FixedInt<Precision>::SetFraction(u32 fracpart)
{ {
Raw = (GetWhole() * Precision) + fracpart; Raw = (GetWhole() * Precision) + fracpart;
return *this; return *this;
} }
template< int Precision > template <int Precision>
wxString FixedInt<Precision>::ToString() const wxString FixedInt<Precision>::ToString() const
{ {
return wxsFormat( L"%d.%02d", GetWhole(), (GetFraction() * 100) / Precision ); return wxsFormat(L"%d.%02d", GetWhole(), (GetFraction() * 100) / Precision);
} }
template< int Precision > template <int Precision>
wxString FixedInt<Precision>::ToString( int fracDigits ) const wxString FixedInt<Precision>::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. pxAssert(fracDigits <= 7); // higher numbers would just cause overflows and bad mojo.
int mulby = (int)pow( 10.0, fracDigits ); int mulby = (int)pow(10.0, fracDigits);
wxString fmt=wxsFormat(L"%%d.%%0%dd", fracDigits); wxString fmt = wxsFormat(L"%%d.%%0%dd", fracDigits);
return wxsFormat( fmt, GetWhole(), (GetFraction() * mulby) / Precision ); return wxsFormat(fmt, GetWhole(), (GetFraction() * mulby) / Precision);
} }
template< int Precision > template <int Precision>
double FixedInt<Precision>::ToDouble() const double FixedInt<Precision>::ToDouble() const
{ {
return ((double)Raw / (double)Precision); return ((double)Raw / (double)Precision);
} }
template< int Precision > template <int Precision>
float FixedInt<Precision>::ToFloat() const float FixedInt<Precision>::ToFloat() const
{ {
return ((float)Raw / (float)Precision); return ((float)Raw / (float)Precision);
} }
template< int Precision > template <int Precision>
int FixedInt<Precision>::ToIntTruncated() const int FixedInt<Precision>::ToIntTruncated() const
{ {
return Raw / Precision; return Raw / Precision;
} }
template< int Precision > template <int Precision>
int FixedInt<Precision>::ToIntRounded() const int FixedInt<Precision>::ToIntRounded() const
{ {
return (Raw + (Precision/2)) / Precision; return (Raw + (Precision / 2)) / Precision;
} }
template< int Precision > template <int Precision>
bool FixedInt<Precision>::TryFromString( FixedInt<Precision>& dest, const wxString& parseFrom ) bool FixedInt<Precision>::TryFromString(FixedInt<Precision> &dest, const wxString &parseFrom)
{ {
long whole=0, frac=0; long whole = 0, frac = 0;
const wxString beforeFirst( parseFrom.BeforeFirst( L'.' ) ); const wxString beforeFirst(parseFrom.BeforeFirst(L'.'));
const wxString afterFirst( parseFrom.AfterFirst( L'.' ).Mid(0, 5) ); const wxString afterFirst(parseFrom.AfterFirst(L'.').Mid(0, 5));
bool success = true; bool success = true;
if( !beforeFirst.IsEmpty() ) if (!beforeFirst.IsEmpty())
success = success && beforeFirst.ToLong( &whole ); success = success && beforeFirst.ToLong(&whole);
if( !afterFirst.IsEmpty() ) if (!afterFirst.IsEmpty())
success = success && afterFirst.ToLong( &frac ); 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 ) if (afterFirst.Length() != 0 && frac != 0) {
{ int fracPower = (int)pow(10.0, (int)afterFirst.Length());
int fracPower = (int)pow( 10.0, (int)afterFirst.Length() ); dest.SetFraction((frac * Precision) / fracPower);
dest.SetFraction( (frac * Precision) / fracPower );
} }
return true; return true;
} }
template< int Precision > template <int Precision>
FixedInt<Precision> FixedInt<Precision>::FromString( const wxString& parseFrom, const FixedInt<Precision>& defval ) FixedInt<Precision> FixedInt<Precision>::FromString(const wxString &parseFrom, const FixedInt<Precision> &defval)
{ {
FixedInt<Precision> dest; FixedInt<Precision> dest;
if( !TryFromString( dest, parseFrom ) ) return defval; if (!TryFromString(dest, parseFrom))
return defval;
return dest; return dest;
} }
// This version of FromString throws a ParseError exception if the conversion fails. // This version of FromString throws a ParseError exception if the conversion fails.
template< int Precision > template <int Precision>
FixedInt<Precision> FixedInt<Precision>::FromString( const wxString parseFrom ) FixedInt<Precision> FixedInt<Precision>::FromString(const wxString parseFrom)
{ {
FixedInt<Precision> dest; FixedInt<Precision> dest;
if( !TryFromString( dest, parseFrom ) ) throw Exception::ParseError() if (!TryFromString(dest, parseFrom))
throw Exception::ParseError()
.SetDiagMsg(wxsFormat(L"Parse error on FixedInt<%d>::FromString", Precision)); .SetDiagMsg(wxsFormat(L"Parse error on FixedInt<%d>::FromString", Precision));
return dest; return dest;

View File

@ -17,16 +17,22 @@
// This macro is actually useful for about any and every possible application of C++ // This macro is actually useful for about any and every possible application of C++
// equality operators. // 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. // Macro used for removing some of the redtape involved in defining bitfield/union helpers.
// //
#define BITFIELD32() \ #define BITFIELD32() \
union { \ union \
{ \
u32 bitset; \ u32 bitset; \
struct { struct \
{
#define BITFIELD_END }; }; #define BITFIELD_END \
} \
; \
} \
;
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
@ -42,13 +48,18 @@
class RecursionGuard class RecursionGuard
{ {
public: public:
int& Counter; int &Counter;
RecursionGuard( int& counter ) : Counter( counter ) RecursionGuard(int &counter)
{ ++Counter; } : Counter(counter)
{
++Counter;
}
virtual ~RecursionGuard() throw() virtual ~RecursionGuard() throw()
{ --Counter; } {
--Counter;
}
bool IsReentrant() const { return Counter > 1; } bool IsReentrant() const { return Counter > 1; }
}; };
@ -60,13 +71,13 @@ class IActionInvocation
{ {
public: public:
virtual ~IActionInvocation() throw() {} virtual ~IActionInvocation() throw() {}
virtual void InvokeAction()=0; virtual void InvokeAction() = 0;
}; };
class ICloneable class ICloneable
{ {
public: public:
virtual ICloneable* Clone() const=0; virtual ICloneable *Clone() const = 0;
}; };
class IDeletableObject class IDeletableObject
@ -74,15 +85,15 @@ class IDeletableObject
public: public:
virtual ~IDeletableObject() throw() {} virtual ~IDeletableObject() throw() {}
virtual void DeleteSelf()=0; virtual void DeleteSelf() = 0;
virtual bool IsBeingDeleted()=0; virtual bool IsBeingDeleted() = 0;
protected: protected:
// This function is GUI implementation dependent! It's implemented by PCSX2's AppHost, // 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 // 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 // yourself. Most GUIs have built in message pumps. If a platform lacks one then you'll
// need to implement one yourself (yay?). // need to implement one yourself (yay?).
virtual void DoDeletion()=0; virtual void DoDeletion() = 0;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -146,28 +157,28 @@ protected:
public: public:
PageProtectionMode() PageProtectionMode()
{ {
All( false ); All(false);
} }
PageProtectionMode& Read( bool allow=true ) PageProtectionMode &Read(bool allow = true)
{ {
m_read = allow; m_read = allow;
return *this; return *this;
} }
PageProtectionMode& Write( bool allow=true ) PageProtectionMode &Write(bool allow = true)
{ {
m_write = allow; m_write = allow;
return *this; return *this;
} }
PageProtectionMode& Execute( bool allow=true ) PageProtectionMode &Execute(bool allow = true)
{ {
m_exec = allow; m_exec = allow;
return *this; return *this;
} }
PageProtectionMode& All( bool allow=true ) PageProtectionMode &All(bool allow = true)
{ {
m_read = m_write = m_exec = allow; m_read = m_write = m_exec = allow;
return *this; return *this;
@ -218,35 +229,35 @@ static __fi PageProtectionMode PageAccess_Any()
// platform prior to wxWidgets .. it should prolly be removed -- air) // platform prior to wxWidgets .. it should prolly be removed -- air)
namespace HostSys namespace HostSys
{ {
void* MmapReserve(uptr base, size_t size); void *MmapReserve(uptr base, size_t size);
bool MmapCommit(uptr base, size_t size, const PageProtectionMode& mode); bool MmapCommit(uptr base, size_t size, const PageProtectionMode &mode);
void MmapReset(uptr base, size_t size); void MmapReset(uptr base, size_t size);
void* MmapReservePtr(void* base, size_t size); void *MmapReservePtr(void *base, size_t size);
bool MmapCommitPtr(void* base, size_t size, const PageProtectionMode& mode); bool MmapCommitPtr(void *base, size_t size, const PageProtectionMode &mode);
void MmapResetPtr(void* base, size_t size); void MmapResetPtr(void *base, size_t size);
// Maps a block of memory for use as a recompiled code buffer. // Maps a block of memory for use as a recompiled code buffer.
// Returns NULL on allocation failure. // Returns NULL on allocation failure.
extern void* Mmap(uptr base, size_t size); extern void *Mmap(uptr base, size_t size);
// Unmaps a block allocated by SysMmap // Unmaps a block allocated by SysMmap
extern void Munmap(uptr base, size_t size); 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 > template <uint size>
void MemProtectStatic( u8 (&arr)[size], const PageProtectionMode& mode ) void MemProtectStatic(u8 (&arr)[size], const PageProtectionMode &mode)
{ {
MemProtect( arr, size, mode ); MemProtect(arr, size, mode);
} }
} }
// Safe version of Munmap -- NULLs the pointer variable immediately after free'ing it. // Safe version of Munmap -- NULLs the pointer variable immediately after free'ing it.
#define SafeSysMunmap( ptr, size ) \ #define SafeSysMunmap(ptr, size) \
((void) ( HostSys::Munmap( (uptr)(ptr), size ), (ptr) = NULL )) ((void)(HostSys::Munmap((uptr)(ptr), size), (ptr) = NULL))
extern void InitCPUTicks(); extern void InitCPUTicks();
extern u64 GetTickFrequency(); extern u64 GetTickFrequency();

View File

@ -15,7 +15,8 @@
#pragma once #pragma once
namespace HashTools { namespace HashTools
{
/// <summary> /// <summary>
/// Type that represents a hashcode; returned by all hash functions. /// Type that represents a hashcode; returned by all hash functions.
@ -26,7 +27,5 @@ namespace HashTools {
/// </remarks> /// </remarks>
typedef u32 hash_key_t; typedef u32 hash_key_t;
hash_key_t Hash(const char* data, int len); hash_key_t Hash(const char *data, int len);
} }

View File

@ -32,53 +32,57 @@
class IniInterface class IniInterface
{ {
protected: protected:
wxConfigBase* m_Config; wxConfigBase *m_Config;
public: public:
virtual ~IniInterface(); virtual ~IniInterface();
explicit IniInterface(); explicit IniInterface();
explicit IniInterface( wxConfigBase& config ); explicit IniInterface(wxConfigBase &config);
explicit IniInterface( wxConfigBase* config ); explicit IniInterface(wxConfigBase *config);
void SetPath( const wxString& path ); void SetPath(const wxString &path);
void Flush(); void Flush();
wxConfigBase& GetConfig() { pxAssert( m_Config ); return *m_Config; } wxConfigBase &GetConfig()
{
pxAssert(m_Config);
return *m_Config;
}
bool IsOk() const { return m_Config != NULL; } bool IsOk() const { return m_Config != NULL; }
virtual bool IsLoading() const=0; virtual bool IsLoading() const = 0;
bool IsSaving() const { return !IsLoading(); } bool IsSaving() const { return !IsLoading(); }
virtual void Entry( const wxString& var, wxString& value, const wxString defvalue=wxString() )=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, 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, 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, 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, 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, bool &value, const bool defvalue = false) = 0;
// This special form of Entry is provided for bitfields, which cannot be passed by reference. // 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 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 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, 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, 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, wxRect &value, const wxRect defvalue = wxDefaultRect) = 0;
template< typename T > template <typename T>
void EnumEntry( const wxString& var, T& value, const wxChar* const* enumArray=NULL, const T defvalue=(T)0 ) void EnumEntry(const wxString &var, T &value, const wxChar *const *enumArray = NULL, const T defvalue = (T)0)
{ {
int tstore = (int)value; int tstore = (int)value;
if( enumArray == NULL ) if (enumArray == NULL)
Entry( var, tstore, defvalue ); Entry(var, tstore, defvalue);
else else
_EnumEntry( var, tstore, enumArray, defvalue ); _EnumEntry(var, tstore, enumArray, defvalue);
value = (T)tstore; value = (T)tstore;
} }
protected: 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,10 +91,10 @@ protected:
class ScopedIniGroup class ScopedIniGroup
{ {
protected: protected:
IniInterface& m_mom; IniInterface &m_mom;
public: public:
ScopedIniGroup( IniInterface& mommy, const wxString& group ); ScopedIniGroup(IniInterface &mommy, const wxString &group);
virtual ~ScopedIniGroup(); virtual ~ScopedIniGroup();
}; };
@ -107,29 +111,29 @@ class IniLoader : public IniInterface
public: public:
virtual ~IniLoader() throw(); virtual ~IniLoader() throw();
explicit IniLoader(); explicit IniLoader();
explicit IniLoader( wxConfigBase& config ); explicit IniLoader(wxConfigBase &config);
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, 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, 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, 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, int &value, const int defvalue = 0);
void Entry( const wxString& var, uint& value, const uint 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, bool &value, const bool defvalue = false);
bool EntryBitBool( 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 ); 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, wxPoint &value, const wxPoint defvalue = wxDefaultPosition);
void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize ); 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, wxRect &value, const wxRect defvalue = wxDefaultRect);
protected: 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);
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -145,43 +149,43 @@ class IniSaver : public IniInterface
public: public:
virtual ~IniSaver(); virtual ~IniSaver();
explicit IniSaver(); explicit IniSaver();
explicit IniSaver( wxConfigBase& config ); explicit IniSaver(wxConfigBase &config);
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, 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, 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, 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, int &value, const int defvalue = 0);
void Entry( const wxString& var, uint& value, const uint 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, bool &value, const bool defvalue = false);
bool EntryBitBool( 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 ); 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, wxPoint &value, const wxPoint defvalue = wxDefaultPosition);
void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize ); 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, wxRect &value, const wxRect defvalue = wxDefaultRect);
protected: 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 // GCC Note: wxT() macro is required when using string token pasting. For some reason L generates
// syntax errors. >_< // syntax errors. >_<
// //
#define IniEntry( varname ) ini.Entry( 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 IniEntryDirFile(varname, isAllowRelative) ini.Entry(wxT(#varname), varname, varname, isAllowRelative)
#define IniBitfield( varname ) varname = ini.EntryBitfield( wxT(#varname), varname, varname ) #define IniBitfield(varname) varname = ini.EntryBitfield(wxT(#varname), varname, varname)
#define IniBitBool( varname ) varname = ini.EntryBitBool( 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 IniBitfieldEx(varname, textname) varname = ini.EntryBitfield(wxT(textname), varname, varname)
#define IniBitBoolEx( varname, textname ) varname = ini.EntryBitBool( wxT(textname), !!varname, varname ) #define IniBitBoolEx(varname, textname) varname = ini.EntryBitBool(wxT(textname), !!varname, varname)
//used for filenames and folder names as ini values. //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. //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);

View File

@ -20,7 +20,8 @@
#include "Pcsx2Defs.h" #include "Pcsx2Defs.h"
// On GCC >= 4.7, this is equivalent to __builtin_clrsb(n); // On GCC >= 4.7, this is equivalent to __builtin_clrsb(n);
inline u32 count_leading_sign_bits(s32 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 the sign bit is 1, we invert the bits to 0 for count-leading-zero.
if (n < 0) if (n < 0)
n = ~n; n = ~n;
@ -29,7 +30,7 @@ inline u32 count_leading_sign_bits(s32 n) {
if (n == 0) if (n == 0)
return 32; return 32;
// Perform our count leading zero. // Perform our count leading zero.
#ifdef _MSC_VER #ifdef _MSC_VER
unsigned long ret; unsigned long ret;
_BitScanReverse(&ret, n); _BitScanReverse(&ret, n);
@ -38,4 +39,3 @@ inline u32 count_leading_sign_bits(s32 n) {
return __builtin_clz(n); return __builtin_clz(n);
#endif #endif
} }

View File

@ -16,15 +16,15 @@
#pragma once #pragma once
#if defined(__POSIX__) #if defined(__POSIX__)
# include "lnx_memzero.h" #include "lnx_memzero.h"
#else #else
# include "win_memzero.h" #include "win_memzero.h"
#endif #endif
// For 32-bit MSVC compiles, memcmp performs much worse than memcmp_mmx and // For 32-bit MSVC compiles, memcmp performs much worse than memcmp_mmx and
// other implementations. So for this combination only, prefer memcmp_mmx // other implementations. So for this combination only, prefer memcmp_mmx
#if defined(_MSC_VER) && !defined(_M_X86_64) #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 #else
#define memcmp_mmx memcmp #define memcmp_mmx memcmp
#endif #endif

View File

@ -17,29 +17,28 @@
#include <xmmintrin.h> #include <xmmintrin.h>
#define StoreDestIdx(idx) case idx: _mm_store_ps(&destxmm[idx-1][0], srcreg) #define StoreDestIdx(idx) \
case idx: \
_mm_store_ps(&destxmm[idx - 1][0], srcreg)
template< u8 data > template <u8 data>
__noinline void memset_sse_a( void* dest, const size_t size ) __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) if (data != 0) {
{ static __aligned16 const u8 loadval[8] = {data, data, data, data, data, data, data, data};
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);
srcreg = _mm_loadh_pi( _mm_load_ps( (float*)loadval ), (__m64*)loadval ); } else
}
else
srcreg = _mm_setzero_ps(); srcreg = _mm_setzero_ps();
float (*destxmm)[4] = (float(*)[4])dest; float(*destxmm)[4] = (float(*)[4])dest;
switch( MZFqwc & 0x07 ) switch (MZFqwc & 0x07) {
{
StoreDestIdx(0x07); StoreDestIdx(0x07);
StoreDestIdx(0x06); StoreDestIdx(0x06);
StoreDestIdx(0x05); StoreDestIdx(0x05);
@ -50,8 +49,7 @@ __noinline void memset_sse_a( void* dest, const size_t size )
} }
destxmm += (MZFqwc & 0x07); destxmm += (MZFqwc & 0x07);
for( uint i=0; i<MZFqwc / 8; ++i, destxmm+=8 ) for (uint i = 0; i < MZFqwc / 8; ++i, destxmm += 8) {
{
_mm_store_ps(&destxmm[0][0], srcreg); _mm_store_ps(&destxmm[0][0], srcreg);
_mm_store_ps(&destxmm[1][0], srcreg); _mm_store_ps(&destxmm[1][0], srcreg);
_mm_store_ps(&destxmm[2][0], srcreg); _mm_store_ps(&destxmm[2][0], srcreg);
@ -63,23 +61,23 @@ __noinline void memset_sse_a( void* dest, const size_t size )
} }
}; };
static __fi void memzero_sse_a( void* dest, const size_t size ) static __fi void memzero_sse_a(void *dest, const size_t size)
{ {
memset_sse_a<0>( dest, size ); memset_sse_a<0>(dest, size);
} }
#undef StoreDestIdx #undef StoreDestIdx
template< u8 data, typename T > template <u8 data, typename T>
__noinline void memset_sse_a( T& dest ) __noinline void memset_sse_a(T &dest)
{ {
static_assert( (sizeof(dest) & 0xf) == 0, "Bad size for SSE memset" ); static_assert((sizeof(dest) & 0xf) == 0, "Bad size for SSE memset");
memset_sse_a<data>( &dest, sizeof(dest) ); memset_sse_a<data>(&dest, sizeof(dest));
} }
template< typename T > template <typename T>
void memzero_sse_a( T& dest ) void memzero_sse_a(T &dest)
{ {
static_assert( (sizeof(dest) & 0xf) == 0, "Bad size for SSE memset" ); static_assert((sizeof(dest) & 0xf) == 0, "Bad size for SSE memset");
memset_sse_a<0>( &dest, sizeof(dest) ); memset_sse_a<0>(&dest, sizeof(dest));
} }

View File

@ -30,7 +30,7 @@ struct PageFaultInfo
{ {
uptr addr; uptr addr;
PageFaultInfo( uptr address ) PageFaultInfo(uptr address)
{ {
addr = address; addr = address;
} }
@ -47,17 +47,17 @@ public:
public: public:
virtual ~IEventListener_PageFault() throw() {} virtual ~IEventListener_PageFault() throw() {}
virtual void DispatchEvent( const PageFaultInfo& evtinfo, bool& handled ) virtual void DispatchEvent(const PageFaultInfo &evtinfo, bool &handled)
{ {
OnPageFaultEvent( evtinfo, handled ); OnPageFaultEvent(evtinfo, handled);
} }
virtual void DispatchEvent( const PageFaultInfo& evtinfo ) virtual void DispatchEvent(const PageFaultInfo &evtinfo)
{ {
pxFailRel( "Don't call me, damnit. Use DispatchException instead." ); 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) {}
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -70,19 +70,19 @@ public:
virtual ~EventListener_PageFault() throw(); virtual ~EventListener_PageFault() throw();
}; };
template< typename TypeToDispatchTo > template <typename TypeToDispatchTo>
class EventListenerHelper_PageFault : public EventListener_PageFault class EventListenerHelper_PageFault : public EventListener_PageFault
{ {
public: public:
TypeToDispatchTo* Owner; TypeToDispatchTo *Owner;
public: public:
EventListenerHelper_PageFault( TypeToDispatchTo& dispatchTo ) EventListenerHelper_PageFault(TypeToDispatchTo &dispatchTo)
{ {
Owner = &dispatchTo; Owner = &dispatchTo;
} }
EventListenerHelper_PageFault( TypeToDispatchTo* dispatchTo ) EventListenerHelper_PageFault(TypeToDispatchTo *dispatchTo)
{ {
Owner = dispatchTo; Owner = dispatchTo;
} }
@ -90,11 +90,10 @@ public:
virtual ~EventListenerHelper_PageFault() throw() {} virtual ~EventListenerHelper_PageFault() throw() {}
protected: protected:
virtual void OnPageFaultEvent( const PageFaultInfo& info, bool& handled ) virtual void OnPageFaultEvent(const PageFaultInfo &info, bool &handled)
{ {
Owner->OnPageFaultEvent( info, handled ); Owner->OnPageFaultEvent(info, handled);
} }
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -109,14 +108,17 @@ protected:
bool m_handled; bool m_handled;
public: public:
SrcType_PageFault() : m_handled(false) {} SrcType_PageFault()
virtual ~SrcType_PageFault() throw() { } : m_handled(false)
{
}
virtual ~SrcType_PageFault() throw() {}
bool WasHandled() const { return m_handled; } bool WasHandled() const { return m_handled; }
virtual void Dispatch( const PageFaultInfo& params ); virtual void Dispatch(const PageFaultInfo &params);
protected: protected:
virtual void _DispatchRaw( ListenerIterator iter, const ListenerIterator& iend, const PageFaultInfo& evt ); virtual void _DispatchRaw(ListenerIterator iter, const ListenerIterator &iend, const PageFaultInfo &evt);
}; };
@ -125,7 +127,7 @@ protected:
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class VirtualMemoryReserve class VirtualMemoryReserve
{ {
DeclareNoncopyableObject( VirtualMemoryReserve ); DeclareNoncopyableObject(VirtualMemoryReserve);
protected: protected:
wxString m_name; wxString m_name;
@ -135,7 +137,7 @@ protected:
// in the Reserve parameters. // in the Reserve parameters.
size_t m_defsize; size_t m_defsize;
void* m_baseptr; void *m_baseptr;
// reserved memory (in pages). // reserved memory (in pages).
uptr m_pages_reserved; uptr m_pages_reserved;
@ -154,21 +156,21 @@ protected:
bool m_allow_writes; bool m_allow_writes;
public: public:
VirtualMemoryReserve( const wxString& name=wxEmptyString, size_t size = 0 ); VirtualMemoryReserve(const wxString &name = wxEmptyString, size_t size = 0);
virtual ~VirtualMemoryReserve() throw() virtual ~VirtualMemoryReserve() throw()
{ {
Release(); Release();
} }
virtual void* Reserve( size_t size = 0, uptr base = 0, uptr upper_bounds = 0 ); virtual void *Reserve(size_t size = 0, uptr base = 0, uptr upper_bounds = 0);
virtual void* ReserveAt( uptr base = 0, uptr upper_bounds = 0 ) virtual void *ReserveAt(uptr base = 0, uptr upper_bounds = 0)
{ {
return Reserve(m_defsize, base, upper_bounds); return Reserve(m_defsize, base, upper_bounds);
} }
virtual void Reset(); virtual void Reset();
virtual void Release(); virtual void Release();
virtual bool TryResize( uint newsize ); virtual bool TryResize(uint newsize);
virtual bool Commit(); virtual bool Commit();
virtual void ForbidModification(); virtual void ForbidModification();
@ -182,35 +184,35 @@ public:
uint GetCommittedPageCount() const { return m_pages_commited; } uint GetCommittedPageCount() const { return m_pages_commited; }
uint GetCommittedBytes() const { return m_pages_commited * __pagesize; } uint GetCommittedBytes() const { return m_pages_commited * __pagesize; }
u8* GetPtr() { return (u8*)m_baseptr; } u8 *GetPtr() { return (u8 *)m_baseptr; }
const u8* GetPtr() const { return (u8*)m_baseptr; } const u8 *GetPtr() const { return (u8 *)m_baseptr; }
u8* GetPtrEnd() { return (u8*)m_baseptr + (m_pages_reserved * __pagesize); } u8 *GetPtrEnd() { return (u8 *)m_baseptr + (m_pages_reserved * __pagesize); }
const u8* GetPtrEnd() const { return (u8*)m_baseptr + (m_pages_reserved * __pagesize); } const u8 *GetPtrEnd() const { return (u8 *)m_baseptr + (m_pages_reserved * __pagesize); }
VirtualMemoryReserve& SetName( const wxString& newname ); VirtualMemoryReserve &SetName(const wxString &newname);
VirtualMemoryReserve& SetBaseAddr( uptr newaddr ); VirtualMemoryReserve &SetBaseAddr(uptr newaddr);
VirtualMemoryReserve& SetPageAccessOnCommit( const PageProtectionMode& mode ); VirtualMemoryReserve &SetPageAccessOnCommit(const PageProtectionMode &mode);
operator void*() { return m_baseptr; } operator void *() { return m_baseptr; }
operator const void*() const { return m_baseptr; } operator const void *() const { return m_baseptr; }
operator u8*() { return (u8*)m_baseptr; } operator u8 *() { return (u8 *)m_baseptr; }
operator const u8*() const { return (u8*)m_baseptr; } operator const u8 *() const { return (u8 *)m_baseptr; }
u8& operator[](uint idx) u8 &operator[](uint idx)
{ {
pxAssert(idx < (m_pages_reserved * __pagesize)); pxAssert(idx < (m_pages_reserved * __pagesize));
return *((u8*)m_baseptr + idx); return *((u8 *)m_baseptr + idx);
} }
const u8& operator[](uint idx) const const u8 &operator[](uint idx) const
{ {
pxAssert(idx < (m_pages_reserved * __pagesize)); pxAssert(idx < (m_pages_reserved * __pagesize));
return *((u8*)m_baseptr + idx); return *((u8 *)m_baseptr + idx);
} }
protected: protected:
virtual void ReprotectCommittedBlocks( const PageProtectionMode& newmode ); virtual void ReprotectCommittedBlocks(const PageProtectionMode &newmode);
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -218,7 +220,7 @@ protected:
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class BaseVmReserveListener : public VirtualMemoryReserve class BaseVmReserveListener : public VirtualMemoryReserve
{ {
DeclareNoncopyableObject( BaseVmReserveListener ); DeclareNoncopyableObject(BaseVmReserveListener);
typedef VirtualMemoryReserve _parent; typedef VirtualMemoryReserve _parent;
@ -229,20 +231,20 @@ protected:
uptr m_blocksize; uptr m_blocksize;
public: public:
BaseVmReserveListener( const wxString& name, size_t size = 0 ); BaseVmReserveListener(const wxString &name, size_t size = 0);
virtual ~BaseVmReserveListener() throw() { } virtual ~BaseVmReserveListener() throw() {}
operator void*() { return m_baseptr; } operator void *() { return m_baseptr; }
operator const void*() const { return m_baseptr; } operator const void *() const { return m_baseptr; }
operator u8*() { return (u8*)m_baseptr; } operator u8 *() { return (u8 *)m_baseptr; }
operator const u8*() const { 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 ) virtual uptr SetBlockSize(uptr bytes)
{ {
m_blocksize = (bytes + __pagesize - 1) / __pagesize; m_blocksize = (bytes + __pagesize - 1) / __pagesize;
return m_blocksize * __pagesize; return m_blocksize * __pagesize;
@ -254,7 +256,6 @@ public:
} }
protected: protected:
// This function is called from OnPageFaultEvent after the address has been translated // This function is called from OnPageFaultEvent after the address has been translated
// and confirmed to apply to this reserved area in question. OnPageFaultEvent contains // and confirmed to apply to this reserved area in question. OnPageFaultEvent contains
// a try/catch exception handler, which ensures "reasonable" error response behavior if // a try/catch exception handler, which ensures "reasonable" error response behavior if
@ -263,35 +264,35 @@ protected:
// Important: This method is called from the context of an exception/signal handler. On // 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 // Windows this isn't a big deal (most operations are ok). On Linux, however, logging
// and other facilities are probably not a good idea. // and other facilities are probably not a good idea.
virtual void DoCommitAndProtect( uptr offset )=0; virtual void DoCommitAndProtect(uptr offset) = 0;
// This function is called for every committed block. // This function is called for every committed block.
virtual void OnCommittedBlock( void* block )=0; virtual void OnCommittedBlock(void *block) = 0;
virtual void CommitBlocks( uptr page, uint blocks ); virtual void CommitBlocks(uptr page, uint blocks);
}; };
#ifdef __POSIX__ #ifdef __POSIX__
# define PCSX2_PAGEFAULT_PROTECT #define PCSX2_PAGEFAULT_PROTECT
# define PCSX2_PAGEFAULT_EXCEPT #define PCSX2_PAGEFAULT_EXCEPT
#elif defined( _WIN32 ) #elif defined(_WIN32)
struct _EXCEPTION_POINTERS; 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_PROTECT __try
# define PCSX2_PAGEFAULT_EXCEPT __except(SysPageFaultExceptionFilter(GetExceptionInformation())) {} #define PCSX2_PAGEFAULT_EXCEPT \
__except (SysPageFaultExceptionFilter(GetExceptionInformation())) {}
#else #else
# error PCSX2 - Unsupported operating system platform. #error PCSX2 - Unsupported operating system platform.
#endif #endif
extern void pxInstallSignalHandler(); extern void pxInstallSignalHandler();
extern void _platform_InstallSignalHandler(); extern void _platform_InstallSignalHandler();
#include "Threading.h" #include "Threading.h"
extern SrcType_PageFault* Source_PageFault; extern SrcType_PageFault *Source_PageFault;
extern Threading::Mutex PageFault_Mutex; extern Threading::Mutex PageFault_Mutex;

View File

@ -26,30 +26,36 @@
class wxDirName : protected wxFileName class wxDirName : protected wxFileName
{ {
public: public:
explicit wxDirName( const wxFileName& src ) explicit wxDirName(const wxFileName &src)
{ {
Assign( src.GetPath(), wxEmptyString ); Assign(src.GetPath(), wxEmptyString);
} }
wxDirName() : wxFileName() {} wxDirName()
wxDirName( const wxDirName& src ) : wxFileName( src ) { } : wxFileName()
explicit wxDirName( const char* src ) { Assign( fromUTF8(src) ); } {
explicit wxDirName( const wxString& src ) { Assign( src ); } }
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 ) void Assign(const wxString &volume, const wxString &path)
{ {
wxFileName::Assign( volume, path, wxEmptyString ); wxFileName::Assign(volume, path, wxEmptyString);
} }
void Assign( const wxString& path ) void Assign(const wxString &path)
{ {
wxFileName::Assign( path, wxEmptyString ); wxFileName::Assign(path, wxEmptyString);
} }
void Assign( const wxDirName& path ) void Assign(const wxDirName &path)
{ {
wxFileName::Assign( path ); wxFileName::Assign(path);
} }
void Clear() { wxFileName::Clear(); } void Clear() { wxFileName::Clear(); }
@ -67,25 +73,24 @@ public:
bool IsRelative() const { return wxFileName::IsRelative(); } bool IsRelative() const { return wxFileName::IsRelative(); }
bool IsAbsolute() const { return wxFileName::IsAbsolute(); } bool IsAbsolute() const { return wxFileName::IsAbsolute(); }
bool SameAs( const wxDirName& filepath ) const bool SameAs(const wxDirName &filepath) const
{ {
return wxFileName::SameAs( filepath ); return wxFileName::SameAs(filepath);
} }
//Returns true if the file is somewhere inside this directory (and both file and directory are not relative). //Returns true if the file is somewhere inside this directory (and both file and directory are not relative).
bool IsContains( const wxFileName& file ) const bool IsContains(const wxFileName &file) const
{ {
if( this->IsRelative() || file.IsRelative() ) if (this->IsRelative() || file.IsRelative())
return false; return false;
wxFileName f( file ); wxFileName f(file);
while( 1 ) while (1) {
{ if (this->SameAs(wxDirName(f.GetPath())))
if( this->SameAs( wxDirName(f.GetPath()) ) )
return true; return true;
if( f.GetDirCount() == 0 ) if (f.GetDirCount() == 0)
return false; return false;
f.RemoveLastDir(); f.RemoveLastDir();
@ -94,9 +99,9 @@ public:
return false; return false;
} }
bool IsContains( const wxDirName& dir ) const bool IsContains(const wxDirName &dir) const
{ {
return IsContains( (wxFileName)dir ); return IsContains((wxFileName)dir);
} }
@ -107,22 +112,21 @@ public:
// 4. else, result is absolute path of subject. // 4. else, result is absolute path of subject.
// //
// returns ok if both this and base are absolute paths. // returns ok if both this and base are absolute paths.
static wxString MakeAutoRelativeTo(const wxFileName _subject, const wxString& pathbase) static wxString MakeAutoRelativeTo(const wxFileName _subject, const wxString &pathbase)
{ {
wxFileName subject( _subject ); wxFileName subject(_subject);
wxDirName base ( pathbase ); wxDirName base(pathbase);
if( base.IsRelative() || subject.IsRelative() ) if (base.IsRelative() || subject.IsRelative())
return subject.GetFullPath(); return subject.GetFullPath();
wxString bv( base.GetVolume() ); bv.MakeUpper(); wxString bv(base.GetVolume());
wxString sv( subject.GetVolume() ); sv.MakeUpper(); bv.MakeUpper();
wxString sv(subject.GetVolume());
sv.MakeUpper();
if( base.IsContains( subject ) ) if (base.IsContains(subject)) {
{ subject.MakeRelativeTo(base.GetFullPath());
subject.MakeRelativeTo( base.GetFullPath() ); } else if (base.HasVolume() && subject.HasVolume() && bv == sv) {
}
else if( base.HasVolume() && subject.HasVolume() && bv == sv )
{
wxString unusedVolume; wxString unusedVolume;
wxString pathSansVolume; wxString pathSansVolume;
subject.SplitVolume(subject.GetFullPath(), &unusedVolume, &pathSansVolume); subject.SplitVolume(subject.GetFullPath(), &unusedVolume, &pathSansVolume);
@ -133,28 +137,28 @@ public:
return subject.GetFullPath(); return subject.GetFullPath();
} }
static wxString MakeAutoRelativeTo(const wxDirName subject, const wxString& pathbase) static wxString MakeAutoRelativeTo(const wxDirName subject, const wxString &pathbase)
{ {
return MakeAutoRelativeTo( wxFileName( subject ), pathbase ); return MakeAutoRelativeTo(wxFileName(subject), pathbase);
} }
// Returns the number of sub folders in this directory path // Returns the number of sub folders in this directory path
size_t GetCount() const { return GetDirCount(); } size_t GetCount() const { return GetDirCount(); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
wxFileName Combine( const wxFileName& right ) const; wxFileName Combine(const wxFileName &right) const;
wxDirName Combine( const wxDirName& right ) const; wxDirName Combine(const wxDirName &right) const;
// removes the lastmost directory from the path // removes the lastmost directory from the path
void RemoveLast() { wxFileName::RemoveDir(GetCount() - 1); } void RemoveLast() { wxFileName::RemoveDir(GetCount() - 1); }
wxDirName& Normalize( int flags = wxPATH_NORM_ALL, const wxString& cwd = wxEmptyString ); wxDirName &Normalize(int flags = wxPATH_NORM_ALL, const wxString &cwd = wxEmptyString);
wxDirName& MakeRelativeTo( const wxString& pathBase = wxEmptyString ); wxDirName &MakeRelativeTo(const wxString &pathBase = wxEmptyString);
wxDirName& MakeAbsolute( const wxString& cwd = wxEmptyString ); wxDirName &MakeAbsolute(const wxString &cwd = wxEmptyString);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void AssignCwd( const wxString& volume = wxEmptyString ) { wxFileName::AssignCwd( volume ); } void AssignCwd(const wxString &volume = wxEmptyString) { wxFileName::AssignCwd(volume); }
bool SetCwd() { return wxFileName::SetCwd(); } bool SetCwd() { return wxFileName::SetCwd(); }
// wxWidgets is missing the const qualifier for this one! Shame! // wxWidgets is missing the const qualifier for this one! Shame!
@ -163,27 +167,39 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
wxDirName& operator=(const wxDirName& dirname) { Assign( dirname ); return *this; } wxDirName &operator=(const wxDirName &dirname)
wxDirName& operator=(const wxString& dirname) { Assign( dirname ); return *this; } {
wxDirName& operator=(const char* dirname) { Assign( fromUTF8(dirname) ); return *this; } 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 ); } wxFileName operator+(const wxFileName &right) const { return Combine(right); }
wxDirName operator+( const wxDirName& 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 wxString &right) const { return Combine(wxFileName(right)); }
wxFileName operator+( const char* right ) const { return Combine( wxFileName(fromUTF8(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 // 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)); }
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; } const wxFileName &GetFilename() const { return *this; }
wxFileName& GetFilename() { return *this; } wxFileName &GetFilename() { return *this; }
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -195,20 +211,20 @@ public:
// //
namespace Path namespace Path
{ {
extern bool IsRelative( const wxString& path ); extern bool IsRelative(const wxString &path);
extern s64 GetFileSize( const wxString& path ); extern s64 GetFileSize(const wxString &path);
extern wxString Normalize( const wxString& srcpath ); extern wxString Normalize(const wxString &srcpath);
extern wxString Normalize( const wxDirName& srcpath ); extern wxString Normalize(const wxDirName &srcpath);
extern wxString MakeAbsolute( const wxString& srcpath ); extern wxString MakeAbsolute(const wxString &srcpath);
extern wxString Combine( const wxString& srcPath, const wxString& srcFile ); extern wxString Combine(const wxString &srcPath, const wxString &srcFile);
extern wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile ); extern wxString Combine(const wxDirName &srcPath, const wxFileName &srcFile);
extern wxString Combine( const wxString& srcPath, const wxDirName& srcFile ); extern wxString Combine(const wxString &srcPath, const wxDirName &srcFile);
extern wxString ReplaceExtension( const wxString& src, const wxString& ext ); extern wxString ReplaceExtension(const wxString &src, const wxString &ext);
extern wxString ReplaceFilename( const wxString& src, const wxString& newfilename ); extern wxString ReplaceFilename(const wxString &src, const wxString &newfilename);
extern wxString GetFilename( const wxString& src ); extern wxString GetFilename(const wxString &src);
extern wxString GetDirectory( const wxString& src ); extern wxString GetDirectory(const wxString &src);
extern wxString GetFilenameWithoutExt( const wxString& src ); extern wxString GetFilenameWithoutExt(const wxString &src);
extern wxString GetRootDirectory( const wxString& src ); extern wxString GetRootDirectory(const wxString &src);
} }

View File

@ -15,10 +15,11 @@
#pragma once #pragma once
namespace Perf { namespace Perf
{
struct Info struct Info
{ {
uptr m_x86; uptr m_x86;
u32 m_size; u32 m_size;
char m_symbol[20]; char m_symbol[20];
@ -26,32 +27,30 @@ namespace Perf {
// once. // once.
bool m_dynamic; bool m_dynamic;
Info(uptr x86, u32 size, const char* symbol); Info(uptr x86, u32 size, const char *symbol);
Info(uptr x86, u32 size, const char* symbol, u32 pc); Info(uptr x86, u32 size, const char *symbol, u32 pc);
void Print(FILE* fp); void Print(FILE *fp);
}; };
class InfoVector class InfoVector
{ {
std::vector<Info> m_v; std::vector<Info> m_v;
char m_prefix[20]; 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 print(FILE* fp);
void map(uptr x86, u32 size, const char* symbol);
void map(uptr x86, u32 size, u32 pc); void map(uptr x86, u32 size, u32 pc);
void reset(); void reset();
};
}; void dump();
void dump_and_reset();
void dump(); extern InfoVector any;
void dump_and_reset(); extern InfoVector ee;
extern InfoVector iop;
extern InfoVector any; extern InfoVector vu;
extern InfoVector ee;
extern InfoVector iop;
extern InfoVector vu;
} }

View File

@ -25,15 +25,15 @@ namespace Threading
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// ThreadDeleteEvent // ThreadDeleteEvent
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class EventListener_Thread : public IEventDispatcher<int> class EventListener_Thread : public IEventDispatcher<int>
{ {
public: public:
typedef int EvtParams; typedef int EvtParams;
protected: protected:
pxThread* m_thread; pxThread *m_thread;
public: public:
EventListener_Thread() EventListener_Thread()
{ {
m_thread = NULL; m_thread = NULL;
@ -41,22 +41,22 @@ namespace Threading
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 ) void DispatchEvent(const int &params)
{ {
OnThreadCleanup(); OnThreadCleanup();
} }
protected: protected:
// Invoked by the pxThread when the thread execution is ending. This is // Invoked by the pxThread when the thread execution is ending. This is
// typically more useful than a delete listener since the extended thread information // typically more useful than a delete listener since the extended thread information
// provided by virtualized functions/methods will be available. // provided by virtualized functions/methods will be available.
// Important! This event is executed *by the thread*, so care must be taken to ensure // 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). // thread sync when necessary (posting messages to the main thread, etc).
virtual void OnThreadCleanup()=0; virtual void OnThreadCleanup() = 0;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// pxThread - Helper class for the basics of starting/managing persistent threads. // pxThread - Helper class for the basics of starting/managing persistent threads.
@ -85,13 +85,13 @@ namespace Threading
// no dependency options for ensuring correct static var initializations). Use heap // no dependency options for ensuring correct static var initializations). Use heap
// allocation to create thread objects instead. // allocation to create thread objects instead.
// //
class pxThread class pxThread
{ {
DeclareNoncopyableObject(pxThread); DeclareNoncopyableObject(pxThread);
friend void pxYield( int ms ); friend void pxYield(int ms);
protected: protected:
wxString m_name; // diagnostic name for our thread. wxString m_name; // diagnostic name for our thread.
pthread_t m_thread; pthread_t m_thread;
uptr m_native_id; // typically an id, but implementing platforms can do whatever. uptr m_native_id; // typically an id, but implementing platforms can do whatever.
@ -113,41 +113,42 @@ namespace Threading
EventSource<EventListener_Thread> m_evtsrc_OnDelete; EventSource<EventListener_Thread> m_evtsrc_OnDelete;
public: public:
virtual ~pxThread() throw(); virtual ~pxThread() throw();
pxThread( const wxString& name=L"pxThread" ); pxThread(const wxString &name = L"pxThread");
pthread_t GetId() const { return m_thread; } pthread_t GetId() const { return m_thread; }
u64 GetCpuTime() const; u64 GetCpuTime() const;
virtual void Start(); virtual void Start();
virtual void Cancel( bool isBlocking = true ); virtual void Cancel(bool isBlocking = true);
virtual bool Cancel( const wxTimeSpan& timeout ); virtual bool Cancel(const wxTimeSpan &timeout);
virtual bool Detach(); virtual bool Detach();
virtual void Block(); virtual void Block();
virtual bool Block( const wxTimeSpan& timeout ); virtual bool Block(const wxTimeSpan &timeout);
virtual void RethrowException() const; virtual void RethrowException() const;
void AddListener( EventListener_Thread& evt ); void AddListener(EventListener_Thread &evt);
void AddListener( EventListener_Thread* evt ) void AddListener(EventListener_Thread *evt)
{ {
if( evt == NULL ) return; if (evt == NULL)
AddListener( *evt ); return;
AddListener(*evt);
} }
void WaitOnSelf( Semaphore& mutex ) const; void WaitOnSelf(Semaphore &mutex) const;
void WaitOnSelf( Mutex& mutex ) const; void WaitOnSelf(Mutex &mutex) const;
bool WaitOnSelf( Semaphore& mutex, const wxTimeSpan& timeout ) const; bool WaitOnSelf(Semaphore &mutex, const wxTimeSpan &timeout) const;
bool WaitOnSelf( Mutex& mutex, const wxTimeSpan& timeout ) const; bool WaitOnSelf(Mutex &mutex, const wxTimeSpan &timeout) const;
bool IsRunning() const; bool IsRunning() const;
bool IsSelf() const; bool IsSelf() const;
bool HasPendingException() const { return !!m_except; } bool HasPendingException() const { return !!m_except; }
wxString GetName() const; wxString GetName() const;
void SetName( const wxString& newname ); void SetName(const wxString &newname);
protected: protected:
// Extending classes should always implement your own OnStart(), which is called by // Extending classes should always implement your own OnStart(), which is called by
// Start() once necessary locks have been obtained. Do not override Start() directly // Start() once necessary locks have been obtained. Do not override Start() directly
// unless you're really sure that's what you need to do. ;) // unless you're really sure that's what you need to do. ;)
@ -160,7 +161,7 @@ namespace Threading
virtual void OnCleanupInThread(); virtual void OnCleanupInThread();
// Implemented by derived class to perform actual threaded task! // Implemented by derived class to perform actual threaded task!
virtual void ExecuteTaskInThread()=0; virtual void ExecuteTaskInThread() = 0;
void TestCancel() const; void TestCancel() const;
@ -173,17 +174,17 @@ namespace Threading
// depending on operating system/platform). If ms is 0 or unspecified, then a single // 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 // 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. // time when ms==0, then no yield is done, but cancellation is still tested.
void Yield( int ms = 0 ) void Yield(int ms = 0)
{ {
pxAssert( IsSelf() ); pxAssert(IsSelf());
Threading::Sleep( ms ); Threading::Sleep(ms);
TestCancel(); TestCancel();
} }
void FrankenMutex( Mutex& mutex ); void FrankenMutex(Mutex &mutex);
bool AffinityAssert_AllowFromSelf( const DiagnosticOrigin& origin ) const; bool AffinityAssert_AllowFromSelf(const DiagnosticOrigin &origin) const;
bool AffinityAssert_DisallowFromSelf( 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.
@ -191,16 +192,16 @@ namespace Threading
void _platform_specific_OnStartInThread(); void _platform_specific_OnStartInThread();
void _platform_specific_OnCleanupInThread(); void _platform_specific_OnCleanupInThread();
bool _basecancel(); bool _basecancel();
void _selfRunningTest( const wxChar* name ) const; void _selfRunningTest(const wxChar *name) const;
void _DoSetThreadName( const wxString& name ); void _DoSetThreadName(const wxString &name);
void _DoSetThreadName( const char* name ); void _DoSetThreadName(const char *name);
void _internal_execute(); void _internal_execute();
void _try_virtual_invoke( void (pxThread::*method)() ); void _try_virtual_invoke(void (pxThread::*method)());
void _ThreadCleanup(); void _ThreadCleanup();
static void* _internal_callback( void* func ); static void *_internal_callback(void *func);
static void _pt_callback_cleanup( void* handle ); static void _pt_callback_cleanup(void *handle);
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -240,19 +241,19 @@ namespace Threading
// into smaller sections. For example, if you have 20,000 items to process, the task // 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. // can be divided into two threads of 10,000 items each.
// //
class BaseTaskThread : public pxThread class BaseTaskThread : public pxThread
{ {
protected: protected:
std::atomic<bool> m_Done; std::atomic<bool> m_Done;
std::atomic<bool> m_TaskPending; std::atomic<bool> m_TaskPending;
Semaphore m_post_TaskComplete; Semaphore m_post_TaskComplete;
Mutex m_lock_TaskComplete; Mutex m_lock_TaskComplete;
public: public:
virtual ~BaseTaskThread() throw() {} virtual ~BaseTaskThread() throw() {}
BaseTaskThread() : BaseTaskThread()
m_Done( false ) : m_Done(false)
, m_TaskPending( false ) , m_TaskPending(false)
, m_post_TaskComplete() , m_post_TaskComplete()
{ {
} }
@ -261,11 +262,11 @@ namespace Threading
void PostTask(); void PostTask();
void WaitForResult(); void WaitForResult();
protected: protected:
// Abstract method run when a task has been posted. Implementing classes should do // Abstract method run when a task has been posted. Implementing classes should do
// all your necessary processing work here. // all your necessary processing work here.
virtual void Task()=0; virtual void Task() = 0;
virtual void ExecuteTaskInThread(); virtual void ExecuteTaskInThread();
}; };
} }

View File

@ -16,7 +16,7 @@
#pragma once #pragma once
#ifdef __WXMSW__ #ifdef __WXMSW__
# include <wx/msw/wrapwin.h> #include <wx/msw/wrapwin.h>
#else #else
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////

View File

@ -22,14 +22,14 @@ namespace Threading
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// RwMutex // RwMutex
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class RwMutex class RwMutex
{ {
DeclareNoncopyableObject(RwMutex); DeclareNoncopyableObject(RwMutex);
protected: protected:
pthread_rwlock_t m_rwlock; pthread_rwlock_t m_rwlock;
public: public:
RwMutex(); RwMutex();
virtual ~RwMutex() throw(); virtual ~RwMutex() throw();
@ -39,22 +39,22 @@ namespace Threading
virtual bool TryAcquireWrite(); virtual bool TryAcquireWrite();
virtual void Release(); virtual void Release();
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// BaseScopedReadWriteLock // BaseScopedReadWriteLock
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class BaseScopedReadWriteLock class BaseScopedReadWriteLock
{ {
DeclareNoncopyableObject(BaseScopedReadWriteLock); DeclareNoncopyableObject(BaseScopedReadWriteLock);
protected: protected:
RwMutex& m_lock; RwMutex &m_lock;
bool m_IsLocked; bool m_IsLocked;
public: public:
BaseScopedReadWriteLock( RwMutex& locker ) BaseScopedReadWriteLock(RwMutex &locker)
: m_lock( locker ) : m_lock(locker)
{ {
} }
@ -62,29 +62,29 @@ namespace Threading
void Release(); void Release();
bool IsLocked() const { return m_IsLocked; } bool IsLocked() const { return m_IsLocked; }
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// ScopedReadLock / ScopedWriteLock // ScopedReadLock / ScopedWriteLock
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class ScopedReadLock : public BaseScopedReadWriteLock class ScopedReadLock : public BaseScopedReadWriteLock
{ {
public: public:
ScopedReadLock( RwMutex& locker ); ScopedReadLock(RwMutex &locker);
virtual ~ScopedReadLock() throw() {} virtual ~ScopedReadLock() throw() {}
void Acquire(); void Acquire();
}; };
class ScopedWriteLock : public BaseScopedReadWriteLock class ScopedWriteLock : public BaseScopedReadWriteLock
{ {
public: public:
ScopedWriteLock( RwMutex& locker ); ScopedWriteLock(RwMutex &locker);
virtual ~ScopedWriteLock() throw() {} virtual ~ScopedWriteLock() throw() {}
void Acquire(); void Acquire();
protected: protected:
ScopedWriteLock( RwMutex& locker, bool isTryLock ); ScopedWriteLock(RwMutex &locker, bool isTryLock);
}; };
} }

View File

@ -23,8 +23,8 @@
// Microsoft Windows only macro, useful for freeing out COM objects: // Microsoft Windows only macro, useful for freeing out COM objects:
#define safe_release( ptr ) \ #define safe_release(ptr) \
((void) (( ( (ptr) != NULL ) && ((ptr)->Release(), !!0) ), (ptr) = NULL)) ((void)((((ptr) != NULL) && ((ptr)->Release(), !!0)), (ptr) = NULL))
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// SafeArray // SafeArray
@ -32,7 +32,7 @@
// Handy little class for allocating a resizable memory block, complete with exception // Handy little class for allocating a resizable memory block, complete with exception
// error handling and automatic cleanup. A lightweight alternative to std::vector. // error handling and automatic cleanup. A lightweight alternative to std::vector.
// //
template< typename T > template <typename T>
class SafeArray class SafeArray
{ {
DeclareNoncopyableObject(SafeArray); DeclareNoncopyableObject(SafeArray);
@ -45,32 +45,32 @@ public:
int ChunkSize; int ChunkSize;
protected: protected:
T* m_ptr; T *m_ptr;
int m_size; // size of the allocation of memory int m_size; // size of the allocation of memory
protected: protected:
SafeArray( const wxChar* name, T* allocated_mem, int initSize ); SafeArray(const wxChar *name, T *allocated_mem, int initSize);
virtual T* _virtual_realloc( int newsize ); virtual T *_virtual_realloc(int newsize);
// A safe array index fetcher. Asserts if the index is out of bounds (dev and debug // 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). // builds only -- no bounds checking is done in release builds).
T* _getPtr( uint i ) const; T *_getPtr(uint i) const;
public: public:
virtual ~SafeArray() throw(); virtual ~SafeArray() throw();
explicit SafeArray( const wxChar* name=L"Unnamed" ); explicit SafeArray(const wxChar *name = L"Unnamed");
explicit SafeArray( int initialSize, const wxChar* name=L"Unnamed" ); explicit SafeArray(int initialSize, const wxChar *name = L"Unnamed");
void Dispose(); void Dispose();
void ExactAlloc( int newsize ); void ExactAlloc(int newsize);
void MakeRoomFor( int newsize ) void MakeRoomFor(int newsize)
{ {
if( newsize > m_size ) if (newsize > m_size)
ExactAlloc( newsize ); ExactAlloc(newsize);
} }
bool IsDisposed() const { return (m_ptr==NULL); } bool IsDisposed() const { return (m_ptr == NULL); }
// Returns the size of the memory allocation, as according to the array type. // Returns the size of the memory allocation, as according to the array type.
int GetLength() const { return m_size; } int GetLength() const { return m_size; }
@ -79,28 +79,28 @@ public:
// Extends the containment area of the array. Extensions are performed // Extends the containment area of the array. Extensions are performed
// in chunks. // in chunks.
void GrowBy( int items ) void GrowBy(int items)
{ {
MakeRoomFor( m_size + ChunkSize + items + 1 ); MakeRoomFor(m_size + ChunkSize + items + 1);
} }
// Gets a pointer to the requested allocation index. // Gets a pointer to the requested allocation index.
// DevBuilds : Generates assertion if the index is invalid. // DevBuilds : Generates assertion if the index is invalid.
T* GetPtr( uint idx=0 ) { return _getPtr( idx ); } T *GetPtr(uint idx = 0) { return _getPtr(idx); }
const T* GetPtr( uint idx=0 ) const { return _getPtr( idx ); } const T *GetPtr(uint idx = 0) const { return _getPtr(idx); }
// Gets a pointer to the element directly after the last element in the array. // 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* // 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. :) // the out-of-bounds assertion check that typically occurs when you do that. :)
T* GetPtrEnd() { return &m_ptr[m_size]; } T *GetPtrEnd() { return &m_ptr[m_size]; }
const T* GetPtrEnd() const { return &m_ptr[m_size]; } const T *GetPtrEnd() const { return &m_ptr[m_size]; }
// Gets an element of this memory allocation much as if it were an array. // Gets an element of this memory allocation much as if it were an array.
// DevBuilds : Generates assertion if the index is invalid. // DevBuilds : Generates assertion if the index is invalid.
T& operator[]( int idx ) { return *_getPtr( (uint)idx ); } T &operator[](int idx) { return *_getPtr((uint)idx); }
const T& operator[]( int idx ) const { return *_getPtr( (uint)idx ); } const T &operator[](int idx) const { return *_getPtr((uint)idx); }
virtual SafeArray<T>* Clone() const; virtual SafeArray<T> *Clone() const;
}; };
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -113,7 +113,7 @@ public:
// * Classes with copy constructors (copying is done using performance memcpy) // * Classes with copy constructors (copying is done using performance memcpy)
// * Classes with destructors (they're not called, sorry!) // * Classes with destructors (they're not called, sorry!)
// //
template< typename T > template <typename T>
class SafeList class SafeList
{ {
DeclareNoncopyableObject(SafeList); DeclareNoncopyableObject(SafeList);
@ -126,28 +126,28 @@ public:
int ChunkSize; // assigned DefaultChunkSize on init, reconfigurable at any time. int ChunkSize; // assigned DefaultChunkSize on init, reconfigurable at any time.
protected: protected:
T* m_ptr; T *m_ptr;
int m_allocsize; // size of the allocation of memory int m_allocsize; // size of the allocation of memory
uint m_length; // length of the array (active items, not buffer allocation) uint m_length; // length of the array (active items, not buffer allocation)
protected: protected:
virtual T* _virtual_realloc( int newsize ); virtual T *_virtual_realloc(int newsize);
void _MakeRoomFor_threshold( int newsize ); void _MakeRoomFor_threshold(int newsize);
T* _getPtr( uint i ) const; T *_getPtr(uint i) const;
public: public:
virtual ~SafeList() throw(); virtual ~SafeList() throw();
explicit SafeList( const wxChar* name=L"Unnamed" ); explicit SafeList(const wxChar *name = L"Unnamed");
explicit SafeList( int initialSize, const wxChar* name=L"Unnamed" ); explicit SafeList(int initialSize, const wxChar *name = L"Unnamed");
virtual SafeList<T>* Clone() const; virtual SafeList<T> *Clone() const;
void Remove( int index ); void Remove(int index);
void MakeRoomFor( int blockSize ); void MakeRoomFor(int blockSize);
T& New(); T &New();
int Add( const T& src ); int Add(const T &src);
T& AddNew( const T& src ); T &AddNew(const T &src);
// Returns the size of the list, as according to the array type. This includes // 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. // mapped items only. The actual size of the allocation may differ.
@ -162,9 +162,9 @@ public:
m_length = m_allocsize; m_length = m_allocsize;
} }
void GrowBy( int items ) void GrowBy(int items)
{ {
MakeRoomFor( m_length + ChunkSize + items + 1 ); MakeRoomFor(m_length + ChunkSize + items + 1);
} }
// Sets the item length to zero. Does not free memory allocations. // Sets the item length to zero. Does not free memory allocations.
@ -175,14 +175,14 @@ public:
// Gets an element of this memory allocation much as if it were an array. // Gets an element of this memory allocation much as if it were an array.
// DevBuilds : Generates assertion if the index is invalid. // DevBuilds : Generates assertion if the index is invalid.
T& operator[]( int idx ) { return *_getPtr( (uint)idx ); } T &operator[](int idx) { return *_getPtr((uint)idx); }
const T& operator[]( int idx ) const { return *_getPtr( (uint)idx ); } const T &operator[](int idx) const { return *_getPtr((uint)idx); }
T* GetPtr() { return m_ptr; } T *GetPtr() { return m_ptr; }
const T* GetPtr() const { return m_ptr; } const T *GetPtr() const { return m_ptr; }
T& GetLast() { return m_ptr[m_length-1]; } T &GetLast() { return m_ptr[m_length - 1]; }
const T& GetLast() const{ 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. // exception-based error handling and automatic cleanup.
// This one supports aligned data allocations too! // This one supports aligned data allocations too!
template< typename T, uint Alignment > template <typename T, uint Alignment>
class SafeAlignedArray : public SafeArray<T> class SafeAlignedArray : public SafeArray<T>
{ {
typedef SafeArray<T> _parent; typedef SafeArray<T> _parent;
protected: protected:
T* _virtual_realloc( int newsize ); T *_virtual_realloc(int newsize);
public: public:
using _parent::operator[]; using _parent::operator[];
virtual ~SafeAlignedArray() throw(); virtual ~SafeAlignedArray() throw();
explicit SafeAlignedArray( const wxChar* name=L"Unnamed" ) : explicit SafeAlignedArray(const wxChar *name = L"Unnamed")
SafeArray<T>::SafeArray( name ) : SafeArray<T>::SafeArray(name)
{ {
} }
explicit SafeAlignedArray( int initialSize, const wxChar* name=L"Unnamed" ); explicit SafeAlignedArray(int initialSize, const wxChar *name = L"Unnamed");
virtual SafeAlignedArray<T,Alignment>* Clone() const; virtual SafeAlignedArray<T, Alignment> *Clone() const;
}; };

View File

@ -21,103 +21,103 @@
// use its own memory allocation (with an aligned memory, for example). // use its own memory allocation (with an aligned memory, for example).
// Throws: // Throws:
// Exception::OutOfMemory if the allocated_mem pointer is NULL. // Exception::OutOfMemory if the allocated_mem pointer is NULL.
template< typename T > template <typename T>
SafeArray<T>::SafeArray( const wxChar* name, T* allocated_mem, int initSize ) SafeArray<T>::SafeArray(const wxChar *name, T *allocated_mem, int initSize)
: Name( name ) : Name(name)
{ {
ChunkSize = DefaultChunkSize; ChunkSize = DefaultChunkSize;
m_ptr = allocated_mem; m_ptr = allocated_mem;
m_size = initSize; m_size = initSize;
if( m_ptr == NULL ) if (m_ptr == NULL)
throw Exception::OutOfMemory(name) throw Exception::OutOfMemory(name)
.SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initSize)); .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initSize));
} }
template< typename T > template <typename T>
T* SafeArray<T>::_virtual_realloc( int newsize ) T *SafeArray<T>::_virtual_realloc(int newsize)
{ {
T* retval = (T*)((m_ptr == NULL) ? T *retval = (T *)((m_ptr == NULL) ?
malloc( newsize * sizeof(T) ) : malloc(newsize * sizeof(T)) :
realloc( m_ptr, newsize * sizeof(T) ) realloc(m_ptr, newsize * sizeof(T)));
);
if( IsDebugBuild && (retval != NULL)) if (IsDebugBuild && (retval != NULL)) {
{
// Zero everything out to 0xbaadf00d, so that its obviously uncleared // Zero everything out to 0xbaadf00d, so that its obviously uncleared
// to a debuggee // to a debuggee
u32* fill = (u32*)&retval[m_size]; u32 *fill = (u32 *)&retval[m_size];
const u32* end = (u32*)((((uptr)&retval[newsize-1])-3) & ~0x3); const u32 *end = (u32 *)((((uptr)&retval[newsize - 1]) - 3) & ~0x3);
for( ; fill<end; ++fill ) *fill = 0xbaadf00d; for (; fill < end; ++fill)
*fill = 0xbaadf00d;
} }
return retval; return retval;
} }
template< typename T > template <typename T>
SafeArray<T>::~SafeArray() throw() SafeArray<T>::~SafeArray() throw()
{ {
safe_free( m_ptr ); safe_free(m_ptr);
} }
template< typename T > template <typename T>
SafeArray<T>::SafeArray( const wxChar* name ) SafeArray<T>::SafeArray(const wxChar *name)
: Name( name ) : Name(name)
{ {
ChunkSize = DefaultChunkSize; ChunkSize = DefaultChunkSize;
m_ptr = NULL; m_ptr = NULL;
m_size = 0; m_size = 0;
} }
template< typename T > template <typename T>
SafeArray<T>::SafeArray( int initialSize, const wxChar* name ) SafeArray<T>::SafeArray(int initialSize, const wxChar *name)
: Name( name ) : Name(name)
{ {
ChunkSize = DefaultChunkSize; ChunkSize = DefaultChunkSize;
m_ptr = (initialSize==0) ? NULL : (T*)malloc( initialSize * sizeof(T) ); m_ptr = (initialSize == 0) ? NULL : (T *)malloc(initialSize * sizeof(T));
m_size = initialSize; m_size = initialSize;
if( (initialSize != 0) && (m_ptr == NULL) ) if ((initialSize != 0) && (m_ptr == NULL))
throw Exception::OutOfMemory(name) throw Exception::OutOfMemory(name)
.SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initialSize)); .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ctor' [size=%d]", initialSize));
} }
// Clears the contents of the array to zero, and frees all memory allocations. // Clears the contents of the array to zero, and frees all memory allocations.
template< typename T > template <typename T>
void SafeArray<T>::Dispose() void SafeArray<T>::Dispose()
{ {
m_size = 0; m_size = 0;
safe_free( m_ptr ); safe_free(m_ptr);
} }
template< typename T > template <typename T>
T* SafeArray<T>::_getPtr( uint i ) const T *SafeArray<T>::_getPtr(uint i) const
{ {
IndexBoundsAssumeDev( WX_STR(Name), i, m_size ); IndexBoundsAssumeDev(WX_STR(Name), i, m_size);
return &m_ptr[i]; return &m_ptr[i];
} }
// reallocates the array to the explicit size. Can be used to shrink or grow an // reallocates the array to the explicit size. Can be used to shrink or grow an
// array, and bypasses the internal threshold growth indicators. // array, and bypasses the internal threshold growth indicators.
template< typename T > template <typename T>
void SafeArray<T>::ExactAlloc( int newsize ) void SafeArray<T>::ExactAlloc(int newsize)
{ {
if( newsize == m_size ) return; if (newsize == m_size)
return;
m_ptr = _virtual_realloc( newsize ); m_ptr = _virtual_realloc(newsize);
if( m_ptr == NULL ) if (m_ptr == NULL)
throw Exception::OutOfMemory(Name) throw Exception::OutOfMemory(Name)
.SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ExactAlloc' [oldsize=%d] [newsize=%d]", m_size, newsize)); .SetDiagMsg(wxsFormat(L"Called from 'SafeArray::ExactAlloc' [oldsize=%d] [newsize=%d]", m_size, newsize));
m_size = newsize; m_size = newsize;
} }
template< typename T > template <typename T>
SafeArray<T>* SafeArray<T>::Clone() const SafeArray<T> *SafeArray<T>::Clone() const
{ {
SafeArray<T>* retval = new SafeArray<T>( m_size ); SafeArray<T> *retval = new SafeArray<T>(m_size);
memcpy( retval->GetPtr(), m_ptr, sizeof(T) * m_size ); memcpy(retval->GetPtr(), m_ptr, sizeof(T) * m_size);
return retval; return retval;
} }
@ -126,40 +126,38 @@ SafeArray<T>* SafeArray<T>::Clone() const
// SafeAlignedArray<T> (implementations) // SafeAlignedArray<T> (implementations)
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
template< typename T, uint Alignment > template <typename T, uint Alignment>
T* SafeAlignedArray<T,Alignment>::_virtual_realloc( int newsize ) T *SafeAlignedArray<T, Alignment>::_virtual_realloc(int newsize)
{ {
return (T*)( ( this->m_ptr == NULL ) ? return (T *)((this->m_ptr == NULL) ?
_aligned_malloc( newsize * sizeof(T), Alignment ) : _aligned_malloc(newsize * sizeof(T), Alignment) :
pcsx2_aligned_realloc( this->m_ptr, newsize * sizeof(T), Alignment, this->m_size * sizeof(T) ) 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. // Appends "(align: xx)" to the name of the allocation in devel builds.
// Maybe useful,maybe not... no harm in attaching it. :D // Maybe useful,maybe not... no harm in attaching it. :D
template< typename T, uint Alignment > template <typename T, uint Alignment>
SafeAlignedArray<T,Alignment>::~SafeAlignedArray() throw() SafeAlignedArray<T, Alignment>::~SafeAlignedArray() throw()
{ {
safe_aligned_free( this->m_ptr ); safe_aligned_free(this->m_ptr);
// mptr is set to null, so the parent class's destructor won't re-free it. // mptr is set to null, so the parent class's destructor won't re-free it.
} }
template< typename T, uint Alignment > template <typename T, uint Alignment>
SafeAlignedArray<T,Alignment>::SafeAlignedArray( int initialSize, const wxChar* name ) : SafeAlignedArray<T, Alignment>::SafeAlignedArray(int initialSize, const wxChar *name)
SafeArray<T>::SafeArray( : SafeArray<T>::SafeArray(
name, name,
(T*)_aligned_malloc( initialSize * sizeof(T), Alignment ), (T *)_aligned_malloc(initialSize * sizeof(T), Alignment),
initialSize initialSize)
)
{ {
} }
template< typename T, uint Alignment > template <typename T, uint Alignment>
SafeAlignedArray<T,Alignment>* SafeAlignedArray<T,Alignment>::Clone() const SafeAlignedArray<T, Alignment> *SafeAlignedArray<T, Alignment>::Clone() const
{ {
SafeAlignedArray<T,Alignment>* retval = new SafeAlignedArray<T,Alignment>( this->m_size ); SafeAlignedArray<T, Alignment> *retval = new SafeAlignedArray<T, Alignment>(this->m_size);
memcpy( retval->GetPtr(), this->m_ptr, sizeof(T) * this->m_size ); memcpy(retval->GetPtr(), this->m_ptr, sizeof(T) * this->m_size);
return retval; return retval;
} }
@ -167,21 +165,21 @@ SafeAlignedArray<T,Alignment>* SafeAlignedArray<T,Alignment>::Clone() const
// SafeList<T> (implementations) // SafeList<T> (implementations)
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
template< typename T > template <typename T>
T* SafeList<T>::_virtual_realloc( int newsize ) T *SafeList<T>::_virtual_realloc(int newsize)
{ {
return (T*)realloc( m_ptr, newsize * sizeof(T) ); return (T *)realloc(m_ptr, newsize * sizeof(T));
} }
template< typename T > template <typename T>
SafeList<T>::~SafeList() throw() SafeList<T>::~SafeList() throw()
{ {
safe_free( m_ptr ); safe_free(m_ptr);
} }
template< typename T > template <typename T>
SafeList<T>::SafeList( const wxChar* name ) SafeList<T>::SafeList(const wxChar *name)
: Name( name ) : Name(name)
{ {
ChunkSize = DefaultChunkSize; ChunkSize = DefaultChunkSize;
m_ptr = NULL; m_ptr = NULL;
@ -189,74 +187,70 @@ SafeList<T>::SafeList( const wxChar* name )
m_length = 0; m_length = 0;
} }
template< typename T > template <typename T>
SafeList<T>::SafeList( int initialSize, const wxChar* name ) SafeList<T>::SafeList(int initialSize, const wxChar *name)
: Name( name ) : Name(name)
{ {
ChunkSize = DefaultChunkSize; ChunkSize = DefaultChunkSize;
m_allocsize = initialSize; m_allocsize = initialSize;
m_length = 0; m_length = 0;
m_ptr = (T*)malloc( initialSize * sizeof(T) ); m_ptr = (T *)malloc(initialSize * sizeof(T));
if( m_ptr == NULL ) if (m_ptr == NULL)
throw Exception::OutOfMemory(Name) throw Exception::OutOfMemory(Name)
.SetDiagMsg(wxsFormat(L"called from 'SafeList::ctor' [length=%d]", m_length)); .SetDiagMsg(wxsFormat(L"called from 'SafeList::ctor' [length=%d]", m_length));
for( int i=0; i<m_allocsize; ++i ) for (int i = 0; i < m_allocsize; ++i) {
{
new (&m_ptr[i]) T(); new (&m_ptr[i]) T();
} }
} }
template< typename T > template <typename T>
T* SafeList<T>::_getPtr( uint i ) const T *SafeList<T>::_getPtr(uint i) const
{ {
IndexBoundsAssumeDev( WX_STR(Name), i, m_length ); IndexBoundsAssumeDev(WX_STR(Name), i, m_length);
return &m_ptr[i]; return &m_ptr[i];
} }
// Ensures that the allocation is large enough to fit data of the // Ensures that the allocation is large enough to fit data of the
// amount requested. The memory allocation is not resized smaller. // amount requested. The memory allocation is not resized smaller.
template< typename T > template <typename T>
void SafeList<T>::MakeRoomFor( int blockSize ) void SafeList<T>::MakeRoomFor(int blockSize)
{ {
if( blockSize > m_allocsize ) if (blockSize > m_allocsize) {
{
const int newalloc = blockSize + ChunkSize; const int newalloc = blockSize + ChunkSize;
m_ptr = _virtual_realloc( newalloc ); m_ptr = _virtual_realloc(newalloc);
if( m_ptr == NULL ) if (m_ptr == NULL)
throw Exception::OutOfMemory(Name) throw Exception::OutOfMemory(Name)
.SetDiagMsg(wxsFormat(L"Called from 'SafeList::MakeRoomFor' [oldlen=%d] [newlen=%d]", m_length, blockSize)); .SetDiagMsg(wxsFormat(L"Called from 'SafeList::MakeRoomFor' [oldlen=%d] [newlen=%d]", m_length, blockSize));
for( ; m_allocsize<newalloc; ++m_allocsize ) for (; m_allocsize < newalloc; ++m_allocsize) {
{
new (&m_ptr[m_allocsize]) T(); new (&m_ptr[m_allocsize]) T();
} }
} }
} }
// Appends an item to the end of the list and returns a handle to it. // Appends an item to the end of the list and returns a handle to it.
template< typename T > template <typename T>
T& SafeList<T>::New() T &SafeList<T>::New()
{ {
_MakeRoomFor_threshold( m_length + 1 ); _MakeRoomFor_threshold(m_length + 1);
return m_ptr[m_length++]; return m_ptr[m_length++];
} }
template< typename T > template <typename T>
int SafeList<T>::Add( const T& src ) int SafeList<T>::Add(const T &src)
{ {
_MakeRoomFor_threshold( m_length + 1 ); _MakeRoomFor_threshold(m_length + 1);
m_ptr[m_length] = src; m_ptr[m_length] = src;
return m_length++; return m_length++;
} }
// Same as Add, but returns the handle of the new object instead of it's array index. // Same as Add, but returns the handle of the new object instead of it's array index.
template< typename T > template <typename T>
T& SafeList<T>::AddNew( const T& src ) T &SafeList<T>::AddNew(const T &src)
{ {
_MakeRoomFor_threshold( m_length + 1 ); _MakeRoomFor_threshold(m_length + 1);
m_ptr[m_length] = src; m_ptr[m_length] = src;
return m_ptr[m_length]; return m_ptr[m_length];
} }
@ -264,26 +258,26 @@ T& SafeList<T>::AddNew( const T& src )
// Performs a standard array-copy removal of the given item. All items past the // Performs a standard array-copy removal of the given item. All items past the
// given item are copied over. // given item are copied over.
// DevBuilds : Generates assertion if the index is invalid. // DevBuilds : Generates assertion if the index is invalid.
template< typename T > template <typename T>
void SafeList<T>::Remove( int index ) void SafeList<T>::Remove(int index)
{ {
IndexBoundsAssumeDev( Name.c_str(), index, m_length ); IndexBoundsAssumeDev(Name.c_str(), index, m_length);
int copylen = m_length - index; int copylen = m_length - index;
if( copylen > 0 ) if (copylen > 0)
memcpy( &m_ptr[index], &m_ptr[index+1], copylen ); memcpy(&m_ptr[index], &m_ptr[index + 1], copylen);
} }
template< typename T > template <typename T>
SafeList<T>* SafeList<T>::Clone() const SafeList<T> *SafeList<T>::Clone() const
{ {
SafeList<T>* retval = new SafeList<T>( m_length ); SafeList<T> *retval = new SafeList<T>(m_length);
memcpy( retval->m_ptr, m_ptr, sizeof(T) * m_length ); memcpy(retval->m_ptr, m_ptr, sizeof(T) * m_length);
return retval; return retval;
} }
template< typename T > template <typename T>
void SafeList<T>::_MakeRoomFor_threshold( int newsize ) void SafeList<T>::_MakeRoomFor_threshold(int newsize)
{ {
MakeRoomFor( newsize + ChunkSize ); MakeRoomFor(newsize + ChunkSize);
} }

View File

@ -27,32 +27,32 @@
// Safe deallocation macros -- checks pointer validity (non-null) when needed, and sets // Safe deallocation macros -- checks pointer validity (non-null) when needed, and sets
// pointer to null after deallocation. // pointer to null after deallocation.
#define safe_delete( ptr ) \ #define safe_delete(ptr) \
((void) (delete (ptr)), (ptr) = NULL) ((void)(delete (ptr)), (ptr) = NULL)
#define safe_delete_array( ptr ) \ #define safe_delete_array(ptr) \
((void) (delete[] (ptr)), (ptr) = NULL) ((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. // just about every compiler and libc implementation of any recentness.
#define safe_free( ptr ) \ #define safe_free(ptr) \
( (void) (free( ptr ), !!0), (ptr) = NULL ) ((void)(free(ptr), !!0), (ptr) = NULL)
//((void) (( ( (ptr) != NULL ) && (free( ptr ), !!0) ), (ptr) = NULL)) //((void) (( ( (ptr) != NULL ) && (free( ptr ), !!0) ), (ptr) = NULL))
#define safe_fclose( ptr ) \ #define safe_fclose(ptr) \
((void) (( ( (ptr) != NULL ) && (fclose( ptr ), !!0) ), (ptr) = NULL)) ((void)((((ptr) != NULL) && (fclose(ptr), !!0)), (ptr) = NULL))
// Implementation note: all known implementations of _aligned_free check the pointer for // 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 // NULL status (our implementation under GCC, and microsoft's under MSVC), so no need to
// do it here. // do it here.
#define safe_aligned_free( ptr ) \ #define safe_aligned_free(ptr) \
((void) ( _aligned_free( ptr ), (ptr) = NULL )) ((void)(_aligned_free(ptr), (ptr) = NULL))
// aligned_malloc: Implement/declare linux equivalents here! // aligned_malloc: Implement/declare linux equivalents here!
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
extern void* __fastcall _aligned_malloc(size_t size, size_t align); 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 *__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 _aligned_free(void *pmem);
#else #else
#define pcsx2_aligned_realloc(handle, new_size, align, old_size) \ #define pcsx2_aligned_realloc(handle, new_size, align, old_size) \
_aligned_realloc(handle, new_size, align) _aligned_realloc(handle, new_size, align)
@ -62,8 +62,8 @@ extern void _aligned_free(void* pmem);
// pxDoOutOfMemory // pxDoOutOfMemory
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
typedef void FnType_OutOfMemory( uptr blocksize ); typedef void FnType_OutOfMemory(uptr blocksize);
typedef FnType_OutOfMemory* Fnptr_OutOfMemory; typedef FnType_OutOfMemory *Fnptr_OutOfMemory;
// This method is meant to be assigned by applications that link against pxWex. It is called // 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 // (invoked) prior to most pxWex built-in memory/array classes throwing exceptions, and can be
@ -89,11 +89,11 @@ extern Fnptr_OutOfMemory pxDoOutOfMemory;
// destructing container for malloc. The entire class is almost completely dependency free, // destructing container for malloc. The entire class is almost completely dependency free,
// and thus can be included everywhere and anywhere without dependency hassles. // and thus can be included everywhere and anywhere without dependency hassles.
// //
template< typename T > template <typename T>
class BaseScopedAlloc class BaseScopedAlloc
{ {
protected: protected:
T* m_buffer; T *m_buffer;
uint m_size; uint m_size;
public: public:
@ -117,47 +117,48 @@ public:
// Parameter: // Parameter:
// newSize - size of the new allocation, in elements (not bytes!). If the specified // 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(). // size is 0, the the allocation is freed, same as calling Free().
virtual void Alloc( size_t newsize )=0; virtual void Alloc(size_t newsize) = 0;
// Re-sizes the allocation to the requested size, without any data loss. // Re-sizes the allocation to the requested size, without any data loss.
// Parameter: // Parameter:
// newSize - size of the new allocation, in elements (not bytes!). If the specified // 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(). // size is 0, the the allocation is freed, same as calling Free().
virtual void Resize( size_t newsize )=0; virtual void Resize(size_t newsize) = 0;
void Free() void Free()
{ {
Alloc( 0 ); Alloc(0);
} }
// Makes enough room for the requested size. Existing data in the array is retained. // Makes enough room for the requested size. Existing data in the array is retained.
void MakeRoomFor( uint size ) void MakeRoomFor(uint size)
{ {
if (size <= m_size) return; if (size <= m_size)
Resize( size ); return;
Resize(size);
} }
T* GetPtr( uint idx=0 ) const T *GetPtr(uint idx = 0) const
{ {
#if pxUSE_SECURE_MALLOC #if pxUSE_SECURE_MALLOC
IndexBoundsAssumeDev( "ScopedAlloc", idx, m_size ); IndexBoundsAssumeDev("ScopedAlloc", idx, m_size);
#endif #endif
return &m_buffer[idx]; return &m_buffer[idx];
} }
T& operator[]( uint idx ) T &operator[](uint idx)
{ {
#if pxUSE_SECURE_MALLOC #if pxUSE_SECURE_MALLOC
IndexBoundsAssumeDev( "ScopedAlloc", idx, m_size ); IndexBoundsAssumeDev("ScopedAlloc", idx, m_size);
#endif #endif
return m_buffer[idx]; return m_buffer[idx];
} }
const T& operator[]( uint idx ) const const T &operator[](uint idx) const
{ {
#if pxUSE_SECURE_MALLOC #if pxUSE_SECURE_MALLOC
IndexBoundsAssumeDev( "ScopedAlloc", idx, m_size ); IndexBoundsAssumeDev("ScopedAlloc", idx, m_size);
#endif #endif
return m_buffer[idx]; return m_buffer[idx];
} }
}; };
@ -171,13 +172,14 @@ public:
// //
// See docs for BaseScopedAlloc for details and rationale. // See docs for BaseScopedAlloc for details and rationale.
// //
template< typename T > template <typename T>
class ScopedAlloc : public BaseScopedAlloc<T> class ScopedAlloc : public BaseScopedAlloc<T>
{ {
typedef BaseScopedAlloc<T> _parent; typedef BaseScopedAlloc<T> _parent;
public: public:
ScopedAlloc( size_t size=0 ) : _parent() ScopedAlloc(size_t size = 0)
: _parent()
{ {
Alloc(size); Alloc(size);
} }
@ -187,21 +189,22 @@ public:
safe_free(this->m_buffer); safe_free(this->m_buffer);
} }
virtual void Alloc( size_t newsize ) virtual void Alloc(size_t newsize)
{ {
safe_free(this->m_buffer); safe_free(this->m_buffer);
this->m_size = newsize; this->m_size = newsize;
if (!this->m_size) return; if (!this->m_size)
return;
this->m_buffer = (T*)malloc( this->m_size * sizeof(T) ); this->m_buffer = (T *)malloc(this->m_size * sizeof(T));
if (!this->m_buffer) if (!this->m_buffer)
throw Exception::OutOfMemory(L"ScopedAlloc"); throw Exception::OutOfMemory(L"ScopedAlloc");
} }
virtual void Resize( size_t newsize ) virtual void Resize(size_t newsize)
{ {
this->m_size = newsize; this->m_size = newsize;
this->m_buffer = (T*)realloc(this->m_buffer, this->m_size * sizeof(T)); this->m_buffer = (T *)realloc(this->m_buffer, this->m_size * sizeof(T));
if (!this->m_buffer) if (!this->m_buffer)
throw Exception::OutOfMemory(L"ScopedAlloc::Resize"); throw Exception::OutOfMemory(L"ScopedAlloc::Resize");
@ -219,13 +222,14 @@ public:
// //
// See docs for BaseScopedAlloc for details and rationale. // See docs for BaseScopedAlloc for details and rationale.
// //
template< typename T, uint align > template <typename T, uint align>
class ScopedAlignedAlloc : public BaseScopedAlloc<T> class ScopedAlignedAlloc : public BaseScopedAlloc<T>
{ {
typedef BaseScopedAlloc<T> _parent; typedef BaseScopedAlloc<T> _parent;
public: public:
ScopedAlignedAlloc( size_t size=0 ) : _parent() ScopedAlignedAlloc(size_t size = 0)
: _parent()
{ {
Alloc(size); Alloc(size);
} }
@ -235,20 +239,21 @@ public:
safe_aligned_free(this->m_buffer); safe_aligned_free(this->m_buffer);
} }
virtual void Alloc( size_t newsize ) virtual void Alloc(size_t newsize)
{ {
safe_aligned_free(this->m_buffer); safe_aligned_free(this->m_buffer);
this->m_size = newsize; this->m_size = newsize;
if (!this->m_size) return; if (!this->m_size)
return;
this->m_buffer = (T*)_aligned_malloc( this->m_size * sizeof(T), align ); this->m_buffer = (T *)_aligned_malloc(this->m_size * sizeof(T), align);
if (!this->m_buffer) if (!this->m_buffer)
throw Exception::OutOfMemory(L"ScopedAlignedAlloc"); throw Exception::OutOfMemory(L"ScopedAlignedAlloc");
} }
virtual void Resize( size_t newsize ) 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_buffer = (T *)pcsx2_aligned_realloc(this->m_buffer, newsize * sizeof(T), align, this->m_size * sizeof(T));
this->m_size = newsize; this->m_size = newsize;
if (!this->m_buffer) if (!this->m_buffer)

View File

@ -22,35 +22,36 @@ using Threading::ScopedLock;
// ScopedPtrMT // ScopedPtrMT
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
template< typename T > template <typename T>
class ScopedPtrMT class ScopedPtrMT
{ {
DeclareNoncopyableObject(ScopedPtrMT); DeclareNoncopyableObject(ScopedPtrMT);
protected: protected:
std::atomic<T*> m_ptr; std::atomic<T *> m_ptr;
Threading::Mutex m_mtx; Threading::Mutex m_mtx;
public: public:
typedef T element_type; typedef T element_type;
wxEXPLICIT ScopedPtrMT(T * ptr = nullptr) wxEXPLICIT ScopedPtrMT(T *ptr = nullptr)
{ {
m_ptr = ptr; m_ptr = ptr;
} }
~ScopedPtrMT() throw() { _Delete_unlocked(); } ~ScopedPtrMT() throw() { _Delete_unlocked(); }
ScopedPtrMT& Reassign(T * ptr = nullptr) ScopedPtrMT &Reassign(T *ptr = nullptr)
{ {
T* doh = m_ptr.exchange(ptr); T *doh = m_ptr.exchange(ptr);
if ( ptr != doh ) delete doh; if (ptr != doh)
delete doh;
return *this; return *this;
} }
ScopedPtrMT& Delete() throw() ScopedPtrMT &Delete() throw()
{ {
ScopedLock lock( m_mtx ); ScopedLock lock(m_mtx);
_Delete_unlocked(); _Delete_unlocked();
} }
@ -58,23 +59,23 @@ public:
// (ScopedPtr will be nullptr after this method) // (ScopedPtr will be nullptr after this method)
T *DetachPtr() T *DetachPtr()
{ {
ScopedLock lock( m_mtx ); 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 // Returns the managed pointer. Can return nullptr as a valid result if the ScopedPtrMT
// has no object in management. // has no object in management.
T* GetPtr() const T *GetPtr() const
{ {
return m_ptr; return m_ptr;
} }
void SwapPtr(ScopedPtrMT& other) void SwapPtr(ScopedPtrMT &other)
{ {
ScopedLock lock( m_mtx ); ScopedLock lock(m_mtx);
m_ptr.exchange(other.m_ptr.exchange(m_ptr.load())); m_ptr.exchange(other.m_ptr.exchange(m_ptr.load()));
T * const tmp = other.m_ptr; T *const tmp = other.m_ptr;
other.m_ptr = m_ptr; other.m_ptr = m_ptr;
m_ptr = tmp; m_ptr = tmp;
} }
@ -92,25 +93,25 @@ public:
} }
// Equality // Equality
bool operator==(T* pT) const throw() bool operator==(T *pT) const throw()
{ {
return m_ptr == pT; return m_ptr == pT;
} }
// Inequality // Inequality
bool operator!=(T* pT) const throw() bool operator!=(T *pT) const throw()
{ {
return !operator==(pT); return !operator==(pT);
} }
// Convenient assignment operator. ScopedPtrMT = nullptr will issue an automatic deletion // Convenient assignment operator. ScopedPtrMT = nullptr will issue an automatic deletion
// of the managed pointer. // of the managed pointer.
ScopedPtrMT& operator=( T* src ) ScopedPtrMT &operator=(T *src)
{ {
return Reassign( src ); return Reassign(src);
} }
#if 0 #if 0
operator T*() const operator T*() const
{ {
return m_ptr; return m_ptr;
@ -129,7 +130,7 @@ public:
pxAssert(m_ptr != nullptr); pxAssert(m_ptr != nullptr);
return m_ptr; return m_ptr;
} }
#endif #endif
protected: protected:
void _Delete_unlocked() throw() void _Delete_unlocked() throw()

View File

@ -22,10 +22,10 @@
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
#if _WIN32 #if _WIN32
#define WX_STR(str) (str.wc_str()) #define WX_STR(str) (str.wc_str())
#else #else
// Stupid wx3.0 doesn't support c_str for vararg function // Stupid wx3.0 doesn't support c_str for vararg function
#define WX_STR(str) (static_cast<const char*>(str.c_str())) #define WX_STR(str) (static_cast<const char *>(str.c_str()))
#endif #endif
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -34,59 +34,59 @@
// Converts a string to UTF8 and provides an interface for getting its length. // Converts a string to UTF8 and provides an interface for getting its length.
class pxToUTF8 class pxToUTF8
{ {
DeclareNoncopyableObject( pxToUTF8 ); DeclareNoncopyableObject(pxToUTF8);
protected: protected:
wxCharBuffer m_result; wxCharBuffer m_result;
int m_length; int m_length;
public: public:
explicit pxToUTF8(const wxString& src) explicit pxToUTF8(const wxString &src)
: m_result( src.ToUTF8() ) : m_result(src.ToUTF8())
{ {
m_length = -1; m_length = -1;
} }
size_t Length() size_t Length()
{ {
if( -1 == m_length ) if (-1 == m_length)
m_length = strlen( m_result ); m_length = strlen(m_result);
return m_length; return m_length;
} }
void Convert( const wxString& src ) void Convert(const wxString &src)
{ {
m_result = src.ToUTF8(); m_result = src.ToUTF8();
m_length = -1; m_length = -1;
} }
const char* data() const { return m_result; } const char *data() const { return m_result; }
operator const char*() const operator const char *() const
{ {
return m_result.data(); 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... // wxWidgets lacks one of its own...
extern const wxRect wxDefaultRect; extern const wxRect wxDefaultRect;
extern void SplitString( wxArrayString& dest, const wxString& src, const wxString& delims, wxStringTokenizerMode mode = wxTOKEN_RET_EMPTY_ALL ); 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 wxArrayString &src, const wxString &separator);
extern wxString JoinString( const wxChar** 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 wxPoint &src, const wxString &separator = L",");
extern wxString ToString( const wxSize& 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 wxRect &src, const wxString &separator = L",");
extern bool TryParse( wxPoint& dest, const wxStringTokenizer& parts ); extern bool TryParse(wxPoint &dest, const wxStringTokenizer &parts);
extern bool TryParse( wxSize& 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(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(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(wxRect &dest, const wxString &src, const wxRect &defval = wxDefaultRect, const wxString &separators = L",");
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// ParsedAssignmentString // ParsedAssignmentString
@ -108,7 +108,7 @@ struct ParsedAssignmentString
wxString rvalue; wxString rvalue;
bool IsComment; bool IsComment;
ParsedAssignmentString( const wxString& src ); ParsedAssignmentString(const wxString &src);
}; };
// ====================================================================================== // ======================================================================================
@ -145,33 +145,33 @@ protected:
public: public:
FastFormatAscii(); FastFormatAscii();
~FastFormatAscii() throw(); ~FastFormatAscii() throw();
FastFormatAscii& Write( const char* fmt, ... ); FastFormatAscii &Write(const char *fmt, ...);
FastFormatAscii& WriteV( const char* fmt, va_list argptr ); FastFormatAscii &WriteV(const char *fmt, va_list argptr);
void Clear(); void Clear();
bool IsEmpty() const; bool IsEmpty() const;
const char* c_str() const { return m_dest.GetPtr(); } const char *c_str() const { return m_dest.GetPtr(); }
operator const char*() const { return m_dest.GetPtr(); } operator const char *() const { return m_dest.GetPtr(); }
const wxString GetString() const; const wxString GetString() const;
//operator wxString() const; //operator wxString() const;
FastFormatAscii& operator+=(const wxString& s) FastFormatAscii &operator+=(const wxString &s)
{ {
Write( "%s", WX_STR(s) ); Write("%s", WX_STR(s));
return *this; return *this;
} }
FastFormatAscii& operator+=(const wxChar* psz ) FastFormatAscii &operator+=(const wxChar *psz)
{ {
Write( "%ls", psz ); Write("%ls", psz);
return *this; return *this;
} }
FastFormatAscii& operator+=(const char* psz ) FastFormatAscii &operator+=(const char *psz)
{ {
Write( "%s", psz ); Write("%s", psz);
return *this; return *this;
} }
}; };
@ -189,50 +189,50 @@ public:
FastFormatUnicode(); FastFormatUnicode();
~FastFormatUnicode() throw(); ~FastFormatUnicode() throw();
FastFormatUnicode& Write( const char* fmt, ... ); FastFormatUnicode &Write(const char *fmt, ...);
FastFormatUnicode& Write( const wxChar* fmt, ... ); FastFormatUnicode &Write(const wxChar *fmt, ...);
FastFormatUnicode& Write( const wxString fmt, ... ); FastFormatUnicode &Write(const wxString fmt, ...);
FastFormatUnicode& WriteV( const char* fmt, va_list argptr ); FastFormatUnicode &WriteV(const char *fmt, va_list argptr);
FastFormatUnicode& WriteV( const wxChar* fmt, va_list argptr ); FastFormatUnicode &WriteV(const wxChar *fmt, va_list argptr);
void Clear(); void Clear();
bool IsEmpty() const; bool IsEmpty() const;
uint Length() const { return m_Length; } uint Length() const { return m_Length; }
FastFormatUnicode& ToUpper(); FastFormatUnicode &ToUpper();
FastFormatUnicode& ToLower(); FastFormatUnicode &ToLower();
const wxChar* c_str() 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 const wxChar *() const { return (const wxChar *)m_dest.GetPtr(); }
operator wxString() const { return (const wxChar*)m_dest.GetPtr(); } operator wxString() const { return (const wxChar *)m_dest.GetPtr(); }
FastFormatUnicode& operator+=(const wxString& s) FastFormatUnicode &operator+=(const wxString &s)
{ {
Write( L"%s", WX_STR(s) ); Write(L"%s", WX_STR(s));
return *this; return *this;
} }
FastFormatUnicode& operator+=(const wxChar* psz ) FastFormatUnicode &operator+=(const wxChar *psz)
{ {
Write( L"%s", psz ); Write(L"%s", psz);
return *this; 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 pxsFmt FastFormatUnicode().Write
#define pxsFmtV FastFormatUnicode().WriteV #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+=(wxString &str1, const FastFormatUnicode &str2);
extern wxString operator+(const 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 wxChar *str1, const FastFormatUnicode &str2);
extern wxString operator+(const FastFormatUnicode& str1, const wxString& str2); extern wxString operator+(const FastFormatUnicode &str1, const wxString &str2);
extern wxString operator+(const FastFormatUnicode& str1, const wxChar* 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 // These functions are useful since they are ASCII always, even under Unicode. Typically
// even in a unicode app. // even in a unicode app.
extern void ssappendf(std::string& dest, const char* format, ...); extern void ssappendf(std::string &dest, const char *format, ...);

View File

@ -29,7 +29,7 @@
#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() \ #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 // pxThreadLog / ConsoleLogSource_Threading
@ -44,14 +44,17 @@ public:
ConsoleLogSource_Threading(); ConsoleLogSource_Threading();
bool Write( const wxString& thrname, const wxChar* msg ) { bool Write(const wxString &thrname, const wxChar *msg)
return _parent::Write( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg ); {
return _parent::Write(wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg);
} }
bool Warn( const wxString& thrname, const wxChar* msg ) { bool Warn(const wxString &thrname, const wxChar *msg)
return _parent::Warn( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg ); {
return _parent::Warn(wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg);
} }
bool Error( const wxString& thrname, const wxChar* msg ) { bool Error(const wxString &thrname, const wxChar *msg)
return _parent::Error( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg ); {
return _parent::Error(wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg);
} }
}; };
@ -69,50 +72,51 @@ 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) //#define PCSX2_THREAD_LOCAL 0 // uncomment this line to force-disable native TLS (useful for testing TlsVariable on windows/linux)
#ifndef PCSX2_THREAD_LOCAL #ifndef PCSX2_THREAD_LOCAL
# define PCSX2_THREAD_LOCAL 1 #define PCSX2_THREAD_LOCAL 1
#endif #endif
class wxTimeSpan; class wxTimeSpan;
namespace Threading namespace Threading
{ {
class pxThread; class pxThread;
class RwMutex; class RwMutex;
extern void pxTestCancel(); extern void pxTestCancel();
extern pxThread* pxGetCurrentThread(); extern pxThread *pxGetCurrentThread();
extern wxString pxGetCurrentThreadName(); extern wxString pxGetCurrentThreadName();
extern u64 GetThreadCpuTime(); extern u64 GetThreadCpuTime();
extern u64 GetThreadTicksPerSecond(); extern u64 GetThreadTicksPerSecond();
// Yields the current thread and provides cancellation points if the thread is managed by // Yields the current thread and provides cancellation points if the thread is managed by
// pxThread. Unmanaged threads use standard Sleep. // pxThread. Unmanaged threads use standard Sleep.
extern void pxYield( int ms ); extern void pxYield(int ms);
} }
namespace Exception namespace Exception
{ {
class BaseThreadError : public RuntimeError class BaseThreadError : public RuntimeError
{
DEFINE_EXCEPTION_COPYTORS(BaseThreadError, RuntimeError)
DEFINE_EXCEPTION_MESSAGES(BaseThreadError)
public:
Threading::pxThread *m_thread;
protected:
BaseThreadError()
{ {
DEFINE_EXCEPTION_COPYTORS( BaseThreadError, RuntimeError )
DEFINE_EXCEPTION_MESSAGES( BaseThreadError )
public:
Threading::pxThread* m_thread;
protected:
BaseThreadError() {
m_thread = NULL; m_thread = NULL;
} }
public: public:
explicit BaseThreadError( Threading::pxThread* _thread ) explicit BaseThreadError(Threading::pxThread *_thread)
{ {
m_thread = _thread; m_thread = _thread;
m_message_diag = L"An unspecified thread-related error occurred (thread=%s)"; m_message_diag = L"An unspecified thread-related error occurred (thread=%s)";
} }
explicit BaseThreadError( Threading::pxThread& _thread ) explicit BaseThreadError(Threading::pxThread &_thread)
{ {
m_thread = &_thread; m_thread = &_thread;
m_message_diag = L"An unspecified thread-related error occurred (thread=%s)"; m_message_diag = L"An unspecified thread-related error occurred (thread=%s)";
@ -121,27 +125,27 @@ namespace Exception
virtual wxString FormatDiagnosticMessage() const; virtual wxString FormatDiagnosticMessage() const;
virtual wxString FormatDisplayMessage() const; virtual wxString FormatDisplayMessage() const;
Threading::pxThread& Thread(); Threading::pxThread &Thread();
const Threading::pxThread& Thread() const; const Threading::pxThread &Thread() const;
}; };
class ThreadCreationError : public BaseThreadError class ThreadCreationError : public BaseThreadError
{ {
DEFINE_EXCEPTION_COPYTORS( ThreadCreationError, BaseThreadError ) DEFINE_EXCEPTION_COPYTORS(ThreadCreationError, BaseThreadError)
public: public:
explicit ThreadCreationError( Threading::pxThread* _thread ) explicit ThreadCreationError(Threading::pxThread *_thread)
{ {
m_thread = _thread; m_thread = _thread;
SetBothMsgs( L"Thread creation failure. An unspecified error occurred while trying to create the %s thread." ); SetBothMsgs(L"Thread creation failure. An unspecified error occurred while trying to create the %s thread.");
} }
explicit ThreadCreationError( Threading::pxThread& _thread ) explicit ThreadCreationError(Threading::pxThread &_thread)
{ {
m_thread = &_thread; m_thread = &_thread;
SetBothMsgs( L"Thread creation failure. An unspecified error occurred while trying to create the %s 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, // The following set of documented functions have Linux/Win32 specific implementations,
// which are found in WinThreads.cpp and LnxThreads.cpp // which are found in WinThreads.cpp and LnxThreads.cpp
// Releases a timeslice to other threads. // Releases a timeslice to other threads.
extern void Timeslice(); extern void Timeslice();
// For use in spin/wait loops. // For use in spin/wait loops.
extern void SpinWait(); extern void SpinWait();
// Optional implementation to enable hires thread/process scheduler for the operating system. // Optional implementation to enable hires thread/process scheduler for the operating system.
// Needed by Windows, but might not be relevant to other platforms. // Needed by Windows, but might not be relevant to other platforms.
extern void EnableHiresScheduler(); extern void EnableHiresScheduler();
extern void DisableHiresScheduler(); extern void DisableHiresScheduler();
// sleeps the current thread for the given number of milliseconds. // sleeps the current thread for the given number of milliseconds.
extern void Sleep( int ms ); extern void Sleep(int ms);
// pthread Cond is an evil api that is not suited for Pcsx2 needs. // 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) // Let's not use it. Use mutexes and semaphores instead to create waits. (Air)
#if 0 #if 0
struct WaitEvent struct WaitEvent
{ {
@ -194,12 +198,12 @@ namespace Threading
// If TryAcquire() returns true, you've locked the object and are *responsible* for unlocking // If TryAcquire() returns true, you've locked the object and are *responsible* for unlocking
// it later. // it later.
// //
class NonblockingMutex class NonblockingMutex
{ {
protected: protected:
std::atomic_flag val; std::atomic_flag val;
public: public:
NonblockingMutex() { val.clear(); } NonblockingMutex() { val.clear(); }
virtual ~NonblockingMutex() throw() {} virtual ~NonblockingMutex() throw() {}
@ -210,17 +214,20 @@ namespace Threading
// Can be done with a TryAcquire/Release but it is likely better to do it outside of the object // Can be done with a TryAcquire/Release but it is likely better to do it outside of the object
bool IsLocked() bool IsLocked()
{ pxAssertMsg(0, "IsLocked isn't supported for NonblockingMutex"); return false; } {
pxAssertMsg(0, "IsLocked isn't supported for NonblockingMutex");
return false;
}
void Release() void Release()
{ {
val.clear(); val.clear();
} }
}; };
class Semaphore class Semaphore
{ {
protected: protected:
#ifdef __APPLE__ #ifdef __APPLE__
semaphore_t m_sema; semaphore_t m_sema;
int m_counter; int m_counter;
@ -228,30 +235,30 @@ namespace Threading
sem_t m_sema; sem_t m_sema;
#endif #endif
public: public:
Semaphore(); Semaphore();
virtual ~Semaphore() throw(); virtual ~Semaphore() throw();
void Reset(); void Reset();
void Post(); void Post();
void Post( int multiple ); void Post(int multiple);
void WaitWithoutYield(); void WaitWithoutYield();
bool WaitWithoutYield( const wxTimeSpan& timeout ); bool WaitWithoutYield(const wxTimeSpan &timeout);
void WaitNoCancel(); void WaitNoCancel();
void WaitNoCancel( const wxTimeSpan& timeout ); void WaitNoCancel(const wxTimeSpan &timeout);
int Count(); int Count();
void Wait(); void Wait();
bool Wait( const wxTimeSpan& timeout ); bool Wait(const wxTimeSpan &timeout);
}; };
class Mutex class Mutex
{ {
protected: protected:
pthread_mutex_t m_mutex; pthread_mutex_t m_mutex;
public: public:
Mutex(); Mutex();
virtual ~Mutex() throw(); virtual ~Mutex() throw();
virtual bool IsRecursive() const { return false; } virtual bool IsRecursive() const { return false; }
@ -261,114 +268,117 @@ namespace Threading
void Detach(); void Detach();
void Acquire(); void Acquire();
bool Acquire( const wxTimeSpan& timeout ); bool Acquire(const wxTimeSpan &timeout);
bool TryAcquire(); bool TryAcquire();
void Release(); void Release();
void AcquireWithoutYield(); void AcquireWithoutYield();
bool AcquireWithoutYield( const wxTimeSpan& timeout ); bool AcquireWithoutYield(const wxTimeSpan &timeout);
void Wait(); void Wait();
bool Wait( const wxTimeSpan& timeout ); bool Wait(const wxTimeSpan &timeout);
void WaitWithoutYield(); void WaitWithoutYield();
bool WaitWithoutYield( const wxTimeSpan& timeout ); bool WaitWithoutYield(const wxTimeSpan &timeout);
protected: protected:
// empty constructor used by MutexLockRecursive // empty constructor used by MutexLockRecursive
Mutex( bool ) {} Mutex(bool) {}
}; };
class MutexRecursive : public Mutex class MutexRecursive : public Mutex
{ {
public: public:
MutexRecursive(); MutexRecursive();
virtual ~MutexRecursive() throw(); virtual ~MutexRecursive() throw();
virtual bool IsRecursive() const { return true; } virtual bool IsRecursive() const { return true; }
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// ScopedLock // ScopedLock
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// Helper class for using Mutexes. Using this class provides an exception-safe (and // 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 // 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. // will be automatically released on any return or exit from the function.
// //
// Const qualification note: // Const qualification note:
// ScopedLock takes const instances of the mutex, even though the mutex is modified // ScopedLock takes const instances of the mutex, even though the mutex is modified
// by locking and unlocking. Two rationales: // by locking and unlocking. Two rationales:
// //
// 1) when designing classes with accessors (GetString, GetValue, etc) that need mutexes, // 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 // this class needs a const hack to allow those accessors to be const (which is typically
// *very* important). // *very* important).
// //
// 2) The state of the Mutex is guaranteed to be unchanged when the calling function or // 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 // 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. // change, and typically those are only used in very special circumstances of their own.
// //
class ScopedLock class ScopedLock
{ {
DeclareNoncopyableObject(ScopedLock); DeclareNoncopyableObject(ScopedLock);
protected: protected:
Mutex* m_lock; Mutex *m_lock;
bool m_IsLocked; bool m_IsLocked;
public: public:
virtual ~ScopedLock() throw(); virtual ~ScopedLock() throw();
explicit ScopedLock( const Mutex* locker=NULL ); explicit ScopedLock(const Mutex *locker = NULL);
explicit ScopedLock( const Mutex& locker ); explicit ScopedLock(const Mutex &locker);
void AssignAndLock( const Mutex& locker ); void AssignAndLock(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 Release();
void Acquire(); void Acquire();
bool IsLocked() const { return m_IsLocked; } bool IsLocked() const { return m_IsLocked; }
protected: protected:
// Special constructor used by ScopedTryLock // Special constructor used by ScopedTryLock
ScopedLock( const Mutex& locker, bool isTryLock ); ScopedLock(const Mutex &locker, bool isTryLock);
}; };
class ScopedTryLock : public ScopedLock class ScopedTryLock : public ScopedLock
{
public:
ScopedTryLock(const Mutex &locker)
: ScopedLock(locker, true)
{ {
public: }
ScopedTryLock( const Mutex& locker ) : ScopedLock( locker, true ) { }
virtual ~ScopedTryLock() throw() {} virtual ~ScopedTryLock() throw() {}
bool Failed() const { return !m_IsLocked; } bool Failed() const { return !m_IsLocked; }
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// ScopedNonblockingLock // ScopedNonblockingLock
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// A ScopedTryLock branded for use with Nonblocking mutexes. See ScopedTryLock for details. // A ScopedTryLock branded for use with Nonblocking mutexes. See ScopedTryLock for details.
// //
class ScopedNonblockingLock class ScopedNonblockingLock
{ {
DeclareNoncopyableObject(ScopedNonblockingLock); DeclareNoncopyableObject(ScopedNonblockingLock);
protected: protected:
NonblockingMutex& m_lock; NonblockingMutex &m_lock;
bool m_IsLocked; bool m_IsLocked;
public: public:
ScopedNonblockingLock( NonblockingMutex& locker ) : ScopedNonblockingLock(NonblockingMutex &locker)
m_lock( locker ) : m_lock(locker)
, m_IsLocked( m_lock.TryAcquire() ) , m_IsLocked(m_lock.TryAcquire())
{ {
} }
virtual ~ScopedNonblockingLock() throw() virtual ~ScopedNonblockingLock() throw()
{ {
if( m_IsLocked ) if (m_IsLocked)
m_lock.Release(); m_lock.Release();
} }
bool Failed() const { return !m_IsLocked; } bool Failed() const { return !m_IsLocked; }
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// ScopedLockBool // ScopedLockBool
@ -377,26 +387,30 @@ namespace Threading
// Note that the isLockedBool should only be used as an indicator for the locked status, // Note that the isLockedBool should only be used as an indicator for the locked status,
// and not actually depended on for thread synchronization... // and not actually depended on for thread synchronization...
struct ScopedLockBool { struct ScopedLockBool
{
ScopedLock m_lock; ScopedLock m_lock;
std::atomic<bool>& m_bool; std::atomic<bool> &m_bool;
ScopedLockBool(Mutex& mutexToLock, std::atomic<bool>& isLockedBool) ScopedLockBool(Mutex &mutexToLock, std::atomic<bool> &isLockedBool)
: m_lock(mutexToLock), : m_lock(mutexToLock)
m_bool(isLockedBool) { , m_bool(isLockedBool)
{
m_bool.store(m_lock.IsLocked(), std::memory_order_relaxed); m_bool.store(m_lock.IsLocked(), std::memory_order_relaxed);
} }
virtual ~ScopedLockBool() throw() { virtual ~ScopedLockBool() throw()
{
m_bool.store(false, std::memory_order_relaxed); m_bool.store(false, std::memory_order_relaxed);
} }
void Acquire() { void Acquire()
{
m_lock.Acquire(); m_lock.Acquire();
m_bool.store(m_lock.IsLocked(), std::memory_order_relaxed); m_bool.store(m_lock.IsLocked(), std::memory_order_relaxed);
} }
void Release() { void Release()
{
m_bool.store(false, std::memory_order_relaxed); m_bool.store(false, std::memory_order_relaxed);
m_lock.Release(); m_lock.Release();
} }
}; };
} }

View File

@ -22,32 +22,31 @@ wxDECLARE_EVENT(pxEvt_ThreadedTaskComplete, wxCommandEvent);
namespace Threading namespace Threading
{ {
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// WaitForTaskDialog // WaitForTaskDialog
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// This dialog is displayed whenever the main thread is recursively waiting on multiple // 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 // 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 // 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 // the user from starting additional actions), and processes messages (allowing the system
// to continue to manage threads and process logging). // to continue to manage threads and process logging).
// //
class WaitForTaskDialog : public wxDialogWithHelpers class WaitForTaskDialog : public wxDialogWithHelpers
{ {
DECLARE_DYNAMIC_CLASS_NO_COPY(WaitForTaskDialog) DECLARE_DYNAMIC_CLASS_NO_COPY(WaitForTaskDialog)
typedef wxDialogWithHelpers _parent; typedef wxDialogWithHelpers _parent;
protected: protected:
SynchronousActionState m_sync; SynchronousActionState m_sync;
public: public:
WaitForTaskDialog( const wxString& title=wxEmptyString, const wxString& heading=wxEmptyString ); WaitForTaskDialog(const wxString &title = wxEmptyString, const wxString &heading = wxEmptyString);
virtual ~WaitForTaskDialog() throw() {} virtual ~WaitForTaskDialog() throw() {}
virtual int ShowModal(); virtual int ShowModal();
protected: protected:
void OnTaskComplete( wxCommandEvent& evt ); void OnTaskComplete(wxCommandEvent &evt);
//void OnTimer( wxTimerEvent& evt ); //void OnTimer( wxTimerEvent& evt );
}; };
} }

View File

@ -18,9 +18,9 @@
#include "Threading.h" #include "Threading.h"
#if PCSX2_THREAD_LOCAL #if PCSX2_THREAD_LOCAL
# define DeclareTls(x) __threadlocal x #define DeclareTls(x) __threadlocal x
#else #else
# define DeclareTls(x) Threading::TlsVariable<x> #define DeclareTls(x) Threading::TlsVariable<x>
#endif #endif
namespace Threading namespace Threading
@ -38,7 +38,7 @@ namespace Threading
// result in repeated calls to pthread_getspecific. (if the function inlines then it // result in repeated calls to pthread_getspecific. (if the function inlines then it
// should actually optimize well enough, but I doubt it does). // should actually optimize well enough, but I doubt it does).
// //
template< typename T > template <typename T>
class BaseTlsVariable class BaseTlsVariable
{ {
DeclareNoncopyableObject(BaseTlsVariable<T>); DeclareNoncopyableObject(BaseTlsVariable<T>);
@ -55,16 +55,15 @@ public:
Dispose(); Dispose();
} }
T* GetPtr() const; T *GetPtr() const;
T& GetRef() const { return *GetPtr(); } T &GetRef() const { return *GetPtr(); }
operator T&() const { return GetRef(); } operator T &() const { return GetRef(); }
T* operator->() const { return GetPtr(); } T *operator->() const { return GetPtr(); }
void Dispose() void Dispose()
{ {
if (!m_IsDisposed) if (!m_IsDisposed) {
{
m_IsDisposed = true; m_IsDisposed = true;
KillKey(); KillKey();
} }
@ -74,20 +73,21 @@ protected:
void CreateKey(); void CreateKey();
void KillKey(); void KillKey();
virtual void CreateInstance( T* result ) const virtual void CreateInstance(T *result) const
{ {
new (result) T(); new (result) T();
} }
static void _aligned_delete_and_free( void* ptr ) static void _aligned_delete_and_free(void *ptr)
{ {
if (!ptr) return; if (!ptr)
((T*)ptr)->~T(); return;
((T *)ptr)->~T();
_aligned_free(ptr); _aligned_free(ptr);
} }
}; };
template< typename T > template <typename T>
class TlsVariable : public BaseTlsVariable<T> class TlsVariable : public BaseTlsVariable<T>
{ {
DeclareNoncopyableObject(TlsVariable<T>); DeclareNoncopyableObject(TlsVariable<T>);
@ -97,8 +97,10 @@ protected:
public: public:
TlsVariable() {} TlsVariable() {}
TlsVariable( const T& initval ) TlsVariable(const T &initval)
: m_initval(initval) { } : m_initval(initval)
{
}
// This is needed; The C++ standard likes making life suck for programmers. // This is needed; The C++ standard likes making life suck for programmers.
using BaseTlsVariable<T>::GetRef; using BaseTlsVariable<T>::GetRef;
@ -115,75 +117,74 @@ public:
this->m_IsDisposed = true; this->m_IsDisposed = true;
} }
TlsVariable<T>& operator=( const T& src ) TlsVariable<T> &operator=(const T &src)
{ {
GetRef() = src; GetRef() = src;
return *this; return *this;
} }
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; }
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; }
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: protected:
virtual void CreateInstance( T* result ) const virtual void CreateInstance(T *result) const
{ {
new (result) T(m_initval); new (result) T(m_initval);
} }
}; };
}; };
template< typename T > template <typename T>
Threading::BaseTlsVariable<T>::BaseTlsVariable() Threading::BaseTlsVariable<T>::BaseTlsVariable()
{ {
m_IsDisposed = false; m_IsDisposed = false;
CreateKey(); CreateKey();
} }
template< typename T > template <typename T>
void Threading::BaseTlsVariable<T>::KillKey() void Threading::BaseTlsVariable<T>::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!) // 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 // 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 // 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). // ends; which is too damn late (it shows up int he leaked memory blocks).
BaseTlsVariable<T>::_aligned_delete_and_free( pthread_getspecific(m_thread_key) ); BaseTlsVariable<T>::_aligned_delete_and_free(pthread_getspecific(m_thread_key));
pthread_key_delete( m_thread_key ); pthread_key_delete(m_thread_key);
m_thread_key = 0; m_thread_key = 0;
} }
template< typename T > template <typename T>
T* Threading::BaseTlsVariable<T>::GetPtr() const T *Threading::BaseTlsVariable<T>::GetPtr() const
{ {
T* result = (T*)pthread_getspecific( m_thread_key ); T *result = (T *)pthread_getspecific(m_thread_key);
if( result == NULL ) if (result == NULL) {
{ pthread_setspecific(m_thread_key, result = (T *)_aligned_malloc(sizeof(T), 16));
pthread_setspecific( m_thread_key, result = (T*)_aligned_malloc(sizeof(T), 16) );
CreateInstance(result); CreateInstance(result);
if( result == NULL ) if (result == NULL)
throw Exception::OutOfMemory( L"thread local storage variable instance" ); throw Exception::OutOfMemory(L"thread local storage variable instance");
} }
return result; return result;
} }
template< typename T > template <typename T>
void Threading::BaseTlsVariable<T>::CreateKey() void Threading::BaseTlsVariable<T>::CreateKey()
{ {
if( 0 != pthread_key_create(&m_thread_key, BaseTlsVariable<T>::_aligned_delete_and_free) ) if (0 != pthread_key_create(&m_thread_key, BaseTlsVariable<T>::_aligned_delete_and_free)) {
{ pxFailRel("Thread Local Storage Error: key creation failed. This will most likely lead to a rapid application crash.");
pxFailRel( "Thread Local Storage Error: key creation failed. This will most likely lead to a rapid application crash." );
} }
} }

View File

@ -30,13 +30,13 @@
struct TraceLogDescriptor struct TraceLogDescriptor
{ {
// short name, alphanumerics only: used for saving/loading options. // short name, alphanumerics only: used for saving/loading options.
const wxChar* ShortName; const wxChar *ShortName;
// Standard UI name for this log source. Used in menus, options dialogs. // Standard UI name for this log source. Used in menus, options dialogs.
const wxChar* Name; const wxChar *Name;
// Length description for use as a tooltip or menu item description. // Length description for use as a tooltip or menu item description.
const wxChar* Description; const wxChar *Description;
wxString GetShortName() const wxString GetShortName() const
{ {
@ -66,7 +66,7 @@ struct TraceLogDescriptor
class BaseTraceLogSource class BaseTraceLogSource
{ {
protected: protected:
const TraceLogDescriptor* m_Descriptor; const TraceLogDescriptor *m_Descriptor;
public: public:
// Indicates if the user has enabled this specific log. This boolean only represents // Indicates if the user has enabled this specific log. This boolean only represents
@ -77,14 +77,18 @@ public:
bool Enabled; bool Enabled;
protected: protected:
BaseTraceLogSource() : m_Descriptor(NULL), Enabled(false) {} BaseTraceLogSource()
: m_Descriptor(NULL)
, Enabled(false)
{
}
public: public:
TraceLog_ImplementBaseAPI(BaseTraceLogSource) TraceLog_ImplementBaseAPI(BaseTraceLogSource)
BaseTraceLogSource( const TraceLogDescriptor* desc ) BaseTraceLogSource(const TraceLogDescriptor *desc)
{ {
pxAssumeDev( desc, "Trace logs must have a valid (non-NULL) descriptor." ); pxAssumeDev(desc, "Trace logs must have a valid (non-NULL) descriptor.");
Enabled = false; Enabled = false;
m_Descriptor = desc; m_Descriptor = desc;
} }
@ -100,14 +104,13 @@ public:
virtual bool IsActive() const { return Enabled; } virtual bool IsActive() const { return Enabled; }
virtual wxString GetShortName() const { return m_Descriptor->GetShortName(); } virtual wxString GetShortName() const { return m_Descriptor->GetShortName(); }
virtual const wxChar* GetName() const { return m_Descriptor->Name; } virtual const wxChar *GetName() const { return m_Descriptor->Name; }
virtual const wxChar* GetDescription() const virtual const wxChar *GetDescription() const
{ {
return (m_Descriptor->Description!=NULL) ? pxGetTranslation(m_Descriptor->Description) : wxEmptyString; return (m_Descriptor->Description != NULL) ? pxGetTranslation(m_Descriptor->Description) : wxEmptyString;
} }
virtual bool HasDescription() const { return m_Descriptor->Description != NULL;} virtual bool HasDescription() const { return m_Descriptor->Description != NULL; }
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -119,32 +122,32 @@ public:
class TextFileTraceLog : public BaseTraceLogSource class TextFileTraceLog : public BaseTraceLogSource
{ {
public: public:
TextFileTraceLog( const TraceLogDescriptor* desc ) TextFileTraceLog(const TraceLogDescriptor *desc)
: BaseTraceLogSource( desc ) : BaseTraceLogSource(desc)
{ {
} }
bool Write( const char* fmt, ... ) const bool Write(const char *fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( fmt, list ); WriteV(fmt, list);
va_end( list ); va_end(list);
return false; return false;
} }
bool WriteV( const char *fmt, va_list list ) const bool WriteV(const char *fmt, va_list list) const
{ {
FastFormatAscii ascii; FastFormatAscii ascii;
ApplyPrefix(ascii); ApplyPrefix(ascii);
ascii.WriteV( fmt, list ); ascii.WriteV(fmt, list);
DoWrite( ascii ); DoWrite(ascii);
return false; return false;
} }
virtual void ApplyPrefix( FastFormatAscii& ascii ) const {} virtual void ApplyPrefix(FastFormatAscii &ascii) const {}
virtual void DoWrite( const char* fmt ) const=0; virtual void DoWrite(const char *fmt) const = 0;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -159,12 +162,15 @@ public:
ConsoleColors DefaultColor; ConsoleColors DefaultColor;
protected: protected:
ConsoleLogSource() : DefaultColor(Color_Gray) {} ConsoleLogSource()
: DefaultColor(Color_Gray)
{
}
public: public:
ConsoleLog_ImplementBaseAPI(ConsoleLogSource) ConsoleLog_ImplementBaseAPI(ConsoleLogSource)
ConsoleLogSource( const TraceLogDescriptor* desc, ConsoleColors defaultColor = Color_Gray ) ConsoleLogSource(const TraceLogDescriptor *desc, ConsoleColors defaultColor = Color_Gray)
: BaseTraceLogSource(desc) : BaseTraceLogSource(desc)
{ {
DefaultColor = defaultColor; DefaultColor = defaultColor;
@ -173,111 +179,110 @@ public:
// Writes to the console using the source's default color. Note that the source's default // 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 // color will always be used, thus ConsoleColorScope() will not be effectual unless the
// console's default color is Color_Default. // console's default color is Color_Default.
bool Write( const char* fmt, ... ) const bool Write(const char *fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( fmt, list ); WriteV(fmt, list);
va_end( list ); va_end(list);
return false; return false;
} }
bool Write( const wxChar* fmt, ... ) const bool Write(const wxChar *fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( fmt, list ); WriteV(fmt, list);
va_end( list ); va_end(list);
return false; return false;
} }
bool Write( const wxString fmt, ... ) const bool Write(const wxString fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( fmt.wx_str(), list ); WriteV(fmt.wx_str(), list);
va_end( list ); va_end(list);
return false; return false;
} }
// Writes to the console using the specified color. This overrides the default color setting // Writes to the console using the specified color. This overrides the default color setting
// for this log. // for this log.
bool Write( ConsoleColors color, const char* fmt, ... ) const bool Write(ConsoleColors color, const char *fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( color, fmt, list ); WriteV(color, fmt, list);
va_end( list ); va_end(list);
return false; return false;
} }
bool Write( ConsoleColors color, const wxChar* fmt, ... ) const bool Write(ConsoleColors color, const wxChar *fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( color, fmt, list ); WriteV(color, fmt, list);
va_end( list ); va_end(list);
return false; return false;
} }
// Writes to the console using bold yellow text -- overrides the log source's default // Writes to the console using bold yellow text -- overrides the log source's default
// color settings. // color settings.
bool Warn( const wxChar* fmt, ... ) const bool Warn(const wxChar *fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( Color_StrongYellow, fmt, list ); WriteV(Color_StrongYellow, fmt, list);
va_end( list ); va_end(list);
return false; return false;
} }
bool Warn( const wxString fmt, ... ) const bool Warn(const wxString fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( Color_StrongYellow, fmt.wx_str(), list ); WriteV(Color_StrongYellow, fmt.wx_str(), list);
va_end( list ); va_end(list);
return false; return false;
} }
// Writes to the console using bold red text -- overrides the log source's default // Writes to the console using bold red text -- overrides the log source's default
// color settings. // color settings.
bool Error( const wxChar* fmt, ... ) const bool Error(const wxChar *fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( Color_StrongRed, fmt, list ); WriteV(Color_StrongRed, fmt, list);
va_end( list ); va_end(list);
return false; return false;
} }
bool Error( const wxString fmt, ... ) const bool Error(const wxString fmt, ...) const
{ {
va_list list; va_list list;
va_start( list, fmt ); va_start(list, fmt);
WriteV( Color_StrongRed, fmt.wx_str(), list ); WriteV(Color_StrongRed, fmt.wx_str(), list);
va_end( list ); va_end(list);
return false; return false;
} }
bool WriteV( const char *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(const wxChar *fmt, va_list list) const;
bool WriteV( ConsoleColors color, const char *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 wxChar *fmt, va_list list) const;
virtual void DoWrite( const wxChar* msg ) const virtual void DoWrite(const wxChar *msg) const
{ {
Console.DoWriteLn( msg ); Console.DoWriteLn(msg);
} }
}; };

View File

@ -18,8 +18,8 @@
// This header contains non-optimized implementation of memzero_ptr and memset8, etc // This header contains non-optimized implementation of memzero_ptr and memset8, etc
template< u32 data, typename T > template <u32 data, typename T>
static __fi void memset32( T& obj ) static __fi void memset32(T &obj)
{ {
// this function works on 32-bit aligned lengths of data only. // 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 // If the data length is not a factor of 32 bits, the C++ optimizing compiler will
@ -27,32 +27,32 @@ static __fi void memset32( T& obj )
pxAssume((sizeof(T) & 0x3) == 0); pxAssume((sizeof(T) & 0x3) == 0);
u32* dest = (u32*)&obj; u32 *dest = (u32 *)&obj;
for( int i=sizeof(T)>>2; i; --i, ++dest ) for (int i = sizeof(T) >> 2; i; --i, ++dest)
*dest = data; *dest = data;
} }
template< typename T > template <typename T>
static __fi void memzero( T& obj ) static __fi void memzero(T &obj)
{ {
memset( &obj, 0, sizeof( T ) ); memset(&obj, 0, sizeof(T));
} }
template< u8 data, typename T > template <u8 data, typename T>
static __fi void memset8( T& obj ) static __fi void memset8(T &obj)
{ {
// Aligned sizes use the optimized 32 bit inline memset. Unaligned sizes use memset. // Aligned sizes use the optimized 32 bit inline memset. Unaligned sizes use memset.
if( (sizeof(T) & 0x3) != 0 ) if ((sizeof(T) & 0x3) != 0)
memset( &obj, data, sizeof( T ) ); memset(&obj, data, sizeof(T));
else { else {
const u32 data32 = data + (data<<8) + (data<<16) + (data<<24); const u32 data32 = data + (data << 8) + (data << 16) + (data << 24);
memset32<data32>( obj ); memset32<data32>(obj);
} }
} }
// Code is only called in the init so no need to bother with ASM // Code is only called in the init so no need to bother with ASM
template< u8 data, size_t bytes > template <u8 data, size_t bytes>
static __fi void memset_8( void *dest ) static __fi void memset_8(void *dest)
{ {
memset(dest, data, bytes); memset(dest, data, bytes);
} }

View File

@ -29,50 +29,74 @@
class pxCheckBox : public wxPanelWithHelpers class pxCheckBox : public wxPanelWithHelpers
{ {
protected: protected:
wxCheckBox* m_checkbox; wxCheckBox *m_checkbox;
pxStaticText* m_subtext; pxStaticText *m_subtext;
// padding below the subtext (if there's subtext). If there's no subtext, this value is unused. // padding below the subtext (if there's subtext). If there's no subtext, this value is unused.
int m_subPadding; int m_subPadding;
wxSizerItem* m_sizerItem_subtext; wxSizerItem *m_sizerItem_subtext;
public: public:
pxCheckBox( wxWindow* parent, const wxString& label, const wxString& subtext=wxEmptyString, int flags = wxCHK_2STATE ); pxCheckBox(wxWindow *parent, const wxString &label, const wxString &subtext = wxEmptyString, int flags = wxCHK_2STATE);
pxCheckBox( wxWindow* parent, const wxString& label, int flags ); pxCheckBox(wxWindow *parent, const wxString &label, int flags);
virtual ~pxCheckBox() throw() {} virtual ~pxCheckBox() throw() {}
bool HasSubText() const { return m_subtext != NULL; } bool HasSubText() const { return m_subtext != NULL; }
const pxStaticText* GetSubText() const { return m_subtext; } const pxStaticText *GetSubText() const { return m_subtext; }
pxCheckBox& SetSubPadding( int pad ); pxCheckBox &SetSubPadding(int pad);
pxCheckBox& SetToolTip( const wxString& tip ); pxCheckBox &SetToolTip(const wxString &tip);
pxCheckBox& SetValue( bool val ); pxCheckBox &SetValue(bool val);
pxCheckBox& SetIndeterminate(); pxCheckBox &SetIndeterminate();
pxCheckBox& SetState( wxCheckBoxState state ); pxCheckBox &SetState(wxCheckBoxState state);
wxCheckBoxState GetState() const { pxAssert( m_checkbox != NULL ); return m_checkbox->Get3StateValue(); } wxCheckBoxState GetState() const
bool GetValue() const { pxAssert( m_checkbox != NULL ); return m_checkbox->GetValue(); } {
bool IsChecked() const { pxAssert( m_checkbox != NULL ); return m_checkbox->IsChecked(); } pxAssert(m_checkbox != NULL);
bool IsIndeterminate() const { pxAssert( m_checkbox != NULL ); return m_checkbox->Get3StateValue() == wxCHK_UNDETERMINED; } return m_checkbox->Get3StateValue();
operator wxCheckBox&() { pxAssert( m_checkbox != NULL ); return *m_checkbox; } }
operator const wxCheckBox&() const { pxAssert( m_checkbox != NULL ); return *m_checkbox; } 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; } wxCheckBox *GetWxPtr() { return m_checkbox; }
const wxCheckBox* GetWxPtr() const { 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: protected:
void Init( const wxString& label, const wxString& subtext, int flags ); void Init(const wxString &label, const wxString &subtext, int flags);
void OnCheckpartCommand( wxCommandEvent& evt ); void OnCheckpartCommand(wxCommandEvent &evt);
void OnSubtextClicked( wxCommandEvent& evt ); void OnSubtextClicked(wxCommandEvent &evt);
}; };
extern void operator+=( wxSizer& target, pxCheckBox& src ); extern void operator+=(wxSizer &target, pxCheckBox &src);
template<> template <>
inline void operator+=( wxSizer& target, const pxWindowAndFlags<pxCheckBox>& src ) inline void operator+=(wxSizer &target, const pxWindowAndFlags<pxCheckBox> &src)
{ {
target.Add( src.window, src.flags ); target.Add(src.window, src.flags);
} }

View File

@ -26,7 +26,7 @@ typedef void FnType_Void();
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
class SynchronousActionState class SynchronousActionState
{ {
DeclareNoncopyableObject( SynchronousActionState ); DeclareNoncopyableObject(SynchronousActionState);
protected: protected:
bool m_posted; bool m_posted;
@ -44,16 +44,16 @@ public:
virtual ~SynchronousActionState() throw() {} virtual ~SynchronousActionState() throw() {}
void SetException( const BaseException& ex ); void SetException(const BaseException &ex);
void SetException( BaseException* ex ); void SetException(BaseException *ex);
Threading::Semaphore& GetSemaphore() { return m_sema; } Threading::Semaphore &GetSemaphore() { return m_sema; }
const Threading::Semaphore& GetSemaphore() const { return m_sema; } const Threading::Semaphore &GetSemaphore() const { return m_sema; }
void RethrowException() const; void RethrowException() const;
int WaitForResult(); int WaitForResult();
int WaitForResult_NoExceptions(); int WaitForResult_NoExceptions();
void PostResult( int res ); void PostResult(int res);
void ClearResult(); void ClearResult();
void PostResult(); void PostResult();
}; };
@ -71,13 +71,15 @@ class pxSimpleEvent : public wxEvent
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSimpleEvent) DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSimpleEvent)
public: public:
explicit pxSimpleEvent( int evtid=0 ) explicit pxSimpleEvent(int evtid = 0)
: wxEvent(0, evtid) : wxEvent(0, evtid)
{ } {
}
pxSimpleEvent( wxWindowID winId, int evtid ) pxSimpleEvent(wxWindowID winId, int evtid)
: wxEvent(winId, evtid) : wxEvent(winId, evtid)
{ } {
}
virtual wxEvent *Clone() const { return new pxSimpleEvent(*this); } virtual wxEvent *Clone() const { return new pxSimpleEvent(*this); }
}; };
@ -94,26 +96,26 @@ class pxActionEvent : public wxEvent
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxActionEvent) DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxActionEvent)
protected: protected:
SynchronousActionState* m_state; SynchronousActionState *m_state;
public: public:
virtual ~pxActionEvent() throw() { } virtual ~pxActionEvent() throw() {}
virtual pxActionEvent *Clone() const { return new pxActionEvent(*this); } virtual pxActionEvent *Clone() const { return new pxActionEvent(*this); }
explicit pxActionEvent( SynchronousActionState* sema=NULL, int msgtype=pxEvt_InvokeAction ); explicit pxActionEvent(SynchronousActionState *sema = NULL, int msgtype = pxEvt_InvokeAction);
explicit pxActionEvent( SynchronousActionState& sema, int msgtype=pxEvt_InvokeAction ); explicit pxActionEvent(SynchronousActionState &sema, int msgtype = pxEvt_InvokeAction);
pxActionEvent( const pxActionEvent& src ); 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; } const SynchronousActionState *GetSyncState() const { return m_state; }
SynchronousActionState* GetSyncState() { 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 ); virtual void SetException(BaseException *ex);
void SetException( const BaseException& ex ); void SetException(const BaseException &ex);
virtual void _DoInvokeEvent(); virtual void _DoInvokeEvent();
@ -137,15 +139,15 @@ class pxExceptionEvent : public pxActionEvent
typedef pxActionEvent _parent; typedef pxActionEvent _parent;
protected: protected:
BaseException* m_except; BaseException *m_except;
public: public:
pxExceptionEvent( BaseException* ex=NULL ) pxExceptionEvent(BaseException *ex = NULL)
{ {
m_except = ex; m_except = ex;
} }
pxExceptionEvent( const BaseException& ex ); pxExceptionEvent(const BaseException &ex);
virtual ~pxExceptionEvent() throw() virtual ~pxExceptionEvent() throw()
{ {
@ -166,26 +168,26 @@ class pxSynchronousCommandEvent : public wxCommandEvent
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSynchronousCommandEvent) DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSynchronousCommandEvent)
protected: protected:
SynchronousActionState* m_sync; SynchronousActionState *m_sync;
wxEventType m_realEvent; wxEventType m_realEvent;
public: public:
virtual ~pxSynchronousCommandEvent() throw() { } virtual ~pxSynchronousCommandEvent() throw() {}
virtual pxSynchronousCommandEvent *Clone() const { return new pxSynchronousCommandEvent(*this); } virtual pxSynchronousCommandEvent *Clone() const { return new pxSynchronousCommandEvent(*this); }
pxSynchronousCommandEvent(SynchronousActionState* sema=NULL, 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, 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; } Threading::Semaphore *GetSemaphore() { return m_sync ? &m_sync->GetSemaphore() : NULL; }
wxEventType GetRealEventType() const { return m_realEvent; } wxEventType GetRealEventType() const { return m_realEvent; }
void SetException( BaseException* ex ); void SetException(BaseException *ex);
void SetException( const BaseException& ex ); void SetException(const BaseException &ex);
}; };
wxDECLARE_EVENT(pxEvt_SynchronousCommand, pxSynchronousCommandEvent); wxDECLARE_EVENT(pxEvt_SynchronousCommand, pxSynchronousCommandEvent);
@ -202,12 +204,12 @@ protected:
wxString m_Content; wxString m_Content;
public: public:
virtual ~BaseMessageBoxEvent() throw() { } virtual ~BaseMessageBoxEvent() throw() {}
virtual BaseMessageBoxEvent *Clone() const { return new BaseMessageBoxEvent(*this); } virtual BaseMessageBoxEvent *Clone() const { return new BaseMessageBoxEvent(*this); }
explicit BaseMessageBoxEvent( const wxString& content=wxEmptyString, SynchronousActionState* instdata=NULL ); explicit BaseMessageBoxEvent(const wxString &content = wxEmptyString, SynchronousActionState *instdata = NULL);
BaseMessageBoxEvent( const wxString& content, SynchronousActionState& instdata ); BaseMessageBoxEvent(const wxString &content, SynchronousActionState &instdata);
BaseMessageBoxEvent( const BaseMessageBoxEvent& event ); BaseMessageBoxEvent(const BaseMessageBoxEvent &event);
protected: protected:
virtual void InvokeEvent(); virtual void InvokeEvent();
@ -222,17 +224,17 @@ class MsgButtons
protected: protected:
BITFIELD32() BITFIELD32()
bool bool
m_OK :1, m_OK : 1,
m_Cancel :1, m_Cancel : 1,
m_Yes :1, m_Yes : 1,
m_No :1, m_No : 1,
m_AllowToAll:1, m_AllowToAll : 1,
m_Apply :1, m_Apply : 1,
m_Abort :1, m_Abort : 1,
m_Retry :1, m_Retry : 1,
m_Ignore :1, m_Ignore : 1,
m_Reset :1, m_Reset : 1,
m_Close :1; m_Close : 1;
BITFIELD_END BITFIELD_END
wxString m_CustomLabel; wxString m_CustomLabel;
@ -241,37 +243,89 @@ protected:
public: public:
MsgButtons() { bitset = 0; } MsgButtons() { bitset = 0; }
MsgButtons& OK() { m_OK = true; return *this; } MsgButtons &OK()
MsgButtons& Cancel() { m_Cancel = true; return *this; } {
MsgButtons& Apply() { m_Apply = true; return *this; } m_OK = true;
MsgButtons& Yes() { m_Yes = true; return *this; } return *this;
MsgButtons& No() { m_No = true; return *this; } }
MsgButtons& ToAll() { m_AllowToAll = 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 &Abort()
MsgButtons& Retry() { m_Retry = true; return *this; } {
MsgButtons& Ignore() { m_Ignore = true; return *this; } m_Abort = true;
MsgButtons& Reset() { m_Reset = true; return *this; } return *this;
MsgButtons& Close() { m_Close = 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 // label - native language label displayed to user
// id - raw ASCII identifier used in the config file (do not translate, hence char*) // id - raw ASCII identifier used in the config file (do not translate, hence char*)
MsgButtons& Custom( const wxString& label, const char* id ) MsgButtons &Custom(const wxString &label, const char *id)
{ {
m_CustomLabel = label; m_CustomLabel = label;
m_CustomLabelId = fromUTF8(id); m_CustomLabelId = fromUTF8(id);
return *this; return *this;
} }
MsgButtons& OKCancel() { m_OK = m_Cancel = true; return *this; } MsgButtons &OKCancel()
MsgButtons& YesNo() { m_Yes = m_No = true; return *this; } {
m_OK = m_Cancel = true;
return *this;
}
MsgButtons &YesNo()
{
m_Yes = m_No = true;
return *this;
}
bool HasOK() const { return m_OK; } bool HasOK() const { return m_OK; }
bool HasCancel() const { return m_Cancel; } bool HasCancel() const { return m_Cancel; }
bool HasApply() const { return m_Apply; } bool HasApply() const { return m_Apply; }
bool HasYes() const { return m_Yes; } bool HasYes() const { return m_Yes; }
bool HasNo() const { return m_No; } bool HasNo() const { return m_No; }
bool AllowsToAll() const{ return m_AllowToAll; } bool AllowsToAll() const { return m_AllowToAll; }
bool HasAbort() const { return m_Abort; } bool HasAbort() const { return m_Abort; }
bool HasRetry() const { return m_Retry; } bool HasRetry() const { return m_Retry; }
@ -280,21 +334,21 @@ public:
bool HasClose() const { return m_Close; } bool HasClose() const { return m_Close; }
bool HasCustom() const { return !m_CustomLabel.IsEmpty(); } bool HasCustom() const { return !m_CustomLabel.IsEmpty(); }
const wxString& GetCustomLabel() const { return m_CustomLabel; } const wxString &GetCustomLabel() const { return m_CustomLabel; }
const wxString& GetCustomLabelId() const { return m_CustomLabelId; } const wxString &GetCustomLabelId() const { return m_CustomLabelId; }
bool Allows( wxWindowID id ) const; bool Allows(wxWindowID id) const;
void SetBestFocus( wxWindow* dialog ) const; void SetBestFocus(wxWindow *dialog) const;
void SetBestFocus( wxWindow& dialog ) const; void SetBestFocus(wxWindow &dialog) const;
bool operator ==( const MsgButtons& right ) const bool operator==(const MsgButtons &right) const
{ {
return OpEqu( bitset ); return OpEqu(bitset);
} }
bool operator !=( const MsgButtons& right ) const bool operator!=(const MsgButtons &right) const
{ {
return !OpEqu( bitset ); return !OpEqu(bitset);
} }
}; };
@ -326,13 +380,13 @@ protected:
MsgButtons m_Buttons; MsgButtons m_Buttons;
public: public:
virtual ~pxMessageBoxEvent() throw() { } virtual ~pxMessageBoxEvent() throw() {}
virtual pxMessageBoxEvent *Clone() const { return new pxMessageBoxEvent(*this); } virtual pxMessageBoxEvent *Clone() const { return new pxMessageBoxEvent(*this); }
pxMessageBoxEvent() {} 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);
pxMessageBoxEvent( const wxString& title, const wxString& content, const MsgButtons& buttons, SynchronousActionState* instdata=NULL ); pxMessageBoxEvent(const wxString &title, const wxString &content, const MsgButtons &buttons, SynchronousActionState *instdata = NULL);
pxMessageBoxEvent( const pxMessageBoxEvent& event ); pxMessageBoxEvent(const pxMessageBoxEvent &event);
protected: protected:
int _DoDialog() const; int _DoDialog() const;
@ -344,20 +398,20 @@ protected:
class pxAssertionEvent : public BaseMessageBoxEvent class pxAssertionEvent : public BaseMessageBoxEvent
{ {
typedef BaseMessageBoxEvent _parent; typedef BaseMessageBoxEvent _parent;
DECLARE_DYNAMIC_CLASS_NO_ASSIGN( pxAssertionEvent ) DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxAssertionEvent)
protected: protected:
wxString m_Stacktrace; wxString m_Stacktrace;
public: public:
virtual ~pxAssertionEvent() throw() { } virtual ~pxAssertionEvent() throw() {}
virtual pxAssertionEvent *Clone() const { return new pxAssertionEvent(*this); } virtual pxAssertionEvent *Clone() const { return new pxAssertionEvent(*this); }
pxAssertionEvent( const wxString& content=wxEmptyString, const wxString& trace=wxEmptyString, SynchronousActionState* instdata=NULL ); pxAssertionEvent(const wxString &content = wxEmptyString, const wxString &trace = wxEmptyString, SynchronousActionState *instdata = NULL);
pxAssertionEvent( const wxString& content, const wxString& trace, SynchronousActionState& instdata ); pxAssertionEvent(const wxString &content, const wxString &trace, SynchronousActionState &instdata);
pxAssertionEvent( const pxAssertionEvent& event ); pxAssertionEvent(const pxAssertionEvent &event);
pxAssertionEvent& SetStacktrace( const wxString& trace ); pxAssertionEvent &SetStacktrace(const wxString &trace);
protected: protected:
int _DoDialog() const; int _DoDialog() const;

View File

@ -40,12 +40,12 @@ extern const wxPoint wxDefaultPosition;
namespace Threading namespace Threading
{ {
class Mutex; class Mutex;
class Semaphore; class Semaphore;
class pxThread; class pxThread;
} }
namespace Exception namespace Exception
{ {
class BaseException; class BaseException;
} }

View File

@ -30,36 +30,36 @@ struct RadioPanelItem
wxString ToolTip; wxString ToolTip;
int SomeInt; int SomeInt;
void* SomePtr; void *SomePtr;
RadioPanelItem( const wxString& label, const wxString& subtext=wxEmptyString, const wxString& tooltip=wxEmptyString ) RadioPanelItem(const wxString &label, const wxString &subtext = wxEmptyString, const wxString &tooltip = wxEmptyString)
: Label( label ) : Label(label)
, SubText( subtext ) , SubText(subtext)
, ToolTip( tooltip ) , ToolTip(tooltip)
{ {
SomeInt = 0; SomeInt = 0;
SomePtr = NULL; SomePtr = NULL;
} }
RadioPanelItem& SetToolTip( const wxString& tip ) RadioPanelItem &SetToolTip(const wxString &tip)
{ {
ToolTip = tip; ToolTip = tip;
return *this; return *this;
} }
RadioPanelItem& SetSubText( const wxString& text ) RadioPanelItem &SetSubText(const wxString &text)
{ {
SubText = text; SubText = text;
return *this; return *this;
} }
RadioPanelItem& SetInt( int intval ) RadioPanelItem &SetInt(int intval)
{ {
SomeInt = intval; SomeInt = intval;
return *this; return *this;
} }
RadioPanelItem& SetPtr( void* ptrval ) RadioPanelItem &SetPtr(void *ptrval)
{ {
SomePtr = ptrval; SomePtr = ptrval;
return *this; return *this;
@ -71,8 +71,8 @@ struct RadioPanelItem
// wrapped and re-wrapped with multiple calls to OnResize(). // wrapped and re-wrapped with multiple calls to OnResize().
struct RadioPanelObjects struct RadioPanelObjects
{ {
wxRadioButton* LabelObj; wxRadioButton *LabelObj;
pxStaticText* SubTextObj; pxStaticText *SubTextObj;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -104,15 +104,15 @@ protected:
int m_DefaultIdx; // index of the default option (gets specific color/font treatment) int m_DefaultIdx; // index of the default option (gets specific color/font treatment)
public: public:
template< int size > template <int size>
pxRadioPanel( wxWindow* parent, const RadioPanelItem (&src)[size] ) pxRadioPanel(wxWindow *parent, const RadioPanelItem (&src)[size])
: wxPanelWithHelpers( parent, wxVERTICAL ) : wxPanelWithHelpers(parent, wxVERTICAL)
{ {
Init( src, size ); Init(src, size);
} }
pxRadioPanel( wxWindow* parent ) pxRadioPanel(wxWindow *parent)
: wxPanelWithHelpers( parent, wxVERTICAL ) : wxPanelWithHelpers(parent, wxVERTICAL)
{ {
Init(); Init();
} }
@ -122,55 +122,55 @@ public:
void Reset(); void Reset();
void Realize(); void Realize();
pxStaticText* GetSubText( int idx ); pxStaticText *GetSubText(int idx);
const pxStaticText* GetSubText( int idx ) const; const pxStaticText *GetSubText(int idx) const;
pxRadioPanel& Append( const RadioPanelItem& entry ); pxRadioPanel &Append(const RadioPanelItem &entry);
pxRadioPanel& SetToolTip( int idx, const wxString& tip ); pxRadioPanel &SetToolTip(int idx, const wxString &tip);
pxRadioPanel& SetSelection( int idx ); pxRadioPanel &SetSelection(int idx);
pxRadioPanel& SetDefaultItem( int idx ); pxRadioPanel &SetDefaultItem(int idx);
pxRadioPanel& EnableItem( int idx, bool enable=true ); pxRadioPanel &EnableItem(int idx, bool enable = true);
const RadioPanelItem& Item(int idx) const; const RadioPanelItem &Item(int idx) const;
RadioPanelItem& Item(int idx); RadioPanelItem &Item(int idx);
int GetSelection() const; int GetSelection() const;
wxWindowID GetSelectionId() const; wxWindowID GetSelectionId() const;
bool IsSelected( int idx ) const; bool IsSelected(int idx) const;
const RadioPanelItem& SelectedItem() const { return Item(GetSelection()); } const RadioPanelItem &SelectedItem() const { return Item(GetSelection()); }
RadioPanelItem& SelectedItem() { return Item(GetSelection()); } RadioPanelItem &SelectedItem() { return Item(GetSelection()); }
wxRadioButton* GetButton( int idx ); wxRadioButton *GetButton(int idx);
const wxRadioButton* GetButton( int idx ) const; const wxRadioButton *GetButton(int idx) const;
int GetPaddingVert() const { return m_padding.GetHeight(); } int GetPaddingVert() const { return m_padding.GetHeight(); }
int GetIndentation() const { return m_Indentation; } int GetIndentation() const { return m_Indentation; }
pxRadioPanel& SetPaddingHoriz( int newpad ) pxRadioPanel &SetPaddingHoriz(int newpad)
{ {
m_padding.SetHeight( newpad ); m_padding.SetHeight(newpad);
return *this; return *this;
} }
pxRadioPanel& SetIndentation( int newdent ) pxRadioPanel &SetIndentation(int newdent)
{ {
m_Indentation = newdent; m_Indentation = newdent;
return *this; return *this;
} }
bool HasSubText( int idx ) const bool HasSubText(int idx) const
{ {
return !m_buttonStrings[idx].SubText.IsEmpty(); return !m_buttonStrings[idx].SubText.IsEmpty();
} }
pxRadioPanel& Append( const wxString& label, const wxString& subtext=wxEmptyString, const wxString& tooltip=wxEmptyString ) pxRadioPanel &Append(const wxString &label, const wxString &subtext = wxEmptyString, const wxString &tooltip = wxEmptyString)
{ {
return Append( RadioPanelItem(label, subtext, tooltip) ); return Append(RadioPanelItem(label, subtext, tooltip));
} }
protected: protected:
void Init( const RadioPanelItem* srcArray=NULL, int arrsize=0 ); void Init(const RadioPanelItem *srcArray = NULL, int arrsize = 0);
void _setToolTipImmediate( int idx, const wxString &tip ); void _setToolTipImmediate(int idx, const wxString &tip);
void _RealizeDefaultOption(); void _RealizeDefaultOption();
}; };

View File

@ -50,7 +50,7 @@ protected:
float m_paddingPct_vert; float m_paddingPct_vert;
protected: protected:
explicit pxStaticText( wxWindow* parent=NULL ); explicit pxStaticText(wxWindow *parent = NULL);
// wxWindow overloads! // wxWindow overloads!
bool AcceptsFocus() const { return false; } bool AcceptsFocus() const { return false; }
@ -58,47 +58,47 @@ protected:
void DoSetSize(int x, int y, int w, int h, int sizeFlags = wxSIZE_AUTO); void DoSetSize(int x, int y, int w, int h, int sizeFlags = wxSIZE_AUTO);
public: public:
pxStaticText( wxWindow* parent, const wxString& label, wxAlignment align=wxALIGN_CENTRE_HORIZONTAL ); pxStaticText(wxWindow *parent, const wxString &label, wxAlignment align = wxALIGN_CENTRE_HORIZONTAL);
pxStaticText( wxWindow* parent, int heightInLines, const wxString& label, wxAlignment align=wxALIGN_CENTRE_HORIZONTAL ); pxStaticText(wxWindow *parent, int heightInLines, const wxString &label, wxAlignment align = wxALIGN_CENTRE_HORIZONTAL);
virtual ~pxStaticText() throw() {} virtual ~pxStaticText() throw() {}
wxFont GetFontOk() const; wxFont GetFontOk() const;
bool Enable( bool enabled=true ); bool Enable(bool enabled = true);
virtual void SetLabel(const wxString& label); virtual void SetLabel(const wxString &label);
virtual wxString GetLabel() const { return m_label; } virtual wxString GetLabel() const { return m_label; }
pxStaticText& SetMinWidth( int width ); pxStaticText &SetMinWidth(int width);
pxStaticText& SetMinHeight( int height ); pxStaticText &SetMinHeight(int height);
pxStaticText& SetHeight( int lines ); pxStaticText &SetHeight(int lines);
pxStaticText& Align( wxAlignment align ); pxStaticText &Align(wxAlignment align);
pxStaticText& Bold(); pxStaticText &Bold();
pxStaticText& WrapAt( int width ); pxStaticText &WrapAt(int width);
pxStaticText& Unwrapped(); pxStaticText &Unwrapped();
pxStaticText& PaddingPixH( int pixels ); pxStaticText &PaddingPixH(int pixels);
pxStaticText& PaddingPixV( int pixels ); pxStaticText &PaddingPixV(int pixels);
pxStaticText& PaddingPctH( float pct ); pxStaticText &PaddingPctH(float pct);
pxStaticText& PaddingPctV( float pct ); pxStaticText &PaddingPctV(float pct);
//pxStaticText& DoBestGuessHeight(); //pxStaticText& DoBestGuessHeight();
protected: protected:
void SetPaddingDefaults(); void SetPaddingDefaults();
void Init( const wxString& label ); void Init(const wxString &label);
wxSize GetBestWrappedSize( const wxClientDC& dc ) const; wxSize GetBestWrappedSize(const wxClientDC &dc) const;
wxSize DoGetBestSize() const; wxSize DoGetBestSize() const;
int calcPaddingWidth( int newWidth ) const; int calcPaddingWidth(int newWidth) const;
int calcPaddingHeight( int newHeight ) const; int calcPaddingHeight(int newHeight) const;
void paintEvent(wxPaintEvent& evt); void paintEvent(wxPaintEvent &evt);
void UpdateWrapping( bool textChanged ); void UpdateWrapping(bool textChanged);
bool _updateWrapping( bool textChanged ); bool _updateWrapping(bool textChanged);
}; };
@ -107,19 +107,18 @@ class pxStaticHeading : public pxStaticText
typedef pxStaticText _parent; typedef pxStaticText _parent;
public: public:
pxStaticHeading( wxWindow* parent=NULL, const wxString& label=wxEmptyString ); pxStaticHeading(wxWindow *parent = NULL, const wxString &label = wxEmptyString);
pxStaticHeading( wxWindow* parent, int heightInLines, const wxString& label=wxEmptyString ); pxStaticHeading(wxWindow *parent, int heightInLines, const wxString &label = wxEmptyString);
virtual ~pxStaticHeading() throw() {} virtual ~pxStaticHeading() throw() {}
protected: protected:
void SetPaddingDefaults(); void SetPaddingDefaults();
}; };
extern void operator+=( wxSizer& target, pxStaticText& src ); extern void operator+=(wxSizer &target, pxStaticText &src);
template<> template <>
inline void operator+=( wxSizer& target, const pxWindowAndFlags<pxStaticText>& src ) inline void operator+=(wxSizer &target, const pxWindowAndFlags<pxStaticText> &src)
{ {
target.Add( src.window, src.flags ); target.Add(src.window, src.flags);
} }

View File

@ -32,15 +32,15 @@ protected:
wxString m_filename; wxString m_filename;
public: public:
pxStreamBase(const wxString& filename); pxStreamBase(const wxString &filename);
virtual ~pxStreamBase() throw() {} virtual ~pxStreamBase() throw() {}
// Implementing classes should return the base wxStream object (usually either a wxInputStream // Implementing classes should return the base wxStream object (usually either a wxInputStream
// or wxOputStream derivative). // or wxOputStream derivative).
virtual wxStreamBase* GetWxStreamBase() const=0; virtual wxStreamBase *GetWxStreamBase() const = 0;
virtual void Close()=0; virtual void Close() = 0;
virtual wxFileOffset Tell() const=0; virtual wxFileOffset Tell() const = 0;
virtual wxFileOffset Seek( wxFileOffset ofs, wxSeekMode mode = wxFromStart )=0; virtual wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart) = 0;
virtual wxFileOffset Length() const; virtual wxFileOffset Length() const;
bool IsOk() const; bool IsOk() const;
@ -59,27 +59,27 @@ protected:
std::unique_ptr<wxOutputStream> m_stream_out; std::unique_ptr<wxOutputStream> m_stream_out;
public: public:
pxOutputStream(const wxString& filename, std::unique_ptr<wxOutputStream>& output); pxOutputStream(const wxString &filename, std::unique_ptr<wxOutputStream> &output);
pxOutputStream(const wxString& filename, wxOutputStream* output); pxOutputStream(const wxString &filename, wxOutputStream *output);
virtual ~pxOutputStream() throw() {} virtual ~pxOutputStream() throw() {}
virtual void Write( const void* data, size_t size ); virtual void Write(const void *data, size_t size);
void SetStream( const wxString& filename, std::unique_ptr<wxOutputStream>& stream ); void SetStream(const wxString &filename, std::unique_ptr<wxOutputStream> &stream);
void SetStream( const wxString& filename, wxOutputStream* stream ); void SetStream(const wxString &filename, wxOutputStream *stream);
void Close() { m_stream_out = nullptr; } void Close() { m_stream_out = nullptr; }
virtual wxStreamBase* GetWxStreamBase() const; virtual wxStreamBase *GetWxStreamBase() const;
template< typename T > template <typename T>
void Write( const T& data ) void Write(const T &data)
{ {
Write( &data, sizeof(data) ); Write(&data, sizeof(data));
} }
wxFileOffset Tell() const; wxFileOffset Tell() const;
wxFileOffset Seek( wxFileOffset ofs, wxSeekMode mode = wxFromStart ); wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -93,25 +93,25 @@ protected:
std::unique_ptr<wxInputStream> m_stream_in; std::unique_ptr<wxInputStream> m_stream_in;
public: public:
pxInputStream(const wxString& filename, std::unique_ptr<wxInputStream>& input); pxInputStream(const wxString &filename, std::unique_ptr<wxInputStream> &input);
pxInputStream(const wxString& filename, wxInputStream* input); pxInputStream(const wxString &filename, wxInputStream *input);
virtual ~pxInputStream() throw() {} virtual ~pxInputStream() throw() {}
virtual void Read( void* dest, size_t size ); virtual void Read(void *dest, size_t size);
void SetStream( const wxString& filename, std::unique_ptr<wxInputStream>& stream ); void SetStream(const wxString &filename, std::unique_ptr<wxInputStream> &stream);
void SetStream( const wxString& filename, wxInputStream* stream ); void SetStream(const wxString &filename, wxInputStream *stream);
void Close() { m_stream_in = nullptr; } void Close() { m_stream_in = nullptr; }
virtual wxStreamBase* GetWxStreamBase() const; virtual wxStreamBase *GetWxStreamBase() const;
template< typename T > template <typename T>
void Read( T& dest ) void Read(T &dest)
{ {
Read( &dest, sizeof(dest) ); Read(&dest, sizeof(dest));
} }
wxFileOffset Tell() const; wxFileOffset Tell() const;
wxFileOffset Seek( wxFileOffset ofs, wxSeekMode mode = wxFromStart ); wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
}; };

View File

@ -16,14 +16,14 @@
#pragma once #pragma once
#ifdef _MSC_VER #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 #endif
// These functions are meant for memset operations of constant length only. // These functions are meant for memset operations of constant length only.
// For dynamic length clears, use the C-compiler provided memset instead. // For dynamic length clears, use the C-compiler provided memset instead.
template< u8 data, size_t bytes > template <u8 data, size_t bytes>
static __fi void memset_8( void *dest ) static __fi void memset_8(void *dest)
{ {
memset(dest, data, bytes); memset(dest, data, bytes);
} }
@ -31,15 +31,15 @@ static __fi void memset_8( void *dest )
// This method can clear any object-like entity -- which is anything that is not a pointer. // 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 // Structures, static arrays, etc. No need to include sizeof() crap, this does it automatically
// for you! // for you!
template< typename T > template <typename T>
static __fi void memzero( T& object ) 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. // This method clears an object with the given 8 bit value.
template< u8 data, typename T > template <u8 data, typename T>
static __fi void memset8( T& object ) static __fi void memset8(T &object)
{ {
memset_8<data, sizeof(T)>( &object ); memset_8<data, sizeof(T)>(&object);
} }

View File

@ -49,16 +49,16 @@ extern ConsoleLogSource_App pxConLog_App;
class ModalButtonPanel : public wxPanelWithHelpers class ModalButtonPanel : public wxPanelWithHelpers
{ {
public: public:
ModalButtonPanel( wxWindow* window, const MsgButtons& buttons ); ModalButtonPanel(wxWindow *window, const MsgButtons &buttons);
virtual ~ModalButtonPanel() throw() { } virtual ~ModalButtonPanel() throw() {}
virtual void AddActionButton( wxWindowID id ); virtual void AddActionButton(wxWindowID id);
virtual void AddCustomButton( wxWindowID id, const wxString& label ); 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<wxEvent *> wxEventList;
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// wxAppWithHelpers // wxAppWithHelpers
@ -78,67 +78,68 @@ public:
wxAppWithHelpers(); wxAppWithHelpers();
virtual ~wxAppWithHelpers() {} virtual ~wxAppWithHelpers() {}
wxAppTraits* CreateTraits(); wxAppTraits *CreateTraits();
void CleanUp(); void CleanUp();
void DeleteObject( BaseDeletableObject& obj ); void DeleteObject(BaseDeletableObject &obj);
void DeleteObject( BaseDeletableObject* obj ) void DeleteObject(BaseDeletableObject *obj)
{ {
if( obj == NULL ) return; if (obj == NULL)
DeleteObject( *obj ); return;
DeleteObject(*obj);
} }
void DeleteThread( Threading::pxThread& obj ); void DeleteThread(Threading::pxThread &obj);
void DeleteThread( Threading::pxThread* obj ) void DeleteThread(Threading::pxThread *obj)
{ {
if( obj == NULL ) return; if (obj == NULL)
DeleteThread( *obj ); return;
DeleteThread(*obj);
} }
void PostCommand( void* clientData, int evtType, int intParam=0, long longParam=0, const wxString& stringParam=wxEmptyString ); 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 PostCommand(int evtType, int intParam = 0, long longParam = 0, const wxString &stringParam = wxEmptyString);
void PostMethod( FnType_Void* method ); void PostMethod(FnType_Void *method);
void PostIdleMethod( FnType_Void* method ); void PostIdleMethod(FnType_Void *method);
void ProcessMethod( FnType_Void* method ); void ProcessMethod(FnType_Void *method);
bool Rpc_TryInvoke( FnType_Void* method ); bool Rpc_TryInvoke(FnType_Void *method);
bool Rpc_TryInvokeAsync( FnType_Void* method ); bool Rpc_TryInvokeAsync(FnType_Void *method);
sptr ProcessCommand( void* clientData, int evtType, int intParam=0, long longParam=0, const wxString& stringParam=wxEmptyString ); 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 ); sptr ProcessCommand(int evtType, int intParam = 0, long longParam = 0, const wxString &stringParam = wxEmptyString);
void ProcessAction( pxActionEvent& evt ); void ProcessAction(pxActionEvent &evt);
void PostAction( const pxActionEvent& evt ); void PostAction(const pxActionEvent &evt);
void Ping(); void Ping();
bool OnInit(); bool OnInit();
//int OnExit(); //int OnExit();
void AddIdleEvent( const wxEvent& evt ); void AddIdleEvent(const wxEvent &evt);
void PostEvent( const wxEvent& evt ); void PostEvent(const wxEvent &evt);
bool ProcessEvent( wxEvent& evt ); bool ProcessEvent(wxEvent &evt);
bool ProcessEvent( wxEvent* evt ); bool ProcessEvent(wxEvent *evt);
bool ProcessEvent( pxActionEvent& evt ); bool ProcessEvent(pxActionEvent &evt);
bool ProcessEvent( pxActionEvent* evt ); bool ProcessEvent(pxActionEvent *evt);
protected: protected:
void IdleEventDispatcher( const wxChar* action=wxEmptyString ); 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 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 namespace Msgbox
{ {
extern int ShowModal( BaseMessageBoxEvent& evt ); extern int ShowModal(BaseMessageBoxEvent &evt);
extern int ShowModal( const wxString& title, const wxString& content, const MsgButtons& buttons ); extern int ShowModal(const wxString &title, const wxString &content, const MsgButtons &buttons);
} }

View File

@ -26,11 +26,11 @@
// which require wxCore, see wxGuiTools.h // which require wxCore, see wxGuiTools.h
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
extern void pxExplore( const wxString& path ); extern void pxExplore(const wxString &path);
extern void pxExplore( const char *path ); extern void pxExplore(const char *path);
extern void pxLaunch( const wxString& path ); extern void pxLaunch(const wxString &path);
extern void pxLaunch( const char *path ); extern void pxLaunch(const char *path);
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// wxDoNotLogInThisScope // wxDoNotLogInThisScope
@ -52,21 +52,20 @@ protected:
public: public:
wxDoNotLogInThisScope() wxDoNotLogInThisScope()
{ {
m_prev = wxLog::EnableLogging( false ); m_prev = wxLog::EnableLogging(false);
} }
virtual ~wxDoNotLogInThisScope() throw() virtual ~wxDoNotLogInThisScope() throw()
{ {
wxLog::EnableLogging( m_prev ); wxLog::EnableLogging(m_prev);
} }
}; };
extern wxString pxReadLine( wxInputStream& input ); extern wxString pxReadLine(wxInputStream &input);
extern void pxReadLine( wxInputStream& input, wxString& dest ); extern void pxReadLine(wxInputStream &input, wxString &dest);
extern void pxReadLine( wxInputStream& input, wxString& dest, std::string& intermed ); extern void pxReadLine(wxInputStream &input, wxString &dest, std::string &intermed);
extern bool pxReadLine( wxInputStream& input, std::string& dest ); extern bool pxReadLine(wxInputStream &input, std::string &dest);
extern void pxWriteLine( wxOutputStream& output ); extern void pxWriteLine(wxOutputStream &output);
extern void pxWriteLine( wxOutputStream& output, const wxString& text ); extern void pxWriteLine(wxOutputStream &output, const wxString &text);
extern void pxWriteMultiline( wxOutputStream& output, const wxString& src ); extern void pxWriteMultiline(wxOutputStream &output, const wxString &src);

View File

@ -40,15 +40,15 @@ class wxSpinCtrl;
namespace pxSizerFlags namespace pxSizerFlags
{ {
static const int StdPadding = 4; static const int StdPadding = 4;
extern wxSizerFlags StdSpace(); extern wxSizerFlags StdSpace();
extern wxSizerFlags StdCenter(); extern wxSizerFlags StdCenter();
extern wxSizerFlags StdExpand(); extern wxSizerFlags StdExpand();
extern wxSizerFlags TopLevelBox(); extern wxSizerFlags TopLevelBox();
extern wxSizerFlags SubGroup(); extern wxSizerFlags SubGroup();
extern wxSizerFlags StdButton(); extern wxSizerFlags StdButton();
extern wxSizerFlags Checkbox(); extern wxSizerFlags Checkbox();
}; };
#define wxSF wxSizerFlags() #define wxSF wxSizerFlags()
@ -61,8 +61,7 @@ namespace pxSizerFlags
// //
struct pxAlignmentType struct pxAlignmentType
{ {
enum enum {
{
Centre, Centre,
Center = Centre, Center = Centre,
Middle, Middle,
@ -74,11 +73,11 @@ struct pxAlignmentType
int intval; int intval;
wxSizerFlags Apply( wxSizerFlags flags=wxSizerFlags() ) const; wxSizerFlags Apply(wxSizerFlags flags = wxSizerFlags()) const;
wxSizerFlags operator& ( const wxSizerFlags& _flgs ) const wxSizerFlags operator&(const wxSizerFlags &_flgs) const
{ {
return Apply( _flgs ); return Apply(_flgs);
} }
wxSizerFlags Expand() const wxSizerFlags Expand() const
@ -86,14 +85,14 @@ struct pxAlignmentType
return Apply().Expand(); return Apply().Expand();
} }
wxSizerFlags Border( int dir, int padding ) const wxSizerFlags Border(int dir, int padding) const
{ {
return Apply().Border( dir, padding ); return Apply().Border(dir, padding);
} }
wxSizerFlags Proportion() const wxSizerFlags Proportion() const
{ {
return Apply().Proportion( intval ); return Apply().Proportion(intval);
} }
operator wxSizerFlags() const operator wxSizerFlags() const
@ -104,8 +103,7 @@ struct pxAlignmentType
struct pxStretchType struct pxStretchType
{ {
enum enum {
{
Shrink, Shrink,
Expand, Expand,
Shaped, Shaped,
@ -115,21 +113,21 @@ struct pxStretchType
int intval; int intval;
wxSizerFlags Apply( wxSizerFlags flags=wxSizerFlags() ) const; wxSizerFlags Apply(wxSizerFlags flags = wxSizerFlags()) const;
wxSizerFlags operator& ( const wxSizerFlags& _flgs ) const wxSizerFlags operator&(const wxSizerFlags &_flgs) const
{ {
return Apply( _flgs ); return Apply(_flgs);
} }
wxSizerFlags Border( int dir, int padding ) const wxSizerFlags Border(int dir, int padding) const
{ {
return Apply().Border( dir, padding ); return Apply().Border(dir, padding);
} }
wxSizerFlags Proportion() const wxSizerFlags Proportion() const
{ {
return Apply().Proportion( intval ); return Apply().Proportion(intval);
} }
operator wxSizerFlags() const operator wxSizerFlags() const
@ -138,14 +136,14 @@ struct pxStretchType
} }
}; };
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 class pxStretchSpacer
@ -153,7 +151,7 @@ class pxStretchSpacer
public: public:
int proportion; int proportion;
pxStretchSpacer( int prop=0 ) pxStretchSpacer(int prop = 0)
{ {
proportion = prop; proportion = prop;
} }
@ -190,27 +188,27 @@ extern const pxStretchType
// template, the type of the window would only be known as "wxWindow" when it's added to the // 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. // sizer, and would thus fail to invoke the correct operator overload.
// //
template< typename WinType > template <typename WinType>
struct pxWindowAndFlags struct pxWindowAndFlags
{ {
WinType* window; WinType *window;
wxSizerFlags flags; wxSizerFlags flags;
}; };
extern wxSizerFlags operator& ( const wxSizerFlags& _flgs, const wxSizerFlags& _flgs2 ); extern wxSizerFlags operator&(const wxSizerFlags &_flgs, const wxSizerFlags &_flgs2);
template< typename WinType > template <typename WinType>
pxWindowAndFlags<WinType> operator | ( WinType* _win, const wxSizerFlags& _flgs ) pxWindowAndFlags<WinType> operator|(WinType *_win, const wxSizerFlags &_flgs)
{ {
pxWindowAndFlags<WinType> result = { _win, _flgs }; pxWindowAndFlags<WinType> result = {_win, _flgs};
return result; return result;
} }
template< typename WinType > template <typename WinType>
pxWindowAndFlags<WinType> operator | ( WinType& _win, const wxSizerFlags& _flgs ) pxWindowAndFlags<WinType> operator|(WinType &_win, const wxSizerFlags &_flgs)
{ {
pxWindowAndFlags<WinType> result = { &_win, _flgs }; pxWindowAndFlags<WinType> result = {&_win, _flgs};
return result; return result;
} }
@ -226,48 +224,51 @@ pxWindowAndFlags<WinType> operator | ( WinType& _win, const wxSizerFlags& _flgs
// has no sizer set via SetSizer(), an assertion is generated. // has no sizer set via SetSizer(), an assertion is generated.
// //
extern void operator+=( wxSizer& target, wxWindow* src ); extern void operator+=(wxSizer &target, wxWindow *src);
extern void operator+=( wxSizer& target, wxSizer* src ); extern void operator+=(wxSizer &target, wxSizer *src);
extern void operator+=( wxSizer& target, wxWindow& src ); extern void operator+=(wxSizer &target, wxWindow &src);
extern void operator+=( wxSizer& target, wxSizer& src ); extern void operator+=(wxSizer &target, wxSizer &src);
extern void operator+=( wxSizer* target, wxWindow& src ); extern void operator+=(wxSizer *target, wxWindow &src);
extern void operator+=( wxSizer* target, wxSizer& src ); extern void operator+=(wxSizer *target, wxSizer &src);
extern void operator+=( wxSizer& target, int spacer ); extern void operator+=(wxSizer &target, int spacer);
extern void operator+=( wxWindow& target, int spacer ); extern void operator+=(wxWindow &target, int spacer);
extern void operator+=( wxSizer& target, const pxStretchSpacer& spacer ); extern void operator+=(wxSizer &target, const pxStretchSpacer &spacer);
extern void operator+=( wxWindow& 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 // 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 // invoke the proper overloaded version of += (which is used by pxStaticText and other
// classes to perform special actions when added to sizers). // classes to perform special actions when added to sizers).
template< typename WinType > template <typename WinType>
void operator+=( wxWindow& target, WinType* src ) void operator+=(wxWindow &target, WinType *src)
{ {
if( !pxAssert( target.GetSizer() != NULL ) ) return; if (!pxAssert(target.GetSizer() != NULL))
return;
*target.GetSizer() += src; *target.GetSizer() += src;
} }
template< typename WinType > template <typename WinType>
void operator+=( wxWindow& target, WinType& src ) void operator+=(wxWindow &target, WinType &src)
{ {
if( !pxAssert( target.GetSizer() != NULL ) ) return; if (!pxAssert(target.GetSizer() != NULL))
return;
*target.GetSizer() += src; *target.GetSizer() += src;
} }
template< typename WinType > template <typename WinType>
void operator+=( wxWindow& target, const pxWindowAndFlags<WinType>& src ) void operator+=(wxWindow &target, const pxWindowAndFlags<WinType> &src)
{ {
if( !pxAssert( target.GetSizer() != NULL ) ) return; if (!pxAssert(target.GetSizer() != NULL))
return;
*target.GetSizer() += src; *target.GetSizer() += src;
} }
template< typename WinType > template <typename WinType>
void operator+=( wxSizer& target, const pxWindowAndFlags<WinType>& src ) void operator+=(wxSizer &target, const pxWindowAndFlags<WinType> &src)
{ {
target.Add( src.window, src.flags ); target.Add(src.window, src.flags);
} }
wxDECLARE_EVENT(pxEvt_OnDialogCreated, wxCommandEvent); wxDECLARE_EVENT(pxEvt_OnDialogCreated, wxCommandEvent);
@ -306,25 +307,25 @@ public:
hasCaption = true; hasCaption = true;
} }
pxDialogCreationFlags& SetSizerOrient( wxOrientation orient ) pxDialogCreationFlags &SetSizerOrient(wxOrientation orient)
{ {
BoxSizerOrient = orient; BoxSizerOrient = orient;
return *this; return *this;
} }
pxDialogCreationFlags& SetResize( bool enable=true ) pxDialogCreationFlags &SetResize(bool enable = true)
{ {
isResizable = enable; isResizable = enable;
return *this; return *this;
} }
pxDialogCreationFlags& SetMinimize( bool enable=true ) pxDialogCreationFlags &SetMinimize(bool enable = true)
{ {
hasMinimizeBox = enable; hasMinimizeBox = enable;
return *this; return *this;
} }
pxDialogCreationFlags& SetMaximize( bool enable=true ) pxDialogCreationFlags &SetMaximize(bool enable = true)
{ {
hasMaximizeBox = enable; hasMaximizeBox = enable;
return *this; return *this;
@ -332,43 +333,45 @@ public:
// NOTE: Enabling system menu on dialogs usually doesn't work, and might cause // NOTE: Enabling system menu on dialogs usually doesn't work, and might cause
// other unwanted behavior, such as a missing close button. // other unwanted behavior, such as a missing close button.
pxDialogCreationFlags& SetSystemMenu( bool enable=true ) pxDialogCreationFlags &SetSystemMenu(bool enable = true)
{ {
hasSystemMenu = enable; hasSystemMenu = enable;
return *this; return *this;
} }
pxDialogCreationFlags& SetCaption( bool enable=true ) pxDialogCreationFlags &SetCaption(bool enable = true)
{ {
hasCaption = enable; hasCaption = enable;
return *this; return *this;
} }
pxDialogCreationFlags& SetCloseBox( bool enable=true ) pxDialogCreationFlags &SetCloseBox(bool enable = true)
{ {
hasCloseBox = enable; hasCloseBox = enable;
return *this; return *this;
} }
pxDialogCreationFlags SetContextHelp( bool enabled=true ) pxDialogCreationFlags SetContextHelp(bool enabled = true)
{ {
hasContextHelp = enabled; hasContextHelp = enabled;
return *this; return *this;
} }
pxDialogCreationFlags& SetMinWidth( int width ) pxDialogCreationFlags &SetMinWidth(int width)
{ {
if( width > MinimumSize.x ) MinimumSize.SetWidth( width ); if (width > MinimumSize.x)
MinimumSize.SetWidth(width);
return *this; return *this;
} }
pxDialogCreationFlags& SetMinHeight( int height ) pxDialogCreationFlags &SetMinHeight(int height)
{ {
if( height > MinimumSize.y ) MinimumSize.SetHeight( height ); if (height > MinimumSize.y)
MinimumSize.SetHeight(height);
return *this; return *this;
} }
pxDialogCreationFlags& SetMinSize( const wxSize& size ) pxDialogCreationFlags &SetMinSize(const wxSize &size)
{ {
return SetMinWidth(size.x).SetMinHeight(size.y); return SetMinWidth(size.x).SetMinHeight(size.y);
} }
@ -376,110 +379,116 @@ public:
pxDialogCreationFlags Horizontal() const pxDialogCreationFlags Horizontal() const
{ {
return pxDialogCreationFlags(*this).SetSizerOrient( wxHORIZONTAL ); return pxDialogCreationFlags(*this).SetSizerOrient(wxHORIZONTAL);
} }
pxDialogCreationFlags Vertical() const pxDialogCreationFlags Vertical() const
{ {
return pxDialogCreationFlags(*this).SetSizerOrient( wxVERTICAL ); return pxDialogCreationFlags(*this).SetSizerOrient(wxVERTICAL);
} }
pxDialogCreationFlags NoSizer() const pxDialogCreationFlags NoSizer() const
{ {
return pxDialogCreationFlags(*this).SetSizerOrient( (wxOrientation)0 ); return pxDialogCreationFlags(*this).SetSizerOrient((wxOrientation)0);
} }
pxDialogCreationFlags Resize( bool enable=true ) const pxDialogCreationFlags Resize(bool enable = true) const
{ {
return pxDialogCreationFlags(*this).SetResize( enable ); return pxDialogCreationFlags(*this).SetResize(enable);
} }
pxDialogCreationFlags Minimize( bool enable=true ) const pxDialogCreationFlags Minimize(bool enable = true) const
{ {
return pxDialogCreationFlags(*this).SetMinimize( enable ); return pxDialogCreationFlags(*this).SetMinimize(enable);
} }
pxDialogCreationFlags Maximize( bool enable=true ) const pxDialogCreationFlags Maximize(bool enable = true) const
{ {
return pxDialogCreationFlags(*this).SetMaximize( enable ); return pxDialogCreationFlags(*this).SetMaximize(enable);
} }
// NOTE: Enabling system menu on dialogs usually doesn't work, and might cause // NOTE: Enabling system menu on dialogs usually doesn't work, and might cause
// other unwanted behavior, such as a missing close button. // other unwanted behavior, such as a missing close button.
pxDialogCreationFlags SystemMenu( bool enable=true ) const pxDialogCreationFlags SystemMenu(bool enable = true) const
{ {
return pxDialogCreationFlags(*this).SetSystemMenu( false ); return pxDialogCreationFlags(*this).SetSystemMenu(false);
} }
pxDialogCreationFlags Caption( bool enable=true ) const pxDialogCreationFlags Caption(bool enable = true) const
{ {
return pxDialogCreationFlags(*this).SetCaption( enable ); return pxDialogCreationFlags(*this).SetCaption(enable);
} }
pxDialogCreationFlags CloseBox( bool enable=true ) const pxDialogCreationFlags CloseBox(bool enable = true) const
{ {
return pxDialogCreationFlags(*this).SetCloseBox( enable ); return pxDialogCreationFlags(*this).SetCloseBox(enable);
} }
pxDialogCreationFlags NoResize() const pxDialogCreationFlags NoResize() const
{ {
return pxDialogCreationFlags(*this).SetResize( false ); return pxDialogCreationFlags(*this).SetResize(false);
} }
pxDialogCreationFlags NoMinimize() const pxDialogCreationFlags NoMinimize() const
{ {
return pxDialogCreationFlags(*this).SetMinimize( false ); return pxDialogCreationFlags(*this).SetMinimize(false);
} }
pxDialogCreationFlags NoMaximize() const pxDialogCreationFlags NoMaximize() const
{ {
return pxDialogCreationFlags(*this).SetMaximize( false ); return pxDialogCreationFlags(*this).SetMaximize(false);
} }
pxDialogCreationFlags NoSystemMenu() const pxDialogCreationFlags NoSystemMenu() const
{ {
return pxDialogCreationFlags(*this).SetSystemMenu( false ); return pxDialogCreationFlags(*this).SetSystemMenu(false);
} }
pxDialogCreationFlags NoCaption() const pxDialogCreationFlags NoCaption() const
{ {
return pxDialogCreationFlags(*this).SetCaption( false ); return pxDialogCreationFlags(*this).SetCaption(false);
} }
pxDialogCreationFlags NoCloseBox() const pxDialogCreationFlags NoCloseBox() const
{ {
return pxDialogCreationFlags(*this).SetCloseBox( false ); return pxDialogCreationFlags(*this).SetCloseBox(false);
} }
pxDialogCreationFlags MinWidth( int width ) const pxDialogCreationFlags MinWidth(int width) const
{ {
return pxDialogCreationFlags(*this).SetMinWidth( width ); return pxDialogCreationFlags(*this).SetMinWidth(width);
} }
pxDialogCreationFlags MinHeight( int height ) const pxDialogCreationFlags MinHeight(int height) const
{ {
return pxDialogCreationFlags(*this).SetMinHeight( height ); return pxDialogCreationFlags(*this).SetMinHeight(height);
} }
pxDialogCreationFlags MinSize( const wxSize& size ) const pxDialogCreationFlags MinSize(const wxSize &size) const
{ {
return pxDialogCreationFlags(*this).SetMinSize( size ); return pxDialogCreationFlags(*this).SetMinSize(size);
} }
pxDialogCreationFlags MinSize( int width, int height ) const pxDialogCreationFlags MinSize(int width, int height) const
{ {
return pxDialogCreationFlags(*this).SetMinWidth( width ).SetMinHeight( height ); return pxDialogCreationFlags(*this).SetMinWidth(width).SetMinHeight(height);
} }
int GetWxWindowFlags() const int GetWxWindowFlags() const
{ {
int retval = 0; int retval = 0;
if( isResizable ) retval |= wxRESIZE_BORDER; if (isResizable)
if( hasCaption ) retval |= wxCAPTION; retval |= wxRESIZE_BORDER;
if( hasMaximizeBox ) retval |= wxMAXIMIZE_BOX; if (hasCaption)
if( hasMinimizeBox ) retval |= wxMINIMIZE_BOX; retval |= wxCAPTION;
if( hasSystemMenu ) retval |= wxSYSTEM_MENU; if (hasMaximizeBox)
if( hasCloseBox ) retval |= wxCLOSE_BOX; retval |= wxMAXIMIZE_BOX;
if (hasMinimizeBox)
retval |= wxMINIMIZE_BOX;
if (hasSystemMenu)
retval |= wxSYSTEM_MENU;
if (hasCloseBox)
retval |= wxCLOSE_BOX;
return retval; return retval;
} }
@ -495,22 +504,22 @@ class wxDialogWithHelpers : public wxDialog
protected: protected:
bool m_hasContextHelp; bool m_hasContextHelp;
wxBoxSizer* m_extraButtonSizer; wxBoxSizer *m_extraButtonSizer;
wxRect m_CreatedRect; wxRect m_CreatedRect;
public: public:
wxDialogWithHelpers(); wxDialogWithHelpers();
wxDialogWithHelpers(wxWindow* parent, const wxString& title, const pxDialogCreationFlags& cflags = pxDialogCreationFlags() ); wxDialogWithHelpers(wxWindow *parent, const wxString &title, const pxDialogCreationFlags &cflags = pxDialogCreationFlags());
virtual ~wxDialogWithHelpers() throw(); virtual ~wxDialogWithHelpers() throw();
void Init( const pxDialogCreationFlags& cflags ); void Init(const pxDialogCreationFlags &cflags);
void AddOkCancel( wxSizer& sizer, bool hasApply=false ); void AddOkCancel(wxSizer &sizer, bool hasApply = false);
void AddOkCancel( wxSizer* sizer=NULL, bool hasApply=false ); void AddOkCancel(wxSizer *sizer = NULL, bool hasApply = false);
void RememberPosition(); void RememberPosition();
virtual void SmartCenterFit(); virtual void SmartCenterFit();
virtual int ShowModal(); virtual int ShowModal();
virtual bool Show( bool show=true ); virtual bool Show(bool show = true);
// Must return the same thing as GetNameStatic; a name ideal for use in uniquely // 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 // identifying dialogs. (this version is the 'instance' version, which is called
@ -518,18 +527,18 @@ public:
// screenshots to disk) // screenshots to disk)
virtual wxString GetDialogName() const; virtual wxString GetDialogName() const;
virtual wxStaticText& Label( const wxString& label ); virtual wxStaticText &Label(const wxString &label);
virtual pxStaticText& Text( const wxString& label ); virtual pxStaticText &Text(const wxString &label);
virtual pxStaticText& Heading( const wxString& label ); virtual pxStaticText &Heading(const wxString &label);
wxDialogWithHelpers& SetMinWidth( int newWidth ); wxDialogWithHelpers &SetMinWidth(int newWidth);
wxDialogWithHelpers& SetMinHeight( int newHeight ); wxDialogWithHelpers &SetMinHeight(int newHeight);
int GetCharHeight() const; int GetCharHeight() const;
protected: protected:
void OnDialogCreated( wxCommandEvent& evt ); void OnDialogCreated(wxCommandEvent &evt);
void OnOkCancel(wxCommandEvent& evt); void OnOkCancel(wxCommandEvent &evt);
bool ShouldPreventAppExit() const { return false; } bool ShouldPreventAppExit() const { return false; }
@ -558,18 +567,18 @@ class wxPanelWithHelpers : public wxPanel
DECLARE_DYNAMIC_CLASS_NO_COPY(wxPanelWithHelpers) DECLARE_DYNAMIC_CLASS_NO_COPY(wxPanelWithHelpers)
public: public:
wxPanelWithHelpers( wxWindow* parent, wxOrientation orient, const wxString& staticBoxLabel ); wxPanelWithHelpers(wxWindow *parent, wxOrientation orient, const wxString &staticBoxLabel);
wxPanelWithHelpers( wxWindow* parent, wxOrientation orient ); wxPanelWithHelpers(wxWindow *parent, wxOrientation orient);
wxPanelWithHelpers( wxWindow* parent, const wxPoint& pos, const wxSize& size=wxDefaultSize ); wxPanelWithHelpers(wxWindow *parent, const wxPoint &pos, const wxSize &size = wxDefaultSize);
explicit wxPanelWithHelpers( wxWindow* parent=NULL ); 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 ); wxStaticText &Label(const wxString &label);
pxStaticText& Text( const wxString& label ); pxStaticText &Text(const wxString &label);
pxStaticText& Heading( const wxString& label ); pxStaticText &Heading(const wxString &label);
virtual wxPanelWithHelpers& SetMinWidth( int newWidth ); virtual wxPanelWithHelpers &SetMinWidth(int newWidth);
protected: protected:
void Init(); void Init();
@ -595,10 +604,10 @@ protected:
wxString m_indent; wxString m_indent;
public: public:
virtual ~pxTextWrapperBase() throw() { } virtual ~pxTextWrapperBase() throw() {}
pxTextWrapperBase( const wxString& indent=wxEmptyString ) pxTextWrapperBase(const wxString &indent = wxEmptyString)
: m_indent( indent ) : m_indent(indent)
{ {
m_eol = false; m_eol = false;
m_linecount = 0; m_linecount = 0;
@ -606,7 +615,7 @@ public:
// win is used for getting the font, text is the text to wrap, width is the // win is used for getting the font, text is the text to wrap, width is the
// max line width or -1 to disable wrapping // 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 int GetLineCount() const
{ {
@ -615,12 +624,12 @@ public:
protected: protected:
// line may be empty // 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) // 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(); bool IsStartOfNewLine();
}; };
@ -638,22 +647,23 @@ protected:
wxString m_text; wxString m_text;
public: public:
pxTextWrapper( const wxString& wrapPrefix=wxEmptyString ) pxTextWrapper(const wxString &wrapPrefix = wxEmptyString)
: pxTextWrapperBase( wrapPrefix ) : pxTextWrapperBase(wrapPrefix)
{ } {
}
virtual ~pxTextWrapper() throw() { } virtual ~pxTextWrapper() throw() {}
const wxString& GetResult() const const wxString &GetResult() const
{ {
return m_text; return m_text;
} }
pxTextWrapper& Wrap( const wxWindow& win, const wxString& text, int widthMax ); pxTextWrapper &Wrap(const wxWindow &win, const wxString &text, int widthMax);
pxTextWrapper& Wrap( const wxWindow* win, const wxString& text, int widthMax ); pxTextWrapper &Wrap(const wxWindow *win, const wxString &text, int widthMax);
protected: protected:
void OnOutputLine(const wxString& line); void OnOutputLine(const wxString &line);
void OnNewLine(); void OnNewLine();
}; };
@ -663,64 +673,64 @@ protected:
class pxWindowTextWriter class pxWindowTextWriter
{ {
protected: protected:
wxDC& m_dc; wxDC &m_dc;
wxAlignment m_align; wxAlignment m_align;
wxPoint m_curpos; wxPoint m_curpos;
int m_leading; int m_leading;
virtual void _DoWriteLn( const wxChar* msg ); virtual void _DoWriteLn(const wxChar *msg);
void _DoWriteLn( const wxString msg ); void _DoWriteLn(const wxString msg);
void _DoWrite( const wxChar* msg ); void _DoWrite(const wxChar *msg);
public: public:
pxWindowTextWriter( wxDC& dc ); pxWindowTextWriter(wxDC &dc);
virtual ~pxWindowTextWriter() throw() { } virtual ~pxWindowTextWriter() throw() {}
virtual void OnFontChanged(); virtual void OnFontChanged();
pxWindowTextWriter& WriteLn(); pxWindowTextWriter &WriteLn();
pxWindowTextWriter& FormatLn( const wxChar* fmt, ... ); pxWindowTextWriter &FormatLn(const wxChar *fmt, ...);
pxWindowTextWriter& WriteLn( const wxChar* fmt ); pxWindowTextWriter &WriteLn(const wxChar *fmt);
pxWindowTextWriter& SetFont( const wxFont& font ); pxWindowTextWriter &SetFont(const wxFont &font);
pxWindowTextWriter& Align( const wxAlignment& align ); pxWindowTextWriter &Align(const wxAlignment &align);
pxWindowTextWriter& WriteLn( const wxString fmt ); pxWindowTextWriter &WriteLn(const wxString fmt);
pxWindowTextWriter& SetLeading( int lead ) pxWindowTextWriter &SetLeading(int lead)
{ {
m_leading = lead; m_leading = lead;
return *this; return *this;
} }
pxWindowTextWriter& SetWeight( wxFontWeight weight ); pxWindowTextWriter &SetWeight(wxFontWeight weight);
pxWindowTextWriter& SetStyle( wxFontStyle style ); pxWindowTextWriter &SetStyle(wxFontStyle style);
pxWindowTextWriter& Normal(); pxWindowTextWriter &Normal();
pxWindowTextWriter& Bold() pxWindowTextWriter &Bold()
{ {
return SetWeight(wxFONTWEIGHT_BOLD); return SetWeight(wxFONTWEIGHT_BOLD);
} }
pxWindowTextWriter& Italic() pxWindowTextWriter &Italic()
{ {
return SetStyle(wxFONTSTYLE_ITALIC); return SetStyle(wxFONTSTYLE_ITALIC);
} }
pxWindowTextWriter& SetPos( const wxPoint& pos ); pxWindowTextWriter &SetPos(const wxPoint &pos);
pxWindowTextWriter& MovePos( const wxSize& delta ); pxWindowTextWriter &MovePos(const wxSize &delta);
pxWindowTextWriter& SetPos( int xpos, int ypos ) pxWindowTextWriter &SetPos(int xpos, int ypos)
{ {
return SetPos( wxPoint(xpos,ypos) ); return SetPos(wxPoint(xpos, ypos));
} }
pxWindowTextWriter& MovePos( int xdelta, int ydelta ) pxWindowTextWriter &MovePos(int xdelta, int ydelta)
{ {
return MovePos( wxSize(xdelta, ydelta) ); return MovePos(wxSize(xdelta, ydelta));
} }
pxWindowTextWriter& SetY( int ypos ); pxWindowTextWriter &SetY(int ypos);
pxWindowTextWriter& MoveY( int ydelta ); pxWindowTextWriter &MoveY(int ydelta);
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -734,13 +744,12 @@ protected:
std::unique_ptr<wxCursor> m_arrowWait; std::unique_ptr<wxCursor> m_arrowWait;
public: public:
MoreStockCursors() { } MoreStockCursors() {}
virtual ~MoreStockCursors() throw() { } virtual ~MoreStockCursors() throw() {}
const wxCursor& GetArrowWait(); const wxCursor &GetArrowWait();
}; };
enum BusyCursorType enum BusyCursorType {
{
Cursor_NotBusy, Cursor_NotBusy,
Cursor_KindaBusy, Cursor_KindaBusy,
Cursor_ReallyBusy, Cursor_ReallyBusy,
@ -761,11 +770,11 @@ protected:
static BusyCursorType m_defBusyType; static BusyCursorType m_defBusyType;
public: public:
ScopedBusyCursor( BusyCursorType busytype ); ScopedBusyCursor(BusyCursorType busytype);
virtual ~ScopedBusyCursor() throw(); virtual ~ScopedBusyCursor() throw();
static void SetDefault( BusyCursorType busytype ); static void SetDefault(BusyCursorType busytype);
static void SetManualBusyCursor( 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 // Fits a given text or spinner control to the number of digits requested, since by default
// they're usually way over-sized. // they're usually way over-sized.
extern void pxFitToDigits( wxWindow* win, int digits ); extern void pxFitToDigits(wxWindow *win, int digits);
extern void pxFitToDigits( wxSpinCtrl* win, int digits ); extern void pxFitToDigits(wxSpinCtrl *win, int digits);
extern wxTextCtrl* CreateNumericalTextCtrl( wxWindow* parent, int digits, long flags = wxTE_RIGHT ); extern wxTextCtrl *CreateNumericalTextCtrl(wxWindow *parent, int digits, long flags = wxTE_RIGHT);
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
extern bool pxDialogExists( const wxString& name ); extern bool pxDialogExists(const wxString &name);
extern bool pxIsValidWindowPosition( const wxWindow& window, const wxPoint& windowPos ); extern bool pxIsValidWindowPosition(const wxWindow &window, const wxPoint &windowPos);
extern wxRect wxGetDisplayArea(); extern wxRect wxGetDisplayArea();
extern wxString pxGetAppName(); 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 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 wxFont pxGetFixedFont(int ptsize = 8, wxFontWeight weight = wxFONTWEIGHT_NORMAL);
extern pxDialogCreationFlags pxDialogFlags(); extern pxDialogCreationFlags pxDialogFlags();

View File

@ -35,36 +35,57 @@
// Basic functions. // Basic functions.
EXPORT_C_(s32) CDVDinit(); EXPORT_C_(s32)
EXPORT_C_(s32) CDVDopen(void *pDisplay, const char* pTitleFilename); CDVDinit();
EXPORT_C_(void) CDVDclose(); EXPORT_C_(s32)
EXPORT_C_(void) CDVDshutdown(); CDVDopen(void *pDisplay, const char *pTitleFilename);
EXPORT_C_(s32) CDVDreadTrack(u32 lsn, int mode); EXPORT_C_(void)
CDVDclose();
EXPORT_C_(void)
CDVDshutdown();
EXPORT_C_(s32)
CDVDreadTrack(u32 lsn, int mode);
// return can be NULL (for async modes) // 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)
EXPORT_C_(s32) CDVDgetTN(cdvdTN *Buffer); //disk information CDVDreadSubQ(u32 lsn, cdvdSubQ *subq); //read subq from disc (only cds have subq data)
EXPORT_C_(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type EXPORT_C_(s32)
EXPORT_C_(s32) CDVDgetTOC(void* toc); //gets ps2 style toc from disc CDVDgetTN(cdvdTN *Buffer); //disk information
EXPORT_C_(s32) CDVDgetDiskType(); //CDVD_TYPE_xxxx EXPORT_C_(s32)
EXPORT_C_(s32) CDVDgetTrayStatus(); //CDVD_TRAY_xxxx CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type
EXPORT_C_(s32) CDVDctrlTrayOpen(); //open disc tray EXPORT_C_(s32)
EXPORT_C_(s32) CDVDctrlTrayClose(); //close disc tray 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 // Extended functions
EXPORT_C_(void) CDVDkeyEvent(keyEvent *ev); EXPORT_C_(void)
EXPORT_C_(void) CDVDconfigure(); CDVDkeyEvent(keyEvent *ev);
EXPORT_C_(s32) CDVDfreeze(u8 mode, freezeData *data); EXPORT_C_(void)
EXPORT_C_(void) CDVDabout(); CDVDconfigure();
EXPORT_C_(s32) CDVDtest(); EXPORT_C_(s32)
EXPORT_C_(void) CDVDnewDiskCB(void (*callback)()); CDVDfreeze(u8 mode, freezeData *data);
EXPORT_C_(void)
CDVDabout();
EXPORT_C_(s32)
CDVDtest();
EXPORT_C_(void)
CDVDnewDiskCB(void (*callback)());
typedef struct _cdvdSubQ { typedef struct _cdvdSubQ
u8 ctrl:4; // control and mode bits {
u8 mode:4; // control and mode bits u8 ctrl : 4; // control and mode bits
u8 mode : 4; // control and mode bits
u8 trackNum; // current track number (1 to 99) u8 trackNum; // current track number (1 to 99)
u8 trackIndex; // current index within track (0 to 99) u8 trackIndex; // current index within track (0 to 99)
u8 trackM; // current minute location on the disc (BCD encoded) u8 trackM; // current minute location on the disc (BCD encoded)
@ -76,60 +97,62 @@ typedef struct _cdvdSubQ {
u8 discF; // current frame offset from first track (BCD encoded) u8 discF; // current frame offset from first track (BCD encoded)
} cdvdSubQ; } cdvdSubQ;
typedef struct _cdvdTD { // NOT bcd coded typedef struct _cdvdTD
{ // NOT bcd coded
u32 lsn; u32 lsn;
u8 type; u8 type;
} cdvdTD; } cdvdTD;
typedef struct _cdvdTN { typedef struct _cdvdTN
{
u8 strack; //number of the first track (usually 1) u8 strack; //number of the first track (usually 1)
u8 etrack; //number of the last track u8 etrack; //number of the last track
} cdvdTN; } cdvdTN;
// CDVDreadTrack mode values: // CDVDreadTrack mode values:
enum { enum {
CDVD_MODE_2352 0, // full 2352 bytes CDVD_MODE_2352 0, // full 2352 bytes
CDVD_MODE_2340 1, // skip sync (12) bytes CDVD_MODE_2340 1, // skip sync (12) bytes
CDVD_MODE_2328 2, // skip sync+head+sub (24) bytes CDVD_MODE_2328 2, // skip sync+head+sub (24) bytes
CDVD_MODE_2048 3, // 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_2368 4 // full 2352 bytes + 16 subq
} TrackModes } TrackModes
// CDVDgetDiskType returns: // CDVDgetDiskType returns:
enum { enum {
CDVD_TYPE_ILLEGAL = 0xff, // Illegal Disc CDVD_TYPE_ILLEGAL = 0xff, // Illegal Disc
CDVD_TYPE_DVDV = 0xfe, // DVD Video CDVD_TYPE_DVDV = 0xfe, // DVD Video
CDVD_TYPE_CDDA = 0xfd, // Audio CD CDVD_TYPE_CDDA = 0xfd, // Audio CD
CDVD_TYPE_PS2DVD = 0x14, // PS2 DVD CDVD_TYPE_PS2DVD = 0x14, // PS2 DVD
CDVD_TYPE_PS2CDDA = 0x13, // PS2 CD (with audio) CDVD_TYPE_PS2CDDA = 0x13, // PS2 CD (with audio)
CDVD_TYPE_PS2CD = 0x12, // PS2 CD CDVD_TYPE_PS2CD = 0x12, // PS2 CD
CDVD_TYPE_PSCDDA = 0x11, // PS CD (with audio) CDVD_TYPE_PSCDDA = 0x11, // PS CD (with audio)
CDVD_TYPE_PSCD = 0x10, // PS CD CDVD_TYPE_PSCD = 0x10, // PS CD
CDVD_TYPE_UNKNOWN = 0x05, // Unknown CDVD_TYPE_UNKNOWN = 0x05, // Unknown
CDVD_TYPE_DETCTDVDD = 0x04, // Detecting Dvd Dual Sided CDVD_TYPE_DETCTDVDD = 0x04, // Detecting Dvd Dual Sided
CDVD_TYPE_DETCTDVDS = 0x03, // Detecting Dvd Single Sided CDVD_TYPE_DETCTDVDS = 0x03, // Detecting Dvd Single Sided
CDVD_TYPE_DETCTCD = 0x02, // Detecting Cd CDVD_TYPE_DETCTCD = 0x02, // Detecting Cd
CDVD_TYPE_DETCT = 0x01, // Detecting CDVD_TYPE_DETCT = 0x01, // Detecting
CDVD_TYPE_NODISC = 0x00 // No Disc CDVD_TYPE_NODISC = 0x00 // No Disc
} DiskType; } DiskType;
// CDVDgetTrayStatus returns: // CDVDgetTrayStatus returns:
enum { enum {
CDVD_TRAY_CLOSE = 0x00, CDVD_TRAY_CLOSE = 0x00,
CDVD_TRAY_OPEN = 0x01 CDVD_TRAY_OPEN = 0x01
} TrayStatus; } TrayStatus;
// cdvdTD.type (track types for cds) // cdvdTD.type (track types for cds)
enum { enum {
CDVD_AUDIO_TRACK = 0x01, CDVD_AUDIO_TRACK = 0x01,
CDVD_MODE1_TRACK = 0x41, CDVD_MODE1_TRACK = 0x41,
CDVD_MODE2_TRACK = 0x61 CDVD_MODE2_TRACK = 0x61
} CDVDTDType; } CDVDTDType;
enum { enum {
CDVD_AUDIO_MASK = 0x00, CDVD_AUDIO_MASK = 0x00,
CDVD_DATA_MASK = 0x40 CDVD_DATA_MASK = 0x40
// CDROM_DATA_TRACK 0x04 //do not enable this! (from linux kernel) // CDROM_DATA_TRACK 0x04 //do not enable this! (from linux kernel)
} CDVD_Masks; } CDVD_Masks;
#endif // __CDVDAPI_H__ #endif // __CDVDAPI_H__

View File

@ -37,32 +37,51 @@ typedef int (*DEV9handler)(void);
// Basic functions. // Basic functions.
// NOTE: The read/write functions CANNOT use XMM/MMX regs // NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones // 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. // pDisplay normally is passed a handle to the GS plugins window.
EXPORT_C_(s32) DEV9open(void *pDisplay); EXPORT_C_(s32)
EXPORT_C_(void) DEV9close(); DEV9open(void *pDisplay);
EXPORT_C_(void) DEV9shutdown(); EXPORT_C_(void)
EXPORT_C_(u8) DEV9read8(u32 addr); DEV9close();
EXPORT_C_(u16) DEV9read16(u32 addr); EXPORT_C_(void)
EXPORT_C_(u32) DEV9read32(u32 addr); DEV9shutdown();
EXPORT_C_(void) DEV9write8(u32 addr, u8 value); EXPORT_C_(u8)
EXPORT_C_(void) DEV9write16(u32 addr, u16 value); DEV9read8(u32 addr);
EXPORT_C_(void) DEV9write32(u32 addr, u32 value); EXPORT_C_(u16)
EXPORT_C_(void) DEV9readDMA8Mem(u32 *pMem, int size); DEV9read16(u32 addr);
EXPORT_C_(void) DEV9writeDMA8Mem(u32 *pMem, int size); 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, // cycles = IOP cycles before calling callback,
// if callback returns 1 the irq is triggered, else not // if callback returns 1 the irq is triggered, else not
EXPORT_C_(void) DEV9irqCallback(DEV9callback callback); EXPORT_C_(void)
EXPORT_C_(DEV9handler) DEV9irqHandler(void); DEV9irqCallback(DEV9callback callback);
EXPORT_C_(DEV9handler)
DEV9irqHandler(void);
// Extended functions // Extended functions
EXPORT_C_(void) DEV9keyEvent(keyEvent *ev); EXPORT_C_(void)
EXPORT_C_(s32) DEV9freeze(u8 mode, freezeData *data); DEV9keyEvent(keyEvent *ev);
EXPORT_C_(void) DEV9configure(); EXPORT_C_(s32)
EXPORT_C_(void) DEV9about(); DEV9freeze(u8 mode, freezeData *data);
EXPORT_C_(s32) DEV9test(); EXPORT_C_(void)
DEV9configure();
EXPORT_C_(void)
DEV9about();
EXPORT_C_(s32)
DEV9test();
#endif // __DEV9API_H__ #endif // __DEV9API_H__

View File

@ -37,22 +37,34 @@
// NOTE: The read/write functions CANNOT use XMM/MMX regs // NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones // 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. // pDisplay normally is passed a handle to the GS plugins window.
EXPORT_C_(s32) FWopen(void *pDisplay); EXPORT_C_(s32)
EXPORT_C_(void) FWclose(); FWopen(void *pDisplay);
EXPORT_C_(void) FWshutdown(); EXPORT_C_(void)
EXPORT_C_(u32) FWread32(u32 addr); FWclose();
EXPORT_C_(void) FWwrite32(u32 addr, u32 value); EXPORT_C_(void)
EXPORT_C_(void) FWirqCallback(void (*callback)()); FWshutdown();
EXPORT_C_(u32)
FWread32(u32 addr);
EXPORT_C_(void)
FWwrite32(u32 addr, u32 value);
EXPORT_C_(void)
FWirqCallback(void (*callback)());
// Extended functions // Extended functions
EXPORT_C_(void) FWkeyEvent(keyEvent *ev); EXPORT_C_(void)
EXPORT_C_(s32) FWfreeze(u8 mode, freezeData *data); FWkeyEvent(keyEvent *ev);
EXPORT_C_(void) FWconfigure(); EXPORT_C_(s32)
EXPORT_C_(void) FWabout(); FWfreeze(u8 mode, freezeData *data);
EXPORT_C_(s32) FWtest(); EXPORT_C_(void)
FWconfigure();
EXPORT_C_(void)
FWabout();
EXPORT_C_(s32)
FWtest();
#endif #endif
#endif // __USBAPI_H__ #endif // __USBAPI_H__

View File

@ -31,55 +31,86 @@
#include "Pcsx2Api.h" #include "Pcsx2Api.h"
typedef struct _GSdriverInfo { typedef struct _GSdriverInfo
{
char name[8]; char name[8];
void *common; void *common;
} GSdriverInfo; } GSdriverInfo;
// Basic functions. // Basic functions.
EXPORT_C_(s32) GSinit(); EXPORT_C_(s32)
GSinit();
// pDisplay normally is passed a handle to the GS plugins window. // pDisplay normally is passed a handle to the GS plugins window.
EXPORT_C_(s32) GSopen(void *pDisplay, char *Title, bool multithread); EXPORT_C_(s32)
EXPORT_C_(void) GSclose(); GSopen(void *pDisplay, char *Title, bool multithread);
EXPORT_C_(void) GSshutdown(); EXPORT_C_(void)
EXPORT_C_(void) GSvsync(int field); GSclose();
EXPORT_C_(void) GSgifTransfer1(u32 *pMem, u32 addr); EXPORT_C_(void)
EXPORT_C_(void) GSgifTransfer2(u32 *pMem, u32 size); GSshutdown();
EXPORT_C_(void) GSgifTransfer3(u32 *pMem, u32 size); EXPORT_C_(void)
EXPORT_C_(void) GSgetLastTag(u64* ptag); // returns the last tag processed (64 bits) GSvsync(int field);
EXPORT_C_(void) GSgifSoftReset(u32 mask); EXPORT_C_(void)
EXPORT_C_(void) GSreadFIFO(u64 *mem); GSgifTransfer1(u32 *pMem, u32 addr);
EXPORT_C_(void) GSreadFIFO2(u64 *mem, int qwc); 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 // Extended functions
// GSkeyEvent gets called when there is a keyEvent from the PAD plugin // GSkeyEvent gets called when there is a keyEvent from the PAD plugin
EXPORT_C_(void) GSkeyEvent(keyEvent *ev); EXPORT_C_(void)
EXPORT_C_(void) GSchangeSaveState(s32 state, const char* filename); GSkeyEvent(keyEvent *ev);
EXPORT_C_(void) GSmakeSnapshot(char *path); EXPORT_C_(void)
EXPORT_C_(void) GSmakeSnapshot2(char *pathname, int* snapdone, int savejpg); GSchangeSaveState(s32 state, const char *filename);
EXPORT_C_(void) GSirqCallback(void (*callback)()); EXPORT_C_(void)
EXPORT_C_(void) CALLBACK GSprintf(s32 timeout, char *fmt, ...); GSmakeSnapshot(char *path);
EXPORT_C_(void) GSsetBaseMem(void*); EXPORT_C_(void)
EXPORT_C_(void) GSsetGameCRC(s32 crc, s32 gameoptions); 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 // 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 // if start is true, starts recording spu2 data, else stops
// returns true if successful // returns true if successful
// for now, pData is not used // 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)
EXPORT_C_(void) GSwriteCSR(u32 value); GSreset();
EXPORT_C_(void ) GSgetDriverInfo(GSdriverInfo *info); EXPORT_C_(void)
GSwriteCSR(u32 value);
EXPORT_C_(void)
GSgetDriverInfo(GSdriverInfo *info);
#ifdef _WIN32 #ifdef _WIN32
EXPORT_C_(s32) CALLBACK GSsetWindowInfo(winInfo *info); EXPORT_C_(s32)
CALLBACK GSsetWindowInfo(winInfo *info);
#endif #endif
EXPORT_C_(s32) GSfreeze(u8 mode, freezeData *data); EXPORT_C_(s32)
EXPORT_C_(void) GSconfigure(); GSfreeze(u8 mode, freezeData *data);
EXPORT_C_(void) GSabout(); EXPORT_C_(void)
EXPORT_C_(s32) GStest(); GSconfigure();
EXPORT_C_(void)
GSabout();
EXPORT_C_(s32)
GStest();
#endif // __GSAPI_H__ #endif // __GSAPI_H__

View File

@ -35,19 +35,27 @@
/* So obsolete that everyone uses it. */ /* So obsolete that everyone uses it. */
// Basic functions. // 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. // pDisplay normally is passed a handle to the GS plugins window.
EXPORT_C_(s32) PADopen(void *pDisplay); EXPORT_C_(s32)
EXPORT_C_(void) PADclose(); PADopen(void *pDisplay);
EXPORT_C_(void) PADshutdown(); EXPORT_C_(void)
PADclose();
EXPORT_C_(void)
PADshutdown();
// PADkeyEvent is called every vsync (return NULL if no event) // PADkeyEvent is called every vsync (return NULL if no event)
EXPORT_C_(keyEvent*) PADkeyEvent(); EXPORT_C_(keyEvent *)
EXPORT_C_(u8) PADstartPoll(u8 pad); PADkeyEvent();
EXPORT_C_(u8) PADpoll(u8 value); EXPORT_C_(u8)
PADstartPoll(u8 pad);
EXPORT_C_(u8)
PADpoll(u8 value);
// returns: 1 if supported pad1 // returns: 1 if supported pad1
// 2 if supported pad2 // 2 if supported pad2
// 3 if both are supported // 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 // 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. // 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 // the window (and input). Note that PADupdate can be called from a different
// thread than the other functions, so mutex or other multithreading primitives // thread than the other functions, so mutex or other multithreading primitives
// have to be added to maintain data integrity. // have to be added to maintain data integrity.
EXPORT_C_(void) PADupdate(u8 pad); EXPORT_C_(void)
PADupdate(u8 pad);
// Extended functions // Extended functions
EXPORT_C_(void) PADgsDriverInfo(GSdriverInfo *info); EXPORT_C_(void)
EXPORT_C_(s32) PADfreeze(u8 mode, freezeData *data); PADgsDriverInfo(GSdriverInfo *info);
EXPORT_C_(s32)
PADfreeze(u8 mode, freezeData *data);
// Returns 1 if the pad plugin wants a multitap on the specified port. // Returns 1 if the pad plugin wants a multitap on the specified port.
// 0 otherwise. // 0 otherwise.
EXPORT_C_(s32) PADqueryMtap(u8 port); EXPORT_C_(s32)
PADqueryMtap(u8 port);
// Sets the active pad slot for the specified port. // Sets the active pad slot for the specified port.
// Both numbers are 1-based indices. Should return 0 if there's no // Both numbers are 1-based indices. Should return 0 if there's no
// pad on the specified slot. Even if PADqueryMtap(port) returns 0, // pad on the specified slot. Even if PADqueryMtap(port) returns 0,
// should handle this properly for slot != 1, so emulator can allow // should handle this properly for slot != 1, so emulator can allow
// Multitap to be enabled/disabled elsewhere. // 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)
EXPORT_C_(void) PADabout(); PADconfigure();
EXPORT_C_(s32) PADtest(); EXPORT_C_(void)
PADabout();
EXPORT_C_(s32)
PADtest();
#endif // __PADAPI_H__ #endif // __PADAPI_H__

View File

@ -38,49 +38,61 @@
// MTAP SIO plugins should ignore slot values on startPoll, as should RMs (probably). // MTAP SIO plugins should ignore slot values on startPoll, as should RMs (probably).
// Port isn't strictly necessary, but doesn't hurt. // 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. // Basic functions.
// Types is an or-ed combination of SioTypes to initialize. It'd probably be simplest // 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. // just to make each SIO plugin support only one type, for simplicity.
// SIOchangeSlotCB should *only* be called by MTAP plugins. // 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, // 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 // but not both a PAD and MTAP. Simplifies plugin selection and interface, as well
// as API. // as API.
// pDisplay normally is passed a handle to the GS plugins window. // pDisplay normally is passed a handle to the GS plugins window.
EXPORT_C_(s32) SIOopen(void *pDisplay); EXPORT_C_(s32)
EXPORT_C_(void) SIOclose(); SIOopen(void *pDisplay);
EXPORT_C_(void) SIOshutdown(); EXPORT_C_(void)
SIOclose();
EXPORT_C_(void)
SIOshutdown();
// Returns 0 if device doesn't exist. Means old pad plugins can just say nothing // 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. // 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. // 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} // returns: SIO_TYPE_{PAD,MTAP,RM,MC}
EXPORT_C_(u32) SIOquery(); EXPORT_C_(u32)
SIOquery();
// extended funcs // extended funcs
EXPORT_C_(void) SIOconfigure(); EXPORT_C_(void)
EXPORT_C_(keyEvent*) CALLBACK SIOkeyEvent(); SIOconfigure();
EXPORT_C_(keyEvent *)
CALLBACK SIOkeyEvent();
// Save one type at a time. If a plugin supports all 4 types, // Save one type at a time. If a plugin supports all 4 types,
// should expect 4 calls. Increases savestate compatibility. // should expect 4 calls. Increases savestate compatibility.
EXPORT_C_(s32) SIOfreeze(u8 mode, freezeData *data, int type); EXPORT_C_(s32)
EXPORT_C_(void) SIOabout(); SIOfreeze(u8 mode, freezeData *data, int type);
EXPORT_C_(s32) SIOtest(); EXPORT_C_(void)
SIOabout();
EXPORT_C_(s32)
SIOtest();
enum { enum {
SIO_TYPE_PAD = 0x00000001, SIO_TYPE_PAD = 0x00000001,
SIO_TYPE_MTAP = 0x00000004, SIO_TYPE_MTAP = 0x00000004,
SIO_TYPE_RM = 0x00000040, SIO_TYPE_RM = 0x00000040,
SIO_TYPE_MC = 0x00000100 SIO_TYPE_MC = 0x00000100
} SioTypes; } SioTypes;
#endif // __SIOAPI_H__ #endif // __SIOAPI_H__

View File

@ -31,47 +31,74 @@
#include "Pcsx2Api.h" #include "Pcsx2Api.h"
EXPORT_C_(s32) SPU2init(); EXPORT_C_(s32)
SPU2init();
// pDisplay normally is passed a handle to the GS plugins window. // pDisplay normally is passed a handle to the GS plugins window.
EXPORT_C_(s32) SPU2open(void *pDisplay); EXPORT_C_(s32)
EXPORT_C_(void) SPU2close(); SPU2open(void *pDisplay);
EXPORT_C_(void) SPU2shutdown(); EXPORT_C_(void)
EXPORT_C_(void) SPU2write(u32 mem, u16 value); SPU2close();
EXPORT_C_(u16) SPU2read(u32 mem); EXPORT_C_(void)
SPU2shutdown();
EXPORT_C_(void)
SPU2write(u32 mem, u16 value);
EXPORT_C_(u16)
SPU2read(u32 mem);
// The following calls are depreciated. // The following calls are depreciated.
EXPORT_C_(void) SPU2readDMA4Mem(u16 *pMem, u32 size); EXPORT_C_(void)
EXPORT_C_(void) SPU2readDMA7Mem(u16 *pMem, u32 size); SPU2readDMA4Mem(u16 *pMem, u32 size);
EXPORT_C_(void) SPU2writeDMA4Mem(u16 *pMem, u32 size); EXPORT_C_(void)
EXPORT_C_(void) SPU2writeDMA7Mem(u16 *pMem, u32 size); SPU2readDMA7Mem(u16 *pMem, u32 size);
EXPORT_C_(void) SPU2interruptDMA4(); EXPORT_C_(void)
EXPORT_C_(void) SPU2interruptDMA7(); 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. // These calls replace the calls above.
EXPORT_C_(void) SPU2readDMAMem(u16 *pMem, u32 size, u8 core); EXPORT_C_(void)
EXPORT_C_(void) SPU2writeDMAMem(u16 *pMem, u32 size, u8 core); SPU2readDMAMem(u16 *pMem, u32 size, u8 core);
EXPORT_C_(void) SPU2interruptDMA(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 // 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 // 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_(u32)
EXPORT_C_(void) SPU2WriteMemAddr(u8 core,u32 value); SPU2ReadMemAddr(u8 core);
EXPORT_C_(void) SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)()); EXPORT_C_(void)
SPU2WriteMemAddr(u8 core, u32 value);
EXPORT_C_(void)
SPU2irqCallback(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)());
// extended funcs // extended funcs
// if start is true, starts recording spu2 data, else stops // if start is true, starts recording spu2 data, else stops
// returns true if successful // 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)
EXPORT_C_(void) SPU2setClockPtr(u32* ptr); SPU2keyEvent(keyEvent *ev);
EXPORT_C_(void) SPU2async(u32 cycles); EXPORT_C_(void)
EXPORT_C_(s32) SPU2freeze(u8 mode, freezeData *data); SPU2setClockPtr(u32 *ptr);
EXPORT_C_(void) SPU2configure(); EXPORT_C_(void)
EXPORT_C_(void) SPU2about(); SPU2async(u32 cycles);
EXPORT_C_(s32) SPU2test(); EXPORT_C_(s32)
SPU2freeze(u8 mode, freezeData *data);
EXPORT_C_(void)
SPU2configure();
EXPORT_C_(void)
SPU2about();
EXPORT_C_(s32)
SPU2test();
#endif #endif

View File

@ -35,31 +35,50 @@ typedef void (*USBcallback)(int cycles);
typedef int (*USBhandler)(void); typedef int (*USBhandler)(void);
// Basic functions. // Basic functions.
EXPORT_C_(s32) USBinit(); EXPORT_C_(s32)
USBinit();
// pDisplay normally is passed a handle to the GS plugins window. // pDisplay normally is passed a handle to the GS plugins window.
EXPORT_C_(s32) USBopen(void *pDisplay); EXPORT_C_(s32)
EXPORT_C_(void) USBclose(); USBopen(void *pDisplay);
EXPORT_C_(void) USBshutdown(); EXPORT_C_(void)
EXPORT_C_(u8) USBread8(u32 addr); USBclose();
EXPORT_C_(u16) USBread16(u32 addr); EXPORT_C_(void)
EXPORT_C_(u32) USBread32(u32 addr); USBshutdown();
EXPORT_C_(void) USBwrite8(u32 addr, u8 value); EXPORT_C_(u8)
EXPORT_C_(void) USBwrite16(u32 addr, u16 value); USBread8(u32 addr);
EXPORT_C_(void) USBwrite32(u32 addr, u32 value); EXPORT_C_(u16)
EXPORT_C_(void) USBasync(u32 cycles); 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, // cycles = IOP cycles before calling callback,
// if callback returns 1 the irq is triggered, else not // if callback returns 1 the irq is triggered, else not
EXPORT_C_(void) USBirqCallback(USBcallback callback); EXPORT_C_(void)
EXPORT_C_(USBhandler) USBirqHandler(void); USBirqCallback(USBcallback callback);
EXPORT_C_(void) USBsetRAM(void *mem); EXPORT_C_(USBhandler)
USBirqHandler(void);
EXPORT_C_(void)
USBsetRAM(void *mem);
// Extended functions // Extended functions
EXPORT_C_(void) USBkeyEvent(keyEvent *ev); EXPORT_C_(void)
EXPORT_C_(s32) USBfreeze(u8 mode, freezeData *data); USBkeyEvent(keyEvent *ev);
EXPORT_C_(void) USBconfigure(); EXPORT_C_(s32)
EXPORT_C_(void) USBabout(); USBfreeze(u8 mode, freezeData *data);
EXPORT_C_(s32) USBtest(); EXPORT_C_(void)
USBconfigure();
EXPORT_C_(void)
USBabout();
EXPORT_C_(s32)
USBtest();
#endif // __USBAPI_H__ #endif // __USBAPI_H__

View File

@ -17,10 +17,11 @@
// Implement BMI1/BMI2 instruction set // Implement BMI1/BMI2 instruction set
namespace x86Emitter { namespace x86Emitter
{
struct xImplBMI_RVM struct xImplBMI_RVM
{ {
u8 Prefix; u8 Prefix;
u8 MbPrefix; u8 MbPrefix;
u8 Opcode; u8 Opcode;
@ -30,8 +31,8 @@ namespace x86Emitter {
// PDEP Parallel bits deposit // PDEP Parallel bits deposit
// PEXT Parallel bits extract // PEXT Parallel bits extract
// ANDN Logical and not ~x & y // 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 xRegisterInt &from2) const;
void operator()( const xRegisterInt& to, const xRegisterInt& from1, const xIndirectVoid& from2) const; void operator()(const xRegisterInt &to, const xRegisterInt &from1, const xIndirectVoid &from2) const;
#if 0 #if 0
// RMV // RMV
@ -56,6 +57,5 @@ namespace x86Emitter {
void operator()( const xRegisterInt& to, const xRegisterInt& from, u8 imm) const; void operator()( const xRegisterInt& to, const xRegisterInt& from, u8 imm) const;
void operator()( const xRegisterInt& to, const xIndirectVoid& from, u8 imm) const; void operator()( const xRegisterInt& to, const xIndirectVoid& from, u8 imm) const;
#endif #endif
}; };
} }

View File

@ -15,7 +15,8 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
{
// Implementations here cover SHLD and SHRD. // Implementations here cover SHLD and SHRD.
@ -32,12 +33,12 @@ 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, const xRegisterCL &clreg) const;
void operator()( const xIndirectVoid& dest,const xRegister16or32or64& from, u8 shiftcnt ) const; void operator()(const xIndirectVoid &dest, const xRegister16or32or64 &from, u8 shiftcnt) const;
}; };
} // End namespace x86Emitter } // End namespace x86Emitter

View File

@ -15,11 +15,11 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
enum G1Type
{ {
G1Type_ADD=0,
enum G1Type {
G1Type_ADD = 0,
G1Type_OR, G1Type_OR,
G1Type_ADC, G1Type_ADC,
G1Type_SBB, G1Type_SBB,
@ -29,7 +29,7 @@ enum G1Type
G1Type_CMP 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 // xImpl_Group1
@ -38,12 +38,12 @@ 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 xIndirectVoid &to, const xRegisterInt &from) const;
void operator()( const xRegisterInt& to, const xIndirectVoid& from ) const; void operator()(const xRegisterInt &to, const xIndirectVoid &from) const;
void operator()( const xRegisterInt& to, int imm ) 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;
#if 0 #if 0
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -89,13 +89,13 @@ 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 xIndirectVoid &to, const xRegisterInt &from) const;
void operator()( const xRegisterInt& to, const xIndirectVoid& from ) const; void operator()(const xRegisterInt &to, const xIndirectVoid &from) const;
void operator()( const xRegisterInt& to, int imm ) 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 PS; // packed single precision
xImplSimd_DestRegSSE PD; // packed double precision xImplSimd_DestRegSSE PD; // packed double precision
@ -108,13 +108,13 @@ 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 xIndirectVoid &to, const xRegisterInt &from) const;
void operator()( const xRegisterInt& to, const xIndirectVoid& from ) const; void operator()(const xRegisterInt &to, const xIndirectVoid &from) const;
void operator()( const xRegisterInt& to, int imm ) 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 PS; // packed single precision
xImplSimd_DestRegSSE PD; // packed double precision xImplSimd_DestRegSSE PD; // packed double precision
@ -125,13 +125,13 @@ struct xImpl_G1Arith
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
struct xImpl_G1Compare 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 xIndirectVoid &to, const xRegisterInt &from) const;
void operator()( const xRegisterInt& to, const xIndirectVoid& from ) const; void operator()(const xRegisterInt &to, const xIndirectVoid &from) const;
void operator()( const xRegisterInt& to, int imm ) 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 PS;
xImplSimd_DestSSE_CmpImm PD; xImplSimd_DestSSE_CmpImm PD;
@ -140,4 +140,3 @@ struct xImpl_G1Compare
}; };
} // End namespace x86Emitter } // End namespace x86Emitter

View File

@ -15,11 +15,11 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
enum G2Type
{ {
G2Type_ROL=0,
enum G2Type {
G2Type_ROL = 0,
G2Type_ROR, G2Type_ROR,
G2Type_RCL, G2Type_RCL,
G2Type_RCR, G2Type_RCR,
@ -40,10 +40,10 @@ struct xImpl_Group2
{ {
G2Type InstType; G2Type InstType;
void operator()( const xRegisterInt& to, const xRegisterCL& from ) const; void operator()(const xRegisterInt &to, const xRegisterCL &from) const;
void operator()( const xIndirect64orLess& 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 xRegisterInt &to, u8 imm) const;
void operator()( const xIndirect64orLess& to, u8 imm ) const; void operator()(const xIndirect64orLess &to, u8 imm) const;
#if 0 #if 0
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

View File

@ -15,10 +15,10 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
enum G3Type
{ {
enum G3Type {
G3Type_NOT = 2, G3Type_NOT = 2,
G3Type_NEG = 3, G3Type_NEG = 3,
G3Type_MUL = 4, G3Type_MUL = 4,
@ -34,8 +34,8 @@ struct xImpl_Group3
{ {
G3Type InstType; G3Type InstType;
void operator()( const xRegisterInt& from ) const; void operator()(const xRegisterInt &from) const;
void operator()( const xIndirect64orLess& from ) const; void operator()(const xIndirect64orLess &from) const;
#if 0 #if 0
template< typename T > template< typename T >
@ -56,8 +56,8 @@ struct xImpl_MulDivBase
G3Type InstType; G3Type InstType;
u16 OpcodeSSE; u16 OpcodeSSE;
void operator()( const xRegisterInt& from ) const; void operator()(const xRegisterInt &from) const;
void operator()( const xIndirect64orLess& from ) const; void operator()(const xIndirect64orLess &from) const;
const xImplSimd_DestRegSSE PS; const xImplSimd_DestRegSSE PS;
const xImplSimd_DestRegSSE PD; const xImplSimd_DestRegSSE PD;
@ -70,8 +70,8 @@ struct xImpl_MulDivBase
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
struct xImpl_iDiv struct xImpl_iDiv
{ {
void operator()( const xRegisterInt& from ) const; void operator()(const xRegisterInt &from) const;
void operator()( const xIndirect64orLess& from ) const; void operator()(const xIndirect64orLess &from) const;
const xImplSimd_DestRegSSE PS; const xImplSimd_DestRegSSE PS;
const xImplSimd_DestRegSSE PD; const xImplSimd_DestRegSSE PD;
@ -85,25 +85,24 @@ struct xImpl_iDiv
// //
struct xImpl_iMul struct xImpl_iMul
{ {
void operator()( const xRegisterInt& from ) const; void operator()(const xRegisterInt &from) const;
void operator()( const xIndirect64orLess& 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 xRegister32 &from) const;
void operator()( const xRegister32& to, const xIndirectVoid& src ) 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 xRegister16 &from) const;
void operator()( const xRegister16& to, const xIndirectVoid& src ) 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 xRegister32 &from, s32 imm) const;
void operator()( const xRegister32& to, const xIndirectVoid& 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 xRegister16 &from, s16 imm) const;
void operator()( const xRegister16& to, const xIndirectVoid& from, s16 imm ) const; void operator()(const xRegister16 &to, const xIndirectVoid &from, s16 imm) const;
const xImplSimd_DestRegSSE PS; const xImplSimd_DestRegSSE PS;
const xImplSimd_DestRegSSE PD; const xImplSimd_DestRegSSE PD;
const xImplSimd_DestRegSSE SS; const xImplSimd_DestRegSSE SS;
const xImplSimd_DestRegSSE SD; const xImplSimd_DestRegSSE SD;
}; };
} }

View File

@ -15,7 +15,8 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
{
// helpermess is currently broken >_< // helpermess is currently broken >_<

View File

@ -18,7 +18,8 @@
// Implementations found here: Increment and Decrement Instructions! // Implementations found here: Increment and Decrement Instructions!
// (They're soooo lonely... but I dunno where else to stick this class!) // (They're soooo lonely... but I dunno where else to stick this class!)
namespace x86Emitter { namespace x86Emitter
{
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// xImpl_IncDec // xImpl_IncDec
@ -27,8 +28,8 @@ struct xImpl_IncDec
{ {
bool isDec; bool isDec;
void operator()( const xRegisterInt& to ) const; void operator()(const xRegisterInt &to) const;
void operator()( const xIndirect64orLess& to ) const; void operator()(const xIndirect64orLess &to) const;
}; };
} // End namespace x86Emitter } // End namespace x86Emitter

View File

@ -17,32 +17,32 @@
// Implementations found here: CALL and JMP! (unconditional only) // 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 struct xImpl_JmpCall
{ {
bool isJmp; bool isJmp;
void operator()( const xRegisterInt& absreg ) const; void operator()(const xRegisterInt &absreg) const;
void operator()( const xIndirect64orLess& src ) const; void operator()(const xIndirect64orLess &src) const;
// Special form for calling functions. This form automatically resolves the // Special form for calling functions. This form automatically resolves the
// correct displacement based on the size of the instruction being generated. // correct displacement based on the size of the instruction being generated.
void operator()( void* func ) const void operator()(void *func) const
{
if( isJmp )
xJccKnownTarget( Jcc_Unconditional, (void*)(uptr)func, false ); // double cast to/from (uptr) needed to appease GCC
else
{ {
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 // 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). // always 5 bytes (16 bit calls are bad mojo, so no bother to do special logic).
sptr dest = (sptr)func - ((sptr)xGetPtr() + 5); sptr dest = (sptr)func - ((sptr)xGetPtr() + 5);
xWrite8( 0xe8 ); xWrite8(0xe8);
xWrite32( dest ); xWrite32(dest);
} }
} }
}; };
@ -53,11 +53,11 @@ extern const xImpl_JmpCall xCALL;
struct xImpl_FastCall struct xImpl_FastCall
{ {
// FIXME: current 64 bits is mostly a copy/past potentially it would require to push/pop // 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. // some registers. But I think it is enough to handle the first call.
// Type unsafety is nice // Type unsafety is nice
#ifdef __x86_64__ #ifdef __x86_64__
#define XFASTCALL \ #define XFASTCALL \
@ -88,7 +88,7 @@ struct xImpl_FastCall
#endif #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__ #ifdef __x86_64__
if (a1.IsEmpty()) { if (a1.IsEmpty()) {
@ -109,10 +109,10 @@ struct xImpl_FastCall
#endif #endif
} }
template< typename T > __fi template <typename T>
void operator()( T* func, u32 a1, const xRegisterLong& a2) const __fi void operator()(T *func, u32 a1, const xRegisterLong &a2) const
{ {
void* f = (void*)func; void *f = (void *)func;
#ifdef __x86_64__ #ifdef __x86_64__
XFASTCALL2; XFASTCALL2;
@ -121,10 +121,10 @@ struct xImpl_FastCall
#endif #endif
} }
template< typename T > __fi template <typename T>
void operator()( T* func, const xIndirectVoid& a1) const __fi void operator()(T *func, const xIndirectVoid &a1) const
{ {
void* f = (void*)func; void *f = (void *)func;
#ifdef __x86_64__ #ifdef __x86_64__
XFASTCALL1; XFASTCALL1;
@ -133,10 +133,10 @@ struct xImpl_FastCall
#endif #endif
} }
template< typename T > __fi template <typename T>
void operator()( T* func, u32 a1, u32 a2) const __fi void operator()(T *func, u32 a1, u32 a2) const
{ {
void* f = (void*)func; void *f = (void *)func;
#ifdef __x86_64__ #ifdef __x86_64__
XFASTCALL2; XFASTCALL2;
@ -145,10 +145,10 @@ struct xImpl_FastCall
#endif #endif
} }
template< typename T > __fi template <typename T>
void operator()( T* func, u32 a1) const __fi void operator()(T *func, u32 a1) const
{ {
void* f = (void*)func; void *f = (void *)func;
#ifdef __x86_64__ #ifdef __x86_64__
XFASTCALL1; XFASTCALL1;
@ -157,7 +157,7 @@ struct xImpl_FastCall
#endif #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__ #ifdef __x86_64__
if (a1.IsEmpty()) { if (a1.IsEmpty()) {
@ -184,4 +184,3 @@ struct xImpl_FastCall
}; };
} // End namespace x86Emitter } // End namespace x86Emitter

View File

@ -18,7 +18,8 @@
// Header: ix86_impl_movs.h -- covers mov, cmov, movsx/movzx, and SETcc (which shares // Header: ix86_impl_movs.h -- covers mov, cmov, movsx/movzx, and SETcc (which shares
// with cmov many similarities). // with cmov many similarities).
namespace x86Emitter { namespace x86Emitter
{
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// MovImplAll // MovImplAll
@ -29,11 +30,11 @@ 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 xRegisterInt &to, const xRegisterInt &from) const;
void operator()( const xIndirectVoid& dest, 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 xRegisterInt &to, const xIndirectVoid &src) const;
void operator()( const xIndirect64orLess& dest, int imm ) 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, int imm, bool preserve_flags = false) const;
#if 0 #if 0
template< typename T > __noinline void operator()( const ModSibBase& to, const xImmReg<T>& immOrReg ) const template< typename T > __noinline void operator()( const ModSibBase& to, const xImmReg<T>& immOrReg ) const
@ -85,8 +86,8 @@ struct xImpl_Mov
struct xImpl_CMov struct xImpl_CMov
{ {
JccComparisonType ccType; JccComparisonType ccType;
void operator()( const xRegister16or32or64& to, const xRegister16or32or64& from ) const; void operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from) const;
void operator()( const xRegister16or32or64& to, const xIndirectVoid& sibsrc ) const; void operator()(const xRegister16or32or64 &to, const xIndirectVoid &sibsrc) const;
//void operator()( const xDirectOrIndirect32& to, const xDirectOrIndirect32& from ); //void operator()( const xDirectOrIndirect32& to, const xDirectOrIndirect32& from );
//void operator()( const xDirectOrIndirect16& to, const xDirectOrIndirect16& from ) const; //void operator()( const xDirectOrIndirect16& to, const xDirectOrIndirect16& from ) const;
@ -96,8 +97,8 @@ struct xImpl_Set
{ {
JccComparisonType ccType; JccComparisonType ccType;
void operator()( const xRegister8& to ) const; void operator()(const xRegister8 &to) const;
void operator()( const xIndirect8& dest ) const; void operator()(const xIndirect8 &dest) const;
//void operator()( const xDirectOrIndirect8& dest ) const; //void operator()( const xDirectOrIndirect8& dest ) const;
}; };
@ -112,10 +113,10 @@ struct xImpl_MovExtend
{ {
bool SignExtend; bool SignExtend;
void operator()( const xRegister16or32or64& to, const xRegister8& from ) const; void operator()(const xRegister16or32or64 &to, const xRegister8 &from) const;
void operator()( const xRegister16or32or64& to, const xIndirect8& sibsrc ) 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 xRegister16 &from) const;
void operator()( const xRegister32or64& to, const xIndirect16& sibsrc ) const; void operator()(const xRegister32or64 &to, const xIndirect16 &sibsrc) const;
//void operator()( const xRegister32& to, const xDirectOrIndirect16& src ) const; //void operator()( const xRegister32& to, const xDirectOrIndirect16& src ) const;
//void operator()( const xRegister16or32& to, const xDirectOrIndirect8& src ) const; //void operator()( const xRegister16or32& to, const xDirectOrIndirect8& src ) const;

View File

@ -15,7 +15,8 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
{
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// _SimdShiftHelper // _SimdShiftHelper
@ -27,10 +28,10 @@ struct _SimdShiftHelper
u16 OpcodeImm; u16 OpcodeImm;
u8 Modcode; u8 Modcode;
void operator()( const xRegisterSSE& 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 xRegisterSSE &to, const xIndirectVoid &from) const;
void operator()( const xRegisterSSE& to, u8 imm8 ) const; void operator()(const xRegisterSSE &to, u8 imm8) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -53,7 +54,7 @@ struct xImplSimd_Shift
const _SimdShiftHelper D; const _SimdShiftHelper D;
const _SimdShiftHelper Q; const _SimdShiftHelper Q;
void DQ( const xRegisterSSE& to, u8 imm8 ) const; void DQ(const xRegisterSSE &to, u8 imm8) const;
}; };
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -178,7 +179,6 @@ struct xImplSimd_PSign
// is unchanged. If a data element in src is zero, the corresponding data element in // is unchanged. If a data element in src is zero, the corresponding data element in
// dest is set to zero. // dest is set to zero.
const xImplSimd_DestRegEither D; const xImplSimd_DestRegEither D;
}; };
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -314,4 +314,3 @@ struct xImplSimd_Round
}; };
} // End namespace x86Emitter } // End namespace x86Emitter

View File

@ -15,7 +15,8 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
{
struct xImplSimd_MinMax struct xImplSimd_MinMax
{ {
@ -31,17 +32,17 @@ struct xImplSimd_Compare
{ {
SSE2_ComparisonType CType; SSE2_ComparisonType CType;
void PS( const xRegisterSSE& to, const xRegisterSSE& from ) const; void PS(const xRegisterSSE &to, const xRegisterSSE &from) const;
void PS( const xRegisterSSE& to, const xIndirectVoid& 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 xRegisterSSE &from) const;
void PD( const xRegisterSSE& to, const xIndirectVoid& 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 xRegisterSSE &from) const;
void SS( const xRegisterSSE& to, const xIndirectVoid& 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 xRegisterSSE &from) const;
void SD( const xRegisterSSE& to, const xIndirectVoid& from ) const; void SD(const xRegisterSSE &to, const xIndirectVoid &from) const;
}; };
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -120,4 +121,3 @@ struct xImplSimd_PMinMax
}; };
} // end namespace x86Emitter } // end namespace x86Emitter

View File

@ -15,7 +15,8 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
{
// ===================================================================================================== // =====================================================================================================
// xImpl_SIMD Types (template free!) // xImpl_SIMD Types (template free!)
@ -30,8 +31,8 @@ struct xImplSimd_DestRegSSE
u8 Prefix; u8 Prefix;
u16 Opcode; u16 Opcode;
void operator()( const xRegisterSSE& 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 xRegisterSSE &to, const xIndirectVoid &from) const;
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -43,8 +44,8 @@ struct xImplSimd_DestRegImmSSE
u8 Prefix; u8 Prefix;
u16 Opcode; u16 Opcode;
void operator()( const xRegisterSSE& to, const xRegisterSSE& 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; void operator()(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm) const;
}; };
struct xImplSimd_DestSSE_CmpImm struct xImplSimd_DestSSE_CmpImm
@ -52,8 +53,8 @@ struct xImplSimd_DestSSE_CmpImm
u8 Prefix; u8 Prefix;
u16 Opcode; u16 Opcode;
void operator()( const xRegisterSSE& to, const xRegisterSSE& 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; void operator()(const xRegisterSSE &to, const xIndirectVoid &from, SSE2_ComparisonType imm) const;
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -65,9 +66,8 @@ struct xImplSimd_DestRegEither
u8 Prefix; u8 Prefix;
u16 Opcode; u16 Opcode;
void operator()( const xRegisterSSE& 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 xRegisterSSE &to, const xIndirectVoid &from) const;
}; };
} // end namespace x86Emitter } // end namespace x86Emitter

View File

@ -15,7 +15,8 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
{
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// xImplSimd_MovHL // xImplSimd_MovHL
@ -27,11 +28,11 @@ struct xImplSimd_MovHL
{ {
u16 Opcode; u16 Opcode;
void PS( const xRegisterSSE& to, const xIndirectVoid& from ) const; void PS(const xRegisterSSE &to, const xIndirectVoid &from) const;
void PS( const xIndirectVoid& to, const xRegisterSSE& from ) const; void PS(const xIndirectVoid &to, const xRegisterSSE &from) const;
void PD( const xRegisterSSE& to, const xIndirectVoid& from ) const; void PD(const xRegisterSSE &to, const xIndirectVoid &from) const;
void PD( const xIndirectVoid& to, const xRegisterSSE& from ) const; void PD(const xIndirectVoid &to, const xRegisterSSE &from) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -44,8 +45,8 @@ struct xImplSimd_MovHL_RtoR
{ {
u16 Opcode; u16 Opcode;
void PS( 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; void PD(const xRegisterSSE &to, const xRegisterSSE &from) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -62,9 +63,9 @@ struct xImplSimd_MoveSSE
u8 Prefix; u8 Prefix;
bool isAligned; bool isAligned;
void operator()( const xRegisterSSE& 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 xRegisterSSE &to, const xIndirectVoid &from) const;
void operator()( const xIndirectVoid& to, const xRegisterSSE& from ) const; void operator()(const xIndirectVoid &to, const xRegisterSSE &from) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -81,9 +82,9 @@ struct xImplSimd_MoveDQ
u8 Prefix; u8 Prefix;
bool isAligned; bool isAligned;
void operator()( const xRegisterSSE& 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 xRegisterSSE &to, const xIndirectVoid &from) const;
void operator()( const xIndirectVoid& to, const xRegisterSSE& from ) const; void operator()(const xIndirectVoid &to, const xRegisterSSE &from) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -141,34 +142,32 @@ struct xImplSimd_PMove
// [SSE-4.1] Zero/Sign-extend the low byte values in src into word integers // [SSE-4.1] Zero/Sign-extend the low byte values in src into word integers
// and store them in dest. // and store them in dest.
void BW( const xRegisterSSE& to, const xRegisterSSE& from ) const; void BW(const xRegisterSSE &to, const xRegisterSSE &from) const;
void BW( const xRegisterSSE& to, const xIndirect64& 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 // [SSE-4.1] Zero/Sign-extend the low byte values in src into dword integers
// and store them in dest. // and store them in dest.
void BD( const xRegisterSSE& to, const xRegisterSSE& from ) const; void BD(const xRegisterSSE &to, const xRegisterSSE &from) const;
void BD( const xRegisterSSE& to, const xIndirect32& 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 // [SSE-4.1] Zero/Sign-extend the low byte values in src into qword integers
// and store them in dest. // and store them in dest.
void BQ( const xRegisterSSE& to, const xRegisterSSE& from ) const; void BQ(const xRegisterSSE &to, const xRegisterSSE &from) const;
void BQ( const xRegisterSSE& to, const xIndirect16& 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 // [SSE-4.1] Zero/Sign-extend the low word values in src into dword integers
// and store them in dest. // and store them in dest.
void WD( const xRegisterSSE& to, const xRegisterSSE& from ) const; void WD(const xRegisterSSE &to, const xRegisterSSE &from) const;
void WD( const xRegisterSSE& to, const xIndirect64& 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 // [SSE-4.1] Zero/Sign-extend the low word values in src into qword integers
// and store them in dest. // and store them in dest.
void WQ( const xRegisterSSE& to, const xRegisterSSE& from ) const; void WQ(const xRegisterSSE &to, const xRegisterSSE &from) const;
void WQ( const xRegisterSSE& to, const xIndirect32& 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 // [SSE-4.1] Zero/Sign-extend the low dword values in src into qword integers
// and store them in dest. // and store them in dest.
void DQ( const xRegisterSSE& to, const xRegisterSSE& from ) const; void DQ(const xRegisterSSE &to, const xRegisterSSE &from) const;
void DQ( const xRegisterSSE& to, const xIndirect64& from ) const; void DQ(const xRegisterSSE &to, const xIndirect64 &from) const;
}; };
} }

View File

@ -15,20 +15,21 @@
#pragma once #pragma once
namespace x86Emitter { namespace x86Emitter
{
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// xImplSimd_Shuffle // xImplSimd_Shuffle
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
struct 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 xRegisterSSE &from, u8 selector) const;
void PS( const xRegisterSSE& to, const xIndirectVoid& 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 xRegisterSSE &from, u8 selector) const;
void PD( const xRegisterSSE& to, const xIndirectVoid& from, u8 selector ) const; void PD(const xRegisterSSE &to, const xIndirectVoid &from, u8 selector) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -59,10 +60,10 @@ struct xImplSimd_PShuffle
// //
const xImplSimd_DestRegEither B; const xImplSimd_DestRegEither B;
// below is my test bed for a new system, free of subclasses. Was supposed to improve intellisense // 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 // 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 // Copies words from src and inserts them into dest at word locations selected with
// the order operand (8 bit immediate). // 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 xRegisterSSE& from ) const { OpWriteSSE( 0x66, 0x0038 ); }
void B( const xRegisterSSE& to, const xIndirectVoid& from ) const { OpWriteSSE( 0x66, 0x0038 ); } void B( const xRegisterSSE& to, const xIndirectVoid& from ) const { OpWriteSSE( 0x66, 0x0038 ); }
#endif #endif
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -188,10 +189,10 @@ struct xImplSimd_InsertExtractHelper
u16 Opcode; u16 Opcode;
// [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid)
void operator()( const xRegisterSSE& to, const xRegister32& from, u8 imm8 ) const; void operator()(const xRegisterSSE &to, const xRegister32 &from, u8 imm8) const;
// [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid)
void operator()( const xRegisterSSE& to, const xIndirectVoid& from, u8 imm8 ) const; void operator()(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm8) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -201,8 +202,8 @@ struct xImplSimd_InsertExtractHelper
// //
struct xImplSimd_PInsert struct xImplSimd_PInsert
{ {
void W( const xRegisterSSE& to, const xRegister32& 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; void W(const xRegisterSSE &to, const xIndirectVoid &from, u8 imm8) const;
// [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid) // [SSE-4.1] Allowed with SSE registers only (MMX regs are invalid)
xImplSimd_InsertExtractHelper B; xImplSimd_InsertExtractHelper B;
@ -225,8 +226,8 @@ struct SimdImpl_PExtract
// //
// [SSE-4.1] Note: Indirect memory forms of this instruction are an SSE-4.1 extension! // [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 xRegister32 &to, const xRegisterSSE &from, u8 imm8) const;
void W( const xIndirectVoid& dest, 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 // [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 // of dest are zero-extended (cleared). This can be used to extract any single packed
@ -237,5 +238,4 @@ struct SimdImpl_PExtract
// used to extract any single packed dword value from src into an x86 32 bit register. // used to extract any single packed dword value from src into an x86 32 bit register.
const xImplSimd_InsertExtractHelper D; const xImplSimd_InsertExtractHelper D;
}; };
} }

View File

@ -22,16 +22,16 @@
// For implementing SSE-only logic operations that have xmmreg,xmmreg/rm forms only, // For implementing SSE-only logic operations that have xmmreg,xmmreg/rm forms only,
// like ANDPS/ANDPD // like ANDPS/ANDPD
// //
template< u8 Prefix, u16 Opcode > template <u8 Prefix, u16 Opcode>
class SimdImpl_DestRegSSE class SimdImpl_DestRegSSE
{ {
public: public:
__forceinline void operator()( const xRegisterSSE& to, const xRegisterSSE& from ) const { 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 __forceinline void operator()(const xRegisterSSE &to, const ModSibBase &from) const
{ {
bool isReallyAligned = ((from.Displacement & 0x0f) == 0) && from.Index.IsEmpty() && from.Base.IsEmpty(); bool isReallyAligned = ((from.Displacement & 0x0f) == 0) && from.Index.IsEmpty() && from.Base.IsEmpty();
pxAssertDev( isReallyAligned, "Alignment check failed on SSE indirect load." ); pxAssertDev(isReallyAligned, "Alignment check failed on SSE indirect load.");
xOpWrite0F( Prefix, Opcode, to, from ); xOpWrite0F(Prefix, Opcode, to, from);
} }
SimdImpl_DestRegSSE() {} //GCWho? SimdImpl_DestRegSSE() {} //GCWho?

View File

@ -17,7 +17,8 @@
// Implementations found here: TEST + BTS/BT/BTC/BTR + BSF/BSR! (for lack of better location) // Implementations found here: TEST + BTS/BT/BTC/BTR + BSF/BSR! (for lack of better location)
namespace x86Emitter { namespace x86Emitter
{
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// xImpl_Test // xImpl_Test
@ -25,13 +26,12 @@ namespace x86Emitter {
// //
struct xImpl_Test struct xImpl_Test
{ {
void operator()( const xRegisterInt& to, const xRegisterInt& from ) const; void operator()(const xRegisterInt &to, const xRegisterInt &from) const;
void operator()( const xIndirect64orLess& dest, int imm ) const; void operator()(const xIndirect64orLess &dest, int imm) const;
void operator()( const xRegisterInt& to, int imm ) const; void operator()(const xRegisterInt &to, int imm) const;
}; };
enum G8Type enum G8Type {
{
G8Type_BT = 4, G8Type_BT = 4,
G8Type_BTS, G8Type_BTS,
G8Type_BTR, G8Type_BTR,
@ -48,8 +48,8 @@ struct xImpl_BitScan
// 0xbc [fwd] / 0xbd [rev] // 0xbc [fwd] / 0xbd [rev]
u16 Opcode; u16 Opcode;
void operator()( const xRegister16or32or64& to, const xRegister16or32or64& from ) const; void operator()(const xRegister16or32or64 &to, const xRegister16or32or64 &from) const;
void operator()( const xRegister16or32or64& to, const xIndirectVoid& sibsrc ) const; void operator()(const xRegister16or32or64 &to, const xIndirectVoid &sibsrc) const;
}; };
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -61,15 +61,14 @@ struct xImpl_Group8
{ {
G8Type InstType; G8Type InstType;
void operator()( const xRegister16or32or64& bitbase, const xRegister16or32or64& bitoffset ) const; void operator()(const xRegister16or32or64 &bitbase, const xRegister16or32or64 &bitoffset) const;
void operator()( const xRegister16or32or64& bitbase, u8 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 xIndirect64 &bitbase, u8 bitoffset) const;
void operator()( const xIndirect32& bitbase, u8 bitoffset ) const; void operator()(const xIndirect32 &bitbase, u8 bitoffset) const;
void operator()( const xIndirect16& bitbase, u8 bitoffset ) const; void operator()(const xIndirect16 &bitbase, u8 bitoffset) const;
}; };
} // End namespace x86Emitter } // End namespace x86Emitter

View File

@ -18,7 +18,8 @@
// This header file is intended to be the future home of xchg, cmpxchg, xadd, and // This header file is intended to be the future home of xchg, cmpxchg, xadd, and
// other threading-related exchange instructions. // other threading-related exchange instructions.
namespace x86Emitter { namespace x86Emitter
{
} // End namespace x86Emitter } // End namespace x86Emitter

View File

@ -32,72 +32,71 @@
namespace x86Emitter namespace x86Emitter
{ {
extern void xStoreReg( const xRegisterSSE& src ); extern void xStoreReg(const xRegisterSSE &src);
extern void xRestoreReg( const xRegisterSSE& dest ); extern void xRestoreReg(const xRegisterSSE &dest);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Group 1 Instruction Class // Group 1 Instruction Class
extern const xImpl_Group1 xADC; extern const xImpl_Group1 xADC;
extern const xImpl_Group1 xSBB; extern const xImpl_Group1 xSBB;
extern const xImpl_G1Logic xAND; extern const xImpl_G1Logic xAND;
extern const xImpl_G1Logic xOR; extern const xImpl_G1Logic xOR;
extern const xImpl_G1Logic xXOR; extern const xImpl_G1Logic xXOR;
extern const xImpl_G1Arith xADD; extern const xImpl_G1Arith xADD;
extern const xImpl_G1Arith xSUB; extern const xImpl_G1Arith xSUB;
extern const xImpl_G1Compare xCMP; extern const xImpl_G1Compare xCMP;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Group 2 Instruction Class // Group 2 Instruction Class
// //
// Optimization Note: For Imm forms, we ignore the instruction if the shift count is // 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 // zero. This is a safe optimization since any zero-value shift does not affect any
// flags. // flags.
extern const xImpl_Mov xMOV; extern const xImpl_Mov xMOV;
extern const xImpl_Test xTEST; extern const xImpl_Test xTEST;
extern const xImpl_Group2 xROL, xROR, extern const xImpl_Group2 xROL, xROR,
xRCL, xRCR, xRCL, xRCR,
xSHL, xSHR, xSHL, xSHR,
xSAR; xSAR;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Group 3 Instruction Class // Group 3 Instruction Class
extern const xImpl_Group3 xNOT, xNEG; extern const xImpl_Group3 xNOT, xNEG;
extern const xImpl_Group3 xUMUL, xUDIV; extern const xImpl_Group3 xUMUL, xUDIV;
extern const xImpl_iDiv xDIV; extern const xImpl_iDiv xDIV;
extern const xImpl_iMul xMUL; 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 xBT;
extern const xImpl_Group8 xBTR; extern const xImpl_Group8 xBTR;
extern const xImpl_Group8 xBTS; extern const xImpl_Group8 xBTS;
extern const xImpl_Group8 xBTC; 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__ #ifdef __x86_64__
// 32 bits Call won't be compatible in 64 bits (different ABI) // 32 bits Call won't be compatible in 64 bits (different ABI)
// Just a reminder to port the code // Just a reminder to port the code
[[deprecated]] extern const xImpl_JmpCall xCALL; [[deprecated]] extern const xImpl_JmpCall xCALL;
#else #else
extern const xImpl_JmpCall xCALL; extern const xImpl_JmpCall xCALL;
#endif #endif
extern const xImpl_FastCall xFastCall; extern const xImpl_FastCall xFastCall;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
extern const xImpl_CMov extern const xImpl_CMov xCMOVA, xCMOVAE,
xCMOVA, xCMOVAE,
xCMOVB, xCMOVBE, xCMOVB, xCMOVBE,
xCMOVG, xCMOVGE, xCMOVG, xCMOVGE,
xCMOVL, xCMOVLE, xCMOVL, xCMOVLE,
@ -110,9 +109,8 @@ namespace x86Emitter
xCMOVS, xCMOVNS, xCMOVS, xCMOVNS,
xCMOVPE, xCMOVPO; xCMOVPE, xCMOVPO;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
extern const xImpl_Set extern const xImpl_Set xSETA, xSETAE,
xSETA, xSETAE,
xSETB, xSETBE, xSETB, xSETBE,
xSETG, xSETGE, xSETG, xSETGE,
xSETL, xSETLE, xSETL, xSETLE,
@ -125,379 +123,460 @@ namespace x86Emitter
xSETS, xSETNS, xSETS, xSETNS,
xSETPE, xSETPO; xSETPE, xSETPO;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// BMI extra instruction requires BMI1/BMI2 // BMI extra instruction requires BMI1/BMI2
extern const xImplBMI_RVM xMULX, xPDEP, xPEXT, xANDN_S; // Warning xANDN is already used by SSE extern const xImplBMI_RVM xMULX, xPDEP, xPEXT, xANDN_S; // Warning xANDN is already used by SSE
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// Miscellaneous Instructions // Miscellaneous Instructions
// These are all defined inline or in ix86.cpp. // These are all defined inline or in ix86.cpp.
// //
extern void xBSWAP( const xRegister32or64& to ); extern void xBSWAP(const xRegister32or64 &to);
// ----- Lea Instructions (Load Effective Address) ----- // ----- Lea Instructions (Load Effective Address) -----
// Note: alternate (void*) forms of these instructions are not provided since those // 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 // forms are functionally equivalent to Mov reg,imm, and thus better written as MOVs
// instead. // instead.
extern void xLEA( xRegister64 to, const xIndirectVoid& src, bool preserve_flags=false ); 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(xRegister32 to, const xIndirectVoid &src, bool preserve_flags = false);
extern void xLEA( xRegister16 to, const xIndirectVoid& src, bool preserve_flags=false ); extern void xLEA(xRegister16 to, const xIndirectVoid &src, bool preserve_flags = false);
// ----- Push / Pop Instructions ----- // ----- Push / Pop Instructions -----
// Note: pushad/popad implementations are intentionally left out. The instructions are // 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. // invalid in x64, and are super slow on x32. Use multiple Push/Pop instructions instead.
extern void xPOP( const xIndirectVoid& from ); extern void xPOP(const xIndirectVoid &from);
extern void xPUSH( const xIndirectVoid& from ); extern void xPUSH(const xIndirectVoid &from);
extern void xPOP( xRegister32or64 from ); extern void xPOP(xRegister32or64 from);
extern void xPUSH( u32 imm ); extern void xPUSH(u32 imm);
extern void xPUSH( xRegister32or64 from ); extern void xPUSH(xRegister32or64 from);
// pushes the EFLAGS register onto the stack // pushes the EFLAGS register onto the stack
extern void xPUSHFD(); extern void xPUSHFD();
// pops the EFLAGS register from the stack // pops the EFLAGS register from the stack
extern void xPOPFD(); extern void xPOPFD();
// ----- Miscellaneous Instructions ----- // ----- Miscellaneous Instructions -----
// Various Instructions with no parameter and no special encoding logic. // Various Instructions with no parameter and no special encoding logic.
extern void xLEAVE(); extern void xLEAVE();
extern void xRET(); extern void xRET();
extern void xCBW(); extern void xCBW();
extern void xCWD(); extern void xCWD();
extern void xCDQ(); extern void xCDQ();
extern void xCWDE(); extern void xCWDE();
extern void xLAHF(); extern void xLAHF();
extern void xSAHF(); extern void xSAHF();
extern void xSTC(); extern void xSTC();
extern void xCLC(); extern void xCLC();
// NOP 1-byte // NOP 1-byte
extern void xNOP(); extern void xNOP();
extern void xINT( u8 imm ); extern void xINT(u8 imm);
extern void xINTO(); extern void xINTO();
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// Helper object to handle the various functions ABI // Helper object to handle the various functions ABI
class xScopedStackFrame class xScopedStackFrame
{ {
bool m_base_frame; bool m_base_frame;
bool m_save_base_pointer; bool m_save_base_pointer;
int m_offset; int m_offset;
public: public:
xScopedStackFrame(bool base_frame, bool save_base_pointer = false, int offset = 0); xScopedStackFrame(bool base_frame, bool save_base_pointer = false, int offset = 0);
~xScopedStackFrame(); ~xScopedStackFrame();
}; };
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// JMP / Jcc Instructions! // JMP / Jcc Instructions!
extern void xJcc( JccComparisonType comparison, const void* target ); extern void xJcc(JccComparisonType comparison, const void *target);
extern s8* xJcc8( JccComparisonType comparison=Jcc_Unconditional, s8 displacement=0 ); extern s8 *xJcc8(JccComparisonType comparison = Jcc_Unconditional, s8 displacement = 0);
extern s32* xJcc32( JccComparisonType comparison=Jcc_Unconditional, s32 displacement=0 ); extern s32 *xJcc32(JccComparisonType comparison = Jcc_Unconditional, s32 displacement = 0);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Conditional jumps to fixed targets. // Conditional jumps to fixed targets.
// Jumps accept any pointer as a valid target (function or data), and will generate either // 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 // 8 or 32 bit displacement versions of the jump, depending on relative displacement of
// the target (efficient!) // the target (efficient!)
// //
template< typename T > __fi void xJE( T* func ) { xJcc( Jcc_Equal, (void*)(uptr)func ); } template <typename T>
template< typename T > __fi void xJZ( T* func ) { xJcc( Jcc_Zero, (void*)(uptr)func ); } __fi void xJE(T *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 ); } 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>
template< typename T > __fi void xJNO( T* func ) { xJcc( Jcc_NotOverflow, (void*)(uptr)func ); } __fi void xJO(T *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 ); } xJcc(Jcc_Overflow, (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 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>
template< typename T > __fi void xJPO( T* func ) { xJcc( Jcc_ParityOdd, (void*)(uptr)func ); } __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>
template< typename T > __fi void xJLE( T* func ) { xJcc( Jcc_LessOrEqual, (void*)(uptr)func ); } __fi void xJL(T *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 ); } 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>
template< typename T > __fi void xJBE( T* func ) { xJcc( Jcc_BelowOrEqual, (void*)(uptr)func ); } __fi void xJB(T *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 ); } 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!) // Forward Jump Helpers (act as labels!)
#define DEFINE_FORWARD_JUMP( label, cond ) \ #define DEFINE_FORWARD_JUMP(label, cond) \
template< typename OperandType > \ template <typename OperandType> \
class xForward##label : public xForwardJump<OperandType> \ class xForward##label : public xForwardJump<OperandType> \
{ \ { \
public: \ public: \
xForward##label() : xForwardJump<OperandType>( cond ) {} \ xForward##label() \
: xForwardJump<OperandType>(cond) \
{ \
} \
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Note: typedefs below are defined individually in order to appease Intellisense // Note: typedefs below are defined individually in order to appease Intellisense
// resolution. Including them into the class definition macro above breaks it. // resolution. Including them into the class definition macro above breaks it.
typedef xForwardJump<s8> xForwardJump8; typedef xForwardJump<s8> xForwardJump8;
typedef xForwardJump<s32> xForwardJump32; typedef xForwardJump<s32> xForwardJump32;
DEFINE_FORWARD_JUMP( JA, Jcc_Above ); DEFINE_FORWARD_JUMP(JA, Jcc_Above);
DEFINE_FORWARD_JUMP( JB, Jcc_Below ); DEFINE_FORWARD_JUMP(JB, Jcc_Below);
DEFINE_FORWARD_JUMP( JAE, Jcc_AboveOrEqual ); DEFINE_FORWARD_JUMP(JAE, Jcc_AboveOrEqual);
DEFINE_FORWARD_JUMP( JBE, Jcc_BelowOrEqual ); DEFINE_FORWARD_JUMP(JBE, Jcc_BelowOrEqual);
typedef xForwardJA<s8> xForwardJA8; typedef xForwardJA<s8> xForwardJA8;
typedef xForwardJA<s32> xForwardJA32; typedef xForwardJA<s32> xForwardJA32;
typedef xForwardJB<s8> xForwardJB8; typedef xForwardJB<s8> xForwardJB8;
typedef xForwardJB<s32> xForwardJB32; typedef xForwardJB<s32> xForwardJB32;
typedef xForwardJAE<s8> xForwardJAE8; typedef xForwardJAE<s8> xForwardJAE8;
typedef xForwardJAE<s32> xForwardJAE32; typedef xForwardJAE<s32> xForwardJAE32;
typedef xForwardJBE<s8> xForwardJBE8; typedef xForwardJBE<s8> xForwardJBE8;
typedef xForwardJBE<s32> xForwardJBE32; typedef xForwardJBE<s32> xForwardJBE32;
DEFINE_FORWARD_JUMP( JG, Jcc_Greater ); DEFINE_FORWARD_JUMP(JG, Jcc_Greater);
DEFINE_FORWARD_JUMP( JL, Jcc_Less ); DEFINE_FORWARD_JUMP(JL, Jcc_Less);
DEFINE_FORWARD_JUMP( JGE, Jcc_GreaterOrEqual ); DEFINE_FORWARD_JUMP(JGE, Jcc_GreaterOrEqual);
DEFINE_FORWARD_JUMP( JLE, Jcc_LessOrEqual ); DEFINE_FORWARD_JUMP(JLE, Jcc_LessOrEqual);
typedef xForwardJG<s8> xForwardJG8; typedef xForwardJG<s8> xForwardJG8;
typedef xForwardJG<s32> xForwardJG32; typedef xForwardJG<s32> xForwardJG32;
typedef xForwardJL<s8> xForwardJL8; typedef xForwardJL<s8> xForwardJL8;
typedef xForwardJL<s32> xForwardJL32; typedef xForwardJL<s32> xForwardJL32;
typedef xForwardJGE<s8> xForwardJGE8; typedef xForwardJGE<s8> xForwardJGE8;
typedef xForwardJGE<s32> xForwardJGE32; typedef xForwardJGE<s32> xForwardJGE32;
typedef xForwardJLE<s8> xForwardJLE8; typedef xForwardJLE<s8> xForwardJLE8;
typedef xForwardJLE<s32> xForwardJLE32; typedef xForwardJLE<s32> xForwardJLE32;
DEFINE_FORWARD_JUMP( JZ, Jcc_Zero ); DEFINE_FORWARD_JUMP(JZ, Jcc_Zero);
DEFINE_FORWARD_JUMP( JE, Jcc_Equal ); DEFINE_FORWARD_JUMP(JE, Jcc_Equal);
DEFINE_FORWARD_JUMP( JNZ, Jcc_NotZero ); DEFINE_FORWARD_JUMP(JNZ, Jcc_NotZero);
DEFINE_FORWARD_JUMP( JNE, Jcc_NotEqual ); DEFINE_FORWARD_JUMP(JNE, Jcc_NotEqual);
typedef xForwardJZ<s8> xForwardJZ8; typedef xForwardJZ<s8> xForwardJZ8;
typedef xForwardJZ<s32> xForwardJZ32; typedef xForwardJZ<s32> xForwardJZ32;
typedef xForwardJE<s8> xForwardJE8; typedef xForwardJE<s8> xForwardJE8;
typedef xForwardJE<s32> xForwardJE32; typedef xForwardJE<s32> xForwardJE32;
typedef xForwardJNZ<s8> xForwardJNZ8; typedef xForwardJNZ<s8> xForwardJNZ8;
typedef xForwardJNZ<s32> xForwardJNZ32; typedef xForwardJNZ<s32> xForwardJNZ32;
typedef xForwardJNE<s8> xForwardJNE8; typedef xForwardJNE<s8> xForwardJNE8;
typedef xForwardJNE<s32> xForwardJNE32; typedef xForwardJNE<s32> xForwardJNE32;
DEFINE_FORWARD_JUMP( JS, Jcc_Signed ); DEFINE_FORWARD_JUMP(JS, Jcc_Signed);
DEFINE_FORWARD_JUMP( JNS, Jcc_Unsigned ); DEFINE_FORWARD_JUMP(JNS, Jcc_Unsigned);
typedef xForwardJS<s8> xForwardJS8; typedef xForwardJS<s8> xForwardJS8;
typedef xForwardJS<s32> xForwardJS32; typedef xForwardJS<s32> xForwardJS32;
typedef xForwardJNS<s8> xForwardJNS8; typedef xForwardJNS<s8> xForwardJNS8;
typedef xForwardJNS<s32> xForwardJNS32; typedef xForwardJNS<s32> xForwardJNS32;
DEFINE_FORWARD_JUMP( JO, Jcc_Overflow ); DEFINE_FORWARD_JUMP(JO, Jcc_Overflow);
DEFINE_FORWARD_JUMP( JNO, Jcc_NotOverflow ); DEFINE_FORWARD_JUMP(JNO, Jcc_NotOverflow);
typedef xForwardJO<s8> xForwardJO8; typedef xForwardJO<s8> xForwardJO8;
typedef xForwardJO<s32> xForwardJO32; typedef xForwardJO<s32> xForwardJO32;
typedef xForwardJNO<s8> xForwardJNO8; typedef xForwardJNO<s8> xForwardJNO8;
typedef xForwardJNO<s32> xForwardJNO32; typedef xForwardJNO<s32> xForwardJNO32;
DEFINE_FORWARD_JUMP( JC, Jcc_Carry ); DEFINE_FORWARD_JUMP(JC, Jcc_Carry);
DEFINE_FORWARD_JUMP( JNC, Jcc_NotCarry ); DEFINE_FORWARD_JUMP(JNC, Jcc_NotCarry);
typedef xForwardJC<s8> xForwardJC8; typedef xForwardJC<s8> xForwardJC8;
typedef xForwardJC<s32> xForwardJC32; typedef xForwardJC<s32> xForwardJC32;
typedef xForwardJNC<s8> xForwardJNC8; typedef xForwardJNC<s8> xForwardJNC8;
typedef xForwardJNC<s32> xForwardJNC32; typedef xForwardJNC<s32> xForwardJNC32;
DEFINE_FORWARD_JUMP( JPE, Jcc_ParityEven ); DEFINE_FORWARD_JUMP(JPE, Jcc_ParityEven);
DEFINE_FORWARD_JUMP( JPO, Jcc_ParityOdd ); DEFINE_FORWARD_JUMP(JPO, Jcc_ParityOdd);
typedef xForwardJPE<s8> xForwardJPE8; typedef xForwardJPE<s8> xForwardJPE8;
typedef xForwardJPE<s32> xForwardJPE32; typedef xForwardJPE<s32> xForwardJPE32;
typedef xForwardJPO<s8> xForwardJPO8; typedef xForwardJPO<s8> xForwardJPO8;
typedef xForwardJPO<s32> xForwardJPO32; typedef xForwardJPO<s32> xForwardJPO32;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
extern void xEMMS(); extern void xEMMS();
extern void xSTMXCSR( const xIndirect32& dest ); extern void xSTMXCSR(const xIndirect32 &dest);
extern void xLDMXCSR( const xIndirect32& src ); extern void xLDMXCSR(const xIndirect32 &src);
extern void xFXSAVE( const xIndirectVoid& dest ); extern void xFXSAVE(const xIndirectVoid &dest);
extern void xFXRSTOR( const xIndirectVoid& src ); extern void xFXRSTOR(const xIndirectVoid &src);
extern void xMOVDZX( const xRegisterSSE& to, const xRegister32or64& from ); extern void xMOVDZX(const xRegisterSSE &to, const xRegister32or64 &from);
extern void xMOVDZX( const xRegisterSSE& to, const xIndirectVoid& src ); extern void xMOVDZX(const xRegisterSSE &to, const xIndirectVoid &src);
extern void xMOVD( const xRegister32or64& to, const xRegisterSSE& from ); extern void xMOVD(const xRegister32or64 &to, const xRegisterSSE &from);
extern void xMOVD( const xIndirectVoid& dest, const xRegisterSSE& from ); extern void xMOVD(const xIndirectVoid &dest, const xRegisterSSE &from);
extern void xMOVQ( 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 xIndirectVoid &src);
extern void xMOVQZX( const xRegisterSSE& to, const xRegisterSSE& from ); extern void xMOVQZX(const xRegisterSSE &to, const xRegisterSSE &from);
extern void xMOVSS( 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 xMOVSS(const xIndirectVoid &to, const xRegisterSSE &from);
extern void xMOVSD( const xRegisterSSE& to, const xRegisterSSE& from ); extern void xMOVSD(const xRegisterSSE &to, const xRegisterSSE &from);
extern void xMOVSD( const xIndirectVoid& to, const xRegisterSSE& from ); extern void xMOVSD(const xIndirectVoid &to, const xRegisterSSE &from);
extern void xMOVSSZX( const xRegisterSSE& to, const xIndirectVoid& from ); extern void xMOVSSZX(const xRegisterSSE &to, const xIndirectVoid &from);
extern void xMOVSDZX( 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 xRegisterSSE &to, const xIndirectVoid &from);
extern void xMOVNTDQA( const xIndirectVoid& to, const xRegisterSSE& from ); extern void xMOVNTDQA(const xIndirectVoid &to, const xRegisterSSE &from);
extern void xMOVNTPD( 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 xMOVNTPS(const xIndirectVoid &to, const xRegisterSSE &from);
extern void xMOVMSKPS( const xRegister32or64& to, const xRegisterSSE& from ); extern void xMOVMSKPS(const xRegister32or64 &to, const xRegisterSSE &from);
extern void xMOVMSKPD( 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 xMASKMOV(const xRegisterSSE &to, const xRegisterSSE &from);
extern void xPMOVMSKB( const xRegister32or64& 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 void xPALIGNR(const xRegisterSSE &to, const xRegisterSSE &from, u8 imm8);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
extern const xImplSimd_MoveSSE xMOVAPS; extern const xImplSimd_MoveSSE xMOVAPS;
extern const xImplSimd_MoveSSE xMOVUPS; extern const xImplSimd_MoveSSE xMOVUPS;
extern const xImplSimd_MoveSSE xMOVAPD; extern const xImplSimd_MoveSSE xMOVAPD;
extern const xImplSimd_MoveSSE xMOVUPD; extern const xImplSimd_MoveSSE xMOVUPD;
#ifdef ALWAYS_USE_MOVAPS #ifdef ALWAYS_USE_MOVAPS
extern const xImplSimd_MoveSSE xMOVDQA; extern const xImplSimd_MoveSSE xMOVDQA;
extern const xImplSimd_MoveSSE xMOVDQU; extern const xImplSimd_MoveSSE xMOVDQU;
#else #else
extern const xImplSimd_MoveDQ xMOVDQA; extern const xImplSimd_MoveDQ xMOVDQA;
extern const xImplSimd_MoveDQ xMOVDQU; extern const xImplSimd_MoveDQ xMOVDQU;
#endif #endif
extern const xImplSimd_MovHL xMOVH; extern const xImplSimd_MovHL xMOVH;
extern const xImplSimd_MovHL xMOVL; extern const xImplSimd_MovHL xMOVL;
extern const xImplSimd_MovHL_RtoR xMOVLH; extern const xImplSimd_MovHL_RtoR xMOVLH;
extern const xImplSimd_MovHL_RtoR xMOVHL; extern const xImplSimd_MovHL_RtoR xMOVHL;
extern const xImplSimd_Blend xBLEND; extern const xImplSimd_Blend xBLEND;
extern const xImplSimd_PMove xPMOVSX; extern const xImplSimd_PMove xPMOVSX;
extern const xImplSimd_PMove xPMOVZX; extern const xImplSimd_PMove xPMOVZX;
extern const xImplSimd_DestRegSSE xMOVSLDUP; extern const xImplSimd_DestRegSSE xMOVSLDUP;
extern const xImplSimd_DestRegSSE xMOVSHDUP; extern const xImplSimd_DestRegSSE xMOVSHDUP;
extern void xINSERTPS( const xRegisterSSE& to, const xRegisterSSE& from, u8 imm8 ); extern void xINSERTPS(const xRegisterSSE &to, const xRegisterSSE &from, u8 imm8);
extern void xINSERTPS( const xRegisterSSE& to, const xIndirect32& 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 xRegister32or64 &to, const xRegisterSSE &from, u8 imm8);
extern void xEXTRACTPS( const xIndirect32& dest, 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 xPAND;
extern const xImplSimd_DestRegEither xPANDN; extern const xImplSimd_DestRegEither xPANDN;
extern const xImplSimd_DestRegEither xPOR; extern const xImplSimd_DestRegEither xPOR;
extern const xImplSimd_DestRegEither xPXOR; extern const xImplSimd_DestRegEither xPXOR;
extern const xImplSimd_Shuffle xSHUF; extern const xImplSimd_Shuffle xSHUF;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
extern const xImplSimd_DestRegSSE xPTEST; extern const xImplSimd_DestRegSSE xPTEST;
extern const xImplSimd_MinMax xMIN; extern const xImplSimd_MinMax xMIN;
extern const xImplSimd_MinMax xMAX; extern const xImplSimd_MinMax xMAX;
extern const xImplSimd_Compare xCMPEQ, xCMPLT, extern const xImplSimd_Compare xCMPEQ, xCMPLT,
xCMPLE, xCMPUNORD, xCMPLE, xCMPUNORD,
xCMPNE, xCMPNLT, xCMPNE, xCMPNLT,
xCMPNLE,xCMPORD; xCMPNLE, xCMPORD;
extern const xImplSimd_COMI xCOMI; extern const xImplSimd_COMI xCOMI;
extern const xImplSimd_COMI xUCOMI; extern const xImplSimd_COMI xUCOMI;
extern const xImplSimd_PCompare xPCMP; extern const xImplSimd_PCompare xPCMP;
extern const xImplSimd_PMinMax xPMIN; extern const xImplSimd_PMinMax xPMIN;
extern const xImplSimd_PMinMax xPMAX; extern const xImplSimd_PMinMax xPMAX;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// //
// //
extern void xCVTDQ2PD( const xRegisterSSE& to, const xRegisterSSE& from ); extern void xCVTDQ2PD(const xRegisterSSE &to, const xRegisterSSE &from);
extern void xCVTDQ2PD( const xRegisterSSE& to, const xIndirect64& 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 xRegisterSSE &from);
extern void xCVTDQ2PS( const xRegisterSSE& to, const xIndirect128& 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 xRegisterSSE &from);
extern void xCVTPD2DQ( const xRegisterSSE& to, const xIndirect128& 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 xRegisterSSE &from);
extern void xCVTPD2PS( const xRegisterSSE& to, const xIndirect128& from ); extern void xCVTPD2PS(const xRegisterSSE &to, const xIndirect128 &from);
extern void xCVTPI2PD( const xRegisterSSE& to, const xIndirect64& from ); extern void xCVTPI2PD(const xRegisterSSE &to, const xIndirect64 &from);
extern void xCVTPI2PS( 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 xRegisterSSE &from);
extern void xCVTPS2DQ( const xRegisterSSE& to, const xIndirect128& 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 xRegisterSSE &from);
extern void xCVTPS2PD( const xRegisterSSE& to, const xIndirect64& 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 xRegisterSSE &from);
extern void xCVTSD2SI( const xRegister32or64& to, const xIndirect64& 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 xRegisterSSE &from);
extern void xCVTSD2SS( const xRegisterSSE& to, const xIndirect64& 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 xRegister32or64 &from);
extern void xCVTSI2SS( const xRegisterSSE& to, const xIndirect32& 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 xRegisterSSE &from);
extern void xCVTSS2SD( const xRegisterSSE& to, const xIndirect32& 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 xRegisterSSE &from);
extern void xCVTSS2SI( const xRegister32or64& to, const xIndirect32& 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 xRegisterSSE &from);
extern void xCVTTPD2DQ( const xRegisterSSE& to, const xIndirect128& 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 xRegisterSSE &from);
extern void xCVTTPS2DQ( const xRegisterSSE& to, const xIndirect128& 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 xRegisterSSE &from);
extern void xCVTTSD2SI( const xRegister32or64& to, const xIndirect64& 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 xRegisterSSE &from);
extern void xCVTTSS2SI( const xRegister32or64& to, const xIndirect32& from ); extern void xCVTTSS2SI(const xRegister32or64 &to, const xIndirect32 &from);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
extern const xImplSimd_AndNot xANDN; extern const xImplSimd_AndNot xANDN;
extern const xImplSimd_rSqrt xRCP; extern const xImplSimd_rSqrt xRCP;
extern const xImplSimd_rSqrt xRSQRT; extern const xImplSimd_rSqrt xRSQRT;
extern const xImplSimd_Sqrt xSQRT; extern const xImplSimd_Sqrt xSQRT;
extern const xImplSimd_Shift xPSLL; extern const xImplSimd_Shift xPSLL;
extern const xImplSimd_Shift xPSRL; extern const xImplSimd_Shift xPSRL;
extern const xImplSimd_ShiftWithoutQ xPSRA; extern const xImplSimd_ShiftWithoutQ xPSRA;
extern const xImplSimd_AddSub xPADD; extern const xImplSimd_AddSub xPADD;
extern const xImplSimd_AddSub xPSUB; extern const xImplSimd_AddSub xPSUB;
extern const xImplSimd_PMul xPMUL; extern const xImplSimd_PMul xPMUL;
extern const xImplSimd_PAbsolute xPABS; extern const xImplSimd_PAbsolute xPABS;
extern const xImplSimd_PSign xPSIGN; extern const xImplSimd_PSign xPSIGN;
extern const xImplSimd_PMultAdd xPMADD; extern const xImplSimd_PMultAdd xPMADD;
extern const xImplSimd_HorizAdd xHADD; extern const xImplSimd_HorizAdd xHADD;
extern const xImplSimd_DotProduct xDP; extern const xImplSimd_DotProduct xDP;
extern const xImplSimd_Round xROUND; 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 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;
} }

View File

@ -19,96 +19,106 @@
#include "instructions.h" #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 SimdPrefix(u8 prefix, u16 opcode);
extern void EmitSibMagic( uint regfield, const void* address ); extern void EmitSibMagic(uint regfield, const void *address);
extern void EmitSibMagic( uint regfield, const xIndirectVoid& info ); extern void EmitSibMagic(uint regfield, const xIndirectVoid &info);
extern void EmitSibMagic( uint reg1, const xRegisterBase& reg2 ); extern void EmitSibMagic(uint reg1, const xRegisterBase &reg2);
extern void EmitSibMagic( const xRegisterBase& 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 void *src);
extern void EmitSibMagic( const xRegisterBase& reg1, const xIndirectVoid& sib ); extern void EmitSibMagic(const xRegisterBase &reg1, const xIndirectVoid &sib);
extern void EmitRex( uint regfield, const void* address ); extern void EmitRex(uint regfield, const void *address);
extern void EmitRex( uint regfield, const xIndirectVoid& info ); extern void EmitRex(uint regfield, const xIndirectVoid &info);
extern void EmitRex( uint reg1, const xRegisterBase& reg2 ); extern void EmitRex(uint reg1, const xRegisterBase &reg2);
extern void EmitRex( const xRegisterBase& 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 void *src);
extern void EmitRex( const xRegisterBase& reg1, const xIndirectVoid& sib ); extern void EmitRex(const xRegisterBase &reg1, const xIndirectVoid &sib);
extern void _xMovRtoR( const xRegisterInt& to, const xRegisterInt& from ); extern void _xMovRtoR(const xRegisterInt &to, const xRegisterInt &from);
template< typename T > inline template <typename T>
void xWrite( T val ) inline void xWrite(T val)
{ {
*(T*)x86Ptr = val; *(T *)x86Ptr = val;
x86Ptr += sizeof(T); x86Ptr += sizeof(T);
} }
template< typename T1, typename T2 > __emitinline template <typename T1, typename T2>
void xOpWrite( u8 prefix, u8 opcode, const T1& param1, const T2& param2 ) __emitinline void xOpWrite(u8 prefix, u8 opcode, const T1 &param1, const T2 &param2)
{ {
if( prefix != 0 ) xWrite8( prefix ); if (prefix != 0)
EmitRex( param1, param2 ); xWrite8(prefix);
EmitRex(param1, param2);
xWrite8( opcode ); xWrite8(opcode);
EmitSibMagic( param1, param2 ); EmitSibMagic(param1, param2);
} }
template< typename T1, typename T2 > __emitinline template <typename T1, typename T2>
void xOpAccWrite( u8 prefix, u8 opcode, const T1& param1, const T2& param2 ) __emitinline void xOpAccWrite(u8 prefix, u8 opcode, const T1 &param1, const T2 &param2)
{ {
if( prefix != 0 ) xWrite8( prefix ); if (prefix != 0)
EmitRex( param1, param2 ); xWrite8(prefix);
EmitRex(param1, param2);
xWrite8( opcode ); xWrite8(opcode);
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// emitter helpers for xmm instruction with prefixes, most of which are using // emitter helpers for xmm instruction with prefixes, most of which are using
// the basic opcode format (items inside braces denote optional or conditional // the basic opcode format (items inside braces denote optional or conditional
// emission): // emission):
// //
// [Prefix] / 0x0f / [OpcodePrefix] / Opcode / ModRM+[SibSB] // [Prefix] / 0x0f / [OpcodePrefix] / Opcode / ModRM+[SibSB]
// //
// Prefixes are typically 0x66, 0xf2, or 0xf3. OpcodePrefixes are either 0x38 or // Prefixes are typically 0x66, 0xf2, or 0xf3. OpcodePrefixes are either 0x38 or
// 0x3a [and other value will result in assertion failue]. // 0x3a [and other value will result in assertion failue].
// //
template< typename T1, typename T2 > __emitinline template <typename T1, typename T2>
void xOpWrite0F( u8 prefix, u16 opcode, const T1& param1, const T2& param2 ) __emitinline void xOpWrite0F(u8 prefix, u16 opcode, const T1 &param1, const T2 &param2)
{ {
if( prefix != 0 ) xWrite8( prefix ); if (prefix != 0)
EmitRex( param1, param2 ); xWrite8(prefix);
EmitRex(param1, param2);
SimdPrefix( 0, opcode ); SimdPrefix(0, opcode);
EmitSibMagic( param1, param2 ); EmitSibMagic(param1, param2);
} }
template< typename T1, typename T2 > __emitinline template <typename T1, typename T2>
void xOpWrite0F( u8 prefix, u16 opcode, const T1& param1, const T2& param2, u8 imm8 ) __emitinline void xOpWrite0F(u8 prefix, u16 opcode, const T1 &param1, const T2 &param2, u8 imm8)
{ {
xOpWrite0F( prefix, opcode, param1, param2 ); xOpWrite0F(prefix, opcode, param1, param2);
xWrite8( imm8 ); xWrite8(imm8);
} }
template< typename T1, typename T2 > __emitinline template <typename T1, typename T2>
void xOpWrite0F( u16 opcode, const T1& param1, const T2& param2 ) { xOpWrite0F( 0, opcode, param1, param2 ); } __emitinline void xOpWrite0F(u16 opcode, const T1 &param1, const T2 &param2)
{
xOpWrite0F(0, opcode, param1, param2);
}
template< typename T1, typename T2 > __emitinline template <typename T1, typename T2>
void xOpWrite0F( u16 opcode, const T1& param1, const T2& param2, u8 imm8 ) { xOpWrite0F( 0, opcode, param1, param2, imm8 ); } __emitinline void xOpWrite0F(u16 opcode, const T1 &param1, const T2 &param2, u8 imm8)
{
xOpWrite0F(0, opcode, param1, param2, imm8);
}
// VEX 2 Bytes Prefix // VEX 2 Bytes Prefix
template< typename T1, typename T2, typename T3 > __emitinline template <typename T1, typename T2, typename T3>
void xOpWriteC5( u8 prefix, u8 opcode, const T1& param1, const T2& param2, const T3& param3 ) __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 ); pxAssert(prefix == 0 || prefix == 0x66 || prefix == 0xF3 || prefix == 0xF2);
const xRegisterInt& reg = param1.IsReg() ? param1 : param2; const xRegisterInt &reg = param1.IsReg() ? param1 : param2;
#ifdef __x86_64__ #ifdef __x86_64__
u8 nR = reg.IsExtended() ? 0x00 : 0x80; u8 nR = reg.IsExtended() ? 0x00 : 0x80;
@ -124,20 +134,20 @@ namespace x86Emitter {
prefix == 0xF3 ? 2 : prefix == 0xF3 ? 2 :
prefix == 0x66 ? 1 : 0; prefix == 0x66 ? 1 : 0;
xWrite8( 0xC5 ); xWrite8(0xC5);
xWrite8( nR | nv | L | p ); xWrite8(nR | nv | L | p);
xWrite8( opcode ); xWrite8(opcode);
EmitSibMagic( param1, param3 ); EmitSibMagic(param1, param3);
} }
// VEX 3 Bytes Prefix // VEX 3 Bytes Prefix
template< typename T1, typename T2, typename T3 > __emitinline template <typename T1, typename T2, typename T3>
void xOpWriteC4( u8 prefix, u8 mb_prefix, u8 opcode, const T1& param1, const T2& param2, const T3& param3, int w = -1 ) __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(prefix == 0 || prefix == 0x66 || prefix == 0xF3 || prefix == 0xF2);
pxAssert( mb_prefix == 0x0F || mb_prefix == 0x38 || mb_prefix == 0x3A ); pxAssert(mb_prefix == 0x0F || mb_prefix == 0x38 || mb_prefix == 0x3A);
const xRegisterInt& reg = param1.IsReg() ? param1 : param2; const xRegisterInt &reg = param1.IsReg() ? param1 : param2;
#ifdef __x86_64__ #ifdef __x86_64__
u8 nR = reg.IsExtended() ? 0x00 : 0x80; u8 nR = reg.IsExtended() ? 0x00 : 0x80;
@ -163,12 +173,10 @@ namespace x86Emitter {
mb_prefix == 0x3A ? 3 : mb_prefix == 0x3A ? 3 :
mb_prefix == 0x38 ? 2 : 1; mb_prefix == 0x38 ? 2 : 1;
xWrite8( 0xC4 ); xWrite8(0xC4);
xWrite8( nR | nX | nB | m ); xWrite8(nR | nX | nB | m);
xWrite8( W | nv | L | p ); xWrite8(W | nv | L | p);
xWrite8( opcode ); xWrite8(opcode);
EmitSibMagic( param1, param3 ); EmitSibMagic(param1, param3);
} }
} }

View File

@ -25,15 +25,15 @@
//------------------------------------------------------------------ //------------------------------------------------------------------
// legacy jump/align functions // legacy jump/align functions
//------------------------------------------------------------------ //------------------------------------------------------------------
ATTR_DEP extern void x86SetPtr( u8 *ptr ); ATTR_DEP extern void x86SetPtr(u8 *ptr);
ATTR_DEP extern void x86SetJ8( u8 *j8 ); ATTR_DEP extern void x86SetJ8(u8 *j8);
ATTR_DEP extern void x86SetJ8A( u8 *j8 ); ATTR_DEP extern void x86SetJ8A(u8 *j8);
ATTR_DEP extern void x86SetJ16( u16 *j16 ); ATTR_DEP extern void x86SetJ16(u16 *j16);
ATTR_DEP extern void x86SetJ16A( u16 *j16 ); ATTR_DEP extern void x86SetJ16A(u16 *j16);
ATTR_DEP extern void x86SetJ32( u32 *j32 ); ATTR_DEP extern void x86SetJ32(u32 *j32);
ATTR_DEP extern void x86SetJ32A( u32 *j32 ); ATTR_DEP extern void x86SetJ32A(u32 *j32);
ATTR_DEP extern void x86Align( int bytes ); ATTR_DEP extern void x86Align(int bytes);
ATTR_DEP extern void x86AlignExecutable( int align ); ATTR_DEP extern void x86AlignExecutable(int align);
//------------------------------------------------------------------ //------------------------------------------------------------------
//////////////////////////////////// ////////////////////////////////////
@ -41,55 +41,55 @@ ATTR_DEP extern void x86AlignExecutable( int align );
//////////////////////////////////// ////////////////////////////////////
// jmp rel8 // jmp rel8
ATTR_DEP extern u8* JMP8( u8 to ); ATTR_DEP extern u8 *JMP8(u8 to);
// jmp rel32 // jmp rel32
ATTR_DEP extern u32* JMP32( uptr to ); ATTR_DEP extern u32 *JMP32(uptr to);
// jp rel8 // jp rel8
ATTR_DEP extern u8* JP8( u8 to ); ATTR_DEP extern u8 *JP8(u8 to);
// jnp rel8 // jnp rel8
ATTR_DEP extern u8* JNP8( u8 to ); ATTR_DEP extern u8 *JNP8(u8 to);
// je rel8 // je rel8
ATTR_DEP extern u8* JE8( u8 to ); ATTR_DEP extern u8 *JE8(u8 to);
// jz rel8 // jz rel8
ATTR_DEP extern u8* JZ8( u8 to ); ATTR_DEP extern u8 *JZ8(u8 to);
// jg rel8 // jg rel8
ATTR_DEP extern u8* JG8( u8 to ); ATTR_DEP extern u8 *JG8(u8 to);
// jge rel8 // jge rel8
ATTR_DEP extern u8* JGE8( u8 to ); ATTR_DEP extern u8 *JGE8(u8 to);
// js rel8 // js rel8
ATTR_DEP extern u8* JS8( u8 to ); ATTR_DEP extern u8 *JS8(u8 to);
// jns rel8 // jns rel8
ATTR_DEP extern u8* JNS8( u8 to ); ATTR_DEP extern u8 *JNS8(u8 to);
// jl rel8 // jl rel8
ATTR_DEP extern u8* JL8( u8 to ); ATTR_DEP extern u8 *JL8(u8 to);
// ja rel8 // ja rel8
ATTR_DEP extern u8* JA8( u8 to ); ATTR_DEP extern u8 *JA8(u8 to);
// jae rel8 // jae rel8
ATTR_DEP extern u8* JAE8( u8 to ); ATTR_DEP extern u8 *JAE8(u8 to);
// jb rel8 // jb rel8
ATTR_DEP extern u8* JB8( u8 to ); ATTR_DEP extern u8 *JB8(u8 to);
// jbe rel8 // jbe rel8
ATTR_DEP extern u8* JBE8( u8 to ); ATTR_DEP extern u8 *JBE8(u8 to);
// jle rel8 // jle rel8
ATTR_DEP extern u8* JLE8( u8 to ); ATTR_DEP extern u8 *JLE8(u8 to);
// jne rel8 // jne rel8
ATTR_DEP extern u8* JNE8( u8 to ); ATTR_DEP extern u8 *JNE8(u8 to);
// jnz rel8 // jnz rel8
ATTR_DEP extern u8* JNZ8( u8 to ); ATTR_DEP extern u8 *JNZ8(u8 to);
// jng rel8 // jng rel8
ATTR_DEP extern u8* JNG8( u8 to ); ATTR_DEP extern u8 *JNG8(u8 to);
// jnge rel8 // jnge rel8
ATTR_DEP extern u8* JNGE8( u8 to ); ATTR_DEP extern u8 *JNGE8(u8 to);
// jnl rel8 // jnl rel8
ATTR_DEP extern u8* JNL8( u8 to ); ATTR_DEP extern u8 *JNL8(u8 to);
// jnle rel8 // jnle rel8
ATTR_DEP extern u8* JNLE8( u8 to ); ATTR_DEP extern u8 *JNLE8(u8 to);
// jo rel8 // jo rel8
ATTR_DEP extern u8* JO8( u8 to ); ATTR_DEP extern u8 *JO8(u8 to);
// jno rel8 // jno rel8
ATTR_DEP extern u8* JNO8( u8 to ); ATTR_DEP extern u8 *JNO8(u8 to);
/* /*
// jb rel16 // jb rel16
@ -103,51 +103,51 @@ ATTR_DEP extern u16* JZ16( u16 to );
*/ */
// jns rel32 // jns rel32
ATTR_DEP extern u32* JNS32( u32 to ); ATTR_DEP extern u32 *JNS32(u32 to);
// js rel32 // js rel32
ATTR_DEP extern u32* JS32( u32 to ); ATTR_DEP extern u32 *JS32(u32 to);
// jb rel32 // jb rel32
ATTR_DEP extern u32* JB32( u32 to ); ATTR_DEP extern u32 *JB32(u32 to);
// je rel32 // je rel32
ATTR_DEP extern u32* JE32( u32 to ); ATTR_DEP extern u32 *JE32(u32 to);
// jz rel32 // jz rel32
ATTR_DEP extern u32* JZ32( u32 to ); ATTR_DEP extern u32 *JZ32(u32 to);
// jg rel32 // jg rel32
ATTR_DEP extern u32* JG32( u32 to ); ATTR_DEP extern u32 *JG32(u32 to);
// jge rel32 // jge rel32
ATTR_DEP extern u32* JGE32( u32 to ); ATTR_DEP extern u32 *JGE32(u32 to);
// jl rel32 // jl rel32
ATTR_DEP extern u32* JL32( u32 to ); ATTR_DEP extern u32 *JL32(u32 to);
// jle rel32 // jle rel32
ATTR_DEP extern u32* JLE32( u32 to ); ATTR_DEP extern u32 *JLE32(u32 to);
// jae rel32 // jae rel32
ATTR_DEP extern u32* JAE32( u32 to ); ATTR_DEP extern u32 *JAE32(u32 to);
// jne rel32 // jne rel32
ATTR_DEP extern u32* JNE32( u32 to ); ATTR_DEP extern u32 *JNE32(u32 to);
// jnz rel32 // jnz rel32
ATTR_DEP extern u32* JNZ32( u32 to ); ATTR_DEP extern u32 *JNZ32(u32 to);
// jng rel32 // jng rel32
ATTR_DEP extern u32* JNG32( u32 to ); ATTR_DEP extern u32 *JNG32(u32 to);
// jnge rel32 // jnge rel32
ATTR_DEP extern u32* JNGE32( u32 to ); ATTR_DEP extern u32 *JNGE32(u32 to);
// jnl rel32 // jnl rel32
ATTR_DEP extern u32* JNL32( u32 to ); ATTR_DEP extern u32 *JNL32(u32 to);
// jnle rel32 // jnle rel32
ATTR_DEP extern u32* JNLE32( u32 to ); ATTR_DEP extern u32 *JNLE32(u32 to);
// jo rel32 // jo rel32
ATTR_DEP extern u32* JO32( u32 to ); ATTR_DEP extern u32 *JO32(u32 to);
// jno rel32 // jno rel32
ATTR_DEP extern u32* JNO32( u32 to ); ATTR_DEP extern u32 *JNO32(u32 to);
// js rel32 // js rel32
ATTR_DEP extern u32* JS32( u32 to ); ATTR_DEP extern u32 *JS32(u32 to);
//****************** //******************
// FPU instructions // FPU instructions
//****************** //******************
// fld m32 to fpu reg stack // fld m32 to fpu reg stack
ATTR_DEP extern void FLD32( u32 from ); ATTR_DEP extern void FLD32(u32 from);
// fld st(i) // fld st(i)
ATTR_DEP extern void FLD(int st); ATTR_DEP extern void FLD(int st);
// fld1 (push +1.0f on the stack) // fld1 (push +1.0f on the stack)
@ -155,7 +155,7 @@ ATTR_DEP extern void FLD1();
// fld1 (push log_2 e on the stack) // fld1 (push log_2 e on the stack)
ATTR_DEP extern void FLDL2E(); ATTR_DEP extern void FLDL2E();
// fstp m32 from fpu reg stack // fstp m32 from fpu reg stack
ATTR_DEP extern void FSTP32( u32 to ); ATTR_DEP extern void FSTP32(u32 to);
// fstp st(i) // fstp st(i)
ATTR_DEP extern void FSTP(int st); ATTR_DEP extern void FSTP(int st);
@ -166,32 +166,32 @@ ATTR_DEP extern void F2XM1();
ATTR_DEP extern void FSCALE(); ATTR_DEP extern void FSCALE();
// fadd ST(0) to fpu reg stack ST(src) // 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) // 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 // 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 // fdiv m32 to fpu reg stack
ATTR_DEP extern void FDIV32( u32 from ); ATTR_DEP extern void FDIV32(u32 from);
// ftan fpu reg stack // ftan fpu reg stack
ATTR_DEP extern void FPATAN( void ); ATTR_DEP extern void FPATAN(void);
// fsin fpu reg stack // fsin fpu reg stack
ATTR_DEP extern void FSIN( void ); ATTR_DEP extern void FSIN(void);
//********************* //*********************
// SSE instructions * // SSE instructions *
//********************* //*********************
ATTR_DEP extern void SSE_MAXSS_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_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_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_SUBSS_XMM_to_XMM(x86SSERegType to, x86SSERegType from);
//********************* //*********************
// SSE 2 Instructions* // SSE 2 Instructions*
//********************* //*********************
ATTR_DEP extern void SSE2_MAXSD_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_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_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_SUBSD_XMM_to_XMM(x86SSERegType to, x86SSERegType from);

View File

@ -33,9 +33,8 @@ using x86Emitter::xWrite64;
#define MEMADDR(addr, oplen) (addr) #define MEMADDR(addr, oplen) (addr)
extern void ModRM( uint mod, uint reg, uint rm ); extern void ModRM(uint mod, uint reg, uint rm);
extern void SibSB( uint ss, uint index, uint base ); extern void SibSB(uint ss, uint index, uint base);
extern void SET8R( int cc, int to ); extern void SET8R(int cc, int to);
extern u8* J8Rel( int cc, int to ); extern u8 *J8Rel(int cc, int to);
extern u32* J32Rel( int cc, u32 to ); extern u32 *J32Rel(int cc, u32 to);

View File

@ -17,8 +17,7 @@
#include "x86emitter.h" #include "x86emitter.h"
enum x86VendorType enum x86VendorType {
{
x86Vendor_Intel = 0, x86Vendor_Intel = 0,
x86Vendor_AMD = 1, x86Vendor_AMD = 1,
x86Vendor_Unknown = 2 x86Vendor_Unknown = 2
@ -53,51 +52,53 @@ public:
// x86 CPU Capabilities Section (all boolean flags!) // x86 CPU Capabilities Section (all boolean flags!)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
union { union
struct { {
u32 hasFloatingPointUnit :1; struct
u32 hasVirtual8086ModeEnhancements :1; {
u32 hasDebuggingExtensions :1; u32 hasFloatingPointUnit : 1;
u32 hasPageSizeExtensions :1; u32 hasVirtual8086ModeEnhancements : 1;
u32 hasTimeStampCounter :1; u32 hasDebuggingExtensions : 1;
u32 hasModelSpecificRegisters :1; u32 hasPageSizeExtensions : 1;
u32 hasPhysicalAddressExtension :1; u32 hasTimeStampCounter : 1;
u32 hasCOMPXCHG8BInstruction :1; u32 hasModelSpecificRegisters : 1;
u32 hasAdvancedProgrammableInterruptController :1; u32 hasPhysicalAddressExtension : 1;
u32 hasSEPFastSystemCall :1; u32 hasCOMPXCHG8BInstruction : 1;
u32 hasMemoryTypeRangeRegisters :1; u32 hasAdvancedProgrammableInterruptController : 1;
u32 hasPTEGlobalFlag :1; u32 hasSEPFastSystemCall : 1;
u32 hasMachineCheckArchitecture :1; u32 hasMemoryTypeRangeRegisters : 1;
u32 hasConditionalMoveAndCompareInstructions :1; u32 hasPTEGlobalFlag : 1;
u32 hasFGPageAttributeTable :1; u32 hasMachineCheckArchitecture : 1;
u32 has36bitPageSizeExtension :1; u32 hasConditionalMoveAndCompareInstructions : 1;
u32 hasProcessorSerialNumber :1; u32 hasFGPageAttributeTable : 1;
u32 hasCFLUSHInstruction :1; u32 has36bitPageSizeExtension : 1;
u32 hasDebugStore :1; u32 hasProcessorSerialNumber : 1;
u32 hasACPIThermalMonitorAndClockControl :1; u32 hasCFLUSHInstruction : 1;
u32 hasFastStreamingSIMDExtensionsSaveRestore :1; u32 hasDebugStore : 1;
u32 hasStreamingSIMDExtensions :1; u32 hasACPIThermalMonitorAndClockControl : 1;
u32 hasStreamingSIMD2Extensions :1; u32 hasFastStreamingSIMDExtensionsSaveRestore : 1;
u32 hasSelfSnoop :1; u32 hasStreamingSIMDExtensions : 1;
u32 hasStreamingSIMD2Extensions : 1;
u32 hasSelfSnoop : 1;
// is TRUE for both multi-core and Hyperthreaded CPUs. // is TRUE for both multi-core and Hyperthreaded CPUs.
u32 hasMultiThreading :1; u32 hasMultiThreading : 1;
u32 hasThermalMonitor :1; u32 hasThermalMonitor : 1;
u32 hasIntel64BitArchitecture :1; u32 hasIntel64BitArchitecture : 1;
u32 hasStreamingSIMD3Extensions :1; u32 hasStreamingSIMD3Extensions : 1;
u32 hasSupplementalStreamingSIMD3Extensions :1; u32 hasSupplementalStreamingSIMD3Extensions : 1;
u32 hasStreamingSIMD4Extensions :1; u32 hasStreamingSIMD4Extensions : 1;
u32 hasStreamingSIMD4Extensions2 :1; u32 hasStreamingSIMD4Extensions2 : 1;
u32 hasAVX :1; u32 hasAVX : 1;
u32 hasAVX2 :1; u32 hasAVX2 : 1;
u32 hasBMI1 :1; u32 hasBMI1 : 1;
u32 hasBMI2 :1; u32 hasBMI2 : 1;
u32 hasFMA :1; u32 hasFMA : 1;
// AMD-specific CPU Features // AMD-specific CPU Features
u32 hasAMD64BitArchitecture :1; u32 hasAMD64BitArchitecture : 1;
u32 hasStreamingSIMD4ExtensionsA :1; u32 hasStreamingSIMD4ExtensionsA : 1;
}; };
u64 AllCapabilities; u64 AllCapabilities;
@ -119,12 +120,11 @@ public:
void SIMD_EstablishMXCSRmask(); void SIMD_EstablishMXCSRmask();
protected: protected:
s64 _CPUSpeedHz( u64 time ) const; s64 _CPUSpeedHz(u64 time) const;
void CountLogicalCores(); void CountLogicalCores();
}; };
enum SSE_RoundMode enum SSE_RoundMode {
{
SSE_RoundMode_FIRST = 0, SSE_RoundMode_FIRST = 0,
SSEround_Nearest = 0, SSEround_Nearest = 0,
SSEround_NegInf, SSEround_NegInf,
@ -133,7 +133,7 @@ enum SSE_RoundMode
SSE_RoundMode_COUNT SSE_RoundMode_COUNT
}; };
ImplementEnumOperators( SSE_RoundMode ); ImplementEnumOperators(SSE_RoundMode);
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// SSE_MXCSR - Control/Status Register (bitfield) // SSE_MXCSR - Control/Status Register (bitfield)
@ -151,43 +151,43 @@ union SSE_MXCSR
struct struct
{ {
u32 u32
InvalidOpFlag :1, InvalidOpFlag : 1,
DenormalFlag :1, DenormalFlag : 1,
DivideByZeroFlag :1, DivideByZeroFlag : 1,
OverflowFlag :1, OverflowFlag : 1,
UnderflowFlag :1, UnderflowFlag : 1,
PrecisionFlag :1, PrecisionFlag : 1,
// This bit is supported only on SSE2 or better CPUs. Setting it to 1 on // 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 // SSE1 cpus will result in an invalid instruction exception when executing
// LDMXSCR. // LDMXSCR.
DenormalsAreZero :1, DenormalsAreZero : 1,
InvalidOpMask :1, InvalidOpMask : 1,
DenormalMask :1, DenormalMask : 1,
DivideByZeroMask :1, DivideByZeroMask : 1,
OverflowMask :1, OverflowMask : 1,
UnderflowMask :1, UnderflowMask : 1,
PrecisionMask :1, PrecisionMask : 1,
RoundingControl :2, RoundingControl : 2,
FlushToZero :1; FlushToZero : 1;
}; };
SSE_RoundMode GetRoundMode() const; SSE_RoundMode GetRoundMode() const;
SSE_MXCSR& SetRoundMode( SSE_RoundMode mode ); SSE_MXCSR &SetRoundMode(SSE_RoundMode mode);
SSE_MXCSR& ClearExceptionFlags(); SSE_MXCSR &ClearExceptionFlags();
SSE_MXCSR& EnableExceptions(); SSE_MXCSR &EnableExceptions();
SSE_MXCSR& DisableExceptions(); SSE_MXCSR &DisableExceptions();
SSE_MXCSR& ApplyReserveMask(); SSE_MXCSR &ApplyReserveMask();
bool operator ==( const SSE_MXCSR& right ) const bool operator==(const SSE_MXCSR &right) const
{ {
return bitmask == right.bitmask; return bitmask == right.bitmask;
} }
bool operator !=( const SSE_MXCSR& right ) const bool operator!=(const SSE_MXCSR &right) const
{ {
return bitmask != right.bitmask; return bitmask != right.bitmask;
} }
@ -199,4 +199,3 @@ extern SSE_MXCSR MXCSR_Mask;
extern __aligned16 x86capabilities x86caps; extern __aligned16 x86capabilities x86caps;

View File

@ -39,18 +39,22 @@
#include <cpuid.h> #include <cpuid.h>
static __inline__ __attribute__((always_inline)) void cpuidex(int CPUInfo[], const int InfoType, const int count) { 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]); __cpuid_count(InfoType, count, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
} }
static __inline__ __attribute__((always_inline)) void cpuid(int CPUInfo[], const int InfoType) { static __inline__ __attribute__((always_inline)) void cpuid(int CPUInfo[], const int InfoType)
{
__cpuid(InfoType, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); __cpuid(InfoType, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
} }
static __inline__ __attribute__((always_inline)) unsigned long long _xgetbv(unsigned int index) static __inline__ __attribute__((always_inline)) unsigned long long _xgetbv(unsigned int index)
{ {
unsigned int eax, edx; unsigned int eax, edx;
__asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); __asm__ __volatile__("xgetbv"
: "=a"(eax), "=d"(edx)
: "c"(index));
return ((unsigned long long)edx << 32) | eax; return ((unsigned long long)edx << 32) | eax;
} }
@ -72,5 +76,5 @@ static unsigned int _rotl(unsigned int x, int s)
// Not correctly defined in GCC4.8 and below ! (dunno for VS) // Not correctly defined in GCC4.8 and below ! (dunno for VS)
#ifndef _MM_MK_INSERTPS_NDX #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 #endif

File diff suppressed because it is too large Load Diff

View File

@ -18,9 +18,9 @@
#include "PrecompiledHeader.h" #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 #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 #else
@ -30,11 +30,11 @@ void* __fastcall _aligned_malloc(size_t size, size_t align)
#endif #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) { if (newbuf != NULL && handle != NULL) {
memcpy(newbuf, handle, std::min(old_size, new_size)); memcpy(newbuf, handle, std::min(old_size, new_size));
@ -43,7 +43,7 @@ void* __fastcall pcsx2_aligned_realloc(void* handle, size_t new_size, size_t ali
return newbuf; return newbuf;
} }
__fi void _aligned_free(void* pmem) __fi void _aligned_free(void *pmem)
{ {
free(pmem); free(pmem);
} }

View File

@ -16,40 +16,39 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "CheckedStaticBox.h" #include "CheckedStaticBox.h"
CheckedStaticBox::CheckedStaticBox( wxWindow* parent, int orientation, const wxString& title ) CheckedStaticBox::CheckedStaticBox(wxWindow *parent, int orientation, const wxString &title)
: wxPanelWithHelpers( parent, wxVERTICAL ) : wxPanelWithHelpers(parent, wxVERTICAL)
, ThisSizer( *new wxStaticBoxSizer( orientation, this ) ) , ThisSizer(*new wxStaticBoxSizer(orientation, this))
, ThisToggle( *new wxCheckBox( this, wxID_ANY, title, wxPoint( 8, 0 ) ) ) , ThisToggle(*new wxCheckBox(this, wxID_ANY, title, wxPoint(8, 0)))
{ {
*this += ThisToggle; *this += ThisToggle;
*this += ThisSizer | pxExpand; *this += ThisSizer | pxExpand;
// Ensure that the right-side of the static group box isn't too cozy: // Ensure that the right-side of the static group box isn't too cozy:
SetMinWidth( ThisToggle.GetSize().GetWidth() + 32 ); 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) // 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. // 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 // Sets the main checkbox status, and enables/disables all child controls
// bound to the StaticBox accordingly. // 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) for (wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter) {
{
wxWindow *current = *iter; wxWindow *current = *iter;
if( current != &ThisToggle ) if (current != &ThisToggle)
current->Enable( val ); current->Enable(val);
} }
ThisToggle.SetValue( val ); ThisToggle.SetValue(val);
} }
bool CheckedStaticBox::GetValue() const bool CheckedStaticBox::GetValue() const
@ -59,18 +58,18 @@ bool CheckedStaticBox::GetValue() const
// This override is here so to only enable the children if both the main toggle and // 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! // 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(); bool val = enable && ThisToggle.GetValue();
wxWindowList& list = GetChildren(); wxWindowList &list = GetChildren();
for( wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter) for (wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter) {
{
wxWindow *current = *iter; wxWindow *current = *iter;
if( current != &ThisToggle ) if (current != &ThisToggle)
current->Enable( val ); current->Enable(val);
} }
return true; return true;

View File

@ -23,10 +23,10 @@
using namespace Threading; using namespace Threading;
// thread-local console indentation setting. // thread-local console indentation setting.
static DeclareTls(int) conlog_Indent( 0 ); static DeclareTls(int) conlog_Indent(0);
// thread-local console color storage. // thread-local console color storage.
static DeclareTls(ConsoleColors) conlog_Color( DefaultConsoleColor ); static DeclareTls(ConsoleColors) conlog_Color(DefaultConsoleColor);
#ifdef __POSIX__ #ifdef __POSIX__
static FILE *stdout_fp = stdout; static FILE *stdout_fp = stdout;
@ -44,14 +44,13 @@ void Console_SetStdout(FILE *fp)
// Important! Only Assert and Null console loggers are allowed during C++ startup init (when // 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 // 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. // 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( pxAssertDev(
(writer.WriteRaw != NULL) && (writer.DoWriteLn != NULL) && (writer.WriteRaw != NULL) && (writer.DoWriteLn != NULL) &&
(writer.Newline != NULL) && (writer.SetTitle != NULL) && (writer.Newline != NULL) && (writer.SetTitle != NULL) &&
(writer.DoSetColor != NULL), (writer.DoSetColor != NULL),
"Invalid IConsoleWriter object! All function pointer interfaces must be implemented." "Invalid IConsoleWriter object! All function pointer interfaces must be implemented.");
);
Console = writer; Console = writer;
DevConWriter = writer; DevConWriter = writer;
@ -63,11 +62,12 @@ void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp )
// Writes text to the Visual Studio Output window (Microsoft Windows only). // Writes text to the Visual Studio Output window (Microsoft Windows only).
// On all other platforms this pipes to Stdout instead. // 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__) #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
static bool hasDebugger = wxIsDebuggerRunning(); static bool hasDebugger = wxIsDebuggerRunning();
if( hasDebugger ) OutputDebugString( text ); if (hasDebugger)
OutputDebugString(text);
#else #else
fputs(text.utf8_str(), stdout_fp); fputs(text.utf8_str(), stdout_fp);
fflush(stdout_fp); fflush(stdout_fp);
@ -79,14 +79,14 @@ void MSW_OutputDebugString( const wxString& text )
// ConsoleNull // ConsoleNull
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
static void __concall ConsoleNull_SetTitle( const wxString& title ) {} static void __concall ConsoleNull_SetTitle(const wxString &title) {}
static void __concall ConsoleNull_DoSetColor( ConsoleColors color ) {} static void __concall ConsoleNull_DoSetColor(ConsoleColors color) {}
static void __concall ConsoleNull_Newline() {} static void __concall ConsoleNull_Newline() {}
static void __concall ConsoleNull_DoWrite( const wxString& fmt ) {} static void __concall ConsoleNull_DoWrite(const wxString &fmt) {}
static void __concall ConsoleNull_DoWriteLn( const wxString& fmt ) {} static void __concall ConsoleNull_DoWriteLn(const wxString &fmt) {}
const IConsoleWriter ConsoleWriter_Null = const IConsoleWriter ConsoleWriter_Null =
{ {
ConsoleNull_DoWrite, ConsoleNull_DoWrite,
ConsoleNull_DoWriteLn, ConsoleNull_DoWriteLn,
ConsoleNull_DoSetColor, ConsoleNull_DoSetColor,
@ -103,65 +103,80 @@ const IConsoleWriter ConsoleWriter_Null =
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
#if defined(__unix__) #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_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_Red:
case Color_StrongRed: return "\033[31m\033[1m"; return "\033[31m";
case Color_StrongRed:
return "\033[31m\033[1m";
case Color_Green: return "\033[32m"; case Color_Green:
case Color_StrongGreen: return "\033[32m\033[1m"; return "\033[32m";
case Color_StrongGreen:
return "\033[32m\033[1m";
case Color_Yellow: return "\033[33m"; case Color_Yellow:
case Color_StrongYellow: return "\033[33m\033[1m"; return "\033[33m";
case Color_StrongYellow:
return "\033[33m\033[1m";
case Color_Blue: return "\033[34m"; case Color_Blue:
case Color_StrongBlue: return "\033[34m\033[1m"; return "\033[34m";
case Color_StrongBlue:
return "\033[34m\033[1m";
// No orange, so use magenta. // No orange, so use magenta.
case Color_Orange: case Color_Orange:
case Color_Magenta: return "\033[35m"; case Color_Magenta:
return "\033[35m";
case Color_StrongOrange: 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_Cyan:
case Color_StrongCyan: return "\033[36m\033[1m"; return "\033[36m";
case Color_StrongCyan:
return "\033[36m\033[1m";
// Use 'white' instead of grey. // Use 'white' instead of grey.
case Color_Gray: case Color_Gray:
case Color_White: return "\033[37m"; case Color_White:
return "\033[37m";
case Color_StrongGray: 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. // On some other value being passed, clear any formatting.
case Color_Default: case Color_Default:
default: return "\033[0m"; default:
return "\033[0m";
} }
} }
#endif #endif
// One possible default write action at startup and shutdown is to use the stdout. // 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. // 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() 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__) #if defined(__unix__)
fprintf(stdout_fp, "\033[0m%s", GetLinuxConsoleColor(color)); fprintf(stdout_fp, "\033[0m%s", GetLinuxConsoleColor(color));
@ -169,7 +184,7 @@ static void __concall ConsoleStdout_DoSetColor( ConsoleColors color )
#endif #endif
} }
static void __concall ConsoleStdout_SetTitle( const wxString& title ) static void __concall ConsoleStdout_SetTitle(const wxString &title)
{ {
#if defined(__unix__) #if defined(__unix__)
fputs("\033]0;", stdout_fp); fputs("\033]0;", stdout_fp);
@ -179,7 +194,7 @@ static void __concall ConsoleStdout_SetTitle( const wxString& title )
} }
const IConsoleWriter ConsoleWriter_Stdout = const IConsoleWriter ConsoleWriter_Stdout =
{ {
ConsoleStdout_DoWrite, // Writes without newlines go to buffer to avoid error log spam. ConsoleStdout_DoWrite, // Writes without newlines go to buffer to avoid error log spam.
ConsoleStdout_DoWriteLn, ConsoleStdout_DoWriteLn,
ConsoleStdout_DoSetColor, ConsoleStdout_DoSetColor,
@ -194,18 +209,18 @@ const IConsoleWriter ConsoleWriter_Stdout =
// ConsoleAssert // 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 = const IConsoleWriter ConsoleWriter_Assert =
{ {
ConsoleAssert_DoWrite, ConsoleAssert_DoWrite,
ConsoleAssert_DoWriteLn, ConsoleAssert_DoWriteLn,
ConsoleNull_DoSetColor, ConsoleNull_DoSetColor,
@ -227,28 +242,29 @@ const IConsoleWriter ConsoleWriter_Assert =
// glob_indent - this parameter is used to specify a global indentation setting. It is used by // 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 // WriteLn function, but defaults to 0 for Warning and Error calls. Local indentation always
// applies to all writes. // 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; const int indent = glob_indent + _imm_indentation;
if( indent == 0 ) return src; if (indent == 0)
return src;
wxString result( src ); wxString result(src);
const wxString indentStr( L'\t', indent ); const wxString indentStr(L'\t', indent);
result.Replace( L"\n", L"\n" + indentStr ); result.Replace(L"\n", L"\n" + indentStr);
return indentStr + result; return indentStr + result;
} }
// Sets the indentation to be applied to all WriteLn's. The indentation is added to the // 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 // 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. // 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; conlog_Indent += tabcount;
pxAssert( conlog_Indent >= 0 ); pxAssert(conlog_Indent >= 0);
return *this; return *this;
} }
IConsoleWriter IConsoleWriter::Indent( int tabcount ) const IConsoleWriter IConsoleWriter::Indent(int tabcount) const
{ {
IConsoleWriter retval = *this; IConsoleWriter retval = *this;
retval._imm_indentation = tabcount; retval._imm_indentation = tabcount;
@ -258,15 +274,16 @@ IConsoleWriter IConsoleWriter::Indent( int tabcount ) const
// Changes the active console color. // Changes the active console color.
// This color will be unset by calls to colored text methods // This color will be unset by calls to colored text methods
// such as ErrorMsg and Notice. // 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. ;) // Ignore current color requests since, well, the current color is already set. ;)
if( color == Color_Current ) return *this; 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 ) if (conlog_Color != color)
DoSetColor( conlog_Color = color ); DoSetColor(conlog_Color = color);
return *this; return *this;
} }
@ -277,10 +294,10 @@ ConsoleColors IConsoleWriter::GetColor() const
} }
// Restores the console color to default (usually black, or low-intensity white if the console uses a black background) // 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 ) if (conlog_Color != DefaultConsoleColor)
DoSetColor( conlog_Color = DefaultConsoleColor ); DoSetColor(conlog_Color = DefaultConsoleColor);
return *this; return *this;
} }
@ -289,49 +306,49 @@ const IConsoleWriter& IConsoleWriter::ClearColor() const
// ASCII/UTF8 (char*) // 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 ) ); DoWriteLn(_addIndentation(pxsFmtV(fmt, args), conlog_Indent));
return false; return false;
} }
bool IConsoleWriter::WriteLn( const char* fmt, ... ) const bool IConsoleWriter::WriteLn(const char *fmt, ...) const
{ {
va_list args; va_list args;
va_start(args,fmt); va_start(args, fmt);
FormatV(fmt, args); FormatV(fmt, args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( color ); ConsoleColorScope cs(color);
FormatV(fmt, args); FormatV(fmt, args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( Color_StrongRed ); ConsoleColorScope cs(Color_StrongRed);
FormatV(fmt, args); FormatV(fmt, args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( Color_StrongOrange ); ConsoleColorScope cs(Color_StrongOrange);
FormatV(fmt, args); FormatV(fmt, args);
va_end(args); va_end(args);
@ -342,50 +359,50 @@ bool IConsoleWriter::Warning( const char* fmt, ... ) const
// Write Variants - Unicode/UTF16 style // 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 ) ); DoWriteLn(_addIndentation(pxsFmtV(fmt, args), conlog_Indent));
return false; return false;
} }
bool IConsoleWriter::WriteLn( const wxChar* fmt, ... ) const bool IConsoleWriter::WriteLn(const wxChar *fmt, ...) const
{ {
va_list args; va_list args;
va_start(args,fmt); va_start(args, fmt);
FormatV(fmt,args); FormatV(fmt, args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( color ); ConsoleColorScope cs(color);
FormatV(fmt,args); FormatV(fmt, args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( Color_StrongRed ); ConsoleColorScope cs(Color_StrongRed);
FormatV(fmt,args); FormatV(fmt, args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( Color_StrongOrange ); ConsoleColorScope cs(Color_StrongOrange);
FormatV(fmt,args); FormatV(fmt, args);
va_end(args); va_end(args);
return false; return false;
@ -394,44 +411,44 @@ bool IConsoleWriter::Warning( const wxChar* fmt, ... ) const
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// Write Variants - Unknown style // Write Variants - Unknown style
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
bool IConsoleWriter::WriteLn( const wxString fmt, ... ) const bool IConsoleWriter::WriteLn(const wxString fmt, ...) const
{ {
va_list args; va_list args;
va_start(args,fmt); va_start(args, fmt);
FormatV(fmt.wx_str(),args); FormatV(fmt.wx_str(), args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( color ); ConsoleColorScope cs(color);
FormatV(fmt.wx_str(),args); FormatV(fmt.wx_str(), args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( Color_StrongRed ); ConsoleColorScope cs(Color_StrongRed);
FormatV(fmt.wx_str(),args); FormatV(fmt.wx_str(), args);
va_end(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_list args;
va_start(args,fmt); va_start(args, fmt);
ConsoleColorScope cs( Color_StrongOrange ); ConsoleColorScope cs(Color_StrongOrange);
FormatV(fmt.wx_str(),args); FormatV(fmt.wx_str(), args);
va_end(args); va_end(args);
return false; return false;
@ -442,7 +459,7 @@ bool IConsoleWriter::Warning( const wxString fmt, ... ) const
// ConsoleColorScope / ConsoleIndentScope // ConsoleColorScope / ConsoleIndentScope
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
ConsoleColorScope::ConsoleColorScope( ConsoleColors newcolor ) ConsoleColorScope::ConsoleColorScope(ConsoleColors newcolor)
{ {
m_IsScoped = false; m_IsScoped = false;
m_newcolor = newcolor; m_newcolor = newcolor;
@ -456,20 +473,19 @@ ConsoleColorScope::~ConsoleColorScope() throw()
void ConsoleColorScope::EnterScope() void ConsoleColorScope::EnterScope()
{ {
if (!m_IsScoped) if (!m_IsScoped) {
{
m_old_color = Console.GetColor(); m_old_color = Console.GetColor();
Console.SetColor( m_newcolor ); Console.SetColor(m_newcolor);
m_IsScoped = true; m_IsScoped = true;
} }
} }
void ConsoleColorScope::LeaveScope() 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_IsScoped = false;
m_amount = tabs; m_amount = tabs;
@ -486,27 +502,27 @@ ConsoleIndentScope::~ConsoleIndentScope() throw()
void ConsoleIndentScope::EnterScope() void ConsoleIndentScope::EnterScope()
{ {
m_IsScoped = m_IsScoped || (Console.SetIndent( m_amount ),true); m_IsScoped = m_IsScoped || (Console.SetIndent(m_amount), true);
} }
void ConsoleIndentScope::LeaveScope() 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(); m_old_color = Console.GetColor();
Console.SetIndent( m_tabsize = indent ); Console.SetIndent(m_tabsize = indent);
Console.SetColor( newcolor ); Console.SetColor(newcolor);
} }
ConsoleAttrScope::~ConsoleAttrScope() throw() ConsoleAttrScope::~ConsoleAttrScope() throw()
{ {
try { try {
Console.SetColor( m_old_color ); Console.SetColor(m_old_color);
Console.SetIndent( -m_tabsize ); Console.SetIndent(-m_tabsize);
} }
DESTRUCTOR_CATCHALL DESTRUCTOR_CATCHALL
} }
@ -539,31 +555,31 @@ NullConsoleWriter NullCon = {};
// Writes to the console using the specified color. This overrides the default color setting // Writes to the console using the specified color. This overrides the default color setting
// for this log. // 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); ConsoleColorScope cs(color);
DoWrite( pxsFmtV(fmt,list).c_str() ); DoWrite(pxsFmtV(fmt, list).c_str());
return false; 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); ConsoleColorScope cs(color);
DoWrite( pxsFmtV(fmt,list).c_str() ); DoWrite(pxsFmtV(fmt, list).c_str());
return false; return false;
} }
// Writes to the console using the source's default color. Note that the source's default // 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 // color will always be used, thus ConsoleColorScope() will not be effectual unless the
// console's default color is Color_Default. // 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 ); WriteV(DefaultColor, fmt, list);
return false; 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 ); WriteV(DefaultColor, fmt, list);
return false; return false;
} }

View File

@ -24,7 +24,7 @@
#include <mach/mach_time.h> #include <mach/mach_time.h>
#define NELEM(x) \ #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 // 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 // the OS because of its BSD/Mach heritage. Helpfully, most of this code
@ -47,7 +47,7 @@ u64 GetPhysicalMemory()
if (__atomic_load_n(&mem, __ATOMIC_SEQ_CST) == 0) { if (__atomic_load_n(&mem, __ATOMIC_SEQ_CST) == 0) {
u64 getmem = 0; u64 getmem = 0;
size_t len = sizeof(getmem); size_t len = sizeof(getmem);
int mib[] = { CTL_HW, HW_MEMSIZE }; int mib[] = {CTL_HW, HW_MEMSIZE};
if (sysctl(mib, NELEM(mib), &getmem, &len, NULL, 0) < 0) { if (sysctl(mib, NELEM(mib), &getmem, &len, NULL, 0) < 0) {
perror("sysctl:"); perror("sysctl:");
} }
@ -87,7 +87,7 @@ u64 GetTickFrequency()
} }
// store the calculated value atomically // store the calculated value atomically
__atomic_store_n(&freq, (u64) 1e9 * (u64) info.denom / (u64) info.numer, __ATOMIC_SEQ_CST); __atomic_store_n(&freq, (u64)1e9 * (u64)info.denom / (u64)info.numer, __ATOMIC_SEQ_CST);
} }
return freq; return freq;
@ -115,7 +115,7 @@ wxString GetOSVersionString()
#define SYSCTL_GET(var, base, name) \ #define SYSCTL_GET(var, base, name) \
do { \ do { \
int mib[] = { base, name }; \ int mib[] = {base, name}; \
size_t len = sizeof(var); \ size_t len = sizeof(var); \
sysctl(mib, NELEM(mib), NULL, &len, NULL, 0); \ sysctl(mib, NELEM(mib), NULL, &len, NULL, 0); \
sysctl(mib, NELEM(mib), var, &len, NULL, 0); \ sysctl(mib, NELEM(mib), var, &len, NULL, 0); \

View File

@ -66,14 +66,14 @@ Threading::Semaphore::Semaphore()
Threading::Semaphore::~Semaphore() throw() Threading::Semaphore::~Semaphore() throw()
{ {
MACH_CHECK(semaphore_destroy(mach_task_self(), (semaphore_t) m_sema)); MACH_CHECK(semaphore_destroy(mach_task_self(), (semaphore_t)m_sema));
__atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST); __atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST);
} }
void Threading::Semaphore::Reset() void Threading::Semaphore::Reset()
{ {
MACH_CHECK(semaphore_destroy(mach_task_self(), (semaphore_t) m_sema)); 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)); MACH_CHECK(semaphore_create(mach_task_self(), (semaphore_t *)&m_sema, SYNC_POLICY_FIFO, 0));
__atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST); __atomic_store_n(&m_counter, 0, __ATOMIC_SEQ_CST);
} }
@ -98,7 +98,7 @@ void Threading::Semaphore::WaitWithoutYield()
__atomic_sub_fetch(&m_counter, 1, __ATOMIC_SEQ_CST); __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 // This method is the reason why there has to be a special Darwin
// implementation of Semaphore. Note that semaphore_timedwait() is prone // implementation of Semaphore. Note that semaphore_timedwait() is prone
@ -155,14 +155,12 @@ bool Threading::Semaphore::WaitWithoutYield(const wxTimeSpan& timeout)
void Threading::Semaphore::Wait() void Threading::Semaphore::Wait()
{ {
#if wxUSE_GUI #if wxUSE_GUI
if(!wxThread::IsMain() || (wxTheApp == NULL)) { if (!wxThread::IsMain() || (wxTheApp == NULL)) {
WaitWithoutYield(); WaitWithoutYield();
} } else if (_WaitGui_RecursionGuard(L"Semaphore::Wait")) {
else if(_WaitGui_RecursionGuard( L"Semaphore::Wait" )) { ScopedBusyCursor hourglass(Cursor_ReallyBusy);
ScopedBusyCursor hourglass( Cursor_ReallyBusy );
WaitWithoutYield(); WaitWithoutYield();
} } else {
else {
while (!WaitWithoutYield(def_yieldgui_interval)) { while (!WaitWithoutYield(def_yieldgui_interval)) {
YieldToMain(); YieldToMain();
} }
@ -181,22 +179,21 @@ void Threading::Semaphore::Wait()
// false if the wait timed out before the semaphore was signaled, or true if the signal was // false if the wait timed out before the semaphore was signaled, or true if the signal was
// reached prior to timeout. // reached prior to timeout.
// //
bool Threading::Semaphore::Wait(const wxTimeSpan& timeout) bool Threading::Semaphore::Wait(const wxTimeSpan &timeout)
{ {
#if wxUSE_GUI #if wxUSE_GUI
if(!wxThread::IsMain() || (wxTheApp == NULL)) { if (!wxThread::IsMain() || (wxTheApp == NULL)) {
return WaitWithoutYield(timeout); return WaitWithoutYield(timeout);
} } else if (_WaitGui_RecursionGuard(L"Semaphore::TimedWait")) {
else if (_WaitGui_RecursionGuard( L"Semaphore::TimedWait")) {
ScopedBusyCursor hourglass(Cursor_ReallyBusy); ScopedBusyCursor hourglass(Cursor_ReallyBusy);
return WaitWithoutYield(timeout); return WaitWithoutYield(timeout);
} } else {
else {
//ScopedBusyCursor hourglass( Cursor_KindaBusy ); //ScopedBusyCursor hourglass( Cursor_KindaBusy );
wxTimeSpan countdown((timeout)); wxTimeSpan countdown((timeout));
do { do {
if (WaitWithoutYield(def_yieldgui_interval)) break; if (WaitWithoutYield(def_yieldgui_interval))
break;
YieldToMain(); YieldToMain();
countdown -= def_yieldgui_interval; countdown -= def_yieldgui_interval;
} while (countdown.GetMilliseconds() > 0); } while (countdown.GetMilliseconds() > 0);
@ -229,7 +226,7 @@ void Threading::Semaphore::WaitNoCancel()
pthread_setcancelstate(oldstate, NULL); pthread_setcancelstate(oldstate, NULL);
} }
void Threading::Semaphore::WaitNoCancel(const wxTimeSpan& timeout) void Threading::Semaphore::WaitNoCancel(const wxTimeSpan &timeout)
{ {
int oldstate; int oldstate;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);

View File

@ -19,7 +19,7 @@
#include <unistd.h> #include <unistd.h>
#if !defined(__APPLE__) #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 #else
#include <mach/mach_init.h> #include <mach/mach_init.h>
@ -30,7 +30,7 @@
// the LOCK prefix. The prefix works on single core CPUs fine (but is slow), but not // the LOCK prefix. The prefix works on single core CPUs fine (but is slow), but not
// having the LOCK prefix is very bad indeed. // 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);
} }
@ -41,7 +41,7 @@ __forceinline void Threading::SpinWait()
{ {
// If this doesn't compile you can just comment it out (it only serves as a // If this doesn't compile you can just comment it out (it only serves as a
// performance hint and isn't required). // performance hint and isn't required).
__asm__ ( "pause" ); __asm__("pause");
} }
__forceinline void Threading::EnableHiresScheduler() __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 // gets the CPU time used by the current thread (both system and user), in
// microseconds, returns 0 on failure // 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; mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
thread_basic_info_data_t info; thread_basic_info_data_t info;
kern_return_t kr = thread_info(thread, THREAD_BASIC_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) { if (kr != KERN_SUCCESS) {
return 0; return 0;
} }
// add system and user time // add system and user time
return (u64) info.user_time.seconds * (u64) 1e6 + return (u64)info.user_time.seconds * (u64)1e6 +
(u64) info.user_time.microseconds + (u64)info.user_time.microseconds +
(u64) info.system_time.seconds * (u64) 1e6 + (u64)info.system_time.seconds * (u64)1e6 +
(u64) info.system_time.microseconds; (u64)info.system_time.microseconds;
} }
// Returns the current timestamp (not relative to a real world clock) in // Returns the current timestamp (not relative to a real world clock) in
@ -109,19 +110,19 @@ u64 Threading::pxThread::GetCpuTime() const
return 0; 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() 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() void Threading::pxThread::_platform_specific_OnCleanupInThread()
{ {
// cleanup of handles that were upened in // cleanup of handles that were upened in
// _platform_specific_OnStartInThread // _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 // name can be up to 16 bytes

View File

@ -43,34 +43,34 @@ Fnptr_OutOfMemory pxDoOutOfMemory = NULL;
// const false). // const false).
// //
#ifdef PCSX2_DEVBUILD #ifdef PCSX2_DEVBUILD
# define DEVASSERT_INLINE __noinline #define DEVASSERT_INLINE __noinline
#else #else
# define DEVASSERT_INLINE __fi #define DEVASSERT_INLINE __fi
#endif #endif
// Using a threadlocal assertion guard. Separate threads can assert at the same time. // 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. // 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 // make life easier for people using VC++ IDE by using this format, which allows double-click
// response times from the Output window... // 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 ) if (function != NULL)
message.Write( " Function: %s\n", function ); 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 ) if (condition != NULL)
message.Write(L" Condition: %ls\n", condition); message.Write(L" Condition: %ls\n", condition);
if( msg != NULL ) if (msg != NULL)
message.Write(L" Message: %ls\n", msg); message.Write(L" Message: %ls\n", msg);
return message; return message;
@ -83,37 +83,39 @@ void pxTrap()
#if defined(__WXMSW__) && !defined(__WXMICROWIN__) #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
__debugbreak(); __debugbreak();
#elif defined(__WXMAC__) && !defined(__DARWIN__) #elif defined(__WXMAC__) && !defined(__DARWIN__)
#if __powerc #if __powerc
Debugger(); Debugger();
#else #else
SysBreak(); SysBreak();
#endif #endif
#elif defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS #elif defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
Debugger(); Debugger();
#elif defined(__UNIX__) #elif defined(__UNIX__)
raise(SIGTRAP); raise(SIGTRAP);
#else #else
// TODO // TODO
#endif // Win/Unix #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() ); //wxLogError( L"%s", origin.ToString( msg ).c_str() );
wxMessageOutputDebug().Printf( L"%s", origin.ToString( msg ).c_str() ); wxMessageOutputDebug().Printf(L"%s", origin.ToString(msg).c_str());
pxTrap(); pxTrap();
return false; 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 // 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. // we get meaningless assertions while unwinding stack traces after exceptions have occurred.
RecursionGuard guard( s_assert_guard ); RecursionGuard guard(s_assert_guard);
if (guard.Counter > 2) { return pxTrap(); } if (guard.Counter > 2) {
return pxTrap();
}
// wxWidgets doesn't come with debug builds on some Linux distros, and other distros make // 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 // it difficult to use the debug build (compilation failures). To handle these I've had to
@ -122,32 +124,31 @@ DEVASSERT_INLINE void pxOnAssert( const DiagnosticOrigin& origin, const wxChar*
bool trapit; bool trapit;
if( pxDoAssert == NULL ) if (pxDoAssert == NULL) {
{
// Note: Format uses MSVC's syntax for output window hotlinking. // Note: Format uses MSVC's syntax for output window hotlinking.
trapit = pxAssertImpl_LogIt( origin, msg ); trapit = pxAssertImpl_LogIt(origin, msg);
} } else {
else trapit = pxDoAssert(origin, msg);
{
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,19 +157,19 @@ __fi void pxOnAssert( const DiagnosticOrigin& origin, const FastFormatUnicode& m
BaseException::~BaseException() throw() {} 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(""); m_message_user = msg_diag ? wxString(wxGetTranslation(msg_diag)) : wxString("");
return SetDiagMsg( msg_diag ); return SetDiagMsg(msg_diag);
} }
BaseException& BaseException::SetDiagMsg( const wxString& msg_diag ) BaseException &BaseException::SetDiagMsg(const wxString &msg_diag)
{ {
m_message_diag = msg_diag; m_message_diag = msg_diag;
return *this; return *this;
} }
BaseException& BaseException::SetUserMsg( const wxString& msg_user ) BaseException &BaseException::SetUserMsg(const wxString &msg_user)
{ {
m_message_user = msg_user; m_message_user = msg_user;
return *this; return *this;
@ -187,30 +188,28 @@ wxString BaseException::FormatDisplayMessage() const
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// Exception::RuntimeError (implementations) // 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", SetDiagMsg(pxsFmt(L"STL Runtime Error%s: %s",
(prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()), (prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()),
WX_STR(fromUTF8( ex.what() )) 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", SetDiagMsg(pxsFmt(L"STL Exception%s: %s",
(prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()), (prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()),
WX_STR(fromUTF8( ex.what() )) WX_STR(fromUTF8(ex.what()))));
) );
} }
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// Exception::OutOfMemory (implementations) // Exception::OutOfMemory (implementations)
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
Exception::OutOfMemory::OutOfMemory( const wxString& allocdesc ) Exception::OutOfMemory::OutOfMemory(const wxString &allocdesc)
{ {
AllocDescription = allocdesc; AllocDescription = allocdesc;
} }
@ -231,7 +230,7 @@ wxString Exception::OutOfMemory::FormatDiagnosticMessage() const
wxString Exception::OutOfMemory::FormatDisplayMessage() const wxString Exception::OutOfMemory::FormatDisplayMessage() const
{ {
FastFormatUnicode retmsg; FastFormatUnicode retmsg;
retmsg.Write( L"%s", _("Oh noes! Out of memory!") ); retmsg.Write(L"%s", _("Oh noes! Out of memory!"));
if (!m_message_user.IsEmpty()) if (!m_message_user.IsEmpty())
retmsg.Write(L"\n\n%s", WX_STR(m_message_user)); retmsg.Write(L"\n\n%s", WX_STR(m_message_user));
@ -243,7 +242,7 @@ wxString Exception::OutOfMemory::FormatDisplayMessage() const
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// Exception::VirtualMemoryMapConflict (implementations) // Exception::VirtualMemoryMapConflict (implementations)
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
Exception::VirtualMemoryMapConflict::VirtualMemoryMapConflict( const wxString& allocdesc ) Exception::VirtualMemoryMapConflict::VirtualMemoryMapConflict(const wxString &allocdesc)
{ {
AllocDescription = 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."); 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.");
@ -265,10 +264,8 @@ wxString Exception::VirtualMemoryMapConflict::FormatDiagnosticMessage() const
wxString Exception::VirtualMemoryMapConflict::FormatDisplayMessage() const wxString Exception::VirtualMemoryMapConflict::FormatDisplayMessage() const
{ {
FastFormatUnicode retmsg; FastFormatUnicode retmsg;
retmsg.Write( L"%s", 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." 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()) if (!m_message_diag.IsEmpty())
retmsg.Write(L"\n\n%s", WX_STR(m_message_diag)); retmsg.Write(L"\n\n%s", WX_STR(m_message_diag));
@ -305,25 +302,25 @@ wxString Exception::BadStream::FormatDisplayMessage() const
return retval; return retval;
} }
void Exception::BadStream::_formatDiagMsg( FastFormatUnicode& dest ) const void Exception::BadStream::_formatDiagMsg(FastFormatUnicode &dest) const
{ {
dest.Write( L"Path: " ); dest.Write(L"Path: ");
if (!StreamName.IsEmpty()) if (!StreamName.IsEmpty())
dest.Write( L"%s", WX_STR(StreamName) ); dest.Write(L"%s", WX_STR(StreamName));
else else
dest.Write( L"[Unnamed or unknown]" ); dest.Write(L"[Unnamed or unknown]");
if (!m_message_diag.IsEmpty()) if (!m_message_diag.IsEmpty())
dest.Write(L"\n%s", WX_STR(m_message_diag)); 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: ") ); dest.Write(_("Path: "));
if (!StreamName.IsEmpty()) if (!StreamName.IsEmpty())
dest.Write( L"%s", WX_STR(StreamName) ); dest.Write(L"%s", WX_STR(StreamName));
else else
dest.Write( _("[Unnamed or unknown]") ); dest.Write(_("[Unnamed or unknown]"));
if (!m_message_user.IsEmpty()) if (!m_message_user.IsEmpty())
dest.Write(L"\n%s", WX_STR(m_message_user)); dest.Write(L"\n%s", WX_STR(m_message_user));
@ -415,35 +412,34 @@ wxString Exception::EndOfStream::FormatDisplayMessage() const
// Translates an Errno code into an exception. // Translates an Errno code into an exception.
// Throws an exception based on the given error code (usually taken from ANSI C's errno) // 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 ) switch (errcode) {
{
case EINVAL: case EINVAL:
pxFailDev( L"Invalid argument" ); pxFailDev(L"Invalid argument");
return &(new Exception::BadStream( streamname ))->SetDiagMsg(L"Invalid argument? (likely caused by an unforgivable programmer error!)" ); return &(new Exception::BadStream(streamname))->SetDiagMsg(L"Invalid argument? (likely caused by an unforgivable programmer error!)");
case EACCES: // Access denied! case EACCES: // Access denied!
return new Exception::AccessDenied( streamname ); return new Exception::AccessDenied(streamname);
case EMFILE: // Too many open files! case EMFILE: // Too many open files!
return &(new Exception::CannotCreateStream( streamname ))->SetDiagMsg(L"Too many open files"); // File handle allocation failure return &(new Exception::CannotCreateStream(streamname))->SetDiagMsg(L"Too many open files"); // File handle allocation failure
case EEXIST: case EEXIST:
return &(new Exception::CannotCreateStream( streamname ))->SetDiagMsg(L"File already exists"); return &(new Exception::CannotCreateStream(streamname))->SetDiagMsg(L"File already exists");
case ENOENT: // File not found! case ENOENT: // File not found!
return new Exception::FileNotFound( streamname ); return new Exception::FileNotFound(streamname);
case EPIPE: case EPIPE:
return &(new Exception::BadStream( streamname ))->SetDiagMsg(L"Broken pipe"); return &(new Exception::BadStream(streamname))->SetDiagMsg(L"Broken pipe");
case EBADF: case EBADF:
return &(new Exception::BadStream( streamname ))->SetDiagMsg(L"Bad file number"); return &(new Exception::BadStream(streamname))->SetDiagMsg(L"Bad file number");
default: default:
return &(new Exception::BadStream( streamname ))->SetDiagMsg(pxsFmt( L"General file/stream error [errno: %d]", errcode )); return &(new Exception::BadStream(streamname))->SetDiagMsg(pxsFmt(L"General file/stream error [errno: %d]", errcode));
} }
} }

View File

@ -24,9 +24,9 @@ template class SafeArray<char>;
template class SafeArray<wchar_t>; template class SafeArray<wchar_t>;
template class SafeArray<u8>; template class SafeArray<u8>;
template class SafeAlignedArray<char,16>; template class SafeAlignedArray<char, 16>;
template class SafeAlignedArray<wchar_t,16>; template class SafeAlignedArray<wchar_t, 16>;
template class SafeAlignedArray<u8,16>; template class SafeAlignedArray<u8, 16>;
// Sanity check: truncate strings if they exceed 512k in length. Anything like that // 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 // is either a bug or really horrible code that needs to be stopped before it causes
@ -35,36 +35,38 @@ static const int MaxFormattedStringLength = 0x80000;
static static
#ifndef __linux__ #ifndef __linux__
__ri __ri
#endif #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; va_list args;
while( true ) while (true) {
{
int size = buffer.GetLength(); int size = buffer.GetLength();
va_copy(args, argptr); va_copy(args, argptr);
int len = vsnprintf(buffer.GetPtr(writepos), size-writepos, fmt, args); int len = vsnprintf(buffer.GetPtr(writepos), size - writepos, fmt, args);
va_end(args); va_end(args);
// some implementations of vsnprintf() don't NUL terminate // some implementations of vsnprintf() don't NUL terminate
// the string if there is not enough space for it so // the string if there is not enough space for it so
// always do it manually // always do it manually
buffer[size-1] = '\0'; buffer[size - 1] = '\0';
if (size >= MaxFormattedStringLength) break; if (size >= MaxFormattedStringLength)
break;
// vsnprintf() may return either -1 (traditional Unix behavior) or the // vsnprintf() may return either -1 (traditional Unix behavior) or the
// total number of characters which would have been written if the // total number of characters which would have been written if the
// buffer were large enough (newer standards such as Unix98) // buffer were large enough (newer standards such as Unix98)
if (len < 0) if (len < 0)
len = size + (size/4); len = size + (size / 4);
len += writepos; len += writepos;
if (len < size) break; if (len < size)
buffer.Resize( len + 128 ); break;
buffer.Resize(len + 128);
}; };
// performing an assertion or log of a truncated string is unsafe, so let's not; even // performing an assertion or log of a truncated string is unsafe, so let's not; even
@ -74,42 +76,44 @@ void format_that_ascii_mess( CharBufferType& buffer, uint writepos, const char*
// returns the length of the formatted string, in characters (wxChars). // returns the length of the formatted string, in characters (wxChars).
static static
#ifndef __linux__ #ifndef __linux__
__ri __ri
#endif #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; va_list args;
while( true ) while (true) {
{
int size = buffer.GetLength() / sizeof(wxChar); int size = buffer.GetLength() / sizeof(wxChar);
va_copy(args, argptr); va_copy(args, argptr);
int len = wxVsnprintf((wxChar*)buffer.GetPtr(writepos*sizeof(wxChar)), size-writepos, fmt, args); int len = wxVsnprintf((wxChar *)buffer.GetPtr(writepos * sizeof(wxChar)), size - writepos, fmt, args);
va_end(args); va_end(args);
// some implementations of vsnprintf() don't NUL terminate // some implementations of vsnprintf() don't NUL terminate
// the string if there is not enough space for it so // the string if there is not enough space for it so
// always do it manually // always do it manually
((wxChar*)buffer.GetPtr())[size-1] = L'\0'; ((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 // vsnprintf() may return either -1 (traditional Unix behavior) or the
// total number of characters which would have been written if the // total number of characters which would have been written if the
// buffer were large enough (newer standards such as Unix98) // buffer were large enough (newer standards such as Unix98)
if (len < 0) if (len < 0)
len = size + (size/4); len = size + (size / 4);
len += writepos; len += writepos;
if (len < size) return len; if (len < size)
buffer.Resize( (len + 128) * sizeof(wxChar) ); return len;
buffer.Resize((len + 128) * sizeof(wxChar));
}; };
// performing an assertion or log of a truncated string is unsafe, so let's not; even // 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. // though it'd be kinda nice if we did.
pxAssume( false ); pxAssume(false);
return 0; // unreachable. return 0; // unreachable.
} }
@ -135,112 +139,112 @@ FastFormatUnicode::~FastFormatUnicode() throw()
void FastFormatUnicode::Clear() void FastFormatUnicode::Clear()
{ {
m_Length = 0; m_Length = 0;
((wxChar*)m_dest.GetPtr())[0] = 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 inspos = m_Length;
const uint convLen = converted.Length(); const uint convLen = converted.Length();
m_dest.MakeRoomFor((inspos + convLen + 64) * sizeof(wxChar)); m_dest.MakeRoomFor((inspos + convLen + 64) * sizeof(wxChar));
memcpy( &((wxChar*)m_dest.GetPtr())[inspos], converted.wc_str(), (convLen+1)*sizeof(wxChar) ); memcpy(&((wxChar *)m_dest.GetPtr())[inspos], converted.wc_str(), (convLen + 1) * sizeof(wxChar));
m_Length += convLen; 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 ); m_Length = format_that_unicode_mess(m_dest, m_Length, fmt, argptr);
return *this; return *this;
} }
FastFormatUnicode& FastFormatUnicode::Write( const char* fmt, ... ) FastFormatUnicode &FastFormatUnicode::Write(const char *fmt, ...)
{ {
va_list list; va_list list;
va_start(list, fmt); va_start(list, fmt);
WriteV(fmt,list); WriteV(fmt, list);
va_end(list); va_end(list);
return *this; return *this;
} }
FastFormatUnicode& FastFormatUnicode::Write( const wxChar* fmt, ... ) FastFormatUnicode &FastFormatUnicode::Write(const wxChar *fmt, ...)
{ {
va_list list; va_list list;
va_start(list, fmt); va_start(list, fmt);
WriteV(fmt,list); WriteV(fmt, list);
va_end(list); va_end(list);
return *this; return *this;
} }
FastFormatUnicode& FastFormatUnicode::Write( const wxString fmt, ... ) FastFormatUnicode &FastFormatUnicode::Write(const wxString fmt, ...)
{ {
va_list list; va_list list;
va_start(list, fmt); va_start(list, fmt);
WriteV(fmt.wx_str(),list); WriteV(fmt.wx_str(), list);
va_end(list); va_end(list);
return *this; return *this;
} }
bool FastFormatUnicode::IsEmpty() const 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(); wxChar *ch = (wxChar *)m_dest.GetPtr();
for ( uint i=0; i<m_Length; ++i, ++ch ) for (uint i = 0; i < m_Length; ++i, ++ch)
*ch = (wxChar)wxToupper(*ch); *ch = (wxChar)wxToupper(*ch);
return *this; return *this;
} }
FastFormatUnicode& FastFormatUnicode::ToLower() FastFormatUnicode &FastFormatUnicode::ToLower()
{ {
wxChar* ch = (wxChar*)m_dest.GetPtr(); wxChar *ch = (wxChar *)m_dest.GetPtr();
for ( uint i=0; i<m_Length; ++i, ++ch ) for (uint i = 0; i < m_Length; ++i, ++ch)
*ch = (wxChar)wxTolower(*ch); *ch = (wxChar)wxTolower(*ch);
return *this; return *this;
} }
FastFormatUnicode& FastFormatUnicode::operator+=(const char* psz ) FastFormatUnicode &FastFormatUnicode::operator+=(const char *psz)
{ {
Write( L"%s", WX_STR(fromUTF8(psz)) ); Write(L"%s", WX_STR(fromUTF8(psz)));
return *this; return *this;
} }
wxString& operator+=(wxString& str1, const FastFormatUnicode& str2) wxString &operator+=(wxString &str1, const FastFormatUnicode &str2)
{ {
str1.Append(str2.c_str(), str2.Length()); str1.Append(str2.c_str(), str2.Length());
return str1; return str1;
} }
wxString operator+(const wxString& str1, const FastFormatUnicode& str2) wxString operator+(const wxString &str1, const FastFormatUnicode &str2)
{ {
wxString s = str1; wxString s = str1;
s += str2; s += str2;
return s; return s;
} }
wxString operator+(const wxChar* str1, const FastFormatUnicode& str2) wxString operator+(const wxChar *str1, const FastFormatUnicode &str2)
{ {
wxString s = str1; wxString s = str1;
s += str2; s += str2;
return s; return s;
} }
wxString operator+(const FastFormatUnicode& str1, const wxString& str2) wxString operator+(const FastFormatUnicode &str1, const wxString &str2)
{ {
wxString s = str1; wxString s = str1;
s += str2; s += str2;
return s; return s;
} }
wxString operator+(const FastFormatUnicode& str1, const wxChar* str2) wxString operator+(const FastFormatUnicode &str1, const wxChar *str2)
{ {
wxString s = str1; wxString s = str1;
s += str2; s += str2;
@ -271,17 +275,17 @@ const wxString FastFormatAscii::GetString() const
return fromAscii(m_dest.GetPtr()); return fromAscii(m_dest.GetPtr());
} }
FastFormatAscii& FastFormatAscii::WriteV( const char* fmt, va_list argptr ) FastFormatAscii &FastFormatAscii::WriteV(const char *fmt, va_list argptr)
{ {
format_that_ascii_mess( m_dest, strlen(m_dest.GetPtr()), fmt, argptr ); format_that_ascii_mess(m_dest, strlen(m_dest.GetPtr()), fmt, argptr);
return *this; return *this;
} }
FastFormatAscii& FastFormatAscii::Write( const char* fmt, ... ) FastFormatAscii &FastFormatAscii::Write(const char *fmt, ...)
{ {
va_list list; va_list list;
va_start(list, fmt); va_start(list, fmt);
WriteV(fmt,list); WriteV(fmt, list);
va_end(list); va_end(list);
return *this; return *this;
} }

View File

@ -16,9 +16,10 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "HashMap.h" #include "HashMap.h"
namespace HashTools { namespace HashTools
{
#define get16bits(d) (*((const u16 *) (d))) #define get16bits(d) (*((const u16 *)(d)))
/// <summary> /// <summary>
/// Calculates a hash value for an arbitrary set of binary data. /// Calculates a hash value for an arbitrary set of binary data.
@ -52,39 +53,41 @@ namespace HashTools {
/// uint32 hashval = Hash( (const char*)&data, sizeof( data ) ); /// uint32 hashval = Hash( (const char*)&data, sizeof( data ) );
/// </code> /// </code>
/// </example> /// </example>
u32 Hash(const s8 * data, int len) u32 Hash(const s8 *data, int len)
{ {
u32 hash = len; u32 hash = len;
int rem; int rem;
if (len <= 0 || data == NULL) return 0; if (len <= 0 || data == NULL)
return 0;
rem = len & 3; rem = len & 3;
len >>= 2; len >>= 2;
/* Main loop */ /* Main loop */
for (;len > 0; --len) for (; len > 0; --len) {
{ hash += get16bits(data);
hash += get16bits (data); u32 tmp = (get16bits(data + 2) << 11) ^ hash;
u32 tmp = (get16bits (data+2) << 11) ^ hash;
hash = (hash << 16) ^ tmp; hash = (hash << 16) ^ tmp;
data += 2*sizeof (u16); data += 2 * sizeof(u16);
hash += hash >> 11; hash += hash >> 11;
} }
/* Handle end cases */ /* Handle end cases */
switch (rem) switch (rem) {
{ case 3:
case 3: hash += get16bits (data); hash += get16bits(data);
hash ^= hash << 16; hash ^= hash << 16;
hash ^= data[sizeof (u16)] << 18; hash ^= data[sizeof(u16)] << 18;
hash += hash >> 11; hash += hash >> 11;
break; break;
case 2: hash += get16bits (data); case 2:
hash += get16bits(data);
hash ^= hash << 11; hash ^= hash << 11;
hash += hash >> 17; hash += hash >> 17;
break; break;
case 1: hash += *data; case 1:
hash += *data;
hash ^= hash << 10; hash ^= hash << 10;
hash += hash >> 1; hash += hash >> 1;
} }

View File

@ -18,7 +18,7 @@
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
const wxRect wxDefaultRect( wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord ); const wxRect wxDefaultRect(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord);
// Implement FixedPointTypes (for lack of a better location, for now) // Implement FixedPointTypes (for lack of a better location, for now)
@ -27,16 +27,15 @@ template struct FixedInt<100>;
template struct FixedInt<256>; template struct FixedInt<256>;
wxDirName g_fullBaseDirName = wxDirName(L""); 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; int cnt = 0;
while( *enumArray != NULL ) while (*enumArray != NULL) {
{
enumArray++; enumArray++;
cnt++; cnt++;
} }
@ -44,34 +43,34 @@ static int _calcEnumLength( const wxChar* const* enumArray )
return cnt; return cnt;
} }
ScopedIniGroup::ScopedIniGroup( IniInterface& mommy, const wxString& group ) ScopedIniGroup::ScopedIniGroup(IniInterface &mommy, const wxString &group)
: m_mom( mommy ) : m_mom(mommy)
{ {
pxAssertDev( wxStringTokenize( group, L"/" ).Count() <= 1, L"Cannot nest more than one group deep per instance of ScopedIniGroup." ); pxAssertDev(wxStringTokenize(group, L"/").Count() <= 1, L"Cannot nest more than one group deep per instance of ScopedIniGroup.");
m_mom.SetPath( group ); m_mom.SetPath(group);
} }
ScopedIniGroup::~ScopedIniGroup() ScopedIniGroup::~ScopedIniGroup()
{ {
m_mom.SetPath( L".." ); m_mom.SetPath(L"..");
} }
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// IniInterface (implementations) // 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() IniInterface::IniInterface()
{ {
m_Config = wxConfigBase::Get( false ); m_Config = wxConfigBase::Get(false);
} }
IniInterface::~IniInterface() IniInterface::~IniInterface()
@ -79,178 +78,188 @@ 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() void IniInterface::Flush()
{ {
if( m_Config ) m_Config->Flush(); if (m_Config)
m_Config->Flush();
} }
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// IniLoader (implementations) // IniLoader (implementations)
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
IniLoader::IniLoader( wxConfigBase& config ) : IniInterface( config ) { } IniLoader::IniLoader(wxConfigBase &config)
IniLoader::IniLoader( wxConfigBase* config ) : IniInterface( config ) { } : IniInterface(config)
{
}
IniLoader::IniLoader(wxConfigBase *config)
: IniInterface(config)
{
}
IniLoader::IniLoader() : IniInterface() {} IniLoader::IniLoader()
: IniInterface()
{
}
IniLoader::~IniLoader() throw() {} 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 ) if (m_Config)
m_Config->Read( var, &value, defvalue ); m_Config->Read(var, &value, defvalue);
else else
value = defvalue; 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; wxString dest;
if( m_Config ) m_Config->Read( var, &dest, wxEmptyString ); if (m_Config)
m_Config->Read(var, &dest, wxEmptyString);
if( dest.IsEmpty() ) if (dest.IsEmpty())
value = defvalue; value = defvalue;
else else {
{
value = dest; value = dest;
if( isAllowRelative ) if (isAllowRelative)
value = g_fullBaseDirName + value; value = g_fullBaseDirName + value;
if( value.IsAbsolute() ) if (value.IsAbsolute())
value.Normalize(); 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() ); wxString dest(defvalue.GetFullPath());
if( m_Config ) m_Config->Read( var, &dest, defvalue.GetFullPath() ); if (m_Config)
m_Config->Read(var, &dest, defvalue.GetFullPath());
value = dest; value = dest;
if( isAllowRelative ) if (isAllowRelative)
value = g_fullBaseDirName + value; value = g_fullBaseDirName + value;
if( value.IsAbsolute() ) if (value.IsAbsolute())
value.Normalize(); value.Normalize();
if (value.HasVolume()) if (value.HasVolume())
value.SetVolume(value.GetVolume().Upper()); 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 ) if (m_Config)
m_Config->Read( var, &value, defvalue ); m_Config->Read(var, &value, defvalue);
else else
value = defvalue; 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 ) if (m_Config)
m_Config->Read( var, (int*)&value, (int)defvalue ); m_Config->Read(var, (int *)&value, (int)defvalue);
else else
value = defvalue; 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? // TODO : Stricter value checking on enabled/disabled?
wxString dest(defvalue ? L"enabled" : L"disabled"); wxString dest(defvalue ? L"enabled" : L"disabled");
if( m_Config ) m_Config->Read( var, &dest, dest ); if (m_Config)
m_Config->Read(var, &dest, dest);
value = (dest == L"enabled") || (dest == L"1"); 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. // Note: 'value' param is used by inisaver only.
bool result; bool result;
Entry( var, result, defvalue ); Entry(var, result, defvalue);
return result; 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; int result;
Entry( var, result, defvalue ); Entry(var, result, defvalue);
return result; 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 // 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.. >_< // has way too much rounding error so we really need to do things out manually.. >_<
wxString readval( value.ToString() ); wxString readval(value.ToString());
if( m_Config ) m_Config->Read( var, &readval ); if (m_Config)
value = Fixed100::FromString( readval, value ); 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 ) if (!m_Config) {
{ value = defvalue;
value = defvalue; return; return;
} }
TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue ); 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 ) if (!m_Config) {
{ value = defvalue;
value = defvalue; return; return;
} }
TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue ); 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 ) if (!m_Config) {
{ value = defvalue;
value = defvalue; return; return;
} }
TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue ); 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 ); const int cnt = _calcEnumLength(enumArray);
if( !IndexBoundsCheck( L"IniLoader EnumDefaultValue", defvalue, cnt ) ) if (!IndexBoundsCheck(L"IniLoader EnumDefaultValue", defvalue, cnt)) {
{ Console.Error("(LoadSettings) Default enumeration index is out of bounds. Truncating.");
Console.Error( "(LoadSettings) Default enumeration index is out of bounds. Truncating." ); defvalue = cnt - 1;
defvalue = cnt-1;
} }
// Sanity confirmed, proceed with craziness! // Sanity confirmed, proceed with craziness!
if( !m_Config ) if (!m_Config) {
{
value = defvalue; value = defvalue;
return; return;
} }
wxString retval; wxString retval;
m_Config->Read( var, &retval, enumArray[defvalue] ); m_Config->Read(var, &retval, enumArray[defvalue]);
int i=0; int i = 0;
while( enumArray[i] != NULL && ( retval != enumArray[i] ) ) i++; while (enumArray[i] != NULL && (retval != enumArray[i]))
i++;
if( enumArray[i] == NULL ) if (enumArray[i] == NULL) {
{ Console.Warning(L"(LoadSettings) Warning: Unrecognized value '%s' on key '%s'\n\tUsing the default setting of '%s'.",
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]);
WX_STR(retval), WX_STR(var), enumArray[defvalue]
);
value = defvalue; value = defvalue;
} } else
else
value = i; value = i;
} }
@ -258,138 +267,156 @@ void IniLoader::_EnumEntry( const wxString& var, int& value, const wxChar* const
// IniSaver (implementations) // IniSaver (implementations)
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
IniSaver::IniSaver( wxConfigBase& config ) : IniInterface( config ) { } IniSaver::IniSaver(wxConfigBase &config)
IniSaver::IniSaver( wxConfigBase* config ) : IniInterface( config ) { } : IniInterface(config)
{
}
IniSaver::IniSaver() : IniInterface() {} IniSaver::IniSaver(wxConfigBase *config)
IniSaver::~IniSaver() {} : IniInterface(config)
void IniSaver::Entry( const wxString& var, wxString& value, const wxString defvalue )
{ {
if( !m_Config ) return;
m_Config->Write( var, value );
} }
void IniSaver::Entry( const wxString& var, wxDirName& value, const wxDirName defvalue, bool isAllowRelative )
IniSaver::IniSaver()
: IniInterface()
{ {
if( !m_Config ) return; }
IniSaver::~IniSaver() {}
void IniSaver::Entry(const wxString &var, wxString &value, const wxString defvalue)
{
if (!m_Config)
return;
m_Config->Write(var, value);
}
void IniSaver::Entry(const wxString &var, wxDirName &value, const wxDirName defvalue, bool isAllowRelative)
{
if (!m_Config)
return;
wxDirName res(value); wxDirName res(value);
if ( res.IsAbsolute() ) if (res.IsAbsolute())
res.Normalize(); res.Normalize();
if (isAllowRelative) if (isAllowRelative)
res = wxDirName::MakeAutoRelativeTo( res, g_fullBaseDirName.ToString() ); res = wxDirName::MakeAutoRelativeTo(res, g_fullBaseDirName.ToString());
/*if( value == defvalue ) /*if( value == defvalue )
m_Config->Write( var, wxString() ); m_Config->Write( var, wxString() );
else*/ 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; if (!m_Config)
return;
wxFileName res(value); wxFileName res(value);
if ( res.IsAbsolute() ) if (res.IsAbsolute())
res.Normalize(); res.Normalize();
if (isAllowRelative) if (isAllowRelative)
res = wxDirName::MakeAutoRelativeTo( res, g_fullBaseDirName.ToString() ); res = wxDirName::MakeAutoRelativeTo(res, g_fullBaseDirName.ToString());
m_Config->Write( var, res.GetFullPath() ); 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; if (!m_Config)
m_Config->Write( var, value ); 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; if (!m_Config)
m_Config->Write( var, (int)value ); 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; if (!m_Config)
m_Config->Write( var, value ? L"enabled" : L"disabled" ); 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" ); if (m_Config)
m_Config->Write(var, value ? L"enabled" : L"disabled");
return value; 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 ); if (m_Config)
m_Config->Write(var, value);
return 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 // 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. // 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; if (!m_Config)
m_Config->Write( var, ToString( value ) ); 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; if (!m_Config)
m_Config->Write( var, ToString( value ) ); 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; if (!m_Config)
m_Config->Write( var, ToString( value ) ); 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 ) ) if (!IndexBoundsCheck(L"IniSaver EnumDefaultValue", defvalue, cnt)) {
{ Console.Error("(SaveSettings) Default enumeration index is out of bounds. Truncating.");
Console.Error( "(SaveSettings) Default enumeration index is out of bounds. Truncating." ); defvalue = cnt - 1;
defvalue = cnt-1;
} }
if( !m_Config ) return; if (!m_Config)
return;
if( value >= cnt ) if (value >= cnt) {
{ Console.Warning(L"(SaveSettings) An illegal enumerated index was detected when saving '%s'", WX_STR(var));
Console.Warning( L"(SaveSettings) An illegal enumerated index was detected when saving '%s'", WX_STR(var) );
Console.Indent().Warning( Console.Indent().Warning(
L"Illegal Value: %d\n" L"Illegal Value: %d\n"
L"Using Default: %d (%s)\n", L"Using Default: %d (%s)\n",
value, defvalue, enumArray[defvalue] value, defvalue, enumArray[defvalue]);
);
// Cause a debug assertion, since this is a fully recoverable error. // Cause a debug assertion, since this is a fully recoverable error.
pxAssert( value < cnt ); pxAssert(value < cnt);
value = defvalue; value = defvalue;
} }
m_Config->Write( var, enumArray[value] ); m_Config->Write(var, enumArray[value]);
} }

View File

@ -27,15 +27,15 @@
// Apple uses the MAP_ANON define instead of MAP_ANONYMOUS, but they mean // Apple uses the MAP_ANON define instead of MAP_ANONYMOUS, but they mean
// the same thing. // the same thing.
#if defined(__APPLE__) && !defined(MAP_ANONYMOUS) #if defined(__APPLE__) && !defined(MAP_ANONYMOUS)
# define MAP_ANONYMOUS MAP_ANON #define MAP_ANONYMOUS MAP_ANON
#endif #endif
extern void SignalExit(int sig); 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(). // 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. // [TODO] : Add a thread ID filter to the Linux Signal handler here.
// Rationale: On windows, the __try/__except model allows per-thread specific behavior // Rationale: On windows, the __try/__except model allows per-thread specific behavior
@ -59,14 +59,14 @@ static void SysPageFaultSignalFilter( int signal, siginfo_t *siginfo, void * )
// so for now we lock this exception code unless someone can fix this better... // so for now we lock this exception code unless someone can fix this better...
Threading::ScopedLock lock(PageFault_Mutex); 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 // resumes execution right where we left off (re-executes instruction that
// caused the SIGSEGV). // caused the SIGSEGV).
if (Source_PageFault->WasHandled()) return; if (Source_PageFault->WasHandled())
return;
if (!wxThread::IsMain()) if (!wxThread::IsMain()) {
{
pxFailRel(pxsFmt("Unhandled page fault @ 0x%08x", siginfo->si_addr)); pxFailRel(pxsFmt("Unhandled page fault @ 0x%08x", siginfo->si_addr));
} }
@ -74,7 +74,8 @@ static void SysPageFaultSignalFilter( int signal, siginfo_t *siginfo, void * )
// Instigate a trap if we're in a debugger, and if not then do a SIGKILL. // Instigate a trap if we're in a debugger, and if not then do a SIGKILL.
pxTrap(); pxTrap();
if (!IsDebugBuild) raise( SIGKILL ); if (!IsDebugBuild)
raise(SIGKILL);
} }
void _platform_InstallSignalHandler() void _platform_InstallSignalHandler()
@ -88,50 +89,49 @@ void _platform_InstallSignalHandler()
sigaction(SIGSEGV, &sa, NULL); sigaction(SIGSEGV, &sa, NULL);
} }
static __ri void PageSizeAssertionTest( size_t size ) static __ri void PageSizeAssertionTest(size_t size)
{ {
pxAssertMsg( (__pagesize == getpagesize()), pxsFmt( pxAssertMsg((__pagesize == getpagesize()), pxsFmt(
"Internal system error: Operating system pagesize does not match compiled pagesize.\n\t" "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)", L"\tOS Page Size: 0x%x (%d), Compiled Page Size: 0x%x (%u)",
getpagesize(), getpagesize(), __pagesize, __pagesize ) getpagesize(), getpagesize(), __pagesize, __pagesize));
);
pxAssertDev( (size & (__pagesize-1)) == 0, pxsFmt( pxAssertDev((size & (__pagesize - 1)) == 0, pxsFmt(
L"Memory block size must be a multiple of the target platform's page size.\n" 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)", L"\tPage Size: 0x%x (%u), Block Size: 0x%x (%u)",
__pagesize, __pagesize, size, size ) __pagesize, __pagesize, size, size));
);
} }
// returns FALSE if the mprotect call fails with an ENOMEM. // returns FALSE if the mprotect call fails with an ENOMEM.
// Raises assertions on other types of POSIX errors (since those typically reflect invalid object // Raises assertions on other types of POSIX errors (since those typically reflect invalid object
// or memory states). // 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.CanWrite())
if (mode.CanRead()) lnxmode |= PROT_READ; lnxmode |= PROT_WRITE;
if (mode.CanExecute()) lnxmode |= PROT_EXEC | PROT_READ; 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) switch (errno) {
{
case EINVAL: case EINVAL:
pxFailDev(pxsFmt(L"mprotect returned EINVAL @ 0x%08X -> 0x%08X (mode=%s)", pxFailDev(pxsFmt(L"mprotect returned EINVAL @ 0x%08X -> 0x%08X (mode=%s)",
baseaddr, (uptr)baseaddr+size, WX_STR(mode.ToString())) baseaddr, (uptr)baseaddr + size, WX_STR(mode.ToString())));
);
break; break;
case EACCES: case EACCES:
pxFailDev(pxsFmt(L"mprotect returned EACCES @ 0x%08X -> 0x%08X (mode=%s)", pxFailDev(pxsFmt(L"mprotect returned EACCES @ 0x%08X -> 0x%08X (mode=%s)",
baseaddr, (uptr)baseaddr+size, WX_STR(mode.ToString())) baseaddr, (uptr)baseaddr + size, WX_STR(mode.ToString())));
);
break; break;
case ENOMEM: case ENOMEM:
@ -141,7 +141,7 @@ static bool _memprotect( void* baseaddr, size_t size, const PageProtectionMode&
return false; return false;
} }
void* HostSys::MmapReservePtr(void* base, size_t size) void *HostSys::MmapReservePtr(void *base, size_t size)
{ {
PageSizeAssertionTest(size); PageSizeAssertionTest(size);
@ -152,23 +152,26 @@ void* HostSys::MmapReservePtr(void* base, size_t size)
return mmap(base, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 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 // In linux, reserved memory is automatically committed when its permissions are
// changed to something other than PROT_NONE. If the user is committing memory // 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 // 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). // 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; if (!pxDoOutOfMemory)
return false;
pxDoOutOfMemory(size); pxDoOutOfMemory(size);
return _memprotect( base, size, mode ); 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. // 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. // That forces linux to unload all committed pages and start from scratch.
@ -180,52 +183,50 @@ void HostSys::MmapResetPtr(void* base, size_t size)
// pretty well stops all PCSX2 threads anyway). // pretty well stops all PCSX2 threads anyway).
Munmap(base, size); Munmap(base, size);
void* result = MmapReservePtr(base, size); void *result = MmapReservePtr(base, size);
pxAssertRel ((uptr)result == (uptr)base, pxsFmt( pxAssertRel((uptr)result == (uptr)base, pxsFmt(
"Virtual memory decommit failed: memory at 0x%08X -> 0x%08X could not be remapped. " "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 "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) 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) void HostSys::Munmap(uptr base, size_t size)
{ {
if (!base) return; if (!base)
munmap((void*)base, size); 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)) if (!_memprotect(baseaddr, size, mode)) {
{ throw Exception::OutOfMemory(L"MemProtect")
throw Exception::OutOfMemory( L"MemProtect" ) .SetDiagMsg(pxsFmt(L"mprotect failed @ 0x%08X -> 0x%08X (mode=%s)",
.SetDiagMsg(pxsFmt( L"mprotect failed @ 0x%08X -> 0x%08X (mode=%s)", baseaddr, (uptr)baseaddr + size, WX_STR(mode.ToString())));
baseaddr, (uptr)baseaddr+size, WX_STR(mode.ToString())
)
);
} }
} }

View File

@ -47,7 +47,7 @@ u64 GetCPUTicks()
{ {
struct timeval t; struct timeval t;
gettimeofday(&t, NULL); gettimeofday(&t, NULL);
return ((u64)t.tv_sec*GetTickFrequency())+t.tv_usec; return ((u64)t.tv_sec * GetTickFrequency()) + t.tv_usec;
} }
wxString GetOSVersionString() wxString GetOSVersionString()

View File

@ -29,7 +29,7 @@
#if !defined(__unix__) #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 #else
@ -37,9 +37,9 @@
// the LOCK prefix. The prefix works on single core CPUs fine (but is slow), but not // the LOCK prefix. The prefix works on single core CPUs fine (but is slow), but not
// having the LOCK prefix is very bad indeed. // 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 // For use in spin/wait loops, Acts as a hint to Intel CPUs and should, in theory
@ -48,7 +48,7 @@ __forceinline void Threading::SpinWait()
{ {
// If this doesn't compile you can just comment it out (it only serves as a // If this doesn't compile you can just comment it out (it only serves as a
// performance hint and isn't required). // performance hint and isn't required).
__asm__ ( "pause" ); __asm__("pause");
} }
__forceinline void Threading::EnableHiresScheduler() __forceinline void Threading::EnableHiresScheduler()
@ -73,16 +73,18 @@ static u64 get_thread_time(uptr id = 0)
clockid_t cid; clockid_t cid;
if (id) { if (id) {
int err = pthread_getcpuclockid((pthread_t)id, &cid); int err = pthread_getcpuclockid((pthread_t)id, &cid);
if (err) return 0; if (err)
return 0;
} else { } else {
cid = CLOCK_THREAD_CPUTIME_ID; cid = CLOCK_THREAD_CPUTIME_ID;
} }
struct timespec ts; struct timespec ts;
int err = clock_gettime(cid, &ts); int err = clock_gettime(cid, &ts);
if (err) return 0; 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) // Returns the current timestamp (not relative to a real world clock)
@ -98,7 +100,8 @@ u64 Threading::pxThread::GetCpuTime() const
// thread has used on the CPU (scaled by the value returned by GetThreadTicksPerSecond(), // thread has used on the CPU (scaled by the value returned by GetThreadTicksPerSecond(),
// which typically would be an OS-provided scalar or some sort). // 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);
} }
@ -107,7 +110,7 @@ void Threading::pxThread::_platform_specific_OnStartInThread()
{ {
// Obtain linux-specific thread IDs or Handles here, which can be used to query // Obtain linux-specific thread IDs or Handles here, which can be used to query
// kernel scheduler performance information. // kernel scheduler performance information.
m_native_id = (uptr) pthread_self(); m_native_id = (uptr)pthread_self();
} }
void Threading::pxThread::_platform_specific_OnCleanupInThread() void Threading::pxThread::_platform_specific_OnCleanupInThread()
@ -115,7 +118,7 @@ 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__) #if defined(__linux__)
// Extract of manpage: "The name can be up to 16 bytes long, and should be // Extract of manpage: "The name can be up to 16 bytes long, and should be

View File

@ -23,8 +23,8 @@
namespace Threading namespace Threading
{ {
static std::atomic<int> _attr_refcount(0); static std::atomic<int> _attr_refcount(0);
static pthread_mutexattr_t _attr_recursive; static pthread_mutexattr_t _attr_recursive;
} }
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -66,14 +66,15 @@ static int xpthread_mutex_timedlock(
ts.tv_sec = 0; ts.tv_sec = 0;
ts.tv_nsec = TIMEDLOCK_EMU_SLEEP_NS; ts.tv_nsec = TIMEDLOCK_EMU_SLEEP_NS;
int status; int status;
while ((status = nanosleep(&ts, &ts)) == -1); while ((status = nanosleep(&ts, &ts)) == -1)
;
// check if the timeout has expired, gettimeofday() is implemented // check if the timeout has expired, gettimeofday() is implemented
// efficiently (in userspace) on OSX // efficiently (in userspace) on OSX
struct timeval now; struct timeval now;
int res = gettimeofday(&now, NULL); int res = gettimeofday(&now, NULL);
if (abs_timeout->tv_sec == 0 || now.tv_sec > abs_timeout->tv_sec || if (abs_timeout->tv_sec == 0 || now.tv_sec > abs_timeout->tv_sec ||
(u64) now.tv_usec * 1000ULL > (u64) abs_timeout->tv_nsec) { (u64)now.tv_usec * 1000ULL > (u64)abs_timeout->tv_nsec) {
return ETIMEDOUT; return ETIMEDOUT;
} }
} }
@ -84,58 +85,61 @@ static int xpthread_mutex_timedlock(
Threading::Mutex::Mutex() 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() void Threading::Mutex::Detach()
{ {
if( EBUSY != pthread_mutex_destroy(&m_mutex) ) return; if (EBUSY != pthread_mutex_destroy(&m_mutex))
return;
if( IsRecursive() ) if (IsRecursive()) {
{
// Sanity check: Recursive locks could be held by our own thread, which would // Sanity check: Recursive locks could be held by our own thread, which would
// be considered an assertion failure, but can also be handled gracefully. // 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 // (note: if the mutex is locked recursively more than twice then this assert won't
// detect it) // detect it)
Release(); Release(); // in case of double recursion. Release();
int result = pthread_mutex_destroy( &m_mutex ); Release(); // in case of double recursion.
if( pxAssertDev( result != EBUSY, "Detachment of a recursively-locked mutex (self-locked!)." ) ) return; 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) ) if (Wait(def_detach_timeout))
pthread_mutex_destroy( &m_mutex ); pthread_mutex_destroy(&m_mutex);
else else
Console.Error( "(Thread Log) Mutex cleanup failed due to possible deadlock."); Console.Error("(Thread Log) Mutex cleanup failed due to possible deadlock.");
} }
Threading::Mutex::~Mutex() throw() Threading::Mutex::~Mutex() throw()
{ {
try { try {
Mutex::Detach(); Mutex::Detach();
} DESTRUCTOR_CATCHALL; }
DESTRUCTOR_CATCHALL;
} }
Threading::MutexRecursive::MutexRecursive() : Mutex( false ) Threading::MutexRecursive::MutexRecursive()
: Mutex(false)
{ {
if( ++_attr_refcount == 1 ) if (++_attr_refcount == 1) {
{ if (0 != pthread_mutexattr_init(&_attr_recursive))
if( 0 != pthread_mutexattr_init( &_attr_recursive ) )
throw Exception::OutOfMemory(L"Recursive mutexing attributes"); 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 )) if (pthread_mutex_init(&m_mutex, &_attr_recursive))
Console.Error( "(Thread Log) Failed to initialize mutex."); Console.Error("(Thread Log) Failed to initialize mutex.");
} }
Threading::MutexRecursive::~MutexRecursive() throw() Threading::MutexRecursive::~MutexRecursive() throw()
{ {
if( --_attr_refcount == 0 ) if (--_attr_refcount == 0)
pthread_mutexattr_destroy( &_attr_recursive ); pthread_mutexattr_destroy(&_attr_recursive);
} }
// This is a bit of a hackish function, which is technically unsafe, but can be useful for allowing // This is a bit of a hackish function, which is technically unsafe, but can be useful for allowing
@ -145,7 +149,7 @@ Threading::MutexRecursive::~MutexRecursive() throw()
void Threading::Mutex::Recreate() void Threading::Mutex::Recreate()
{ {
Detach(); Detach();
pthread_mutex_init( &m_mutex, NULL ); pthread_mutex_init(&m_mutex, NULL);
} }
// Returns: // Returns:
@ -153,8 +157,7 @@ void Threading::Mutex::Recreate()
// unlocked. // unlocked.
bool Threading::Mutex::RecreateIfLocked() bool Threading::Mutex::RecreateIfLocked()
{ {
if( !Wait(def_detach_timeout) ) if (!Wait(def_detach_timeout)) {
{
Recreate(); Recreate();
return true; return true;
} }
@ -168,25 +171,25 @@ bool Threading::Mutex::RecreateIfLocked()
// other than the main thread. // other than the main thread.
void Threading::Mutex::AcquireWithoutYield() void Threading::Mutex::AcquireWithoutYield()
{ {
pxAssertMsg( !wxThread::IsMain(), "Unyielding mutex acquire issued from the main/gui thread. Please use Acquire() instead." ); pxAssertMsg(!wxThread::IsMain(), "Unyielding mutex acquire issued from the main/gui thread. Please use Acquire() instead.");
pthread_mutex_lock( &m_mutex ); pthread_mutex_lock(&m_mutex);
} }
bool Threading::Mutex::AcquireWithoutYield( const wxTimeSpan& timeout ) bool Threading::Mutex::AcquireWithoutYield(const wxTimeSpan &timeout)
{ {
wxDateTime megafail( wxDateTime::UNow() + timeout ); wxDateTime megafail(wxDateTime::UNow() + timeout);
const timespec fail = { megafail.GetTicks(), megafail.GetMillisecond() * 1000000 }; const timespec fail = {megafail.GetTicks(), megafail.GetMillisecond() * 1000000};
return xpthread_mutex_timedlock( &m_mutex, &fail ) == 0; return xpthread_mutex_timedlock(&m_mutex, &fail) == 0;
} }
void Threading::Mutex::Release() void Threading::Mutex::Release()
{ {
pthread_mutex_unlock( &m_mutex ); pthread_mutex_unlock(&m_mutex);
} }
bool Threading::Mutex::TryAcquire() 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 // This is a wxApp-safe rendition of AcquireWithoutYield, which makes sure to execute pending app events
@ -195,48 +198,39 @@ bool Threading::Mutex::TryAcquire()
void Threading::Mutex::Acquire() void Threading::Mutex::Acquire()
{ {
#if wxUSE_GUI #if wxUSE_GUI
if( !wxThread::IsMain() || (wxTheApp == NULL) ) if (!wxThread::IsMain() || (wxTheApp == NULL)) {
{ pthread_mutex_lock(&m_mutex);
pthread_mutex_lock( &m_mutex ); } else if (_WaitGui_RecursionGuard(L"Mutex::Acquire")) {
} ScopedBusyCursor hourglass(Cursor_ReallyBusy);
else if( _WaitGui_RecursionGuard( L"Mutex::Acquire" ) ) pthread_mutex_lock(&m_mutex);
{ } else {
ScopedBusyCursor hourglass( Cursor_ReallyBusy );
pthread_mutex_lock( &m_mutex );
}
else
{
//ScopedBusyCursor hourglass( Cursor_KindaBusy ); //ScopedBusyCursor hourglass( Cursor_KindaBusy );
while( !AcquireWithoutYield(def_yieldgui_interval) ) while (!AcquireWithoutYield(def_yieldgui_interval))
YieldToMain(); YieldToMain();
} }
#else #else
pthread_mutex_lock( &m_mutex ); pthread_mutex_lock(&m_mutex);
#endif #endif
} }
bool Threading::Mutex::Acquire( const wxTimeSpan& timeout ) bool Threading::Mutex::Acquire(const wxTimeSpan &timeout)
{ {
#if wxUSE_GUI #if wxUSE_GUI
if( !wxThread::IsMain() || (wxTheApp == NULL) ) if (!wxThread::IsMain() || (wxTheApp == NULL)) {
{
return AcquireWithoutYield(timeout); return AcquireWithoutYield(timeout);
} } else if (_WaitGui_RecursionGuard(L"Mutex::TimedAcquire")) {
else if( _WaitGui_RecursionGuard( L"Mutex::TimedAcquire" ) ) ScopedBusyCursor hourglass(Cursor_ReallyBusy);
{ return AcquireWithoutYield(timeout);
ScopedBusyCursor hourglass( Cursor_ReallyBusy ); } else {
return AcquireWithoutYield( timeout );
}
else
{
//ScopedBusyCursor hourglass( Cursor_KindaBusy ); //ScopedBusyCursor hourglass( Cursor_KindaBusy );
wxTimeSpan countdown( (timeout) ); wxTimeSpan countdown((timeout));
do { do {
if( AcquireWithoutYield( def_yieldgui_interval ) ) break; if (AcquireWithoutYield(def_yieldgui_interval))
break;
YieldToMain(); YieldToMain();
countdown -= def_yieldgui_interval; countdown -= def_yieldgui_interval;
} while( countdown.GetMilliseconds() > 0 ); } while (countdown.GetMilliseconds() > 0);
return countdown.GetMilliseconds() > 0; return countdown.GetMilliseconds() > 0;
} }
@ -272,20 +266,18 @@ void Threading::Mutex::WaitWithoutYield()
// true if the mutex was freed and is in an unlocked state; or false if the wait timed out // 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. // 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) ) if (Acquire(timeout)) {
{
Release(); Release();
return true; return true;
} }
return false; return false;
} }
bool Threading::Mutex::WaitWithoutYield( const wxTimeSpan& timeout ) bool Threading::Mutex::WaitWithoutYield(const wxTimeSpan &timeout)
{ {
if( AcquireWithoutYield(timeout) ) if (AcquireWithoutYield(timeout)) {
{
Release(); Release();
return true; return true;
} }
@ -298,67 +290,72 @@ bool Threading::Mutex::WaitWithoutYield( const wxTimeSpan& timeout )
Threading::ScopedLock::~ScopedLock() throw() Threading::ScopedLock::~ScopedLock() throw()
{ {
if( m_IsLocked && m_lock ) if (m_IsLocked && m_lock)
m_lock->Release(); m_lock->Release();
} }
Threading::ScopedLock::ScopedLock( const Mutex* locker ) Threading::ScopedLock::ScopedLock(const Mutex *locker)
{ {
m_IsLocked = false; m_IsLocked = false;
AssignAndLock( locker ); AssignAndLock(locker);
} }
Threading::ScopedLock::ScopedLock( const Mutex& locker ) Threading::ScopedLock::ScopedLock(const Mutex &locker)
{ {
m_IsLocked = false; m_IsLocked = false;
AssignAndLock( locker ); 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<Mutex*>(locker); m_lock = const_cast<Mutex *>(locker);
if( !m_lock ) return; if (!m_lock)
return;
m_IsLocked = true; m_IsLocked = true;
m_lock->Acquire(); m_lock->Acquire();
} }
void Threading::ScopedLock::Assign( const Mutex& locker ) void Threading::ScopedLock::Assign(const Mutex &locker)
{ {
m_lock = const_cast<Mutex*>(&locker); m_lock = const_cast<Mutex *>(&locker);
} }
void Threading::ScopedLock::Assign( const Mutex* locker ) void Threading::ScopedLock::Assign(const Mutex *locker)
{ {
m_lock = const_cast<Mutex*>(locker); m_lock = const_cast<Mutex *>(locker);
} }
// Provides manual unlocking of a scoped lock prior to object destruction. // Provides manual unlocking of a scoped lock prior to object destruction.
void Threading::ScopedLock::Release() void Threading::ScopedLock::Release()
{ {
if( !m_IsLocked ) return; if (!m_IsLocked)
return;
m_IsLocked = false; m_IsLocked = false;
if( m_lock ) m_lock->Release(); if (m_lock)
m_lock->Release();
} }
// provides manual locking of a scoped lock, to re-lock after a manual unlocking. // provides manual locking of a scoped lock, to re-lock after a manual unlocking.
void Threading::ScopedLock::Acquire() void Threading::ScopedLock::Acquire()
{ {
if( m_IsLocked || !m_lock ) return; if (m_IsLocked || !m_lock)
return;
m_lock->Acquire(); m_lock->Acquire();
m_IsLocked = true; m_IsLocked = true;
} }
Threading::ScopedLock::ScopedLock( const Mutex& locker, bool isTryLock ) Threading::ScopedLock::ScopedLock(const Mutex &locker, bool isTryLock)
{ {
m_lock = const_cast<Mutex*>(&locker); m_lock = const_cast<Mutex *>(&locker);
if( !m_lock ) return; if (!m_lock)
return;
m_IsLocked = isTryLock ? m_lock->TryAcquire() : false; m_IsLocked = isTryLock ? m_lock->TryAcquire() : false;
} }

View File

@ -23,71 +23,73 @@
// wxDirName (implementations) // 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." ); pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wxDirName concatenation.");
if( right.IsAbsolute() ) if (right.IsAbsolute())
return right; return right;
// Append any directory parts from right, and then set the filename. // 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 // 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: // for getting each component of the path. So instead let's use Normalize:
wxFileName result( right ); wxFileName result(right);
result.Normalize( wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath() ); result.Normalize(wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath());
return result; 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 ); wxDirName result(right);
result.Normalize( wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath() ); result.Normalize(wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath());
return result; 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." ); pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wDirName normalization.");
if( !wxFileName::Normalize( flags, cwd ) ) if (!wxFileName::Normalize(flags, cwd))
throw Exception::ParseError().SetDiagMsg( L"wxDirName::Normalize operation failed." ); throw Exception::ParseError().SetDiagMsg(L"wxDirName::Normalize operation failed.");
return *this; 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." ); pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wDirName normalization.");
if( !wxFileName::MakeRelativeTo( pathBase ) ) if (!wxFileName::MakeRelativeTo(pathBase))
throw Exception::ParseError().SetDiagMsg( L"wxDirName::MakeRelativeTo operation failed." ); throw Exception::ParseError().SetDiagMsg(L"wxDirName::MakeRelativeTo operation failed.");
return *this; 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." ); pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wDirName normalization.");
if( !wxFileName::MakeAbsolute( cwd ) ) if (!wxFileName::MakeAbsolute(cwd))
throw Exception::ParseError().SetDiagMsg( L"wxDirName::MakeAbsolute operation failed." ); throw Exception::ParseError().SetDiagMsg(L"wxDirName::MakeAbsolute operation failed.");
return *this; return *this;
} }
void wxDirName::Rmdir() void wxDirName::Rmdir()
{ {
if( !Exists() ) return; if (!Exists())
return;
wxFileName::Rmdir(); wxFileName::Rmdir();
// TODO : Throw exception if operation failed? Do we care? // TODO : Throw exception if operation failed? Do we care?
} }
bool wxDirName::Mkdir() 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 #ifndef wxS_DIR_DEFAULT
#define wxS_DIR_DEFAULT 0777 #define wxS_DIR_DEFAULT 0777
#endif #endif
if( Exists() ) return true; if (Exists())
return true;
return wxFileName::Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); return wxFileName::Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
} }
@ -97,34 +99,35 @@ 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. // 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; if (!wxFile::Exists(path.c_str()))
return (s64)wxFileName::GetSize( path ).GetValue(); return -1;
return (s64)wxFileName::GetSize(path).GetValue();
} }
wxString Path::Normalize( const wxString& src ) wxString Path::Normalize(const wxString &src)
{ {
wxFileName normalize( src ); wxFileName normalize(src);
normalize.Normalize(); normalize.Normalize();
return normalize.GetFullPath(); 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 ); wxFileName absolute(src);
absolute.MakeAbsolute(); absolute.MakeAbsolute();
return absolute.GetFullPath(); return absolute.GetFullPath();
} }
@ -132,48 +135,48 @@ wxString Path::MakeAbsolute( const wxString& src )
// Concatenates two pathnames together, inserting delimiters (backslash on win32) // Concatenates two pathnames together, inserting delimiters (backslash on win32)
// as needed! Assumes the 'dest' is allocated to at least g_MaxPath length. // 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. // Replaces the extension of the file with the one given.
// This function works for path names as well as file names. // 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 ); wxFileName jojo(src);
jojo.SetExt( ext ); jojo.SetExt(ext);
return jojo.GetFullPath(); return jojo.GetFullPath();
} }
wxString Path::ReplaceFilename( const wxString& src, const wxString& newfilename ) wxString Path::ReplaceFilename(const wxString &src, const wxString &newfilename)
{ {
wxFileName jojo( src ); wxFileName jojo(src);
jojo.SetFullName( newfilename ); jojo.SetFullName(newfilename);
return jojo.GetFullPath(); 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();
} }
@ -181,26 +184,26 @@ wxString Path::GetDirectory( const wxString& src )
// returns the base/root directory of the given path. // returns the base/root directory of the given path.
// Example /this/that/something.txt -> dest == "/" // 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() ); size_t pos = src.find_first_of(wxFileName::GetPathSeparators());
if( pos == wxString::npos ) if (pos == wxString::npos)
return wxString(); return wxString();
else else
return wxString( src.begin(), src.begin()+pos ); return wxString(src.begin(), src.begin() + pos);
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Launches the specified file according to its mime type // 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) 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 // bypasses wxWidgets internal filename checking, which can end up launching things
// through browser more often than desired. // 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) void pxExplore(const char *path)
{ {
pxExplore( fromUTF8(path) ); pxExplore(fromUTF8(path));
} }

View File

@ -23,84 +23,92 @@
namespace Perf namespace Perf
{ {
// Warning object aren't thread safe // Warning object aren't thread safe
InfoVector any(""); InfoVector any("");
InfoVector ee("EE"); InfoVector ee("EE");
InfoVector iop("IOP"); InfoVector iop("IOP");
InfoVector vu("VU"); InfoVector vu("VU");
// Perf is only supported on linux // Perf is only supported on linux
#if defined(__linux__) && defined(ProfileWithPerf) #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) 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)); 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) 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); snprintf(m_symbol, sizeof(m_symbol), "%s_0x%08x", symbol, pc);
} }
void Info::Print(FILE* fp) void Info::Print(FILE *fp)
{ {
fprintf(fp, "%x %x %s\n", m_x86, m_size, m_symbol); 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) InfoVector::InfoVector(const char *prefix)
{ {
strncpy(m_prefix, prefix, sizeof(m_prefix)); strncpy(m_prefix, prefix, sizeof(m_prefix));
} }
void InfoVector::print(FILE* fp) void InfoVector::print(FILE *fp)
{ {
for(auto&& it : m_v) it.Print(fp); for (auto &&it : m_v)
} it.Print(fp);
}
void InfoVector::map(uptr x86, u32 size, const char* symbol) void InfoVector::map(uptr x86, u32 size, const char *symbol)
{ {
// This function is typically used for dispatcher and recompiler. // This function is typically used for dispatcher and recompiler.
// Dispatchers are on a page and must always be kept. // Dispatchers are on a page and must always be kept.
// Recompilers are much bigger (TODO check VIF) and are only // Recompilers are much bigger (TODO check VIF) and are only
// useful when MERGE_BLOCK_RESULT is defined // useful when MERGE_BLOCK_RESULT is defined
#ifdef MERGE_BLOCK_RESULT #ifdef MERGE_BLOCK_RESULT
m_v.emplace_back(x86, size, symbol); m_v.emplace_back(x86, size, symbol);
#else #else
if (size < 8 * _1kb) m_v.emplace_back(x86, size, symbol); if (size < 8 * _1kb)
m_v.emplace_back(x86, size, symbol);
#endif #endif
} }
void InfoVector::map(uptr x86, u32 size, u32 pc) void InfoVector::map(uptr x86, u32 size, u32 pc)
{ {
#ifndef MERGE_BLOCK_RESULT #ifndef MERGE_BLOCK_RESULT
m_v.emplace_back(x86, size, m_prefix, pc); m_v.emplace_back(x86, size, m_prefix, pc);
#endif #endif
} }
void InfoVector::reset() void InfoVector::reset()
{ {
auto dynamic = std::remove_if(m_v.begin(), m_v.end(), [](Info i) { return i.m_dynamic; }); auto dynamic = std::remove_if(m_v.begin(), m_v.end(), [](Info i) { return i.m_dynamic; });
m_v.erase(dynamic, m_v.end()); m_v.erase(dynamic, m_v.end());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Global function // Global function
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void dump() void dump()
{ {
char file[256]; char file[256];
snprintf(file, 250, "/tmp/perf-%d.map", getpid()); snprintf(file, 250, "/tmp/perf-%d.map", getpid());
FILE* fp = fopen(file, "w"); FILE *fp = fopen(file, "w");
any.print(fp); any.print(fp);
ee.print(fp); ee.print(fp);
@ -109,32 +117,31 @@ namespace Perf
if (fp) if (fp)
fclose(fp); fclose(fp);
} }
void dump_and_reset() void dump_and_reset()
{ {
dump(); dump();
any.reset(); any.reset();
ee.reset(); ee.reset();
iop.reset(); iop.reset();
vu.reset(); vu.reset();
} }
#else #else
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Dummy implementation // Dummy implementation
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
InfoVector::InfoVector(const char* prefix) {} InfoVector::InfoVector(const char *prefix) {}
void InfoVector::map(uptr x86, u32 size, const char* symbol) {} void InfoVector::map(uptr x86, u32 size, const char *symbol) {}
void InfoVector::map(uptr x86, u32 size, u32 pc) {} void InfoVector::map(uptr x86, u32 size, u32 pc) {}
void InfoVector::reset() {} void InfoVector::reset() {}
void dump() {} void dump() {}
void dump_and_reset() {} void dump_and_reset() {}
#endif #endif
} }

View File

@ -28,4 +28,3 @@
#include "General.h" #include "General.h"
#endif #endif

View File

@ -21,37 +21,37 @@
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
Threading::RwMutex::RwMutex() Threading::RwMutex::RwMutex()
{ {
pthread_rwlock_init( &m_rwlock, NULL ); pthread_rwlock_init(&m_rwlock, NULL);
} }
Threading::RwMutex::~RwMutex() throw() Threading::RwMutex::~RwMutex() throw()
{ {
pthread_rwlock_destroy( &m_rwlock ); pthread_rwlock_destroy(&m_rwlock);
} }
void Threading::RwMutex::AcquireRead() void Threading::RwMutex::AcquireRead()
{ {
pthread_rwlock_rdlock( &m_rwlock ); pthread_rwlock_rdlock(&m_rwlock);
} }
void Threading::RwMutex::AcquireWrite() void Threading::RwMutex::AcquireWrite()
{ {
pthread_rwlock_wrlock( &m_rwlock ); pthread_rwlock_wrlock(&m_rwlock);
} }
bool Threading::RwMutex::TryAcquireRead() bool Threading::RwMutex::TryAcquireRead()
{ {
return pthread_rwlock_tryrdlock( &m_rwlock ) != EBUSY; return pthread_rwlock_tryrdlock(&m_rwlock) != EBUSY;
} }
bool Threading::RwMutex::TryAcquireWrite() bool Threading::RwMutex::TryAcquireWrite()
{ {
return pthread_rwlock_trywrlock( &m_rwlock ) != EBUSY; return pthread_rwlock_trywrlock(&m_rwlock) != EBUSY;
} }
void Threading::RwMutex::Release() void Threading::RwMutex::Release()
{ {
pthread_rwlock_unlock( &m_rwlock ); pthread_rwlock_unlock(&m_rwlock);
} }
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -59,14 +59,15 @@ void Threading::RwMutex::Release()
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
Threading::BaseScopedReadWriteLock::~BaseScopedReadWriteLock() throw() Threading::BaseScopedReadWriteLock::~BaseScopedReadWriteLock() throw()
{ {
if( m_IsLocked ) if (m_IsLocked)
m_lock.Release(); m_lock.Release();
} }
// Provides manual unlocking of a scoped lock prior to object destruction. // Provides manual unlocking of a scoped lock prior to object destruction.
void Threading::BaseScopedReadWriteLock::Release() void Threading::BaseScopedReadWriteLock::Release()
{ {
if( !m_IsLocked ) return; if (!m_IsLocked)
return;
m_IsLocked = false; m_IsLocked = false;
m_lock.Release(); m_lock.Release();
} }
@ -74,8 +75,8 @@ void Threading::BaseScopedReadWriteLock::Release()
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// ScopedReadLock / ScopedWriteLock // ScopedReadLock / ScopedWriteLock
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
Threading::ScopedReadLock::ScopedReadLock( RwMutex& locker ) Threading::ScopedReadLock::ScopedReadLock(RwMutex &locker)
: BaseScopedReadWriteLock( locker ) : BaseScopedReadWriteLock(locker)
{ {
m_IsLocked = true; m_IsLocked = true;
m_lock.AcquireRead(); m_lock.AcquireRead();
@ -84,13 +85,14 @@ Threading::ScopedReadLock::ScopedReadLock( RwMutex& locker )
// provides manual locking of a scoped lock, to re-lock after a manual unlocking. // provides manual locking of a scoped lock, to re-lock after a manual unlocking.
void Threading::ScopedReadLock::Acquire() void Threading::ScopedReadLock::Acquire()
{ {
if( m_IsLocked ) return; if (m_IsLocked)
return;
m_lock.AcquireRead(); m_lock.AcquireRead();
m_IsLocked = true; m_IsLocked = true;
} }
Threading::ScopedWriteLock::ScopedWriteLock( RwMutex& locker ) Threading::ScopedWriteLock::ScopedWriteLock(RwMutex &locker)
: BaseScopedReadWriteLock( locker ) : BaseScopedReadWriteLock(locker)
{ {
m_IsLocked = true; m_IsLocked = true;
m_lock.AcquireWrite(); m_lock.AcquireWrite();
@ -99,14 +101,15 @@ Threading::ScopedWriteLock::ScopedWriteLock( RwMutex& locker )
// provides manual locking of a scoped lock, to re-lock after a manual unlocking. // provides manual locking of a scoped lock, to re-lock after a manual unlocking.
void Threading::ScopedWriteLock::Acquire() void Threading::ScopedWriteLock::Acquire()
{ {
if( m_IsLocked ) return; if (m_IsLocked)
return;
m_lock.AcquireWrite(); m_lock.AcquireWrite();
m_IsLocked = true; m_IsLocked = true;
} }
// Special constructor used by ScopedTryLock // Special constructor used by ScopedTryLock
Threading::ScopedWriteLock::ScopedWriteLock( RwMutex& locker, bool isTryLock ) Threading::ScopedWriteLock::ScopedWriteLock(RwMutex &locker, bool isTryLock)
: BaseScopedReadWriteLock( locker ) : BaseScopedReadWriteLock(locker)
{ {
//m_IsLocked = isTryLock ? m_lock.TryAcquireWrite() : false; //m_IsLocked = isTryLock ? m_lock.TryAcquireWrite() : false;
} }

Some files were not shown because too many files have changed in this diff Show More