mirror of https://github.com/PCSX2/pcsx2.git
commit
c03b388786
|
@ -70,7 +70,7 @@ PenaltyBreakFirstLessLess: 120
|
|||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Left
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: false
|
||||
SpaceAfterCStyleCast: false
|
||||
|
|
|
@ -5,6 +5,18 @@ set -x
|
|||
|
||||
ret=0
|
||||
|
||||
if command -v clang-format-3.8 > /dev/null ; then
|
||||
clang_format=clang-format-3.8
|
||||
else
|
||||
if command -v clang-format > /dev/null ; then
|
||||
clang_format=clang-format
|
||||
else
|
||||
return 2;
|
||||
fi
|
||||
fi
|
||||
|
||||
$clang_format -version
|
||||
|
||||
# Doesn't work as travis only populate a single branch history
|
||||
|
||||
#branch=`git rev-parse --abbrev-ref HEAD`
|
||||
|
@ -36,7 +48,6 @@ files=`git diff --name-only --diff-filter=ACMRT $diff_range -- $PWD | \
|
|||
grep -v "${1}common/" | \
|
||||
grep -v "${1}pcsx2/" | \
|
||||
grep -v "${1}plugins/cdvdGigaherz/" | \
|
||||
grep -v "${1}plugins/CDVDiso/" | \
|
||||
grep -v "${1}plugins/CDVDisoEFP/" | \
|
||||
grep -v "${1}plugins/CDVDlinuz/" | \
|
||||
grep -v "${1}plugins/CDVDolio/" | \
|
||||
|
@ -44,8 +55,6 @@ files=`git diff --name-only --diff-filter=ACMRT $diff_range -- $PWD | \
|
|||
grep -v "${1}plugins/dev9ghzdrk/" | \
|
||||
grep -v "${1}plugins/GSdx/" | \
|
||||
grep -v "${1}plugins/GSdx_legacy/" | \
|
||||
grep -v "${1}plugins/LilyPad/" | \
|
||||
grep -v "${1}plugins/onepad/" | \
|
||||
grep -v "${1}plugins/PeopsSPU2/" | \
|
||||
grep -v "${1}plugins/spu2-x/" | \
|
||||
grep -v "${1}plugins/SSSPSXPAD/" | \
|
||||
|
@ -67,7 +76,7 @@ files=`git diff --name-only --diff-filter=ACMRT $diff_range -- $PWD | \
|
|||
# Check remaining files are clang-format compliant
|
||||
for f in $files
|
||||
do
|
||||
clang-format -style=file -output-replacements-xml $f | grep "<replacement " >/dev/null
|
||||
$clang_format -style=file -output-replacements-xml $f | grep "<replacement " >/dev/null
|
||||
if [ $? -ne 1 ]
|
||||
then
|
||||
echo "file $f did not match clang-format"
|
||||
|
|
|
@ -44,35 +44,56 @@
|
|||
|
||||
#endif
|
||||
|
||||
EXPORT_C_(u32) PS2EgetLibType();
|
||||
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type);
|
||||
EXPORT_C_(char*) PS2EgetLibName();
|
||||
EXPORT_C_(u32)
|
||||
PS2EgetLibType();
|
||||
EXPORT_C_(u32)
|
||||
PS2EgetLibVersion2(u32 type);
|
||||
EXPORT_C_(char *)
|
||||
PS2EgetLibName();
|
||||
|
||||
|
||||
EXPORT_C_(s32) CDVDinit();
|
||||
EXPORT_C_(s32) CDVDopen(const char* pTitleFilename);
|
||||
EXPORT_C_(void) CDVDclose();
|
||||
EXPORT_C_(void) CDVDshutdown();
|
||||
EXPORT_C_(s32) CDVDreadTrack(u32 lsn, int mode);
|
||||
EXPORT_C_(s32)
|
||||
CDVDinit();
|
||||
EXPORT_C_(s32)
|
||||
CDVDopen(const char *pTitleFilename);
|
||||
EXPORT_C_(void)
|
||||
CDVDclose();
|
||||
EXPORT_C_(void)
|
||||
CDVDshutdown();
|
||||
EXPORT_C_(s32)
|
||||
CDVDreadTrack(u32 lsn, int mode);
|
||||
|
||||
// return can be NULL (for async modes)
|
||||
EXPORT_C_(u8*) CDVDgetBuffer();
|
||||
EXPORT_C_(u8 *)
|
||||
CDVDgetBuffer();
|
||||
|
||||
EXPORT_C_(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq);//read subq from disc (only cds have subq data)
|
||||
EXPORT_C_(s32) CDVDgetTN(cdvdTN *Buffer); //disk information
|
||||
EXPORT_C_(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type
|
||||
EXPORT_C_(s32) CDVDgetTOC(void* toc); //gets ps2 style toc from disc
|
||||
EXPORT_C_(s32) CDVDgetDiskType(); //CDVD_TYPE_xxxx
|
||||
EXPORT_C_(s32) CDVDgetTrayStatus(); //CDVD_TRAY_xxxx
|
||||
EXPORT_C_(s32) CDVDctrlTrayOpen(); //open disc tray
|
||||
EXPORT_C_(s32) CDVDctrlTrayClose(); //close disc tray
|
||||
EXPORT_C_(s32)
|
||||
CDVDreadSubQ(u32 lsn, cdvdSubQ *subq); //read subq from disc (only cds have subq data)
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetTN(cdvdTN *Buffer); //disk information
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetTOC(void *toc); //gets ps2 style toc from disc
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetDiskType(); //CDVD_TYPE_xxxx
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetTrayStatus(); //CDVD_TRAY_xxxx
|
||||
EXPORT_C_(s32)
|
||||
CDVDctrlTrayOpen(); //open disc tray
|
||||
EXPORT_C_(s32)
|
||||
CDVDctrlTrayClose(); //close disc tray
|
||||
|
||||
// extended funcs
|
||||
|
||||
EXPORT_C_(void) CDVDconfigure();
|
||||
EXPORT_C_(void) CDVDabout();
|
||||
EXPORT_C_(s32) CDVDtest();
|
||||
EXPORT_C_(void) CDVDnewDiskCB(void (*callback)());
|
||||
EXPORT_C_(void)
|
||||
CDVDconfigure();
|
||||
EXPORT_C_(void)
|
||||
CDVDabout();
|
||||
EXPORT_C_(s32)
|
||||
CDVDtest();
|
||||
EXPORT_C_(void)
|
||||
CDVDnewDiskCB(void (*callback)());
|
||||
|
||||
#define CDVD_LOG __Log
|
||||
extern FILE *cdvdLog;
|
||||
|
|
|
@ -44,8 +44,7 @@ char *methods[] =
|
|||
{
|
||||
".Z - compress faster",
|
||||
".BZ - compress better",
|
||||
NULL
|
||||
};
|
||||
NULL};
|
||||
|
||||
#ifdef PCSX2_DEBUG
|
||||
char *LibName = "Linuz Iso CDVD (Debug) ";
|
||||
|
@ -80,17 +79,20 @@ void lba_to_msf(s32 lba, u8* m, u8* s, u8* f)
|
|||
#define itob(i) ((i) / 10 * 16 + (i) % 10) /* u_char to BCD */
|
||||
|
||||
|
||||
EXPORT_C_(char*) PS2EgetLibName()
|
||||
EXPORT_C_(char *)
|
||||
PS2EgetLibName()
|
||||
{
|
||||
return LibName;
|
||||
}
|
||||
|
||||
EXPORT_C_(u32) PS2EgetLibType()
|
||||
EXPORT_C_(u32)
|
||||
PS2EgetLibType()
|
||||
{
|
||||
return PS2E_LT_CDVD;
|
||||
}
|
||||
|
||||
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
|
||||
EXPORT_C_(u32)
|
||||
PS2EgetLibVersion2(u32 type)
|
||||
{
|
||||
return (version << 16) | (revision << 8) | build;
|
||||
}
|
||||
|
@ -100,7 +102,8 @@ void __Log(char *fmt, ...)
|
|||
{
|
||||
va_list list;
|
||||
|
||||
if (cdvdLog == NULL) return;
|
||||
if (cdvdLog == NULL)
|
||||
return;
|
||||
|
||||
va_start(list, fmt);
|
||||
vfprintf(cdvdLog, fmt, list);
|
||||
|
@ -111,15 +114,14 @@ void __Log(char *fmt, ...)
|
|||
#endif
|
||||
|
||||
|
||||
EXPORT_C_(s32) CDVDinit()
|
||||
EXPORT_C_(s32)
|
||||
CDVDinit()
|
||||
{
|
||||
#ifdef PCSX2_DEBUG
|
||||
cdvdLog = fopen("logs/cdvdLog.txt", "w");
|
||||
if (cdvdLog == NULL)
|
||||
{
|
||||
if (cdvdLog == NULL) {
|
||||
cdvdLog = fopen("cdvdLog.txt", "w");
|
||||
if (cdvdLog == NULL)
|
||||
{
|
||||
if (cdvdLog == NULL) {
|
||||
SysMessage("Can't create cdvdLog.txt");
|
||||
return -1;
|
||||
}
|
||||
|
@ -133,30 +135,33 @@ EXPORT_C_(s32) CDVDinit()
|
|||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(void) CDVDshutdown()
|
||||
EXPORT_C_(void)
|
||||
CDVDshutdown()
|
||||
{
|
||||
cdvdCurrentIso[0] = 0;
|
||||
#ifdef CDVD_LOG
|
||||
if (cdvdLog != NULL) fclose(cdvdLog);
|
||||
if (cdvdLog != NULL)
|
||||
fclose(cdvdLog);
|
||||
#endif
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDopen(const char* pTitle)
|
||||
EXPORT_C_(s32)
|
||||
CDVDopen(const char *pTitle)
|
||||
{
|
||||
LoadConf();
|
||||
|
||||
if (pTitle != NULL) strcpy(IsoFile, pTitle);
|
||||
|
||||
if (*IsoFile == 0) strcpy(IsoFile, cdvdCurrentIso);
|
||||
if (pTitle != NULL)
|
||||
strcpy(IsoFile, pTitle);
|
||||
|
||||
if (*IsoFile == 0)
|
||||
{
|
||||
strcpy(IsoFile, cdvdCurrentIso);
|
||||
|
||||
if (*IsoFile == 0) {
|
||||
char temp[256];
|
||||
|
||||
CfgOpenFile();
|
||||
|
||||
if (IsoFile[0] == 0)
|
||||
{
|
||||
if (IsoFile[0] == 0) {
|
||||
// user pressed CANCEL
|
||||
return 1;
|
||||
}
|
||||
|
@ -168,8 +173,7 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
|
|||
}
|
||||
|
||||
iso = isoOpen(IsoFile);
|
||||
if (iso == NULL)
|
||||
{
|
||||
if (iso == NULL) {
|
||||
SysMessage("Error loading %s\nMake sure the iso file is not mounted in any disk emulation software!", IsoFile);
|
||||
return -1;
|
||||
}
|
||||
|
@ -181,8 +185,7 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
|
|||
else
|
||||
cdtype = CDVD_TYPE_PS2CD;
|
||||
|
||||
if (BlockDump)
|
||||
{
|
||||
if (BlockDump) {
|
||||
char fname_only[MAX_PATH];
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -193,8 +196,7 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
|
|||
char *p, *plast;
|
||||
|
||||
plast = p = strchr(IsoFile, '/');
|
||||
while (p != NULL)
|
||||
{
|
||||
while (p != NULL) {
|
||||
plast = p;
|
||||
p = strchr(p + 1, '/');
|
||||
}
|
||||
|
@ -208,40 +210,44 @@ EXPORT_C_(s32) CDVDopen(const char* pTitle)
|
|||
|
||||
plast = p = strchr(fname_only, '.');
|
||||
|
||||
while (p != NULL)
|
||||
{
|
||||
while (p != NULL) {
|
||||
plast = p;
|
||||
p = strchr(p + 1, '.');
|
||||
}
|
||||
|
||||
if (plast != NULL) *plast = 0;
|
||||
if (plast != NULL)
|
||||
*plast = 0;
|
||||
|
||||
#endif
|
||||
strcat(fname_only, ".dump");
|
||||
fdump = isoCreate(fname_only, ISOFLAGS_BLOCKDUMP);
|
||||
if (fdump) isoSetFormat(fdump, iso->blockofs, iso->blocksize, iso->blocks);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fdump)
|
||||
isoSetFormat(fdump, iso->blockofs, iso->blocksize, iso->blocks);
|
||||
} else {
|
||||
fdump = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(void) CDVDclose()
|
||||
EXPORT_C_(void)
|
||||
CDVDclose()
|
||||
{
|
||||
if (!iso) return;
|
||||
if (!iso)
|
||||
return;
|
||||
|
||||
strcpy(cdvdCurrentIso, IsoFile);
|
||||
|
||||
isoClose(iso);
|
||||
if (fdump != NULL) isoClose(fdump);
|
||||
if (fdump != NULL)
|
||||
isoClose(fdump);
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq)
|
||||
EXPORT_C_(s32)
|
||||
CDVDreadSubQ(u32 lsn, cdvdSubQ *subq)
|
||||
{
|
||||
if (!iso) return -1;
|
||||
if (!iso)
|
||||
return -1;
|
||||
|
||||
// fake it
|
||||
u8 min, sec, frm;
|
||||
|
@ -264,7 +270,8 @@ EXPORT_C_(s32) CDVDreadSubQ(u32 lsn, cdvdSubQ* subq)
|
|||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDgetTN(cdvdTN *Buffer)
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetTN(cdvdTN *Buffer)
|
||||
{
|
||||
Buffer->strack = 1;
|
||||
Buffer->etrack = 1;
|
||||
|
@ -272,16 +279,15 @@ EXPORT_C_(s32) CDVDgetTN(cdvdTN *Buffer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDgetTD(u8 Track, cdvdTD *Buffer)
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetTD(u8 Track, cdvdTD *Buffer)
|
||||
{
|
||||
if (!iso) return -1;
|
||||
if (!iso)
|
||||
return -1;
|
||||
|
||||
if (Track == 0)
|
||||
{
|
||||
if (Track == 0) {
|
||||
Buffer->lsn = iso->blocks;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Buffer->type = CDVD_MODE1_TRACK;
|
||||
Buffer->lsn = 0;
|
||||
}
|
||||
|
@ -301,27 +307,26 @@ static bool testForPartitionInfo( const u8 (&tempbuffer)[CD_FRAMESIZE_RAW] )
|
|||
(tempbuffer[off + 2] == 0x44) &&
|
||||
(tempbuffer[off + 3] == 0x30) &&
|
||||
(tempbuffer[off + 4] == 0x30) &&
|
||||
(tempbuffer[off+5] == 0x31)
|
||||
);
|
||||
(tempbuffer[off + 5] == 0x31));
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetTOC(void *toc)
|
||||
{
|
||||
if (!iso) return -1;
|
||||
if (!iso)
|
||||
return -1;
|
||||
|
||||
u8 type = CDVDgetDiskType();
|
||||
u8 *tocBuff = (u8 *)toc;
|
||||
|
||||
//__Log("CDVDgetTOC\n");
|
||||
|
||||
if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD)
|
||||
{
|
||||
if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD) {
|
||||
// get dvd structure format
|
||||
// scsi command 0x43
|
||||
memset(tocBuff, 0, 2048);
|
||||
|
||||
if (layer1start != -2 && iso->blocks >= 0x300000)
|
||||
{
|
||||
if (layer1start != -2 && iso->blocks >= 0x300000) {
|
||||
//int off = iso->blockofs;
|
||||
|
||||
// dual sided
|
||||
|
@ -340,8 +345,7 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
|||
tocBuff[19] = 0x00;
|
||||
|
||||
// search for it
|
||||
if (layer1start == -1)
|
||||
{
|
||||
if (layer1start == -1) {
|
||||
printf("CDVD: searching for layer1...");
|
||||
|
||||
/*tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW * 10);
|
||||
|
@ -361,24 +365,20 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
|||
uint midsector = (iso->blocks / 2) & ~0xf;
|
||||
uint deviation = 0;
|
||||
|
||||
while( (layer1start == -1) && (deviation < midsector-16) )
|
||||
{
|
||||
while ((layer1start == -1) && (deviation < midsector - 16)) {
|
||||
u8 tempbuffer[CD_FRAMESIZE_RAW];
|
||||
isoReadBlock(iso, tempbuffer, midsector - deviation);
|
||||
|
||||
if (testForPartitionInfo(tempbuffer))
|
||||
layer1start = midsector - deviation;
|
||||
else
|
||||
{
|
||||
else {
|
||||
isoReadBlock(iso, tempbuffer, midsector + deviation);
|
||||
if (testForPartitionInfo(tempbuffer))
|
||||
layer1start = midsector + deviation;
|
||||
}
|
||||
|
||||
if( layer1start != -1 )
|
||||
{
|
||||
if( tempbuffer[iso->blockofs] != 0x01 )
|
||||
{
|
||||
if (layer1start != -1) {
|
||||
if (tempbuffer[iso->blockofs] != 0x01) {
|
||||
fprintf(stderr, "(LinuzCDVDiso): Invalid partition type on layer 1!? (type=0x%x)", tempbuffer[iso->blockofs]);
|
||||
}
|
||||
}
|
||||
|
@ -386,8 +386,7 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
|||
}
|
||||
|
||||
|
||||
if (layer1start == -1)
|
||||
{
|
||||
if (layer1start == -1) {
|
||||
printf("(LinuzCDVDiso): Couldn't find second layer on dual layer... ignoring\n");
|
||||
// fake it
|
||||
tocBuff[0] = 0x04;
|
||||
|
@ -413,9 +412,7 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
|||
tocBuff[21] = (layer1start >> 16) & 0xff;
|
||||
tocBuff[22] = (layer1start >> 8) & 0xff;
|
||||
tocBuff[23] = (layer1start >> 0) & 0xff;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// fake it
|
||||
tocBuff[0] = 0x04;
|
||||
tocBuff[1] = 0x02;
|
||||
|
@ -429,10 +426,8 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
|||
tocBuff[18] = 0x00;
|
||||
tocBuff[19] = 0x00;
|
||||
}
|
||||
}
|
||||
else if ((type == CDVD_TYPE_CDDA) || (type == CDVD_TYPE_PS2CDDA) ||
|
||||
(type == CDVD_TYPE_PS2CD) || (type == CDVD_TYPE_PSCDDA) || (type == CDVD_TYPE_PSCD))
|
||||
{
|
||||
} else if ((type == CDVD_TYPE_CDDA) || (type == CDVD_TYPE_PS2CDDA) ||
|
||||
(type == CDVD_TYPE_PS2CD) || (type == CDVD_TYPE_PSCDDA) || (type == CDVD_TYPE_PSCD)) {
|
||||
// cd toc
|
||||
// (could be replaced by 1 command that reads the full toc)
|
||||
u8 min, sec, frm;
|
||||
|
@ -440,12 +435,12 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
|||
cdvdTN diskInfo;
|
||||
cdvdTD trackInfo;
|
||||
memset(tocBuff, 0, 1024);
|
||||
if (CDVDgetTN(&diskInfo) == -1)
|
||||
{
|
||||
if (CDVDgetTN(&diskInfo) == -1) {
|
||||
diskInfo.etrack = 0;
|
||||
diskInfo.strack = 1;
|
||||
}
|
||||
if (CDVDgetTD(0, &trackInfo) == -1) trackInfo.lsn = 0;
|
||||
if (CDVDgetTD(0, &trackInfo) == -1)
|
||||
trackInfo.lsn = 0;
|
||||
|
||||
tocBuff[0] = 0x41;
|
||||
tocBuff[1] = 0x00;
|
||||
|
@ -464,8 +459,7 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
|||
tocBuff[27] = itob(min);
|
||||
tocBuff[28] = itob(sec);
|
||||
|
||||
for (i = diskInfo.strack; i <= diskInfo.etrack; i++)
|
||||
{
|
||||
for (i = diskInfo.strack; i <= diskInfo.etrack; i++) {
|
||||
err = CDVDgetTD(i, &trackInfo);
|
||||
lba_to_msf(trackInfo.lsn, &min, &sec, &frm);
|
||||
tocBuff[i * 10 + 30] = trackInfo.type;
|
||||
|
@ -474,36 +468,34 @@ EXPORT_C_(s32) CDVDgetTOC(void* toc)
|
|||
tocBuff[i * 10 + 38] = itob(sec);
|
||||
tocBuff[i * 10 + 39] = itob(frm);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDreadTrack(u32 lsn, int mode)
|
||||
EXPORT_C_(s32)
|
||||
CDVDreadTrack(u32 lsn, int mode)
|
||||
{
|
||||
if (!iso) return -1;
|
||||
if (!iso)
|
||||
return -1;
|
||||
|
||||
int _lsn = lsn;
|
||||
|
||||
//__Log("CDVDreadTrack: %x %x\n", lsn, mode);
|
||||
if (_lsn < 0)
|
||||
{
|
||||
if (_lsn < 0) {
|
||||
// lsn = 2097152 + (-_lsn);
|
||||
lsn = iso->blocks - (-_lsn);
|
||||
}
|
||||
// printf ("CDRreadTrack %d\n", lsn);
|
||||
|
||||
isoReadBlock(iso, cdbuffer, lsn);
|
||||
if (fdump != NULL)
|
||||
{
|
||||
if (fdump != NULL) {
|
||||
isoWriteBlock(fdump, cdbuffer, lsn);
|
||||
}
|
||||
|
||||
pbuffer = cdbuffer;
|
||||
switch (mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case CDVD_MODE_2352:
|
||||
break;
|
||||
case CDVD_MODE_2340:
|
||||
|
@ -520,39 +512,46 @@ EXPORT_C_(s32) CDVDreadTrack(u32 lsn, int mode)
|
|||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(u8*) CDVDgetBuffer()
|
||||
EXPORT_C_(u8 *)
|
||||
CDVDgetBuffer()
|
||||
{
|
||||
return pbuffer;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDgetDiskType()
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetDiskType()
|
||||
{
|
||||
return cdtype;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDgetTrayStatus()
|
||||
EXPORT_C_(s32)
|
||||
CDVDgetTrayStatus()
|
||||
{
|
||||
return CDVD_TRAY_CLOSE;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) CDVDctrlTrayOpen()
|
||||
EXPORT_C_(s32)
|
||||
CDVDctrlTrayOpen()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
EXPORT_C_(s32) CDVDctrlTrayClose()
|
||||
EXPORT_C_(s32)
|
||||
CDVDctrlTrayClose()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
EXPORT_C_(s32) CDVDtest()
|
||||
EXPORT_C_(s32)
|
||||
CDVDtest()
|
||||
{
|
||||
if (*IsoFile == 0) return 0;
|
||||
if (*IsoFile == 0)
|
||||
return 0;
|
||||
|
||||
iso = isoOpen(IsoFile);
|
||||
if (iso == NULL) return -1;
|
||||
if (iso == NULL)
|
||||
return -1;
|
||||
isoClose(iso);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ void LoadConf()
|
|||
strcpy(cfg, s_strIniPath);
|
||||
f = fopen(cfg, "r");
|
||||
|
||||
if (f == NULL)
|
||||
{
|
||||
if (f == NULL) {
|
||||
printf("Unable to load %s\n", cfg);
|
||||
strcpy(IsoFile, DEV_DEF);
|
||||
strcpy(CdDev, CDDEV_DEF);
|
||||
|
@ -45,8 +44,10 @@ void LoadConf()
|
|||
fscanf(f, "CdDev = %[^\n]\n", CdDev);
|
||||
fscanf(f, "BlockDump = %d\n", &BlockDump);
|
||||
|
||||
if (!strncmp(IsoFile, "CdDev =", 9)) *IsoFile = 0; // quick fix
|
||||
if (*CdDev == 0) strcpy(CdDev, CDDEV_DEF);
|
||||
if (!strncmp(IsoFile, "CdDev =", 9))
|
||||
*IsoFile = 0; // quick fix
|
||||
if (*CdDev == 0)
|
||||
strcpy(CdDev, CDDEV_DEF);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
@ -63,8 +64,7 @@ void SaveConf()
|
|||
strcpy(cfg, s_strIniPath);
|
||||
|
||||
f = fopen(cfg, "w");
|
||||
if (f == NULL)
|
||||
{
|
||||
if (f == NULL) {
|
||||
printf("Unable to save %s\n", cfg);
|
||||
return;
|
||||
}
|
||||
|
@ -147,7 +147,8 @@ void SysMessageLoc(char *fmt, ...)
|
|||
vsprintf(msg, fmt, list);
|
||||
va_end(list);
|
||||
|
||||
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
|
||||
if (msg[strlen(msg) - 1] == '\n')
|
||||
msg[strlen(msg) - 1] = 0;
|
||||
|
||||
w = strlen(msg) * 6 + 20;
|
||||
|
||||
|
@ -191,7 +192,8 @@ void OnOk (GtkButton *button, gpointer user_data)
|
|||
tmp = gtk_entry_get_text(GTK_ENTRY(CdEdit));
|
||||
strcpy(CdDev, tmp);
|
||||
|
||||
if is_checked(ConfDlg, "checkBlockDump")
|
||||
if
|
||||
is_checked(ConfDlg, "checkBlockDump")
|
||||
BlockDump = 1;
|
||||
else
|
||||
BlockDump = 0;
|
||||
|
@ -242,7 +244,8 @@ void OnFileSel(GtkButton *button, gpointer user_data)
|
|||
}
|
||||
|
||||
|
||||
EXPORT_C_(void) CDVDconfigure()
|
||||
EXPORT_C_(void)
|
||||
CDVDconfigure()
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -277,7 +280,6 @@ EXPORT_C_(void) CDVDconfigure()
|
|||
|
||||
gtk_widget_show_all(ConfDlg);
|
||||
gtk_main();
|
||||
|
||||
}
|
||||
|
||||
void OnAboutOk(GtkMenuItem *menuitem, gpointer userdata)
|
||||
|
@ -286,7 +288,8 @@ void OnAboutOk(GtkMenuItem * menuitem, gpointer userdata)
|
|||
gtk_main_quit();
|
||||
}
|
||||
|
||||
EXPORT_C_(void) CDVDabout()
|
||||
EXPORT_C_(void)
|
||||
CDVDabout()
|
||||
{
|
||||
GtkWidget *Label;
|
||||
GtkWidget *Ok;
|
||||
|
|
|
@ -32,8 +32,7 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "support.h"
|
||||
|
@ -78,4 +77,3 @@ extern void OnCreate(GtkButton *button, gpointer user_data);
|
|||
extern void OnCreateZ(GtkButton *button, gpointer user_data);
|
||||
extern void OnOk(GtkButton *button, gpointer user_data);
|
||||
extern void OnCancel(GtkButton *button, gpointer user_data);
|
||||
|
||||
|
|
|
@ -48,8 +48,10 @@ void UpdZmode()
|
|||
const char *tmp;
|
||||
|
||||
tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Method)->entry));
|
||||
if (!strcmp(tmp, methods[0])) Zmode = 1;
|
||||
else Zmode = 2;
|
||||
if (!strcmp(tmp, methods[0]))
|
||||
Zmode = 1;
|
||||
else
|
||||
Zmode = 2;
|
||||
}
|
||||
|
||||
char buffer[2352 * 10];
|
||||
|
@ -69,11 +71,12 @@ void OnCompress(GtkButton *button, gpointer user_data)
|
|||
strcpy(IsoFile, tmp);
|
||||
UpdZmode();
|
||||
|
||||
if (Zmode == 1) sprintf(Zfile, "%s.Z2", IsoFile);
|
||||
if (Zmode == 2) sprintf(Zfile, "%s.BZ2", IsoFile);
|
||||
if (Zmode == 1)
|
||||
sprintf(Zfile, "%s.Z2", IsoFile);
|
||||
if (Zmode == 2)
|
||||
sprintf(Zfile, "%s.BZ2", IsoFile);
|
||||
|
||||
if (stat(Zfile, &buf) != -1)
|
||||
{
|
||||
if (stat(Zfile, &buf) != -1) {
|
||||
/*char str[256];*/
|
||||
return;
|
||||
/* sprintf(str, "'%s' already exists, overwrite?", Zfile);
|
||||
|
@ -83,9 +86,11 @@ void OnCompress(GtkButton *button, gpointer user_data)
|
|||
}
|
||||
|
||||
src = isoOpen(IsoFile);
|
||||
if (src == NULL) return;
|
||||
if (src == NULL)
|
||||
return;
|
||||
dst = isoCreate(Zfile, Zmode == 1 ? ISOFLAGS_Z2 : ISOFLAGS_BZ2);
|
||||
if (dst == NULL) return;
|
||||
if (dst == NULL)
|
||||
return;
|
||||
|
||||
gtk_widget_set_sensitive(BtnCompress, FALSE);
|
||||
gtk_widget_set_sensitive(BtnDecompress, FALSE);
|
||||
|
@ -93,38 +98,38 @@ void OnCompress(GtkButton *button, gpointer user_data)
|
|||
gtk_widget_set_sensitive(BtnCreateZ, FALSE);
|
||||
stop = false;
|
||||
|
||||
for (lsn = 0; lsn < src->blocks; lsn++)
|
||||
{
|
||||
for (lsn = 0; lsn < src->blocks; lsn++) {
|
||||
printf("block %d ", lsn);
|
||||
putchar(13);
|
||||
fflush(stdout);
|
||||
ret = isoReadBlock(src, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
ret = isoWriteBlock(dst, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), (lsn * 100) / src->blocks);
|
||||
while (gtk_events_pending()) gtk_main_iteration();
|
||||
if (stop) break;
|
||||
while (gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
if (stop)
|
||||
break;
|
||||
}
|
||||
isoClose(src);
|
||||
isoClose(dst);
|
||||
|
||||
if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
|
||||
if (!stop)
|
||||
gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
|
||||
|
||||
gtk_widget_set_sensitive(BtnCompress, TRUE);
|
||||
gtk_widget_set_sensitive(BtnDecompress, TRUE);
|
||||
gtk_widget_set_sensitive(BtnCreate, TRUE);
|
||||
gtk_widget_set_sensitive(BtnCreateZ, TRUE);
|
||||
|
||||
if (!stop)
|
||||
{
|
||||
if (ret == -1)
|
||||
{
|
||||
if (!stop) {
|
||||
if (ret == -1) {
|
||||
SysMessageLoc("Error compressing iso image");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SysMessageLoc("Iso image compressed OK");
|
||||
}
|
||||
}
|
||||
|
@ -256,13 +261,11 @@ void OnDecompress(GtkButton *button, gpointer user_data)
|
|||
void incSector()
|
||||
{
|
||||
param[2]++;
|
||||
if (param[2] == 75)
|
||||
{
|
||||
if (param[2] == 75) {
|
||||
param[2] = 0;
|
||||
param[1]++;
|
||||
}
|
||||
if (param[1] == 60)
|
||||
{
|
||||
if (param[1] == 60) {
|
||||
param[1] = 0;
|
||||
param[0]++;
|
||||
}
|
||||
|
@ -273,8 +276,7 @@ long CDR_open(void)
|
|||
if (cddev != -1)
|
||||
return 0;
|
||||
cddev = open(CdDev, O_RDONLY);
|
||||
if (cddev == -1)
|
||||
{
|
||||
if (cddev == -1) {
|
||||
printf("CDR: Could not open %s\n", CdDev);
|
||||
return -1;
|
||||
}
|
||||
|
@ -284,7 +286,8 @@ long CDR_open(void)
|
|||
|
||||
long CDR_close(void)
|
||||
{
|
||||
if (cddev == -1) return 0;
|
||||
if (cddev == -1)
|
||||
return 0;
|
||||
close(cddev);
|
||||
cddev = -1;
|
||||
|
||||
|
@ -299,7 +302,8 @@ long CDR_getTN(unsigned char *buffer)
|
|||
{
|
||||
struct cdrom_tochdr toc;
|
||||
|
||||
if (ioctl(cddev, CDROMREADTOCHDR, &toc) == -1) return -1;
|
||||
if (ioctl(cddev, CDROMREADTOCHDR, &toc) == -1)
|
||||
return -1;
|
||||
|
||||
buffer[0] = toc.cdth_trk0; // start track
|
||||
buffer[1] = toc.cdth_trk1; // end track
|
||||
|
@ -316,11 +320,13 @@ long CDR_getTD(unsigned char track, unsigned char *buffer)
|
|||
{
|
||||
struct cdrom_tocentry entry;
|
||||
|
||||
if (track == 0) track = 0xaa; // total time
|
||||
if (track == 0)
|
||||
track = 0xaa; // total time
|
||||
entry.cdte_track = track;
|
||||
entry.cdte_format = CDROM_MSF;
|
||||
|
||||
if (ioctl(cddev, CDROMREADTOCENTRY, &entry) == -1) return -1;
|
||||
if (ioctl(cddev, CDROMREADTOCENTRY, &entry) == -1)
|
||||
return -1;
|
||||
|
||||
buffer[0] = entry.cdte_addr.msf.minute; /* minute */
|
||||
buffer[1] = entry.cdte_addr.msf.second; /* second */
|
||||
|
@ -340,7 +346,8 @@ unsigned char *CDR_readTrack(unsigned char *time)
|
|||
cr.msf.cdmsf_sec0 = time[1];
|
||||
cr.msf.cdmsf_frame0 = time[2];
|
||||
|
||||
if (ioctl(cddev, CDROMREADRAW, &cr) == -1) return NULL;
|
||||
if (ioctl(cddev, CDROMREADRAW, &cr) == -1)
|
||||
return NULL;
|
||||
return cr.buf;
|
||||
}
|
||||
|
||||
|
@ -369,26 +376,22 @@ void OnCreate(GtkButton *button, gpointer user_data)
|
|||
tmp = gtk_entry_get_text(GTK_ENTRY(Edit));
|
||||
strcpy(IsoFile, tmp);
|
||||
|
||||
if (stat(IsoFile, &buf) == 0)
|
||||
{
|
||||
if (stat(IsoFile, &buf) == 0) {
|
||||
printf("File %s Already exists\n", IsoFile);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CDR_open() == -1)
|
||||
{
|
||||
if (CDR_open() == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (CDR_getTD(ftrack, start) == -1)
|
||||
{
|
||||
if (CDR_getTD(ftrack, start) == -1) {
|
||||
printf("Error getting TD\n");
|
||||
|
||||
CDR_close();
|
||||
return;
|
||||
}
|
||||
if (CDR_getTD(ltrack, end) == -1)
|
||||
{
|
||||
if (CDR_getTD(ltrack, end) == -1) {
|
||||
printf("Error getting TD\n");
|
||||
|
||||
CDR_close();
|
||||
|
@ -396,8 +399,7 @@ void OnCreate(GtkButton *button, gpointer user_data)
|
|||
}
|
||||
|
||||
f = fopen(IsoFile, "wb");
|
||||
if (f == NULL)
|
||||
{
|
||||
if (f == NULL) {
|
||||
CDR_close();
|
||||
printf("Error opening %s", IsoFile);
|
||||
return;
|
||||
|
@ -424,17 +426,15 @@ void OnCreate(GtkButton *button, gpointer user_data)
|
|||
if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
|
||||
break;
|
||||
buffer = CDR_readTrack(param);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
if (buffer == NULL) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = CDR_readTrack(param);
|
||||
if (buffer != NULL) break;
|
||||
if (buffer != NULL)
|
||||
break;
|
||||
}
|
||||
if (buffer == NULL)
|
||||
{
|
||||
if (buffer == NULL) {
|
||||
printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
|
||||
buffer = bufferz;
|
||||
buffer[12] = param[0];
|
||||
|
@ -448,8 +448,7 @@ void OnCreate(GtkButton *button, gpointer user_data)
|
|||
count += CD_FRAMESIZE_RAW;
|
||||
|
||||
printf("reading %2d:%2d:%2d ", param[0], param[1], param[2]);
|
||||
if ((time(NULL) - Ttime) != 0)
|
||||
{
|
||||
if ((time(NULL) - Ttime) != 0) {
|
||||
i = (count / 1024) / (time(NULL) - Ttime);
|
||||
printf("( %5dKbytes/s, %dX)", i, i / 150);
|
||||
}
|
||||
|
@ -462,8 +461,10 @@ void OnCreate(GtkButton *button, gpointer user_data)
|
|||
p++;
|
||||
per = ((float)p / s);
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per);
|
||||
while (gtk_events_pending()) gtk_main_iteration();
|
||||
if (stop) break;
|
||||
while (gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
if (stop)
|
||||
break;
|
||||
}
|
||||
|
||||
Ttime = time(NULL) - Ttime;
|
||||
|
@ -479,7 +480,8 @@ void OnCreate(GtkButton *button, gpointer user_data)
|
|||
gtk_widget_set_sensitive(BtnCreate, TRUE);
|
||||
gtk_widget_set_sensitive(BtnCreateZ, TRUE);
|
||||
|
||||
if (!stop) SysMessageLoc("Iso Image Created OK");
|
||||
if (!stop)
|
||||
SysMessageLoc("Iso Image Created OK");
|
||||
}
|
||||
|
||||
void OnCreateZ(GtkButton *button, gpointer user_data)
|
||||
|
@ -511,19 +513,17 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
|
|||
|
||||
UpdZmode();
|
||||
|
||||
if (Zmode == 1)
|
||||
{
|
||||
if (Zmode == 1) {
|
||||
blocks = 1;
|
||||
if (strstr(IsoFile, ".Z") == NULL) strcat(IsoFile, ".Z");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strstr(IsoFile, ".Z") == NULL)
|
||||
strcat(IsoFile, ".Z");
|
||||
} else {
|
||||
blocks = 10;
|
||||
if (strstr(IsoFile, ".bz") == NULL) strcat(IsoFile, ".bz");
|
||||
if (strstr(IsoFile, ".bz") == NULL)
|
||||
strcat(IsoFile, ".bz");
|
||||
}
|
||||
|
||||
if (stat(IsoFile, &buf) == 0)
|
||||
{
|
||||
if (stat(IsoFile, &buf) == 0) {
|
||||
printf("File %s Already exists\n", IsoFile);
|
||||
return;
|
||||
}
|
||||
|
@ -536,22 +536,20 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
|
|||
|
||||
t = fopen(table, "wb");
|
||||
|
||||
if (t == NULL) return;
|
||||
if (CDR_open() == -1)
|
||||
{
|
||||
if (t == NULL)
|
||||
return;
|
||||
if (CDR_open() == -1) {
|
||||
fclose(t);
|
||||
return;
|
||||
}
|
||||
if (CDR_getTD(ftrack, start) == -1)
|
||||
{
|
||||
if (CDR_getTD(ftrack, start) == -1) {
|
||||
printf("Error getting TD\n");
|
||||
CDR_close();
|
||||
fclose(t);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CDR_getTD(ltrack, end) == -1)
|
||||
{
|
||||
if (CDR_getTD(ltrack, end) == -1) {
|
||||
printf("Error getting TD\n");
|
||||
CDR_close();
|
||||
fclose(t);
|
||||
|
@ -559,8 +557,7 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
|
|||
}
|
||||
|
||||
f = fopen(IsoFile, "wb");
|
||||
if (f == NULL)
|
||||
{
|
||||
if (f == NULL) {
|
||||
CDR_close();
|
||||
fclose(t);
|
||||
printf("Error opening %s", IsoFile);
|
||||
|
@ -587,24 +584,21 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
|
|||
unsigned char Zbuf[CD_FRAMESIZE_RAW * 10 * 2];
|
||||
float per;
|
||||
|
||||
for (b = 0; b < blocks; b++)
|
||||
{
|
||||
for (b = 0; b < blocks; b++) {
|
||||
if ((param[0] == end[0]) & (param[1] == end[1]) & (param[2] == end[2]))
|
||||
break;
|
||||
|
||||
buffer = CDR_readTrack(param);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
if (buffer == NULL) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
for (i = 0; i < 10; i++) {
|
||||
buffer = CDR_readTrack(param);
|
||||
if (buffer != NULL) break;
|
||||
if (buffer != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if (buffer == NULL)
|
||||
{
|
||||
if (buffer == NULL) {
|
||||
printf("Error Reading %2d:%2d:%2d\n", param[0], param[1], param[2]);
|
||||
buffer = bufferz;
|
||||
buffer[12] = param[0];
|
||||
|
@ -627,7 +621,8 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
|
|||
BZ2_bzBuffToBuffCompress((char *)Zbuf, (unsigned int *)&size, (char *)cdbuffer, CD_FRAMESIZE_RAW * 10, 1, 0, 30);
|
||||
|
||||
fwrite(&c, 1, 4, t);
|
||||
if (Zmode == 1) fwrite(&size, 1, 2, t);
|
||||
if (Zmode == 1)
|
||||
fwrite(&size, 1, 2, t);
|
||||
|
||||
fwrite(Zbuf, 1, size, f);
|
||||
|
||||
|
@ -636,8 +631,7 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
|
|||
count += CD_FRAMESIZE_RAW * blocks;
|
||||
|
||||
printf("reading %2d:%2d:%2d ", param[0], param[1], param[2]);
|
||||
if ((time(NULL) - Ttime) != 0)
|
||||
{
|
||||
if ((time(NULL) - Ttime) != 0) {
|
||||
i = (count / 1024) / (time(NULL) - Ttime);
|
||||
printf("( %5dKbytes/s, %dX)", i, i / 150);
|
||||
}
|
||||
|
@ -649,13 +643,17 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
|
|||
per = ((float)p / s);
|
||||
|
||||
gtk_progress_bar_update(GTK_PROGRESS_BAR(Progress), per);
|
||||
while (gtk_events_pending()) gtk_main_iteration();
|
||||
while (gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
|
||||
if (stop) break;
|
||||
if (stop)
|
||||
break;
|
||||
}
|
||||
if (Zmode == 2) fwrite(&c, 1, 4, f);
|
||||
if (Zmode == 2)
|
||||
fwrite(&c, 1, 4, f);
|
||||
|
||||
if (!stop) gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
|
||||
if (!stop)
|
||||
gtk_entry_set_text(GTK_ENTRY(Edit), IsoFile);
|
||||
|
||||
Ttime = time(NULL) - Ttime;
|
||||
Tm = gmtime(&Ttime);
|
||||
|
@ -671,5 +669,6 @@ void OnCreateZ(GtkButton *button, gpointer user_data)
|
|||
gtk_widget_set_sensitive(BtnCreate, TRUE);
|
||||
gtk_widget_set_sensitive(BtnCreateZ, TRUE);
|
||||
|
||||
if (!stop) SysMessageLoc("Compressed Iso Image Created OK");
|
||||
if (!stop)
|
||||
SysMessageLoc("Compressed Iso Image Created OK");
|
||||
}
|
||||
|
|
|
@ -1,34 +1,26 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
|
||||
void
|
||||
OnFileSel (GtkButton *button,
|
||||
void OnFileSel(GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
OnStop (GtkButton *button,
|
||||
void OnStop(GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
OnCompress (GtkButton *button,
|
||||
void OnCompress(GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
OnDecompress (GtkButton *button,
|
||||
void OnDecompress(GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
OnCreate (GtkButton *button,
|
||||
void OnCreate(GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
OnCreateZ (GtkButton *button,
|
||||
void OnCreateZ(GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
OnOk (GtkButton *button,
|
||||
void OnOk(GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
OnCancel (GtkButton *button,
|
||||
void OnCancel(GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
|
|
@ -66,4 +66,3 @@ GdkPixbuf* create_pixbuf (const gchar *filename);
|
|||
void glade_set_atk_action_description(AtkAction *action,
|
||||
const gchar *action_name,
|
||||
const gchar *description);
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include "../CDVDiso.h"
|
||||
|
||||
#define GetKeyV(name, var, s, t) \
|
||||
size = s; type = t; \
|
||||
size = s; \
|
||||
type = t; \
|
||||
RegQueryValueEx(myKey, name, 0, &type, (LPBYTE)var, &size);
|
||||
|
||||
#define GetKeyVdw(name, var) \
|
||||
|
@ -37,8 +38,7 @@ void LoadConf()
|
|||
|
||||
memset(IsoFile, 0, sizeof(IsoFile));
|
||||
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\CDVD\\CDVDiso", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS)
|
||||
{
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\CDVD\\CDVDiso", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS) {
|
||||
SaveConf();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
void SaveConf();
|
||||
void LoadConf();
|
||||
|
||||
|
|
|
@ -67,8 +67,7 @@ int _GetFile(char *out)
|
|||
ofn.lpstrDefExt = NULL;
|
||||
ofn.Flags = OFN_HIDEREADONLY;
|
||||
|
||||
if (GetOpenFileName((LPOPENFILENAME)&ofn))
|
||||
{
|
||||
if (GetOpenFileName((LPOPENFILENAME)&ofn)) {
|
||||
strcpy(out, szFileName);
|
||||
return 1;
|
||||
}
|
||||
|
@ -87,8 +86,7 @@ int _OpenFile(int saveConf)
|
|||
if (IsoCWD[0] != 0)
|
||||
_chdir(IsoCWD);
|
||||
|
||||
if (_GetFile(IsoFile) == 1)
|
||||
{
|
||||
if (_GetFile(IsoFile) == 1) {
|
||||
// Save the user's new cwd:
|
||||
if (_getcwd(IsoCWD, MAXFILENAME) == NULL)
|
||||
IsoCWD[0] = 0;
|
||||
|
@ -100,8 +98,7 @@ int _OpenFile(int saveConf)
|
|||
}
|
||||
|
||||
// Restore Pcsx2's path.
|
||||
if (cwd_pcsx2 != NULL)
|
||||
{
|
||||
if (cwd_pcsx2 != NULL) {
|
||||
_chdir(cwd_pcsx2);
|
||||
free(cwd_pcsx2);
|
||||
cwd_pcsx2 = NULL;
|
||||
|
@ -116,12 +113,9 @@ void CfgOpenFile()
|
|||
|
||||
void UpdZmode()
|
||||
{
|
||||
if (ComboBox_GetCurSel(hMethod) == 0)
|
||||
{
|
||||
if (ComboBox_GetCurSel(hMethod) == 0) {
|
||||
Zmode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Zmode = 2;
|
||||
}
|
||||
}
|
||||
|
@ -131,8 +125,7 @@ void SysUpdate()
|
|||
{
|
||||
MSG msg;
|
||||
|
||||
while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
||||
{
|
||||
while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
@ -150,62 +143,57 @@ void OnCompress()
|
|||
Edit_GetText(hIsoFile, IsoFile, 256);
|
||||
UpdZmode();
|
||||
|
||||
if (Zmode == 1)
|
||||
{
|
||||
if (Zmode == 1) {
|
||||
sprintf(Zfile, "%s.Z2", IsoFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(Zfile, "%s.BZ2", IsoFile);
|
||||
}
|
||||
|
||||
src = isoOpen(IsoFile);
|
||||
if (src == NULL) return;
|
||||
if (Zmode == 1)
|
||||
{
|
||||
if (src == NULL)
|
||||
return;
|
||||
if (Zmode == 1) {
|
||||
dst = isoCreate(Zfile, ISOFLAGS_Z2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dst = isoCreate(Zfile, ISOFLAGS_BZ2);
|
||||
}
|
||||
if (dst == NULL) return;
|
||||
if (dst == NULL)
|
||||
return;
|
||||
|
||||
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
|
||||
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), FALSE);
|
||||
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE);
|
||||
stop = 0;
|
||||
|
||||
for (lsn = 0; lsn < src->blocks; lsn++)
|
||||
{
|
||||
for (lsn = 0; lsn < src->blocks; lsn++) {
|
||||
//printf("block %d ", lsn);
|
||||
//putchar(13);
|
||||
//fflush(stdout);
|
||||
ret = isoReadBlock(src, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
ret = isoWriteBlock(dst, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
|
||||
SendMessage(hProgress, PBM_SETPOS, (lsn * 100) / src->blocks, 0);
|
||||
SysUpdate();
|
||||
if (stop) break;
|
||||
if (stop)
|
||||
break;
|
||||
}
|
||||
isoClose(src);
|
||||
isoClose(dst);
|
||||
|
||||
if (!stop) Edit_SetText(hIsoFile, Zfile);
|
||||
if (!stop)
|
||||
Edit_SetText(hIsoFile, Zfile);
|
||||
|
||||
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE);
|
||||
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE);
|
||||
|
||||
if (!stop)
|
||||
{
|
||||
if (ret == -1)
|
||||
{
|
||||
if (!stop) {
|
||||
if (ret == -1) {
|
||||
SysMessage("Error compressing iso image");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SysMessage("Iso image compressed OK");
|
||||
}
|
||||
}
|
||||
|
@ -223,52 +211,48 @@ void OnDecompress()
|
|||
Edit_GetText(hIsoFile, IsoFile, 256);
|
||||
|
||||
src = isoOpen(IsoFile);
|
||||
if (src == NULL) return;
|
||||
if (src == NULL)
|
||||
return;
|
||||
|
||||
strcpy(file, IsoFile);
|
||||
if (src->flags & ISOFLAGS_Z)
|
||||
{
|
||||
if (src->flags & ISOFLAGS_Z) {
|
||||
file[strlen(file) - 2] = 0;
|
||||
}
|
||||
else
|
||||
if (src->flags & ISOFLAGS_Z2)
|
||||
{
|
||||
} else if (src->flags & ISOFLAGS_Z2) {
|
||||
file[strlen(file) - 3] = 0;
|
||||
}
|
||||
else
|
||||
if (src->flags & ISOFLAGS_BZ2)
|
||||
{
|
||||
} else if (src->flags & ISOFLAGS_BZ2) {
|
||||
file[strlen(file) - 3] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SysMessage("%s is not a compressed image", IsoFile);
|
||||
return;
|
||||
}
|
||||
|
||||
dst = isoCreate(file, 0);
|
||||
if (dst == NULL) return;
|
||||
if (dst == NULL)
|
||||
return;
|
||||
|
||||
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
|
||||
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), FALSE);
|
||||
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE);
|
||||
stop = 0;
|
||||
|
||||
for (lsn = 0; lsn < src->blocks; lsn++)
|
||||
{
|
||||
for (lsn = 0; lsn < src->blocks; lsn++) {
|
||||
printf("block %d ", lsn);
|
||||
putchar(13);
|
||||
fflush(stdout);
|
||||
ret = isoReadBlock(src, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
ret = isoWriteBlock(dst, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
|
||||
SendMessage(hProgress, PBM_SETPOS, (lsn * 100) / src->blocks, 0);
|
||||
SysUpdate();
|
||||
if (stop) break;
|
||||
if (stop)
|
||||
break;
|
||||
}
|
||||
if (!stop) Edit_SetText(hIsoFile, file);
|
||||
if (!stop)
|
||||
Edit_SetText(hIsoFile, file);
|
||||
|
||||
isoClose(src);
|
||||
isoClose(dst);
|
||||
|
@ -276,14 +260,10 @@ void OnDecompress()
|
|||
Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE);
|
||||
Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE);
|
||||
|
||||
if (!stop)
|
||||
{
|
||||
if (ret == -1)
|
||||
{
|
||||
if (!stop) {
|
||||
if (ret == -1) {
|
||||
SysMessage("Error decompressing iso image");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SysMessage("Iso image decompressed OK");
|
||||
}
|
||||
}
|
||||
|
@ -293,8 +273,7 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
int i;
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
switch (uMsg) {
|
||||
case WM_INITDIALOG:
|
||||
hDlg = hW;
|
||||
LoadConf();
|
||||
|
@ -304,8 +283,7 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
hMethod = GetDlgItem(hW, IDC_METHOD);
|
||||
hBlockDump = GetDlgItem(hW, IDC_BLOCKDUMP);
|
||||
|
||||
for (i = 0; methods[i] != NULL; i++)
|
||||
{
|
||||
for (i = 0; methods[i] != NULL; i++) {
|
||||
ComboBox_AddString(hMethod, methods[i]);
|
||||
}
|
||||
|
||||
|
@ -319,8 +297,7 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
return TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam))
|
||||
{
|
||||
switch (LOWORD(wParam)) {
|
||||
case IDC_SELECTISO:
|
||||
if (_OpenFile(FALSE) == 1)
|
||||
Edit_SetText(hIsoFile, IsoFile);
|
||||
|
@ -354,7 +331,8 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
EXPORT_C_(void) CDVDconfigure()
|
||||
EXPORT_C_(void)
|
||||
CDVDconfigure()
|
||||
{
|
||||
DialogBox(hInst,
|
||||
MAKEINTRESOURCE(IDD_CONFIG),
|
||||
|
@ -364,14 +342,12 @@ EXPORT_C_(void) CDVDconfigure()
|
|||
|
||||
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (uMsg)
|
||||
{
|
||||
switch (uMsg) {
|
||||
case WM_INITDIALOG:
|
||||
return TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam))
|
||||
{
|
||||
switch (LOWORD(wParam)) {
|
||||
case IDOK:
|
||||
EndDialog(hW, TRUE);
|
||||
return FALSE;
|
||||
|
@ -380,7 +356,8 @@ BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
EXPORT_C_(void) CDVDabout()
|
||||
EXPORT_C_(void)
|
||||
CDVDabout()
|
||||
{
|
||||
DialogBox(hInst,
|
||||
MAKEINTRESOURCE(IDD_ABOUT),
|
||||
|
@ -395,4 +372,3 @@ BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
|
|||
hInst = (HINSTANCE)hModule;
|
||||
return TRUE; // very quick :)
|
||||
}
|
||||
|
||||
|
|
|
@ -117,14 +117,12 @@ void *_openfile(const char *filename, int flags)
|
|||
HANDLE handle;
|
||||
|
||||
// printf("_openfile %s, %d\n", filename, flags & O_RDONLY);
|
||||
if (flags & O_WRONLY)
|
||||
{
|
||||
if (flags & O_WRONLY) {
|
||||
int _flags = CREATE_NEW;
|
||||
if (flags & O_CREAT) _flags = CREATE_ALWAYS;
|
||||
if (flags & O_CREAT)
|
||||
_flags = CREATE_ALWAYS;
|
||||
handle = CreateFile(filename, GENERIC_WRITE, 0, NULL, _flags, 0, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
handle = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
}
|
||||
|
||||
|
@ -145,12 +143,9 @@ int _seekfile(void *handle, u64 offset, int whence)
|
|||
u64 ofs = (u64)offset;
|
||||
PLONG _ofs = (LONG *)&ofs;
|
||||
// printf("_seekfile %p, %d_%d\n", handle, _ofs[1], _ofs[0]);
|
||||
if (whence == SEEK_SET)
|
||||
{
|
||||
if (whence == SEEK_SET) {
|
||||
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END);
|
||||
}
|
||||
return 0;
|
||||
|
@ -200,12 +195,10 @@ u64 _tellfile(void *handle)
|
|||
{
|
||||
FILE *fp = (FILE *)handle;
|
||||
s64 cursize = ftell(fp);
|
||||
if (cursize == -1)
|
||||
{
|
||||
if (cursize == -1) {
|
||||
// try 64bit
|
||||
cursize = ftello64(fp);
|
||||
if (cursize < -1)
|
||||
{
|
||||
if (cursize < -1) {
|
||||
// zero top 32 bits
|
||||
cursize &= 0xffffffff;
|
||||
}
|
||||
|
@ -217,7 +210,8 @@ int _seekfile(void *handle, u64 offset, int whence)
|
|||
{
|
||||
int seekerr = fseeko64((FILE *)handle, offset, whence);
|
||||
|
||||
if (seekerr == -1) printf("failed to seek\n");
|
||||
if (seekerr == -1)
|
||||
printf("failed to seek\n");
|
||||
|
||||
return seekerr;
|
||||
}
|
||||
|
@ -244,11 +238,13 @@ int detect(isoFile *iso)
|
|||
u8 buf[2448];
|
||||
struct cdVolDesc *volDesc;
|
||||
|
||||
if (isoReadBlock(iso, buf, 16) == -1) return -1;
|
||||
if (isoReadBlock(iso, buf, 16) == -1)
|
||||
return -1;
|
||||
|
||||
volDesc = (struct cdVolDesc *)(buf + 24);
|
||||
|
||||
if (strncmp((char*)volDesc->volID, "CD001", 5)) return 0;
|
||||
if (strncmp((char *)volDesc->volID, "CD001", 5))
|
||||
return 0;
|
||||
|
||||
if (volDesc->rootToc.tocSize == 2048)
|
||||
iso->type = ISOTYPE_CD;
|
||||
|
@ -266,8 +262,7 @@ int _isoReadZtable(isoFile *iso)
|
|||
|
||||
sprintf(table, "%s.table", iso->filename);
|
||||
handle = _openfile(table, O_RDONLY);
|
||||
if (handle == NULL)
|
||||
{
|
||||
if (handle == NULL) {
|
||||
printf("Error loading %s\n", table);
|
||||
return -1;
|
||||
}
|
||||
|
@ -276,8 +271,7 @@ int _isoReadZtable(isoFile *iso)
|
|||
size = _tellfile(handle);
|
||||
iso->Ztable = (char *)malloc(size);
|
||||
|
||||
if (iso->Ztable == NULL)
|
||||
{
|
||||
if (iso->Ztable == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -300,8 +294,7 @@ int _isoReadZ2table(isoFile *iso)
|
|||
sprintf(table, "%s.table", iso->filename);
|
||||
handle = _openfile(table, O_RDONLY);
|
||||
|
||||
if (handle == NULL)
|
||||
{
|
||||
if (handle == NULL) {
|
||||
printf("Error loading %s\n", table);
|
||||
return -1;
|
||||
}
|
||||
|
@ -310,8 +303,7 @@ int _isoReadZ2table(isoFile *iso)
|
|||
size = _tellfile(handle);
|
||||
Ztable = (u32 *)malloc(size);
|
||||
|
||||
if (Ztable == NULL)
|
||||
{
|
||||
if (Ztable == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -321,16 +313,14 @@ int _isoReadZ2table(isoFile *iso)
|
|||
|
||||
iso->Ztable = (char *)malloc(iso->blocks * 8);
|
||||
|
||||
if (iso->Ztable == NULL)
|
||||
{
|
||||
if (iso->Ztable == NULL) {
|
||||
free(Ztable);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ofs = 16;
|
||||
|
||||
for (i = 0; i < iso->blocks; i++)
|
||||
{
|
||||
for (i = 0; i < iso->blocks; i++) {
|
||||
*(u32 *)&iso->Ztable[i * 8 + 0] = ofs;
|
||||
*(u32 *)&iso->Ztable[i * 8 + 4] = Ztable[i];
|
||||
ofs += Ztable[i];
|
||||
|
@ -352,8 +342,7 @@ int _isoReadBZ2table(isoFile *iso)
|
|||
|
||||
sprintf(table, "%s.table", iso->filename);
|
||||
handle = _openfile(table, O_RDONLY);
|
||||
if (handle == NULL)
|
||||
{
|
||||
if (handle == NULL) {
|
||||
printf("Error loading %s\n", table);
|
||||
return -1;
|
||||
}
|
||||
|
@ -361,7 +350,8 @@ int _isoReadBZ2table(isoFile *iso)
|
|||
_seekfile(handle, 0, SEEK_END);
|
||||
size = _tellfile(handle);
|
||||
Ztable = (u32 *)malloc(size);
|
||||
if (Ztable == NULL) return -1;
|
||||
if (Ztable == NULL)
|
||||
return -1;
|
||||
|
||||
_seekfile(handle, 0, SEEK_SET);
|
||||
_readfile(handle, Ztable, size);
|
||||
|
@ -376,15 +366,13 @@ int _isoReadBZ2table(isoFile *iso)
|
|||
|
||||
ofs = 16;
|
||||
|
||||
for (i = 0; i < iso->blocks / 16; i++)
|
||||
{
|
||||
for (i = 0; i < iso->blocks / 16; i++) {
|
||||
*(u32 *)&iso->Ztable[i * 8 + 0] = ofs;
|
||||
*(u32 *)&iso->Ztable[i * 8 + 4] = Ztable[i];
|
||||
ofs += Ztable[i];
|
||||
}
|
||||
|
||||
if (iso->blocks & 0xf)
|
||||
{
|
||||
if (iso->blocks & 0xf) {
|
||||
*(u32 *)&iso->Ztable[i * 8 + 0] = ofs;
|
||||
*(u32 *)&iso->Ztable[i * 8 + 4] = Ztable[i];
|
||||
ofs += Ztable[i];
|
||||
|
@ -404,11 +392,11 @@ int _isoReadDtable(isoFile *iso)
|
|||
iso->dtablesize = (_tellfile(iso->handle) - 16) / (iso->blocksize + 4);
|
||||
iso->dtable = (u32 *)malloc(iso->dtablesize * 4);
|
||||
|
||||
for (i = 0; i < iso->dtablesize; i++)
|
||||
{
|
||||
for (i = 0; i < iso->dtablesize; i++) {
|
||||
_seekfile(iso->handle, 16 + (iso->blocksize + 4) * i, SEEK_SET);
|
||||
ret = _readfile(iso->handle, &iso->dtable[i], 4);
|
||||
if (ret < 4) return -1;
|
||||
if (ret < 4)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -422,10 +410,8 @@ int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
|
|||
iso->type = ISOTYPE_ILLEGAL;
|
||||
|
||||
len = strlen(iso->filename);
|
||||
if (len >= 2)
|
||||
{
|
||||
if (!strncmp(iso->filename + (len - 2), ".Z", 2))
|
||||
{
|
||||
if (len >= 2) {
|
||||
if (!strncmp(iso->filename + (len - 2), ".Z", 2)) {
|
||||
iso->flags = ISOFLAGS_Z;
|
||||
iso->blocksize = 2352;
|
||||
_isoReadZtable(iso);
|
||||
|
@ -436,38 +422,32 @@ int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
|
|||
_seekfile(iso->handle, 0, SEEK_SET);
|
||||
_readfile(iso->handle, buf, 4);
|
||||
|
||||
if (strncmp(buf, "BDV2", 4) == 0)
|
||||
{
|
||||
if (strncmp(buf, "BDV2", 4) == 0) {
|
||||
iso->flags = ISOFLAGS_BLOCKDUMP;
|
||||
_readfile(iso->handle, &iso->blocksize, 4);
|
||||
_readfile(iso->handle, &iso->blocks, 4);
|
||||
_readfile(iso->handle, &iso->blockofs, 4);
|
||||
_isoReadDtable(iso);
|
||||
return detect(iso) == 1 ? 0 : -1;
|
||||
}
|
||||
else if (strncmp(buf, "Z V2", 4) == 0)
|
||||
{
|
||||
} else if (strncmp(buf, "Z V2", 4) == 0) {
|
||||
iso->flags = ISOFLAGS_Z2;
|
||||
_readfile(iso->handle, &iso->blocksize, 4);
|
||||
_readfile(iso->handle, &iso->blocks, 4);
|
||||
_readfile(iso->handle, &iso->blockofs, 4);
|
||||
_isoReadZ2table(iso);
|
||||
return detect(iso) == 1 ? 0 : -1;
|
||||
}
|
||||
else if (strncmp(buf, "BZV2", 4) == 0)
|
||||
{
|
||||
} else if (strncmp(buf, "BZV2", 4) == 0) {
|
||||
iso->flags = ISOFLAGS_BZ2;
|
||||
_readfile(iso->handle, &iso->blocksize, 4);
|
||||
_readfile(iso->handle, &iso->blocks, 4);
|
||||
_readfile(iso->handle, &iso->blockofs, 4);
|
||||
iso->buflsn = -1;
|
||||
iso->buffer = (u8 *)malloc(iso->blocksize * 16);
|
||||
if (iso->buffer == NULL) return -1;
|
||||
if (iso->buffer == NULL)
|
||||
return -1;
|
||||
_isoReadBZ2table(iso);
|
||||
return detect(iso) == 1 ? 0 : -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iso->blocks = 16;
|
||||
}
|
||||
|
||||
|
@ -475,61 +455,71 @@ int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
|
|||
iso->blocksize = 2048;
|
||||
iso->offset = 0;
|
||||
iso->blockofs = 24;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// RAW 2336
|
||||
iso->blocksize = 2336;
|
||||
iso->offset = 0;
|
||||
iso->blockofs = 16;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// RAW 2352
|
||||
iso->blocksize = 2352;
|
||||
iso->offset = 0;
|
||||
iso->blockofs = 0;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// RAWQ 2448
|
||||
iso->blocksize = 2448;
|
||||
iso->offset = 0;
|
||||
iso->blockofs = 0;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// NERO ISO 2048
|
||||
iso->blocksize = 2048;
|
||||
iso->offset = 150 * 2048;
|
||||
iso->blockofs = 24;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// NERO RAW 2352
|
||||
iso->blocksize = 2352;
|
||||
iso->offset = 150 * 2048;
|
||||
iso->blockofs = 0;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// NERO RAWQ 2448
|
||||
iso->blocksize = 2448;
|
||||
iso->offset = 150 * 2048;
|
||||
iso->blockofs = 0;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// ISO 2048
|
||||
iso->blocksize = 2048;
|
||||
iso->offset = -8;
|
||||
iso->blockofs = 24;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// RAW 2352
|
||||
iso->blocksize = 2352;
|
||||
iso->offset = -8;
|
||||
iso->blockofs = 0;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
// RAWQ 2448
|
||||
iso->blocksize = 2448;
|
||||
iso->offset = -8;
|
||||
iso->blockofs = 0;
|
||||
if (detect(iso) == 1) return 0;
|
||||
if (detect(iso) == 1)
|
||||
return 0;
|
||||
|
||||
iso->offset = 0;
|
||||
iso->blocksize = 2352;
|
||||
|
@ -545,34 +535,32 @@ isoFile *isoOpen(const char *filename)
|
|||
int i;
|
||||
|
||||
iso = (isoFile *)malloc(sizeof(isoFile));
|
||||
if (iso == NULL) return NULL;
|
||||
if (iso == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(iso, 0, sizeof(isoFile));
|
||||
strcpy(iso->filename, filename);
|
||||
|
||||
iso->handle = _openfile(iso->filename, O_RDONLY);
|
||||
if (iso->handle == NULL)
|
||||
{
|
||||
if (iso->handle == NULL) {
|
||||
printf("Error loading %s\n", iso->filename);
|
||||
free(iso);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (isoDetect(iso) == -1) return NULL;
|
||||
if (isoDetect(iso) == -1)
|
||||
return NULL;
|
||||
|
||||
printf("detected blocksize = %d\n", iso->blocksize);
|
||||
|
||||
if (strlen(iso->filename) > 3 && strncmp(iso->filename + (strlen(iso->filename) - 3), "I00", 3) == 0)
|
||||
{
|
||||
if (strlen(iso->filename) > 3 && strncmp(iso->filename + (strlen(iso->filename) - 3), "I00", 3) == 0) {
|
||||
_closefile(iso->handle);
|
||||
iso->flags |= ISOFLAGS_MULTI;
|
||||
iso->blocks = 0;
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
iso->filename[strlen(iso->filename) - 1] = '0' + i;
|
||||
iso->multih[i].handle = _openfile(iso->filename, O_RDONLY);
|
||||
if (iso->multih[i].handle == NULL)
|
||||
{
|
||||
if (iso->multih[i].handle == NULL) {
|
||||
break;
|
||||
}
|
||||
iso->multih[i].slsn = iso->blocks;
|
||||
|
@ -582,14 +570,12 @@ isoFile *isoOpen(const char *filename)
|
|||
iso->multih[i].elsn = iso->blocks - 1;
|
||||
}
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
if (i == 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (iso->flags == 0)
|
||||
{
|
||||
if (iso->flags == 0) {
|
||||
_seekfile(iso->handle, 0, SEEK_END);
|
||||
iso->blocks = (u32)((_tellfile(iso->handle) - iso->offset) /
|
||||
(iso->blocksize));
|
||||
|
@ -612,7 +598,8 @@ isoFile *isoCreate(const char *filename, int flags)
|
|||
char Zfile[256];
|
||||
|
||||
iso = (isoFile *)malloc(sizeof(isoFile));
|
||||
if (iso == NULL) return NULL;
|
||||
if (iso == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(iso, 0, sizeof(isoFile));
|
||||
strcpy(iso->filename, filename);
|
||||
|
@ -622,20 +609,17 @@ isoFile *isoCreate(const char *filename, int flags)
|
|||
iso->blocksize = CD_FRAMESIZE_RAW;
|
||||
iso->blocksize = 2048;
|
||||
|
||||
if (iso->flags & (ISOFLAGS_Z | ISOFLAGS_Z2 | ISOFLAGS_BZ2))
|
||||
{
|
||||
if (iso->flags & (ISOFLAGS_Z | ISOFLAGS_Z2 | ISOFLAGS_BZ2)) {
|
||||
sprintf(Zfile, "%s.table", iso->filename);
|
||||
iso->htable = _openfile(Zfile, O_WRONLY);
|
||||
if (iso->htable == NULL)
|
||||
{
|
||||
if (iso->htable == NULL) {
|
||||
free(iso);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
iso->handle = _openfile(iso->filename, O_WRONLY | O_CREAT);
|
||||
if (iso->handle == NULL)
|
||||
{
|
||||
if (iso->handle == NULL) {
|
||||
printf("Error loading %s\n", iso->filename);
|
||||
free(iso);
|
||||
return NULL;
|
||||
|
@ -654,29 +638,39 @@ int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks)
|
|||
printf("blockofs = %d\n", iso->blockofs);
|
||||
printf("blocksize = %d\n", iso->blocksize);
|
||||
printf("blocks = %d\n", iso->blocks);
|
||||
if (iso->flags & ISOFLAGS_Z2)
|
||||
{
|
||||
if (_writefile(iso->handle, "Z V2", 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blocksize, 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blocks, 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
|
||||
if (iso->flags & ISOFLAGS_Z2) {
|
||||
if (_writefile(iso->handle, "Z V2", 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blocksize, 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blocks, 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blockofs, 4) < 4)
|
||||
return -1;
|
||||
}
|
||||
if (iso->flags & ISOFLAGS_BZ2)
|
||||
{
|
||||
if (_writefile(iso->handle, "BZV2", 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blocksize, 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blocks, 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
|
||||
if (iso->flags & ISOFLAGS_BZ2) {
|
||||
if (_writefile(iso->handle, "BZV2", 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blocksize, 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blocks, 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blockofs, 4) < 4)
|
||||
return -1;
|
||||
iso->buflsn = -1;
|
||||
iso->buffer = (u8 *)malloc(iso->blocksize * 16);
|
||||
if (iso->buffer == NULL) return -1;
|
||||
if (iso->buffer == NULL)
|
||||
return -1;
|
||||
}
|
||||
if (iso->flags & ISOFLAGS_BLOCKDUMP)
|
||||
{
|
||||
if (_writefile(iso->handle, "BDV2", 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blocksize, 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blocks, 4) < 4) return -1;
|
||||
if (_writefile(iso->handle, &blockofs, 4) < 4) return -1;
|
||||
if (iso->flags & ISOFLAGS_BLOCKDUMP) {
|
||||
if (_writefile(iso->handle, "BDV2", 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blocksize, 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blocks, 4) < 4)
|
||||
return -1;
|
||||
if (_writefile(iso->handle, &blockofs, 4) < 4)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -715,8 +709,7 @@ int _isoReadBlock(isoFile *iso, u8 *dst, int lsn)
|
|||
memset(dst, 0, iso->blockofs);
|
||||
_seekfile(iso->handle, ofs, SEEK_SET);
|
||||
ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize);
|
||||
if (ret < iso->blocksize)
|
||||
{
|
||||
if (ret < iso->blocksize) {
|
||||
printf("read error %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
@ -737,8 +730,7 @@ int _isoReadBlockZ(isoFile *iso, u8 *dst, int lsn)
|
|||
// printf("%d, %d\n", pos, p);
|
||||
_seekfile(iso->handle, pos, SEEK_SET);
|
||||
ret = _readfile(iso->handle, Zbuf, p);
|
||||
if (ret < p)
|
||||
{
|
||||
if (ret < p) {
|
||||
printf("error reading block!!\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -762,8 +754,7 @@ int _isoReadBlockZ2(isoFile *iso, u8 *dst, int lsn)
|
|||
// printf("%d, %d\n", pos, p);
|
||||
_seekfile(iso->handle, pos, SEEK_SET);
|
||||
ret = _readfile(iso->handle, Zbuf, p);
|
||||
if (ret < p)
|
||||
{
|
||||
if (ret < p) {
|
||||
printf("error reading block!!\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -781,8 +772,7 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn)
|
|||
u8 Zbuf[64 * 1024];
|
||||
int ret;
|
||||
|
||||
if ((lsn / 16) == iso->buflsn)
|
||||
{
|
||||
if ((lsn / 16) == iso->buflsn) {
|
||||
memset(dst, 0, iso->blockofs);
|
||||
memcpy(dst + iso->blockofs, iso->buffer + (iso->blocksize * (lsn & 0xf)), iso->blocksize);
|
||||
return 0;
|
||||
|
@ -796,8 +786,7 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn)
|
|||
_seekfile(iso->handle, pos, SEEK_SET);
|
||||
ret = _readfile(iso->handle, Zbuf, p);
|
||||
|
||||
if (ret < p)
|
||||
{
|
||||
if (ret < p) {
|
||||
printf("error reading block!!\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -805,8 +794,7 @@ int _isoReadBlockBZ2(isoFile *iso, u8 *dst, int lsn)
|
|||
size = iso->blocksize * 64;
|
||||
ret = BZ2_bzBuffToBuffDecompress((s8 *)iso->buffer, &size, (s8 *)Zbuf, p, 0, 0);
|
||||
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
if (ret != BZ_OK) {
|
||||
printf("_isoReadBlockBZ2 %d, %d\n", lsn, iso->blocksize);
|
||||
printf("%d, %d\n", pos, p);
|
||||
printf("error on BZ2: %d\n", ret);
|
||||
|
@ -825,13 +813,14 @@ int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn)
|
|||
|
||||
// printf("_isoReadBlockD %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
|
||||
memset(dst, 0, iso->blockofs);
|
||||
for (i = 0; i < iso->dtablesize;i++)
|
||||
{
|
||||
if (iso->dtable[i] != lsn) continue;
|
||||
for (i = 0; i < iso->dtablesize; i++) {
|
||||
if (iso->dtable[i] != lsn)
|
||||
continue;
|
||||
|
||||
_seekfile(iso->handle, 16 + i * (iso->blocksize + 4) + 4, SEEK_SET);
|
||||
ret = _readfile(iso->handle, dst + iso->blockofs, iso->blocksize);
|
||||
if (ret < iso->blocksize) return -1;
|
||||
if (ret < iso->blocksize)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -846,15 +835,14 @@ int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn)
|
|||
int ret;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (lsn >= iso->multih[i].slsn &&
|
||||
lsn <= iso->multih[i].elsn)
|
||||
{
|
||||
lsn <= iso->multih[i].elsn) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 8) return -1;
|
||||
if (i == 8)
|
||||
return -1;
|
||||
|
||||
ofs = (u64)(lsn - iso->multih[i].slsn) * iso->blocksize + iso->offset;
|
||||
// printf("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
|
||||
|
@ -862,8 +850,7 @@ int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn)
|
|||
_seekfile(iso->multih[i].handle, ofs, SEEK_SET);
|
||||
ret = _readfile(iso->multih[i].handle, dst + iso->blockofs, iso->blocksize);
|
||||
|
||||
if (ret < iso->blocksize)
|
||||
{
|
||||
if (ret < iso->blocksize) {
|
||||
printf("read error %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
@ -875,8 +862,7 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn)
|
|||
{
|
||||
int ret;
|
||||
|
||||
if (lsn > iso->blocks)
|
||||
{
|
||||
if (lsn > iso->blocks) {
|
||||
printf("isoReadBlock: %d > %d\n", lsn, iso->blocks);
|
||||
return -1;
|
||||
}
|
||||
|
@ -894,10 +880,10 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn)
|
|||
else
|
||||
ret = _isoReadBlock(iso, dst, lsn);
|
||||
|
||||
if (ret == -1) return ret;
|
||||
if (ret == -1)
|
||||
return ret;
|
||||
|
||||
if (iso->type == ISOTYPE_CD)
|
||||
{
|
||||
if (iso->type == ISOTYPE_CD) {
|
||||
LSNtoMSF(dst + 12, lsn);
|
||||
dst[15] = 2;
|
||||
}
|
||||
|
@ -915,7 +901,8 @@ int _isoWriteBlock(isoFile *iso, u8 *src, int lsn)
|
|||
_seekfile(iso->handle, ofs, SEEK_SET);
|
||||
ret = _writefile(iso->handle, src + iso->blockofs, iso->blocksize);
|
||||
// printf("_isoWriteBlock %d\n", ret);
|
||||
if (ret < iso->blocksize) return -1;
|
||||
if (ret < iso->blocksize)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -934,14 +921,15 @@ int _isoWriteBlockZ(isoFile *iso, u8 *src, int lsn)
|
|||
|
||||
pos = (u32)_tellfile(iso->handle);
|
||||
ret = _writefile(iso->htable, &pos, 4);
|
||||
if (ret < 4) return -1;
|
||||
if (ret < 4)
|
||||
return -1;
|
||||
ret = _writefile(iso->htable, &size, 2);
|
||||
if (ret < 2) return -1;
|
||||
if (ret < 2)
|
||||
return -1;
|
||||
|
||||
ret = _writefile(iso->handle, Zbuf, size);
|
||||
// printf("_isoWriteBlockZ %d\n", ret);
|
||||
if (ret < size)
|
||||
{
|
||||
if (ret < size) {
|
||||
printf("error writing block!!\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -961,11 +949,11 @@ int _isoWriteBlockZ2(isoFile *iso, u8 *src, int lsn)
|
|||
// printf("_isoWriteBlockZ %d\n", size);
|
||||
|
||||
ret = _writefile(iso->htable, (u8 *)&size, 4);
|
||||
if (ret < 4) return -1;
|
||||
if (ret < 4)
|
||||
return -1;
|
||||
ret = _writefile(iso->handle, Zbuf, size);
|
||||
// printf("_isoWriteBlockZ %d\n", ret);
|
||||
if (ret < size)
|
||||
{
|
||||
if (ret < size) {
|
||||
printf("error writing block!!\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -979,10 +967,12 @@ int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn)
|
|||
|
||||
// printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
|
||||
ret = _writefile(iso->handle, &lsn, 4);
|
||||
if (ret < 4) return -1;
|
||||
if (ret < 4)
|
||||
return -1;
|
||||
ret = _writefile(iso->handle, src + iso->blockofs, iso->blocksize);
|
||||
// printf("_isoWriteBlock %d\n", ret);
|
||||
if (ret < iso->blocksize) return -1;
|
||||
if (ret < iso->blocksize)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -996,34 +986,31 @@ int _isoWriteBlockBZ2(isoFile *iso, u8 *src, int lsn)
|
|||
|
||||
memcpy(iso->buffer + (iso->blocksize * (lsn & 0xf)), src + iso->blockofs, iso->blocksize);
|
||||
|
||||
if (lsn == (iso->blocks - 1))
|
||||
{
|
||||
if (lsn == (iso->blocks - 1)) {
|
||||
blocks = (lsn & 0xf) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
blocks = 16;
|
||||
if ((lsn & 0xf) != 0xf) return 0;
|
||||
if ((lsn & 0xf) != 0xf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// printf("_isoWriteBlockBZ2 %d\n", iso->blocksize);
|
||||
size = 64 * 1024;
|
||||
ret = BZ2_bzBuffToBuffCompress((s8 *)Zbuf, (u32 *)&size, (s8 *)iso->buffer, iso->blocksize * blocks, 9, 0, 30);
|
||||
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
if (ret != BZ_OK) {
|
||||
printf("error on BZ2: %d\n", ret);
|
||||
}
|
||||
|
||||
// printf("_isoWriteBlockBZ2 %d\n", size);
|
||||
|
||||
ret = _writefile(iso->htable, (u8 *)&size, 4);
|
||||
if (ret < 4) return -1;
|
||||
if (ret < 4)
|
||||
return -1;
|
||||
ret = _writefile(iso->handle, Zbuf, size);
|
||||
// printf("_isoWriteBlockZ %d\n", ret);
|
||||
|
||||
if (ret < size)
|
||||
{
|
||||
if (ret < size) {
|
||||
printf("error writing block!!\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -1046,15 +1033,19 @@ int isoWriteBlock(isoFile *iso, u8 *src, int lsn)
|
|||
else
|
||||
ret = _isoWriteBlock(iso, src, lsn);
|
||||
|
||||
if (ret == -1) return ret;
|
||||
if (ret == -1)
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void isoClose(isoFile *iso)
|
||||
{
|
||||
if (iso->handle) _closefile(iso->handle);
|
||||
if (iso->htable) _closefile(iso->htable);
|
||||
if (iso->buffer) free(iso->buffer);
|
||||
if (iso->handle)
|
||||
_closefile(iso->handle);
|
||||
if (iso->htable)
|
||||
_closefile(iso->htable);
|
||||
if (iso->buffer)
|
||||
free(iso->buffer);
|
||||
|
||||
free(iso);
|
||||
}
|
||||
|
|
|
@ -35,17 +35,13 @@ void Compress(char *filename, int mode)
|
|||
isoFile *src;
|
||||
isoFile *dst;
|
||||
|
||||
if (mode == 1)
|
||||
{
|
||||
if (mode == 1) {
|
||||
sprintf(Zfile, "%s.Z2", filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sprintf(Zfile, "%s.BZ2", filename);
|
||||
}
|
||||
|
||||
if (stat(Zfile, &buf) != -1)
|
||||
{
|
||||
if (stat(Zfile, &buf) != -1) {
|
||||
printf("'%s' already exists\n", Zfile);
|
||||
return;
|
||||
/* sprintf(str, "'%s' already exists, overwrite?", Zfile);
|
||||
|
@ -56,38 +52,35 @@ void Compress(char *filename, int mode)
|
|||
|
||||
printf("src %s; dst %s\n", filename, Zfile);
|
||||
src = isoOpen(filename);
|
||||
if (src == NULL) return;
|
||||
if (src == NULL)
|
||||
return;
|
||||
|
||||
if (mode == 1)
|
||||
{
|
||||
if (mode == 1) {
|
||||
dst = isoCreate(Zfile, ISOFLAGS_Z2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dst = isoCreate(Zfile, ISOFLAGS_BZ2);
|
||||
}
|
||||
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
|
||||
if (dst == NULL) return;
|
||||
if (dst == NULL)
|
||||
return;
|
||||
|
||||
for (lsn = 0; lsn < src->blocks; lsn++)
|
||||
{
|
||||
for (lsn = 0; lsn < src->blocks; lsn++) {
|
||||
printf("block %d ", lsn);
|
||||
putchar(13);
|
||||
fflush(stdout);
|
||||
ret = isoReadBlock(src, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
ret = isoWriteBlock(dst, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
}
|
||||
isoClose(src);
|
||||
isoClose(dst);
|
||||
|
||||
if (ret == -1)
|
||||
{
|
||||
if (ret == -1) {
|
||||
printf("Error compressing iso image\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("Iso image compressed OK\n");
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +96,8 @@ void Decompress(char *filename)
|
|||
int ret = 0;
|
||||
|
||||
src = isoOpen(filename);
|
||||
if (src == NULL) return;
|
||||
if (src == NULL)
|
||||
return;
|
||||
|
||||
strcpy(file, filename);
|
||||
if (src->flags & ISOFLAGS_Z)
|
||||
|
@ -112,14 +106,12 @@ void Decompress(char *filename)
|
|||
file[strlen(file) - 3] = 0;
|
||||
else if (src->flags & ISOFLAGS_BZ2)
|
||||
file[strlen(file) - 3] = 0;
|
||||
else
|
||||
{
|
||||
else {
|
||||
printf("%s is not a compressed image\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
if (stat(file, &buf) != -1)
|
||||
{
|
||||
if (stat(file, &buf) != -1) {
|
||||
char str[256];
|
||||
sprintf(str, "'%s' already exists", file);
|
||||
isoClose(src);
|
||||
|
@ -127,18 +119,20 @@ void Decompress(char *filename)
|
|||
}
|
||||
|
||||
dst = isoCreate(file, 0);
|
||||
if (dst == NULL) return;
|
||||
if (dst == NULL)
|
||||
return;
|
||||
isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
|
||||
|
||||
for (lsn = 0; lsn < src->blocks; lsn++)
|
||||
{
|
||||
for (lsn = 0; lsn < src->blocks; lsn++) {
|
||||
printf("block %d ", lsn);
|
||||
putchar(13);
|
||||
fflush(stdout);
|
||||
ret = isoReadBlock(src, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
ret = isoWriteBlock(dst, cdbuff, lsn);
|
||||
if (ret == -1) break;
|
||||
if (ret == -1)
|
||||
break;
|
||||
}
|
||||
|
||||
isoClose(src);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -30,12 +30,14 @@ enum PadType {
|
|||
const int numPadTypes = 4;
|
||||
extern const wchar_t *padTypes[numPadTypes];
|
||||
|
||||
struct PadConfig {
|
||||
struct PadConfig
|
||||
{
|
||||
PadType type;
|
||||
u8 autoAnalog;
|
||||
};
|
||||
|
||||
struct GeneralConfig {
|
||||
struct GeneralConfig
|
||||
{
|
||||
public:
|
||||
PadConfig padConfigs[2][4];
|
||||
|
||||
|
@ -47,14 +49,17 @@ public:
|
|||
// Derived value, calculated by GetInput().
|
||||
u8 ignoreKeys;
|
||||
|
||||
union {
|
||||
struct {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
u8 forceHide;
|
||||
u8 mouseUnfocus;
|
||||
u8 background;
|
||||
u8 multipleBinding;
|
||||
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
u8 directInput;
|
||||
u8 xInput;
|
||||
u8 dualShock3;
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
#include "Linux/JoyEvdev.h"
|
||||
#endif
|
||||
|
||||
void EnumDevices(int hideDXXinput) {
|
||||
void EnumDevices(int hideDXXinput)
|
||||
{
|
||||
// Needed for enumeration of some device types.
|
||||
dm->ReleaseInput();
|
||||
InputDeviceManager *oldDm = dm;
|
||||
|
|
|
@ -16,4 +16,3 @@
|
|||
*/
|
||||
|
||||
void EnumDevices(int hideDXXinput);
|
||||
|
||||
|
|
|
@ -25,14 +25,14 @@
|
|||
|
||||
Device *dev;
|
||||
|
||||
INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
int i;
|
||||
HWND hWndList = GetDlgItem(hWnd, IDC_LIST);
|
||||
static int fullRefresh;
|
||||
if (dev) {
|
||||
switch (uMsg) {
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
case WM_INITDIALOG: {
|
||||
fullRefresh = 1;
|
||||
SetWindowText(hWnd, dev->displayName);
|
||||
LVCOLUMNW c;
|
||||
|
@ -55,8 +55,7 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
|
|||
SetTimer(hWnd, 1, 200, 0);
|
||||
}
|
||||
//break;
|
||||
case WM_TIMER:
|
||||
{
|
||||
case WM_TIMER: {
|
||||
hWndButtonProc.SetWndHandle(hWndList);
|
||||
InitInfo info = {0, 1, hWnd, &hWndButtonProc};
|
||||
dm->Update(&info);
|
||||
|
@ -72,8 +71,7 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
|
|||
ListView_SetItem(hWndList, &item);
|
||||
}
|
||||
fullRefresh = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (i = 0; i < dev->numVirtualControls; i++) {
|
||||
if (fullRefresh || dev->virtualControlState[i] != dev->oldVirtualControlState[i]) {
|
||||
|
||||
|
@ -82,8 +80,7 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
|
|||
int val = dev->virtualControlState[i];
|
||||
if (c->uid & (UID_POV)) {
|
||||
wsprintfW(temp, L"%i", val);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
wchar_t *sign = L"";
|
||||
if (val < 0) {
|
||||
sign = L"-";
|
||||
|
@ -106,17 +103,17 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
|
|||
//LockWindowUpdate(0);
|
||||
//ShowWindow(hWndList, 1);
|
||||
//UpdateWindow(hWnd);
|
||||
}
|
||||
break;
|
||||
case WM_NOTIFY:
|
||||
{
|
||||
} break;
|
||||
case WM_NOTIFY: {
|
||||
NMLVKEYDOWN *n = (NMLVKEYDOWN *)lParam;
|
||||
// Don't always get the notification when testing DirectInput non-keyboard devices.
|
||||
// Don't get it (Or want it) when testing keyboards.
|
||||
if (n->hdr.idFrom != IDC_LIST || n->hdr.code != LVN_KEYDOWN || n->wVKey != VK_ESCAPE) break;
|
||||
if (n->hdr.idFrom != IDC_LIST || n->hdr.code != LVN_KEYDOWN || n->wVKey != VK_ESCAPE)
|
||||
break;
|
||||
}
|
||||
case WM_ACTIVATE:
|
||||
if (uMsg == WM_ACTIVATE && wParam != WA_INACTIVE) break;
|
||||
if (uMsg == WM_ACTIVATE && wParam != WA_INACTIVE)
|
||||
break;
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
KillTimer(hWnd, 1);
|
||||
|
@ -132,13 +129,16 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
|
|||
return 0;
|
||||
}
|
||||
|
||||
void Diagnose(int id, HWND hWnd) {
|
||||
void Diagnose(int id, HWND hWnd)
|
||||
{
|
||||
// init = 0;
|
||||
dev = dm->devices[id];
|
||||
for (int i = 0; i < dm->numDevices; i++) {
|
||||
if (i != id) dm->DisableDevice(i);
|
||||
if (i != id)
|
||||
dm->DisableDevice(i);
|
||||
// Shouldn't be needed.
|
||||
else dm->EnableDevice(i);
|
||||
else
|
||||
dm->EnableDevice(i);
|
||||
}
|
||||
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIAG), hWnd, DiagDialog);
|
||||
ClearKeyQueue();
|
||||
|
|
|
@ -32,20 +32,29 @@
|
|||
// media SDK also be installed for a simple macro. This is
|
||||
// simpler and less silly.
|
||||
#ifndef SAFE_RELEASE
|
||||
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
|
||||
#define SAFE_RELEASE(p) \
|
||||
{ \
|
||||
if (p) { \
|
||||
(p)->Release(); \
|
||||
(p) = NULL; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Aka htons, without the winsock dependency.
|
||||
inline static u16 flipShort(u16 s) {
|
||||
inline static u16 flipShort(u16 s)
|
||||
{
|
||||
return (s >> 8) | (s << 8);
|
||||
}
|
||||
|
||||
// Aka htonl, without the winsock dependency.
|
||||
inline static u32 flipLong(u32 l) {
|
||||
inline static u32 flipLong(u32 l)
|
||||
{
|
||||
return (((u32)flipShort((u16)l)) << 16) | flipShort((u16)(l >> 16));
|
||||
}
|
||||
|
||||
static void GUIDtoString(wchar_t *data, const GUID *pg) {
|
||||
static void GUIDtoString(wchar_t *data, const GUID *pg)
|
||||
{
|
||||
wsprintfW(data, L"%08X-%04X-%04X-%04X-%04X%08X",
|
||||
pg->Data1, (u32)pg->Data2, (u32)pg->Data3,
|
||||
flipShort(((u16 *)pg->Data4)[0]),
|
||||
|
@ -53,7 +62,8 @@ static void GUIDtoString(wchar_t *data, const GUID *pg) {
|
|||
flipLong(((u32 *)pg->Data4)[1]));
|
||||
}
|
||||
|
||||
struct DirectInput8Data {
|
||||
struct DirectInput8Data
|
||||
{
|
||||
IDirectInput8 *lpDI8;
|
||||
int refCount;
|
||||
int deviceCount;
|
||||
|
@ -61,14 +71,17 @@ struct DirectInput8Data {
|
|||
|
||||
DirectInput8Data di8d = {0, 0, 0};
|
||||
|
||||
IDirectInput8* GetDirectInput() {
|
||||
IDirectInput8 *GetDirectInput()
|
||||
{
|
||||
if (!di8d.lpDI8) {
|
||||
if (FAILED(DirectInput8Create(hInst, 0x800, IID_IDirectInput8, (void**) &di8d.lpDI8, 0))) return 0;
|
||||
if (FAILED(DirectInput8Create(hInst, 0x800, IID_IDirectInput8, (void **)&di8d.lpDI8, 0)))
|
||||
return 0;
|
||||
}
|
||||
di8d.refCount++;
|
||||
return di8d.lpDI8;
|
||||
}
|
||||
void ReleaseDirectInput() {
|
||||
void ReleaseDirectInput()
|
||||
{
|
||||
if (di8d.refCount) {
|
||||
di8d.refCount--;
|
||||
if (!di8d.refCount) {
|
||||
|
@ -78,9 +91,11 @@ void ReleaseDirectInput() {
|
|||
}
|
||||
}
|
||||
|
||||
static int StringToGUID(GUID *pg, wchar_t *dataw) {
|
||||
static int StringToGUID(GUID *pg, wchar_t *dataw)
|
||||
{
|
||||
char data[100];
|
||||
if (wcslen(dataw) > 50) return 0;
|
||||
if (wcslen(dataw) > 50)
|
||||
return 0;
|
||||
int w = 0;
|
||||
while (dataw[w]) {
|
||||
data[w] = (char)dataw[w];
|
||||
|
@ -100,20 +115,24 @@ static int StringToGUID(GUID *pg, wchar_t *dataw) {
|
|||
}
|
||||
|
||||
|
||||
struct DI8Effect {
|
||||
struct DI8Effect
|
||||
{
|
||||
IDirectInputEffect *die;
|
||||
int scale;
|
||||
};
|
||||
|
||||
BOOL CALLBACK EnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef);
|
||||
BOOL CALLBACK EnumEffectsCallback(LPCDIEFFECTINFOW pdei, LPVOID pvRef);
|
||||
class DirectInputDevice : public Device {
|
||||
class DirectInputDevice : public Device
|
||||
{
|
||||
public:
|
||||
DI8Effect *diEffects;
|
||||
|
||||
IDirectInputDevice8 *did;
|
||||
GUID guidInstance;
|
||||
DirectInputDevice(DeviceType type, IDirectInputDevice8* did, wchar_t *displayName, wchar_t *instanceID, wchar_t *productID, GUID guid) : Device(DI, type, displayName, instanceID, productID) {
|
||||
DirectInputDevice(DeviceType type, IDirectInputDevice8 *did, wchar_t *displayName, wchar_t *instanceID, wchar_t *productID, GUID guid)
|
||||
: Device(DI, type, displayName, instanceID, productID)
|
||||
{
|
||||
diEffects = 0;
|
||||
guidInstance = guid;
|
||||
this->did = 0;
|
||||
|
@ -122,7 +141,8 @@ public:
|
|||
did->Release();
|
||||
}
|
||||
|
||||
void SetEffect(ForceFeedbackBinding *binding, unsigned char force) {
|
||||
void SetEffect(ForceFeedbackBinding *binding, unsigned char force)
|
||||
{
|
||||
int index = 0;
|
||||
if (!diEffects) {
|
||||
return;
|
||||
|
@ -142,7 +162,8 @@ public:
|
|||
if (die) {
|
||||
DIEFFECT dieffect;
|
||||
memset(&dieffect, 0, sizeof(dieffect));
|
||||
union {
|
||||
union
|
||||
{
|
||||
DIPERIODIC periodic;
|
||||
DIRAMPFORCE ramp;
|
||||
DICONSTANTFORCE constant;
|
||||
|
@ -151,20 +172,19 @@ public:
|
|||
dieffect.dwSize = sizeof(dieffect);
|
||||
dieffect.lpvTypeSpecificParams = &periodic;
|
||||
int magnitude = abs((int)((force * 10000 * (__int64)diEffects[index].scale) / BASE_SENSITIVITY / 255));
|
||||
if (magnitude > 10000) magnitude = 10000;
|
||||
if (magnitude > 10000)
|
||||
magnitude = 10000;
|
||||
int type = ffEffectTypes[binding->effectIndex].type;
|
||||
if (type == EFFECT_CONSTANT) {
|
||||
dieffect.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
|
||||
constant.lMagnitude = magnitude;
|
||||
}
|
||||
else if (type == EFFECT_PERIODIC) {
|
||||
} else if (type == EFFECT_PERIODIC) {
|
||||
dieffect.cbTypeSpecificParams = sizeof(DIPERIODIC);
|
||||
periodic.dwMagnitude = 0;
|
||||
periodic.lOffset = magnitude;
|
||||
periodic.dwPhase = 0;
|
||||
periodic.dwPeriod = 2000000;
|
||||
}
|
||||
else if (type == EFFECT_RAMP) {
|
||||
} else if (type == EFFECT_RAMP) {
|
||||
dieffect.cbTypeSpecificParams = sizeof(DIRAMPFORCE);
|
||||
ramp.lEnd = ramp.lStart = magnitude;
|
||||
}
|
||||
|
@ -174,11 +194,13 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
int Activate(InitInfo *initInfo) {
|
||||
int Activate(InitInfo *initInfo)
|
||||
{
|
||||
int i;
|
||||
IDirectInput8 *di8 = GetDirectInput();
|
||||
Deactivate();
|
||||
if (!di8) return 0;
|
||||
if (!di8)
|
||||
return 0;
|
||||
if (DI_OK != di8->CreateDevice(guidInstance, &did, 0)) {
|
||||
ReleaseDirectInput();
|
||||
did = 0;
|
||||
|
@ -230,11 +252,9 @@ public:
|
|||
// Note: Have to use hWndTop to properly hide cursor for mouse device.
|
||||
if (type == OTHER) {
|
||||
did->SetCooperativeLevel(initInfo->hWndTop, DISCL_BACKGROUND | DISCL_EXCLUSIVE);
|
||||
}
|
||||
else if (type == KEYBOARD) {
|
||||
} else if (type == KEYBOARD) {
|
||||
did->SetCooperativeLevel(initInfo->hWndTop, DISCL_FOREGROUND);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
did->SetCooperativeLevel(initInfo->hWndTop, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
|
||||
}
|
||||
if (did->Acquire() != DI_OK) {
|
||||
|
@ -255,7 +275,8 @@ public:
|
|||
b = &pads[port][slot].ffBindings[i - subIndex];
|
||||
ForceFeedbackEffectType *eff = ffEffectTypes + b->effectIndex;
|
||||
GUID guid;
|
||||
if (!StringToGUID(&guid, eff->effectID)) continue;
|
||||
if (!StringToGUID(&guid, eff->effectID))
|
||||
continue;
|
||||
|
||||
DIEFFECT dieffect;
|
||||
memset(&dieffect, 0, sizeof(dieffect));
|
||||
|
@ -264,7 +285,8 @@ public:
|
|||
dieffect.dwDuration = 1000000;
|
||||
dieffect.dwGain = 10000;
|
||||
dieffect.dwTriggerButton = DIEB_NOTRIGGER;
|
||||
union {
|
||||
union
|
||||
{
|
||||
DIPERIODIC pediodic;
|
||||
DIRAMPFORCE ramp;
|
||||
DICONSTANTFORCE constant;
|
||||
|
@ -272,11 +294,9 @@ public:
|
|||
|
||||
if (eff->type == EFFECT_CONSTANT) {
|
||||
dieffect.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
|
||||
}
|
||||
else if (eff->type == EFFECT_PERIODIC) {
|
||||
} else if (eff->type == EFFECT_PERIODIC) {
|
||||
dieffect.cbTypeSpecificParams = sizeof(DIPERIODIC);
|
||||
}
|
||||
else if (eff->type == EFFECT_RAMP) {
|
||||
} else if (eff->type == EFFECT_RAMP) {
|
||||
dieffect.cbTypeSpecificParams = sizeof(DIRAMPFORCE);
|
||||
}
|
||||
dieffect.lpvTypeSpecificParams = &stuff;
|
||||
|
@ -321,8 +341,10 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
int Update() {
|
||||
if (!active) return 0;
|
||||
int Update()
|
||||
{
|
||||
if (!active)
|
||||
return 0;
|
||||
if (numPhysicalControls) {
|
||||
HRESULT res = did->Poll();
|
||||
// ??
|
||||
|
@ -334,8 +356,7 @@ public:
|
|||
for (int i = 0; i < numPhysicalControls; i++) {
|
||||
if (physicalControls[i].type & RELAXIS) {
|
||||
physicalControlState[i] *= (FULLY_DOWN / 3);
|
||||
}
|
||||
else if (physicalControls[i].type & BUTTON) {
|
||||
} else if (physicalControls[i].type & BUTTON) {
|
||||
physicalControlState[i] = (physicalControlState[i] & 0x80) * FULLY_DOWN / 128;
|
||||
}
|
||||
}
|
||||
|
@ -343,7 +364,8 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
int GetFFBindingCount() {
|
||||
int GetFFBindingCount()
|
||||
{
|
||||
int count = 0;
|
||||
for (int port = 0; port < 2; port++) {
|
||||
for (int slot = 0; slot < 4; slot++) {
|
||||
|
@ -353,7 +375,8 @@ public:
|
|||
return count;
|
||||
}
|
||||
|
||||
void Deactivate() {
|
||||
void Deactivate()
|
||||
{
|
||||
FreeState();
|
||||
if (diEffects) {
|
||||
int count = GetFFBindingCount();
|
||||
|
@ -375,24 +398,23 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
~DirectInputDevice() {
|
||||
~DirectInputDevice()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
BOOL CALLBACK EnumEffectsCallback(LPCDIEFFECTINFOW pdei, LPVOID pvRef) {
|
||||
BOOL CALLBACK EnumEffectsCallback(LPCDIEFFECTINFOW pdei, LPVOID pvRef)
|
||||
{
|
||||
DirectInputDevice *did = (DirectInputDevice *)pvRef;
|
||||
EffectType type;
|
||||
int diType = DIEFT_GETTYPE(pdei->dwEffType);
|
||||
if (diType == DIEFT_CONSTANTFORCE) {
|
||||
type = EFFECT_CONSTANT;
|
||||
}
|
||||
else if (diType == DIEFT_RAMPFORCE) {
|
||||
} else if (diType == DIEFT_RAMPFORCE) {
|
||||
type = EFFECT_RAMP;
|
||||
}
|
||||
else if (diType == DIEFT_PERIODIC) {
|
||||
} else if (diType == DIEFT_PERIODIC) {
|
||||
type = EFFECT_PERIODIC;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
wchar_t guidString[50];
|
||||
|
@ -402,7 +424,8 @@ BOOL CALLBACK EnumEffectsCallback(LPCDIEFFECTINFOW pdei, LPVOID pvRef) {
|
|||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
BOOL CALLBACK EnumDeviceObjectsCallback (LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
||||
BOOL CALLBACK EnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
|
||||
{
|
||||
DirectInputDevice *did = (DirectInputDevice *)pvRef;
|
||||
if (lpddoi->dwType & DIDFT_FFACTUATOR) {
|
||||
did->AddFFAxis(lpddoi->tszName, lpddoi->dwType);
|
||||
|
@ -426,7 +449,8 @@ BOOL CALLBACK EnumDeviceObjectsCallback (LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOI
|
|||
if ((did->numPhysicalControls > 255 && DIDFT_GETINSTANCE(lpddoi->dwType) > 255) && (type & (DIDFT_PSHBUTTON | DIDFT_TGLBUTTON))) {
|
||||
int i;
|
||||
for (i = did->numPhysicalControls - 1; i > did->numPhysicalControls - 4; i--) {
|
||||
if (!lpddoi->tszName[0]) break;
|
||||
if (!lpddoi->tszName[0])
|
||||
break;
|
||||
const wchar_t *s1 = lpddoi->tszName;
|
||||
const wchar_t *s2 = did->physicalControls[i].name;
|
||||
while (*s1 && *s1 == *s2) {
|
||||
|
@ -434,9 +458,11 @@ BOOL CALLBACK EnumDeviceObjectsCallback (LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOI
|
|||
s2++;
|
||||
}
|
||||
// If perfect match with one of last 4 names, break.
|
||||
if (!*s1 && !*s2) break;
|
||||
if (!*s1 && !*s2)
|
||||
break;
|
||||
|
||||
while (s1 != lpddoi->tszName && (s1[-1] >= '0' && s1[-1] <= '9')) s1--;
|
||||
while (s1 != lpddoi->tszName && (s1[-1] >= '0' && s1[-1] <= '9'))
|
||||
s1--;
|
||||
int check = 0;
|
||||
while (*s1 >= '0' && *s1 <= '9') {
|
||||
check = check * 10 + *s1 - '0';
|
||||
|
@ -447,7 +473,8 @@ BOOL CALLBACK EnumDeviceObjectsCallback (LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOI
|
|||
}
|
||||
// If perfect match other than final number > 30, then break.
|
||||
// takes care of "button xx" case without causing issues with F keys.
|
||||
if (!*s1 && !*s2 && check > 30) break;
|
||||
if (!*s1 && !*s2 && check > 30)
|
||||
break;
|
||||
}
|
||||
if (i != did->numPhysicalControls - 4) {
|
||||
return DIENUM_CONTINUE;
|
||||
|
@ -498,9 +525,15 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput )
|
|||
if (FAILED(hr) || pIWbemLocator == NULL)
|
||||
goto LCleanup;
|
||||
|
||||
bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup;
|
||||
bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup;
|
||||
bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup;
|
||||
bstrNamespace = SysAllocString(L"\\\\.\\root\\cimv2");
|
||||
if (bstrNamespace == NULL)
|
||||
goto LCleanup;
|
||||
bstrClassName = SysAllocString(L"Win32_PNPEntity");
|
||||
if (bstrClassName == NULL)
|
||||
goto LCleanup;
|
||||
bstrDeviceID = SysAllocString(L"DeviceID");
|
||||
if (bstrDeviceID == NULL)
|
||||
goto LCleanup;
|
||||
|
||||
// Connect to WMI
|
||||
hr = pIWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, 0L,
|
||||
|
@ -517,8 +550,7 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput )
|
|||
goto LCleanup;
|
||||
|
||||
// Loop over all devices
|
||||
for( ;; )
|
||||
{
|
||||
for (;;) {
|
||||
// Get 20 at a time
|
||||
hr = pEnumDevices->Next(10000, 20, pDevices, &uReturned);
|
||||
if (FAILED(hr))
|
||||
|
@ -526,16 +558,13 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput )
|
|||
if (uReturned == 0)
|
||||
break;
|
||||
|
||||
for( iDevice=0; iDevice<uReturned; iDevice++ )
|
||||
{
|
||||
for (iDevice = 0; iDevice < uReturned; iDevice++) {
|
||||
// For each device, get its device ID
|
||||
hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL);
|
||||
if( SUCCEEDED( hr ) && var.vt == VT_BSTR && var.bstrVal != NULL )
|
||||
{
|
||||
if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL) {
|
||||
// Check if the device ID contains "IG_". If it does, then it's an XInput device
|
||||
// This information can not be found from DirectInput
|
||||
if( wcsstr( var.bstrVal, L"IG_" ) )
|
||||
{
|
||||
if (wcsstr(var.bstrVal, L"IG_")) {
|
||||
// If it does, then get the VID/PID from var.bstrVal
|
||||
DWORD dwPid = 0, dwVid = 0;
|
||||
WCHAR *strVid = wcsstr(var.bstrVal, L"VID_");
|
||||
|
@ -549,8 +578,7 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput )
|
|||
|
||||
// Compare the VID/PID to the DInput device
|
||||
DWORD dwVidPid = MAKELONG(dwVid, dwPid);
|
||||
if( dwVidPid == pGuidProductFromDirectInput->Data1 )
|
||||
{
|
||||
if (dwVidPid == pGuidProductFromDirectInput->Data1) {
|
||||
bIsXinputDevice = true;
|
||||
goto LCleanup;
|
||||
}
|
||||
|
@ -580,23 +608,23 @@ LCleanup:
|
|||
}
|
||||
|
||||
|
||||
struct DeviceEnumInfo {
|
||||
struct DeviceEnumInfo
|
||||
{
|
||||
IDirectInput8 *di8;
|
||||
int ignoreXInput;
|
||||
};
|
||||
|
||||
BOOL CALLBACK EnumCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) {
|
||||
BOOL CALLBACK EnumCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
|
||||
{
|
||||
IDirectInput8 *di8 = ((DeviceEnumInfo *)pvRef)->di8;
|
||||
const wchar_t *name;
|
||||
wchar_t temp[40];
|
||||
//if (((DeviceEnumInfo*)pvRef)->ignoreXInput && lpddi->
|
||||
if (lpddi->tszInstanceName[0]) {
|
||||
name = lpddi->tszInstanceName;
|
||||
}
|
||||
else if (lpddi->tszProductName[0]) {
|
||||
} else if (lpddi->tszProductName[0]) {
|
||||
name = lpddi->tszProductName;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
wsprintfW(temp, L"Device %i", di8d.deviceCount);
|
||||
name = temp;
|
||||
}
|
||||
|
@ -610,8 +638,7 @@ BOOL CALLBACK EnumCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) {
|
|||
DeviceType type = OTHER;
|
||||
if ((lpddi->dwDevType & 0xFF) == DI8DEVTYPE_KEYBOARD) {
|
||||
type = KEYBOARD;
|
||||
}
|
||||
else if ((lpddi->dwDevType & 0xFF) == DI8DEVTYPE_MOUSE) {
|
||||
} else if ((lpddi->dwDevType & 0xFF) == DI8DEVTYPE_MOUSE) {
|
||||
type = MOUSE;
|
||||
}
|
||||
IDirectInputDevice8 *did;
|
||||
|
@ -619,8 +646,7 @@ BOOL CALLBACK EnumCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) {
|
|||
DirectInputDevice *dev = new DirectInputDevice(type, did, fullName, instanceID, productID, lpddi->guidInstance);
|
||||
if (dev->numPhysicalControls || dev->numFFAxes) {
|
||||
dm->AddDevice(dev);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
delete dev;
|
||||
}
|
||||
}
|
||||
|
@ -628,13 +654,14 @@ BOOL CALLBACK EnumCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) {
|
|||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
void EnumDirectInputDevices(int ignoreXInput) {
|
||||
void EnumDirectInputDevices(int ignoreXInput)
|
||||
{
|
||||
DeviceEnumInfo enumInfo;
|
||||
enumInfo.di8 = GetDirectInput();
|
||||
if (!enumInfo.di8) return;
|
||||
if (!enumInfo.di8)
|
||||
return;
|
||||
enumInfo.ignoreXInput = ignoreXInput;
|
||||
di8d.deviceCount = 0;
|
||||
enumInfo.di8->EnumDevices(DI8DEVCLASS_ALL, EnumCallback, &enumInfo, DIEDFL_ATTACHEDONLY);
|
||||
ReleaseDirectInput();
|
||||
}
|
||||
|
||||
|
|
|
@ -62,14 +62,16 @@ _usb_control_msg pusb_control_msg;
|
|||
|
||||
HMODULE hModLibusb = 0;
|
||||
|
||||
void UninitLibUsb() {
|
||||
void UninitLibUsb()
|
||||
{
|
||||
if (hModLibusb) {
|
||||
FreeLibrary(hModLibusb);
|
||||
hModLibusb = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TryInitDS3(usb_device *dev) {
|
||||
void TryInitDS3(usb_device *dev)
|
||||
{
|
||||
while (dev) {
|
||||
if (dev->descriptor.idVendor == VID && dev->descriptor.idProduct == PID) {
|
||||
usb_dev_handle *handle = pusb_open(dev);
|
||||
|
@ -90,7 +92,8 @@ void TryInitDS3(usb_device *dev) {
|
|||
}
|
||||
}
|
||||
|
||||
void DS3Enum(unsigned int time) {
|
||||
void DS3Enum(unsigned int time)
|
||||
{
|
||||
if (time - lastDS3Enum < DOUBLE_ENUM_DELAY) {
|
||||
return;
|
||||
}
|
||||
|
@ -99,7 +102,8 @@ void DS3Enum(unsigned int time) {
|
|||
pusb_find_devices();
|
||||
}
|
||||
|
||||
void DS3Check(unsigned int time) {
|
||||
void DS3Check(unsigned int time)
|
||||
{
|
||||
if (time - lastDS3Check < DOUBLE_CHECK_DELAY) {
|
||||
return;
|
||||
}
|
||||
|
@ -115,7 +119,8 @@ void DS3Check(unsigned int time) {
|
|||
}
|
||||
}
|
||||
|
||||
int InitLibUsb() {
|
||||
int InitLibUsb()
|
||||
{
|
||||
if (hModLibusb) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -137,18 +142,21 @@ int InitLibUsb() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int DualShock3Possible() {
|
||||
int DualShock3Possible()
|
||||
{
|
||||
return InitLibUsb();
|
||||
}
|
||||
|
||||
#include <pshpack1.h>
|
||||
|
||||
struct MotorState {
|
||||
struct MotorState
|
||||
{
|
||||
unsigned char duration;
|
||||
unsigned char force;
|
||||
};
|
||||
|
||||
struct LightState {
|
||||
struct LightState
|
||||
{
|
||||
// 0xFF makes it stay on.
|
||||
unsigned char duration;
|
||||
// Have to make one or the other non-zero to turn on light.
|
||||
|
@ -160,7 +168,8 @@ struct LightState {
|
|||
};
|
||||
|
||||
// Data sent to DS3 to set state.
|
||||
struct DS3Command {
|
||||
struct DS3Command
|
||||
{
|
||||
unsigned char id;
|
||||
unsigned char unsure;
|
||||
// Small is first, then big.
|
||||
|
@ -175,21 +184,25 @@ struct DS3Command {
|
|||
|
||||
#include <poppack.h>
|
||||
|
||||
int CharToAxis(unsigned char c) {
|
||||
int CharToAxis(unsigned char c)
|
||||
{
|
||||
int v = (int)c + ((unsigned int)c >> 7);
|
||||
return ((c - 128) * FULLY_DOWN) >> 7;
|
||||
}
|
||||
|
||||
int CharToButton(unsigned char c) {
|
||||
int CharToButton(unsigned char c)
|
||||
{
|
||||
int v = (int)c + ((unsigned int)c >> 7);
|
||||
return (v * FULLY_DOWN) >> 8;
|
||||
}
|
||||
|
||||
class DualShock3Device : public Device {
|
||||
class DualShock3Device : public Device
|
||||
{
|
||||
// Cached last vibration values by pad and motor.
|
||||
// Need this, as only one value is changed at a time.
|
||||
int ps2Vibration[2][4][2];
|
||||
int vibration[2];
|
||||
|
||||
public:
|
||||
int index;
|
||||
HANDLE hFile;
|
||||
|
@ -205,12 +218,14 @@ public:
|
|||
int writeQueued;
|
||||
int writing;
|
||||
|
||||
int StartRead() {
|
||||
int StartRead()
|
||||
{
|
||||
int res = ReadFile(hFile, &getState, sizeof(getState), 0, &readop);
|
||||
return (res || GetLastError() == ERROR_IO_PENDING);
|
||||
}
|
||||
|
||||
void QueueWrite() {
|
||||
void QueueWrite()
|
||||
{
|
||||
// max of 2 queued writes allowed, one for either motor.
|
||||
if (writeQueued < 2) {
|
||||
writeQueued++;
|
||||
|
@ -218,7 +233,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
int StartWrite() {
|
||||
int StartWrite()
|
||||
{
|
||||
if (!writing && writeQueued) {
|
||||
lastWrite = GetTickCount();
|
||||
writing++;
|
||||
|
@ -227,7 +243,8 @@ public:
|
|||
sendState.motors[1].duration = 0x50;
|
||||
|
||||
int bigForce = vibration[0] * 256 / FULLY_DOWN;
|
||||
if (bigForce > 255) bigForce = 255;
|
||||
if (bigForce > 255)
|
||||
bigForce = 255;
|
||||
sendState.motors[1].force = (unsigned char)bigForce;
|
||||
sendState.motors[0].force = (unsigned char)(vibration[1] >= FULLY_DOWN / 2);
|
||||
// Can't seem to have them both non-zero at once.
|
||||
|
@ -243,7 +260,9 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
DualShock3Device(int index, wchar_t *name, wchar_t *path) : Device(DS3, OTHER, name, path, L"DualShock 3") {
|
||||
DualShock3Device(int index, wchar_t *name, wchar_t *path)
|
||||
: Device(DS3, OTHER, name, path, L"DualShock 3")
|
||||
{
|
||||
writeCount = 0;
|
||||
writing = 0;
|
||||
writeQueued = 0;
|
||||
|
@ -263,8 +282,7 @@ public:
|
|||
for (i = 0; i < 16; i++) {
|
||||
if (i != 14 && i != 15 && i != 8 && i != 9) {
|
||||
AddPhysicalControl(PRESSURE_BTN, i, 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
AddPhysicalControl(PSHBTN, i, 0);
|
||||
}
|
||||
}
|
||||
|
@ -277,7 +295,8 @@ public:
|
|||
hFile = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
wchar_t *GetPhysicalControlName(PhysicalControl *c) {
|
||||
wchar_t *GetPhysicalControlName(PhysicalControl *c)
|
||||
{
|
||||
const static wchar_t *names[] = {
|
||||
L"Square",
|
||||
L"Cross",
|
||||
|
@ -310,8 +329,10 @@ public:
|
|||
return Device::GetPhysicalControlName(c);
|
||||
}
|
||||
|
||||
int Activate(InitInfo *initInfo) {
|
||||
if (active) Deactivate();
|
||||
int Activate(InitInfo *initInfo)
|
||||
{
|
||||
if (active)
|
||||
Deactivate();
|
||||
// Give grace period before get mad.
|
||||
lastWrite = dataLastReceived = GetTickCount();
|
||||
readop.hEvent = CreateEvent(0, 0, 0, 0);
|
||||
|
@ -327,12 +348,13 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
int Update() {
|
||||
if (!active) return 0;
|
||||
int Update()
|
||||
{
|
||||
if (!active)
|
||||
return 0;
|
||||
HANDLE h[2] = {
|
||||
readop.hEvent,
|
||||
writeop.hEvent
|
||||
};
|
||||
writeop.hEvent};
|
||||
unsigned int time = GetTickCount();
|
||||
if (time - lastWrite > UPDATE_INTERVAL) {
|
||||
QueueWrite();
|
||||
|
@ -370,8 +392,7 @@ public:
|
|||
physicalControlState[21] = CharToAxis(getState[44] + 128);
|
||||
physicalControlState[22] = CharToAxis(getState[46] + 128);
|
||||
continue;
|
||||
}
|
||||
else if (res == WAIT_OBJECT_0+1) {
|
||||
} else if (res == WAIT_OBJECT_0 + 1) {
|
||||
writing = 0;
|
||||
if (!writeQueued && (vibration[0] | vibration[1])) {
|
||||
QueueWrite();
|
||||
|
@ -380,8 +401,7 @@ public:
|
|||
Deactivate();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (time - dataLastReceived >= DEVICE_CHECK_DELAY) {
|
||||
if (time - dataLastReceived >= DEVICE_ENUM_DELAY) {
|
||||
DS3Enum(time);
|
||||
|
@ -395,7 +415,8 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
void SetEffects(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force) {
|
||||
void SetEffects(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force)
|
||||
{
|
||||
ps2Vibration[port][slot][motor] = force;
|
||||
vibration[0] = vibration[1] = 0;
|
||||
for (int p = 0; p < 2; p++) {
|
||||
|
@ -413,7 +434,8 @@ public:
|
|||
QueueWrite();
|
||||
}
|
||||
|
||||
void SetEffect(ForceFeedbackBinding *binding, unsigned char force) {
|
||||
void SetEffect(ForceFeedbackBinding *binding, unsigned char force)
|
||||
{
|
||||
PadBindings pBackup = pads[0][0];
|
||||
pads[0][0].ffBindings = binding;
|
||||
pads[0][0].numFFBindings = 1;
|
||||
|
@ -421,7 +443,8 @@ public:
|
|||
pads[0][0] = pBackup;
|
||||
}
|
||||
|
||||
void Deactivate() {
|
||||
void Deactivate()
|
||||
{
|
||||
if (hFile != INVALID_HANDLE_VALUE) {
|
||||
CancelIo(hFile);
|
||||
CloseHandle(hFile);
|
||||
|
@ -442,17 +465,21 @@ public:
|
|||
active = 0;
|
||||
}
|
||||
|
||||
~DualShock3Device() {
|
||||
~DualShock3Device()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void EnumDualShock3s() {
|
||||
if (!InitLibUsb()) return;
|
||||
void EnumDualShock3s()
|
||||
{
|
||||
if (!InitLibUsb())
|
||||
return;
|
||||
|
||||
HidDeviceInfo *foundDevs = 0;
|
||||
|
||||
int numDevs = FindHids(&foundDevs, VID, PID);
|
||||
if (!numDevs) return;
|
||||
if (!numDevs)
|
||||
return;
|
||||
int index = 0;
|
||||
for (int i = 0; i < numDevs; i++) {
|
||||
if (foundDevs[i].caps.FeatureReportByteLength == 49 &&
|
||||
|
|
|
@ -45,7 +45,8 @@ typedef int64_t __int64;
|
|||
#include <cstdarg>
|
||||
|
||||
template <typename Array>
|
||||
void wsprintfW(Array& buf, const wchar_t *format, ...) {
|
||||
void wsprintfW(Array &buf, const wchar_t *format, ...)
|
||||
{
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
|
||||
|
@ -55,7 +56,8 @@ void wsprintfW(Array& buf, const wchar_t *format, ...) {
|
|||
}
|
||||
|
||||
template <typename Array>
|
||||
void wsprintf(Array& buf, const wchar_t *format, ...) {
|
||||
void wsprintf(Array &buf, const wchar_t *format, ...)
|
||||
{
|
||||
va_list a;
|
||||
va_start(a, format);
|
||||
|
||||
|
@ -64,13 +66,15 @@ void wsprintf(Array& buf, const wchar_t *format, ...) {
|
|||
va_end(a);
|
||||
}
|
||||
|
||||
static inline int wcsicmp(const wchar_t* w1, const wchar_t* w2) {
|
||||
static inline int wcsicmp(const wchar_t *w1, const wchar_t *w2)
|
||||
{
|
||||
// I didn't find a way to put ignore case ...
|
||||
return wcscmp(w1, w2);
|
||||
}
|
||||
|
||||
#include <sys/time.h>
|
||||
static inline unsigned int timeGetTime() {
|
||||
static inline unsigned int timeGetTime()
|
||||
{
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
uint64_t ms = (now.tv_usec / 1000) + ((uint64_t)now.tv_sec * 1000);
|
||||
|
@ -136,7 +140,8 @@ extern HINSTANCE hInst;
|
|||
// Needed for config screen
|
||||
void GetNameAndVersionString(wchar_t *out);
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
unsigned char controllerType;
|
||||
unsigned short buttonStatus;
|
||||
unsigned char rightJoyX, rightJoyY, leftJoyX, leftJoyY;
|
||||
|
@ -144,27 +149,51 @@ typedef struct {
|
|||
unsigned char reserved[91];
|
||||
} PadDataS;
|
||||
|
||||
EXPORT_C_(void) PADupdate(int pad);
|
||||
EXPORT_C_(u32) PS2EgetLibType(void);
|
||||
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type);
|
||||
EXPORT_C_(char*) PSEgetLibName();
|
||||
EXPORT_C_(char*) PS2EgetLibName(void);
|
||||
EXPORT_C_(void) PADshutdown();
|
||||
EXPORT_C_(s32) PADinit(u32 flags);
|
||||
EXPORT_C_(s32) PADopen(void *pDsp);
|
||||
EXPORT_C_(void) PADclose();
|
||||
EXPORT_C_(u8) PADstartPoll(int pad);
|
||||
EXPORT_C_(u8) PADpoll(u8 value);
|
||||
EXPORT_C_(u32) PADquery();
|
||||
EXPORT_C_(void) PADabout();
|
||||
EXPORT_C_(s32) PADtest();
|
||||
EXPORT_C_(keyEvent*) PADkeyEvent();
|
||||
EXPORT_C_(u32) PADreadPort1 (PadDataS* pads);
|
||||
EXPORT_C_(u32) PADreadPort2 (PadDataS* pads);
|
||||
EXPORT_C_(u32) PSEgetLibType();
|
||||
EXPORT_C_(u32) PSEgetLibVersion();
|
||||
EXPORT_C_(void) PADconfigure();
|
||||
EXPORT_C_(s32) PADfreeze(int mode, freezeData *data);
|
||||
EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot);
|
||||
EXPORT_C_(s32) PADqueryMtap(u8 port);
|
||||
EXPORT_C_(void) PADsetSettingsDir(const char *dir);
|
||||
EXPORT_C_(void)
|
||||
PADupdate(int pad);
|
||||
EXPORT_C_(u32)
|
||||
PS2EgetLibType(void);
|
||||
EXPORT_C_(u32)
|
||||
PS2EgetLibVersion2(u32 type);
|
||||
EXPORT_C_(char *)
|
||||
PSEgetLibName();
|
||||
EXPORT_C_(char *)
|
||||
PS2EgetLibName(void);
|
||||
EXPORT_C_(void)
|
||||
PADshutdown();
|
||||
EXPORT_C_(s32)
|
||||
PADinit(u32 flags);
|
||||
EXPORT_C_(s32)
|
||||
PADopen(void *pDsp);
|
||||
EXPORT_C_(void)
|
||||
PADclose();
|
||||
EXPORT_C_(u8)
|
||||
PADstartPoll(int pad);
|
||||
EXPORT_C_(u8)
|
||||
PADpoll(u8 value);
|
||||
EXPORT_C_(u32)
|
||||
PADquery();
|
||||
EXPORT_C_(void)
|
||||
PADabout();
|
||||
EXPORT_C_(s32)
|
||||
PADtest();
|
||||
EXPORT_C_(keyEvent *)
|
||||
PADkeyEvent();
|
||||
EXPORT_C_(u32)
|
||||
PADreadPort1(PadDataS *pads);
|
||||
EXPORT_C_(u32)
|
||||
PADreadPort2(PadDataS *pads);
|
||||
EXPORT_C_(u32)
|
||||
PSEgetLibType();
|
||||
EXPORT_C_(u32)
|
||||
PSEgetLibVersion();
|
||||
EXPORT_C_(void)
|
||||
PADconfigure();
|
||||
EXPORT_C_(s32)
|
||||
PADfreeze(int mode, freezeData *data);
|
||||
EXPORT_C_(s32)
|
||||
PADsetSlot(u8 port, u8 slot);
|
||||
EXPORT_C_(s32)
|
||||
PADqueryMtap(u8 port);
|
||||
EXPORT_C_(void)
|
||||
PADsetSettingsDir(const char *dir);
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include <setupapi.h>
|
||||
#include <hidsdi.h>
|
||||
|
||||
int FindHids(HidDeviceInfo **foundDevs, int vid, int pid) {
|
||||
int FindHids(HidDeviceInfo **foundDevs, int vid, int pid)
|
||||
{
|
||||
GUID GUID_DEVINTERFACE_HID;
|
||||
int numFoundDevs = 0;
|
||||
*foundDevs = 0;
|
||||
|
@ -33,15 +34,18 @@ int FindHids(HidDeviceInfo **foundDevs, int vid, int pid) {
|
|||
|
||||
DWORD size = 0;
|
||||
SetupDiGetDeviceInterfaceDetail(hdev, &devInterfaceData, 0, 0, &size, 0);
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER || !size) continue;
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER || !size)
|
||||
continue;
|
||||
SP_DEVICE_INTERFACE_DETAIL_DATA *devInterfaceDetails = (SP_DEVICE_INTERFACE_DETAIL_DATA *)malloc(size);
|
||||
if (!devInterfaceDetails) continue;
|
||||
if (!devInterfaceDetails)
|
||||
continue;
|
||||
|
||||
devInterfaceDetails->cbSize = sizeof(*devInterfaceDetails);
|
||||
SP_DEVINFO_DATA devInfoData;
|
||||
devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
||||
|
||||
if (!SetupDiGetDeviceInterfaceDetail(hdev, &devInterfaceData, devInterfaceDetails, size, &size, &devInfoData)) continue;
|
||||
if (!SetupDiGetDeviceInterfaceDetail(hdev, &devInterfaceData, devInterfaceDetails, size, &size, &devInfoData))
|
||||
continue;
|
||||
|
||||
HANDLE hfile = CreateFile(devInterfaceDetails->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
|
||||
if (hfile != INVALID_HANDLE_VALUE) {
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
|
||||
#include <hidsdi.h>
|
||||
|
||||
struct HidDeviceInfo {
|
||||
struct HidDeviceInfo
|
||||
{
|
||||
HIDP_CAPS caps;
|
||||
wchar_t *path;
|
||||
unsigned short vid;
|
||||
|
|
|
@ -21,11 +21,13 @@
|
|||
|
||||
InputDeviceManager *dm = 0;
|
||||
|
||||
InputDeviceManager::InputDeviceManager() {
|
||||
InputDeviceManager::InputDeviceManager()
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
}
|
||||
|
||||
void InputDeviceManager::ClearDevices() {
|
||||
void InputDeviceManager::ClearDevices()
|
||||
{
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
delete devices[i];
|
||||
}
|
||||
|
@ -34,11 +36,13 @@ void InputDeviceManager::ClearDevices() {
|
|||
numDevices = 0;
|
||||
}
|
||||
|
||||
InputDeviceManager::~InputDeviceManager() {
|
||||
InputDeviceManager::~InputDeviceManager()
|
||||
{
|
||||
ClearDevices();
|
||||
}
|
||||
|
||||
Device::Device(DeviceAPI api, DeviceType d, const wchar_t *displayName, const wchar_t *instanceID, const wchar_t *productID) {
|
||||
Device::Device(DeviceAPI api, DeviceType d, const wchar_t *displayName, const wchar_t *instanceID, const wchar_t *productID)
|
||||
{
|
||||
memset(pads, 0, sizeof(pads));
|
||||
this->api = api;
|
||||
type = d;
|
||||
|
@ -73,14 +77,17 @@ Device::Device(DeviceAPI api, DeviceType d, const wchar_t *displayName, const wc
|
|||
numFFAxes = 0;
|
||||
}
|
||||
|
||||
void Device::FreeState() {
|
||||
if (virtualControlState) free(virtualControlState);
|
||||
void Device::FreeState()
|
||||
{
|
||||
if (virtualControlState)
|
||||
free(virtualControlState);
|
||||
virtualControlState = 0;
|
||||
oldVirtualControlState = 0;
|
||||
physicalControlState = 0;
|
||||
}
|
||||
|
||||
Device::~Device() {
|
||||
Device::~Device()
|
||||
{
|
||||
Deactivate();
|
||||
// Generally called by deactivate, but just in case...
|
||||
FreeState();
|
||||
|
@ -97,7 +104,8 @@ Device::~Device() {
|
|||
free(virtualControls);
|
||||
|
||||
for (i = numPhysicalControls - 1; i >= 0; i--) {
|
||||
if (physicalControls[i].name) free(physicalControls[i].name);
|
||||
if (physicalControls[i].name)
|
||||
free(physicalControls[i].name);
|
||||
}
|
||||
free(physicalControls);
|
||||
|
||||
|
@ -119,7 +127,8 @@ Device::~Device() {
|
|||
}
|
||||
}
|
||||
|
||||
void Device::AddFFEffectType(const wchar_t *displayName, const wchar_t *effectID, EffectType type) {
|
||||
void Device::AddFFEffectType(const wchar_t *displayName, const wchar_t *effectID, EffectType type)
|
||||
{
|
||||
ffEffectTypes = (ForceFeedbackEffectType *)realloc(ffEffectTypes, sizeof(ForceFeedbackEffectType) * (numFFEffectTypes + 1));
|
||||
ffEffectTypes[numFFEffectTypes].displayName = wcsdup(displayName);
|
||||
ffEffectTypes[numFFEffectTypes].effectID = wcsdup(effectID);
|
||||
|
@ -127,7 +136,8 @@ void Device::AddFFEffectType(const wchar_t *displayName, const wchar_t *effectID
|
|||
numFFEffectTypes++;
|
||||
}
|
||||
|
||||
void Device::AddFFAxis(const wchar_t *displayName, int id) {
|
||||
void Device::AddFFAxis(const wchar_t *displayName, int id)
|
||||
{
|
||||
ffAxes = (ForceFeedbackAxis *)realloc(ffAxes, sizeof(ForceFeedbackAxis) * (numFFAxes + 1));
|
||||
ffAxes[numFFAxes].id = id;
|
||||
ffAxes[numFFAxes].displayName = wcsdup(displayName);
|
||||
|
@ -155,22 +165,26 @@ void Device::AddFFAxis(const wchar_t *displayName, int id) {
|
|||
}
|
||||
}
|
||||
|
||||
void Device::AllocState() {
|
||||
void Device::AllocState()
|
||||
{
|
||||
FreeState();
|
||||
virtualControlState = (int *)calloc(numVirtualControls + numVirtualControls + numPhysicalControls, sizeof(int));
|
||||
oldVirtualControlState = virtualControlState + numVirtualControls;
|
||||
physicalControlState = oldVirtualControlState + numVirtualControls;
|
||||
}
|
||||
|
||||
void Device::FlipState() {
|
||||
void Device::FlipState()
|
||||
{
|
||||
memcpy(oldVirtualControlState, virtualControlState, sizeof(int) * numVirtualControls);
|
||||
}
|
||||
|
||||
void Device::PostRead() {
|
||||
void Device::PostRead()
|
||||
{
|
||||
FlipState();
|
||||
}
|
||||
|
||||
void Device::CalcVirtualState() {
|
||||
void Device::CalcVirtualState()
|
||||
{
|
||||
for (int i = 0; i < numPhysicalControls; i++) {
|
||||
PhysicalControl *c = physicalControls + i;
|
||||
int index = c->baseVirtualControlIndex;
|
||||
|
@ -191,30 +205,29 @@ void Device::CalcVirtualState() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (i<numPhysicalControls) continue;
|
||||
if (i < numPhysicalControls)
|
||||
continue;
|
||||
}
|
||||
int event = KEYPRESS;
|
||||
if (!(virtualControlState[index]>>15)) event = KEYRELEASE;
|
||||
if (!(virtualControlState[index] >> 15))
|
||||
event = KEYRELEASE;
|
||||
QueueKeyEvent(c->vkey, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (c->type & ABSAXIS) {
|
||||
} else if (c->type & ABSAXIS) {
|
||||
virtualControlState[index] = (val + FULLY_DOWN) / 2;
|
||||
// Positive. Overkill.
|
||||
virtualControlState[index + 1] = (val & ~(val >> 31));
|
||||
// Negative
|
||||
virtualControlState[index + 2] = (-val & (val >> 31));
|
||||
}
|
||||
else if (c->type & RELAXIS) {
|
||||
} else if (c->type & RELAXIS) {
|
||||
int delta = val - oldVirtualControlState[index];
|
||||
virtualControlState[index] = val;
|
||||
// Positive
|
||||
virtualControlState[index + 1] = (delta & ~(delta >> 31));
|
||||
// Negative
|
||||
virtualControlState[index + 2] = (-delta & (delta >> 31));
|
||||
}
|
||||
else if (c->type & POV) {
|
||||
} else if (c->type & POV) {
|
||||
virtualControlState[index] = val;
|
||||
int iSouth = 0;
|
||||
int iEast = 0;
|
||||
|
@ -243,7 +256,8 @@ void Device::CalcVirtualState() {
|
|||
}
|
||||
}
|
||||
|
||||
VirtualControl *Device::GetVirtualControl(unsigned int uid) {
|
||||
VirtualControl *Device::GetVirtualControl(unsigned int uid)
|
||||
{
|
||||
for (int i = 0; i < numVirtualControls; i++) {
|
||||
if (virtualControls[i].uid == uid)
|
||||
return virtualControls + i;
|
||||
|
@ -251,7 +265,8 @@ VirtualControl *Device::GetVirtualControl(unsigned int uid) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
VirtualControl *Device::AddVirtualControl(unsigned int uid, int physicalControlIndex) {
|
||||
VirtualControl *Device::AddVirtualControl(unsigned int uid, int physicalControlIndex)
|
||||
{
|
||||
// Not really necessary, as always call AllocState when activated, but doesn't hurt.
|
||||
FreeState();
|
||||
|
||||
|
@ -267,7 +282,8 @@ VirtualControl *Device::AddVirtualControl(unsigned int uid, int physicalControlI
|
|||
return c;
|
||||
}
|
||||
|
||||
PhysicalControl *Device::AddPhysicalControl(ControlType type, unsigned short id, unsigned short vkey, const wchar_t *name) {
|
||||
PhysicalControl *Device::AddPhysicalControl(ControlType type, unsigned short id, unsigned short vkey, const wchar_t *name)
|
||||
{
|
||||
// Not really necessary, as always call AllocState when activated, but doesn't hurt.
|
||||
FreeState();
|
||||
|
||||
|
@ -279,19 +295,18 @@ PhysicalControl *Device::AddPhysicalControl(ControlType type, unsigned short id,
|
|||
memset(control, 0, sizeof(PhysicalControl));
|
||||
control->type = type;
|
||||
control->id = id;
|
||||
if (name) control->name = wcsdup(name);
|
||||
if (name)
|
||||
control->name = wcsdup(name);
|
||||
control->baseVirtualControlIndex = numVirtualControls;
|
||||
unsigned int uid = id | (type << 16);
|
||||
if (type & BUTTON) {
|
||||
AddVirtualControl(uid, numPhysicalControls);
|
||||
control->vkey = vkey;
|
||||
}
|
||||
else if (type & AXIS) {
|
||||
} else if (type & AXIS) {
|
||||
AddVirtualControl(uid | UID_AXIS, numPhysicalControls);
|
||||
AddVirtualControl(uid | UID_AXIS_POS, numPhysicalControls);
|
||||
AddVirtualControl(uid | UID_AXIS_NEG, numPhysicalControls);
|
||||
}
|
||||
else if (type & POV) {
|
||||
} else if (type & POV) {
|
||||
AddVirtualControl(uid | UID_POV, numPhysicalControls);
|
||||
AddVirtualControl(uid | UID_POV_N, numPhysicalControls);
|
||||
AddVirtualControl(uid | UID_POV_E, numPhysicalControls);
|
||||
|
@ -302,7 +317,8 @@ PhysicalControl *Device::AddPhysicalControl(ControlType type, unsigned short id,
|
|||
return control;
|
||||
}
|
||||
|
||||
void Device::SetEffects(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force) {
|
||||
void Device::SetEffects(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force)
|
||||
{
|
||||
for (int i = 0; i < pads[port][slot].numFFBindings; i++) {
|
||||
ForceFeedbackBinding *binding = pads[port][slot].ffBindings + i;
|
||||
if (binding->motor == motor) {
|
||||
|
@ -311,29 +327,29 @@ void Device::SetEffects(unsigned char port, unsigned int slot, unsigned char mot
|
|||
}
|
||||
}
|
||||
|
||||
wchar_t *GetDefaultControlName(unsigned short id, int type) {
|
||||
wchar_t *GetDefaultControlName(unsigned short id, int type)
|
||||
{
|
||||
static wchar_t name[20];
|
||||
if (type & BUTTON) {
|
||||
wsprintfW(name, L"Button %i", id);
|
||||
}
|
||||
else if (type & AXIS) {
|
||||
} else if (type & AXIS) {
|
||||
wsprintfW(name, L"Axis %i", id);
|
||||
}
|
||||
else if (type & POV) {
|
||||
} else if (type & POV) {
|
||||
wsprintfW(name, L"POV %i", id);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
wcscpy(name, L"Unknown");
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
wchar_t *Device::GetVirtualControlName(VirtualControl *control) {
|
||||
wchar_t *Device::GetVirtualControlName(VirtualControl *control)
|
||||
{
|
||||
static wchar_t temp[100];
|
||||
wchar_t *baseName = 0;
|
||||
if (control->physicalControlIndex >= 0) {
|
||||
baseName = physicalControls[control->physicalControlIndex].name;
|
||||
if (!baseName) baseName = GetPhysicalControlName(&physicalControls[control->physicalControlIndex]);
|
||||
if (!baseName)
|
||||
baseName = GetPhysicalControlName(&physicalControls[control->physicalControlIndex]);
|
||||
}
|
||||
unsigned int uid = control->uid;
|
||||
if (!baseName) {
|
||||
|
@ -341,49 +357,51 @@ wchar_t *Device::GetVirtualControlName(VirtualControl *control) {
|
|||
}
|
||||
uid &= 0xFF000000;
|
||||
int len = (int)wcslen(baseName);
|
||||
if (len > 99) len = 99;
|
||||
if (len > 99)
|
||||
len = 99;
|
||||
memcpy(temp, baseName, len * sizeof(wchar_t));
|
||||
temp[len] = 0;
|
||||
if (uid) {
|
||||
if (len > 95) len = 95;
|
||||
if (len > 95)
|
||||
len = 95;
|
||||
wchar_t *out = temp + len;
|
||||
if (uid == UID_AXIS_POS) {
|
||||
wcscpy(out, L" +");
|
||||
}
|
||||
else if (uid == UID_AXIS_NEG) {
|
||||
} else if (uid == UID_AXIS_NEG) {
|
||||
wcscpy(out, L" -");
|
||||
}
|
||||
else if (uid == UID_POV_N) {
|
||||
} else if (uid == UID_POV_N) {
|
||||
wcscpy(out, L" N");
|
||||
}
|
||||
else if (uid == UID_POV_E) {
|
||||
} else if (uid == UID_POV_E) {
|
||||
wcscpy(out, L" E");
|
||||
}
|
||||
else if (uid == UID_POV_S) {
|
||||
} else if (uid == UID_POV_S) {
|
||||
wcscpy(out, L" S");
|
||||
}
|
||||
else if (uid == UID_POV_W) {
|
||||
} else if (uid == UID_POV_W) {
|
||||
wcscpy(out, L" W");
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
wchar_t *Device::GetPhysicalControlName(PhysicalControl *control) {
|
||||
if (control->name) return control->name;
|
||||
wchar_t *Device::GetPhysicalControlName(PhysicalControl *control)
|
||||
{
|
||||
if (control->name)
|
||||
return control->name;
|
||||
return GetDefaultControlName(control->id, control->type);
|
||||
}
|
||||
|
||||
void InputDeviceManager::AddDevice(Device *d) {
|
||||
void InputDeviceManager::AddDevice(Device *d)
|
||||
{
|
||||
devices = (Device **)realloc(devices, sizeof(Device *) * (numDevices + 1));
|
||||
devices[numDevices++] = d;
|
||||
}
|
||||
|
||||
void InputDeviceManager::Update(InitInfo *info) {
|
||||
void InputDeviceManager::Update(InitInfo *info)
|
||||
{
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
if (devices[i]->enabled) {
|
||||
if (!devices[i]->active) {
|
||||
if (!devices[i]->Activate(info) || !devices[i]->Update()) continue;
|
||||
if (!devices[i]->Activate(info) || !devices[i]->Update())
|
||||
continue;
|
||||
devices[i]->CalcVirtualState();
|
||||
devices[i]->PostRead();
|
||||
}
|
||||
|
@ -393,14 +411,16 @@ void InputDeviceManager::Update(InitInfo *info) {
|
|||
}
|
||||
}
|
||||
|
||||
void InputDeviceManager::PostRead() {
|
||||
void InputDeviceManager::PostRead()
|
||||
{
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
if (devices[i]->active)
|
||||
devices[i]->PostRead();
|
||||
}
|
||||
}
|
||||
|
||||
Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, int *index, int *value) {
|
||||
Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, int *index, int *value)
|
||||
{
|
||||
int i, j;
|
||||
Update(info);
|
||||
int bestDiff = FULLY_DOWN / 2;
|
||||
|
@ -408,8 +428,10 @@ Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, i
|
|||
for (i = 0; i < numDevices; i++) {
|
||||
if (devices[i]->active) {
|
||||
for (j = 0; j < devices[i]->numVirtualControls; j++) {
|
||||
if (devices[i]->virtualControlState[j] == devices[i]->oldVirtualControlState[j]) continue;
|
||||
if (devices[i]->virtualControls[j].uid & UID_POV) continue;
|
||||
if (devices[i]->virtualControlState[j] == devices[i]->oldVirtualControlState[j])
|
||||
continue;
|
||||
if (devices[i]->virtualControls[j].uid & UID_POV)
|
||||
continue;
|
||||
// Fix for releasing button used to click on bind button
|
||||
if (!((devices[i]->virtualControls[j].uid >> 16) & (POV | RELAXIS | ABSAXIS))) {
|
||||
if (abs(devices[i]->oldVirtualControlState[j]) > abs(devices[i]->virtualControlState[j])) {
|
||||
|
@ -427,14 +449,14 @@ Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, i
|
|||
}
|
||||
if (diff > bestDiff) {
|
||||
if (devices[i]->virtualControls[j].uid & UID_AXIS) {
|
||||
if ((((devices[i]->virtualControls[j].uid>>16)&0xFF) != ABSAXIS)) continue;
|
||||
if ((((devices[i]->virtualControls[j].uid >> 16) & 0xFF) != ABSAXIS))
|
||||
continue;
|
||||
// Very picky when binding entire axes. Prefer binding half-axes.
|
||||
if (!((devices[i]->oldVirtualControlState[j] < FULLY_DOWN / 32 && devices[i]->virtualControlState[j] > FULLY_DOWN / 8) ||
|
||||
(devices[i]->oldVirtualControlState[j] > 31 * FULLY_DOWN / 32 && devices[i]->virtualControlState[j] < 7 * FULLY_DOWN / 8))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if ((((devices[i]->virtualControls[j].uid>>16)&0xFF) == ABSAXIS)) {
|
||||
} else if ((((devices[i]->virtualControls[j].uid >> 16) & 0xFF) == ABSAXIS)) {
|
||||
if (devices[i]->oldVirtualControlState[j] > 15 * FULLY_DOWN / 16)
|
||||
continue;
|
||||
}
|
||||
|
@ -445,8 +467,7 @@ Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, i
|
|||
if (value) {
|
||||
if ((devices[i]->virtualControls[j].uid >> 16) & RELAXIS) {
|
||||
*value = devices[i]->virtualControlState[j] - devices[i]->oldVirtualControlState[j];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*value = devices[i]->virtualControlState[j];
|
||||
}
|
||||
}
|
||||
|
@ -459,13 +480,16 @@ Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, i
|
|||
return bestDevice;
|
||||
}
|
||||
|
||||
void InputDeviceManager::ReleaseInput() {
|
||||
void InputDeviceManager::ReleaseInput()
|
||||
{
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
if (devices[i]->active) devices[i]->Deactivate();
|
||||
if (devices[i]->active)
|
||||
devices[i]->Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
void InputDeviceManager::EnableDevices(DeviceType type, DeviceAPI api) {
|
||||
void InputDeviceManager::EnableDevices(DeviceType type, DeviceAPI api)
|
||||
{
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
if (devices[i]->api == api && devices[i]->type == type) {
|
||||
EnableDevice(i);
|
||||
|
@ -473,20 +497,23 @@ void InputDeviceManager::EnableDevices(DeviceType type, DeviceAPI api) {
|
|||
}
|
||||
}
|
||||
|
||||
void InputDeviceManager::DisableAllDevices() {
|
||||
void InputDeviceManager::DisableAllDevices()
|
||||
{
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
DisableDevice(i);
|
||||
}
|
||||
}
|
||||
|
||||
void InputDeviceManager::DisableDevice(int index) {
|
||||
void InputDeviceManager::DisableDevice(int index)
|
||||
{
|
||||
devices[index]->enabled = 0;
|
||||
if (devices[index]->active) {
|
||||
devices[index]->Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
ForceFeedbackEffectType *Device::GetForcefeedbackEffect(wchar_t *id) {
|
||||
ForceFeedbackEffectType *Device::GetForcefeedbackEffect(wchar_t *id)
|
||||
{
|
||||
for (int i = 0; i < numFFEffectTypes; i++) {
|
||||
if (!wcsicmp(id, ffEffectTypes[i].effectID)) {
|
||||
return &ffEffectTypes[i];
|
||||
|
@ -495,14 +522,17 @@ ForceFeedbackEffectType *Device::GetForcefeedbackEffect(wchar_t *id) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
ForceFeedbackAxis *Device::GetForceFeedbackAxis(int id) {
|
||||
ForceFeedbackAxis *Device::GetForceFeedbackAxis(int id)
|
||||
{
|
||||
for (int i = 0; i < numFFAxes; i++) {
|
||||
if (ffAxes[i].id == id) return &ffAxes[i];
|
||||
if (ffAxes[i].id == id)
|
||||
return &ffAxes[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices) {
|
||||
void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices)
|
||||
{
|
||||
int *oldMatches = (int *)malloc(sizeof(int) * numOldDevices);
|
||||
int *matches = (int *)malloc(sizeof(int) * numDevices);
|
||||
int i, j, port, slot;
|
||||
|
@ -525,7 +555,8 @@ void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices) {
|
|||
// Loops through ids looking for match, from most specific to most general.
|
||||
for (int id = 0; id < 3; id++) {
|
||||
for (i = 0; i < numOldDevices; i++) {
|
||||
if (oldMatches[i] >= 0) continue;
|
||||
if (oldMatches[i] >= 0)
|
||||
continue;
|
||||
for (j = 0; j < numDevices; j++) {
|
||||
if (matches[j] >= 0) {
|
||||
continue;
|
||||
|
@ -545,7 +576,8 @@ void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices) {
|
|||
}
|
||||
|
||||
for (i = 0; i < numOldDevices; i++) {
|
||||
if (oldMatches[i] == -2) continue;
|
||||
if (oldMatches[i] == -2)
|
||||
continue;
|
||||
old = oldDevices[i];
|
||||
if (oldMatches[i] < 0) {
|
||||
dev = new Device(old->api, old->type, old->displayName, old->instanceID, old->productID);
|
||||
|
@ -567,8 +599,7 @@ void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices) {
|
|||
// Indices will be the same.
|
||||
memcpy(dev->pads, old->pads, sizeof(old->pads));
|
||||
memset(old->pads, 0, sizeof(old->pads));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dev = devices[oldMatches[i]];
|
||||
for (port = 0; port < 2; port++) {
|
||||
for (slot = 0; slot < 4; slot++) {
|
||||
|
@ -613,7 +644,8 @@ void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices) {
|
|||
free(matches);
|
||||
}
|
||||
|
||||
void InputDeviceManager::SetEffect(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force) {
|
||||
void InputDeviceManager::SetEffect(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force)
|
||||
{
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
Device *dev = devices[i];
|
||||
if (dev->enabled && dev->numFFEffectTypes) {
|
||||
|
@ -621,4 +653,3 @@ void InputDeviceManager::SetEffect(unsigned char port, unsigned int slot, unsign
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,8 @@ enum ControlType {
|
|||
#define BINARY_BUTTON (PSHBTN | TGLBTN)
|
||||
#define AXIS 3
|
||||
|
||||
struct Binding {
|
||||
struct Binding
|
||||
{
|
||||
int controlIndex;
|
||||
int command;
|
||||
int sensitivity;
|
||||
|
@ -88,7 +89,8 @@ struct Binding {
|
|||
// and individual axis/pov directions. Not that pov controls
|
||||
// cannot actually be bound, but when trying to bind as an axis,
|
||||
// all directions are assigned individually.
|
||||
struct VirtualControl {
|
||||
struct VirtualControl
|
||||
{
|
||||
// Unique id for control, given device. Based on source control's id,
|
||||
// source control type, axis/pov flags if it's a pov/axis (Rather than
|
||||
// a button or a pov/axis control's individual button), and an index,
|
||||
|
@ -103,7 +105,8 @@ struct VirtualControl {
|
|||
// updates their state, standard function then populates
|
||||
// the VirtualControls and queues the keyboard messages, if
|
||||
// needed.
|
||||
struct PhysicalControl {
|
||||
struct PhysicalControl
|
||||
{
|
||||
// index of the first virtual control corresponding to this.
|
||||
// Buttons have 1 virtual control, axes 3, and povs 5, all
|
||||
// in a row.
|
||||
|
@ -152,11 +155,13 @@ enum EffectType {
|
|||
// Order matches ForceFeedbackAxis order. force of 0 means to
|
||||
// ignore that axis completely. Force of 1 or -1 means to initialize
|
||||
// the axis with minimum force (Possibly 0 force), if applicable.
|
||||
struct AxisEffectInfo {
|
||||
struct AxisEffectInfo
|
||||
{
|
||||
int force;
|
||||
};
|
||||
|
||||
struct ForceFeedbackBinding {
|
||||
struct ForceFeedbackBinding
|
||||
{
|
||||
AxisEffectInfo *axes;
|
||||
int effectIndex;
|
||||
unsigned char motor;
|
||||
|
@ -164,7 +169,8 @@ struct ForceFeedbackBinding {
|
|||
|
||||
// Bindings listed by effect, so I don't have to bother with
|
||||
// indexing effects.
|
||||
struct ForceFeedbackEffectType {
|
||||
struct ForceFeedbackEffectType
|
||||
{
|
||||
wchar_t *displayName;
|
||||
// Because I'm lazy, can only have ASCII characters and no spaces.
|
||||
wchar_t *effectID;
|
||||
|
@ -173,7 +179,8 @@ struct ForceFeedbackEffectType {
|
|||
};
|
||||
|
||||
|
||||
struct ForceFeedbackAxis {
|
||||
struct ForceFeedbackAxis
|
||||
{
|
||||
wchar_t *displayName;
|
||||
int id;
|
||||
};
|
||||
|
@ -184,7 +191,8 @@ struct ForceFeedbackAxis {
|
|||
// one set of generic devices. Then I enumerate all devices. Then I merge
|
||||
// them, moving settings from the generic devices to the enumerated ones.
|
||||
|
||||
struct PadBindings {
|
||||
struct PadBindings
|
||||
{
|
||||
Binding *bindings;
|
||||
int numBindings;
|
||||
ForceFeedbackBinding *ffBindings;
|
||||
|
@ -193,7 +201,8 @@ struct PadBindings {
|
|||
|
||||
class WndProcEater;
|
||||
|
||||
struct InitInfo {
|
||||
struct InitInfo
|
||||
{
|
||||
// 1 when binding key to ignore.
|
||||
int bindingIgnore;
|
||||
// 1 when binding.
|
||||
|
@ -216,7 +225,8 @@ struct InitInfo {
|
|||
|
||||
// Mostly self-contained, but bindings are modified by config.cpp, to make
|
||||
// updating the ListView simpler.
|
||||
class Device {
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
DeviceAPI api;
|
||||
DeviceType type;
|
||||
|
@ -231,10 +241,12 @@ public:
|
|||
WndProcEater *hWndProc;
|
||||
#endif
|
||||
|
||||
union {
|
||||
union
|
||||
{
|
||||
// Allows for one loop to compare all 3 in order.
|
||||
wchar_t *IDs[3];
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
// Same as DisplayName, when not given. Absolutely must be unique.
|
||||
// Used for loading/saving controls. If matches, all other strings
|
||||
// are ignored, so must be unique.
|
||||
|
@ -298,17 +310,20 @@ public:
|
|||
|
||||
void CalcVirtualState();
|
||||
|
||||
virtual int Activate(InitInfo *args) {
|
||||
virtual int Activate(InitInfo *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline virtual void Deactivate() {
|
||||
inline virtual void Deactivate()
|
||||
{
|
||||
FreeState();
|
||||
active = 0;
|
||||
}
|
||||
|
||||
// Default update proc. All that's needed for post-based APIs.
|
||||
inline virtual int Update() {
|
||||
inline virtual int Update()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
|
@ -328,7 +343,8 @@ public:
|
|||
virtual void PostRead();
|
||||
};
|
||||
|
||||
class InputDeviceManager {
|
||||
class InputDeviceManager
|
||||
{
|
||||
public:
|
||||
Device **devices;
|
||||
int numDevices;
|
||||
|
@ -362,7 +378,8 @@ public:
|
|||
void ReleaseInput();
|
||||
|
||||
void DisableDevice(int index);
|
||||
inline void EnableDevice(int i) {
|
||||
inline void EnableDevice(int i)
|
||||
{
|
||||
devices[i]->enabled = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ static u8 lastQueuedEvent = 0;
|
|||
static u8 nextQueuedEvent = 0;
|
||||
static keyEvent queuedEvents[EVENT_QUEUE_LEN];
|
||||
|
||||
void QueueKeyEvent(int key, int event) {
|
||||
void QueueKeyEvent(int key, int event)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
if (!csInitialized) {
|
||||
csInitialized = 1;
|
||||
|
@ -70,8 +71,10 @@ void QueueKeyEvent(int key, int event) {
|
|||
#endif
|
||||
}
|
||||
|
||||
int GetQueuedKeyEvent(keyEvent *event) {
|
||||
if (lastQueuedEvent == nextQueuedEvent) return 0;
|
||||
int GetQueuedKeyEvent(keyEvent *event)
|
||||
{
|
||||
if (lastQueuedEvent == nextQueuedEvent)
|
||||
return 0;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
EnterCriticalSection(&cSection);
|
||||
|
@ -86,7 +89,8 @@ int GetQueuedKeyEvent(keyEvent *event) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
void ClearKeyQueue() {
|
||||
void ClearKeyQueue()
|
||||
{
|
||||
lastQueuedEvent = nextQueuedEvent;
|
||||
#ifdef _MSC_VER
|
||||
if (csInitialized) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -73,14 +73,16 @@ remove 0x10F0 to compute the cmd value
|
|||
|
||||
#endif
|
||||
|
||||
struct GeneralSettingsBool {
|
||||
struct GeneralSettingsBool
|
||||
{
|
||||
const wchar_t *name;
|
||||
unsigned int ControlId;
|
||||
u8 defaultValue;
|
||||
};
|
||||
|
||||
// XXX: I try to remove only gui stuff
|
||||
void DeleteBinding(int port, int slot, Device *dev, Binding *b) {
|
||||
void DeleteBinding(int port, int slot, Device *dev, Binding *b)
|
||||
{
|
||||
fprintf(stderr, "delete binding %d:%d\n", port, slot);
|
||||
Binding *bindings = dev->pads[port][slot].bindings;
|
||||
int i = b - bindings;
|
||||
|
@ -88,27 +90,28 @@ void DeleteBinding(int port, int slot, Device *dev, Binding *b) {
|
|||
dev->pads[port][slot].numBindings--;
|
||||
}
|
||||
|
||||
void DeleteBinding(int port, int slot, Device *dev, ForceFeedbackBinding *b) {
|
||||
void DeleteBinding(int port, int slot, Device *dev, ForceFeedbackBinding *b)
|
||||
{
|
||||
ForceFeedbackBinding *bindings = dev->pads[port][slot].ffBindings;
|
||||
int i = b - bindings;
|
||||
memmove(bindings + i, bindings + i + 1, sizeof(Binding) * (dev->pads[port][slot].numFFBindings - i - 1));
|
||||
dev->pads[port][slot].numFFBindings--;
|
||||
}
|
||||
|
||||
int BindCommand(Device *dev, unsigned int uid, unsigned int port, unsigned int slot, int command, int sensitivity, int turbo, int deadZone) {
|
||||
int BindCommand(Device *dev, unsigned int uid, unsigned int port, unsigned int slot, int command, int sensitivity, int turbo, int deadZone)
|
||||
{
|
||||
// Checks needed because I use this directly when loading bindings.
|
||||
if (port > 1 || slot > 3) {
|
||||
return -1;
|
||||
}
|
||||
if (!sensitivity) sensitivity = BASE_SENSITIVITY;
|
||||
if (!sensitivity)
|
||||
sensitivity = BASE_SENSITIVITY;
|
||||
if ((uid >> 16) & (PSHBTN | TGLBTN)) {
|
||||
deadZone = 0;
|
||||
}
|
||||
else if (!deadZone) {
|
||||
} else if (!deadZone) {
|
||||
if ((uid >> 16) & PRESSURE_BTN) {
|
||||
deadZone = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
deadZone = DEFAULT_DEADZONE;
|
||||
}
|
||||
}
|
||||
|
@ -117,14 +120,16 @@ int BindCommand(Device *dev, unsigned int uid, unsigned int port, unsigned int s
|
|||
sensitivity = abs(sensitivity);
|
||||
}
|
||||
VirtualControl *c = dev->GetVirtualControl(uid);
|
||||
if (!c) return -1;
|
||||
if (!c)
|
||||
return -1;
|
||||
// Add before deleting. Means I won't scroll up one line when scrolled down to bottom.
|
||||
int controlIndex = c - dev->virtualControls;
|
||||
int index = 0;
|
||||
PadBindings *p = dev->pads[port] + slot;
|
||||
p->bindings = (Binding *)realloc(p->bindings, (p->numBindings + 1) * sizeof(Binding));
|
||||
for (index = p->numBindings; index > 0; index--) {
|
||||
if (p->bindings[index-1].controlIndex < controlIndex) break;
|
||||
if (p->bindings[index - 1].controlIndex < controlIndex)
|
||||
break;
|
||||
p->bindings[index] = p->bindings[index - 1];
|
||||
}
|
||||
Binding *b = p->bindings + index;
|
||||
|
@ -149,8 +154,7 @@ int BindCommand(Device *dev, unsigned int uid, unsigned int port, unsigned int s
|
|||
if (config.multipleBinding) {
|
||||
if (b->controlIndex == controlIndex && b->command == command)
|
||||
nuke = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int uid2 = dev->virtualControls[b->controlIndex].uid;
|
||||
if (b->controlIndex == controlIndex || (!((uid2 ^ uid) & 0xFFFFFF) && ((uid | uid2) & (UID_POV | UID_AXIS))))
|
||||
nuke = 1;
|
||||
|
@ -168,7 +172,8 @@ int BindCommand(Device *dev, unsigned int uid, unsigned int port, unsigned int s
|
|||
if (!config.multipleBinding) {
|
||||
for (int port2 = 0; port2 < 2; port2++) {
|
||||
for (int slot2 = 0; slot2 < 4; slot2++) {
|
||||
if (port2==(int)port && slot2 == (int)slot) continue;
|
||||
if (port2 == (int)port && slot2 == (int)slot)
|
||||
continue;
|
||||
PadBindings *p = dev->pads[port2] + slot2;
|
||||
for (int i = 0; i < p->numBindings; i++) {
|
||||
Binding *b = p->bindings + i;
|
||||
|
@ -215,7 +220,8 @@ void CALLBACK PADsetSettingsDir( const char *dir )
|
|||
CfgHelper::SetSettingsDir(dir);
|
||||
}
|
||||
|
||||
int SaveSettings(wchar_t *file=0) {
|
||||
int SaveSettings(wchar_t *file = 0)
|
||||
{
|
||||
CfgHelper cfg;
|
||||
|
||||
for (size_t i = 0; i < sizeof(BoolOptionsInfo) / sizeof(BoolOptionsInfo[0]); i++) {
|
||||
|
@ -246,9 +252,11 @@ int SaveSettings(wchar_t *file=0) {
|
|||
wchar_t *name = dev->displayName;
|
||||
while (name[0] == '[') {
|
||||
wchar_t *name2 = wcschr(name, ']');
|
||||
if (!name2) break;
|
||||
if (!name2)
|
||||
break;
|
||||
name = name2 + 1;
|
||||
while (iswspace(name[0])) name++;
|
||||
while (iswspace(name[0]))
|
||||
name++;
|
||||
}
|
||||
|
||||
cfg.WriteStr(id, L"Display Name", name);
|
||||
|
@ -291,8 +299,10 @@ int SaveSettings(wchar_t *file=0) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int LoadSettings(int force, wchar_t *file) {
|
||||
if (dm && !force) return 0;
|
||||
int LoadSettings(int force, wchar_t *file)
|
||||
{
|
||||
if (dm && !force)
|
||||
return 0;
|
||||
|
||||
// Could just do ClearDevices() instead, but if I ever add any extra stuff,
|
||||
// this will still work.
|
||||
|
@ -307,10 +317,12 @@ int LoadSettings(int force, wchar_t *file) {
|
|||
|
||||
|
||||
config.closeHacks = (u8)cfg.ReadInt(L"General Settings", L"Close Hacks");
|
||||
if (config.closeHacks&1) config.closeHacks &= ~2;
|
||||
if (config.closeHacks & 1)
|
||||
config.closeHacks &= ~2;
|
||||
|
||||
config.keyboardApi = (DeviceAPI)cfg.ReadInt(L"General Settings", L"Keyboard Mode", LNX_KEYBOARD);
|
||||
if (!config.keyboardApi) config.keyboardApi = LNX_KEYBOARD;
|
||||
if (!config.keyboardApi)
|
||||
config.keyboardApi = LNX_KEYBOARD;
|
||||
config.mouseApi = (DeviceAPI)cfg.ReadInt(L"General Settings", L"Mouse Mode");
|
||||
|
||||
for (int port = 0; port < 2; port++) {
|
||||
|
@ -332,7 +344,8 @@ int LoadSettings(int force, wchar_t *file) {
|
|||
wsprintfW(id, L"Device %i", i++);
|
||||
if (!cfg.ReadStr(id, L"Display Name", temp2) || !temp2[0] ||
|
||||
!cfg.ReadStr(id, L"Instance ID", temp3) || !temp3[0]) {
|
||||
if (i >= 100) break;
|
||||
if (i >= 100)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
wchar_t *id2 = 0;
|
||||
|
@ -341,7 +354,8 @@ int LoadSettings(int force, wchar_t *file) {
|
|||
|
||||
int api = cfg.ReadInt(id, L"API");
|
||||
int type = cfg.ReadInt(id, L"Type");
|
||||
if (!api || !type) continue;
|
||||
if (!api || !type)
|
||||
continue;
|
||||
|
||||
Device *dev = new Device((DeviceAPI)api, (DeviceType)type, temp2, temp3, id2);
|
||||
dev->attached = 0;
|
||||
|
@ -352,7 +366,8 @@ int LoadSettings(int force, wchar_t *file) {
|
|||
wsprintfW(temp, L"Binding %i", j++);
|
||||
if (!cfg.ReadStr(id, temp, temp2)) {
|
||||
if (j >= 100) {
|
||||
if (!last) break;
|
||||
if (!last)
|
||||
break;
|
||||
last = 0;
|
||||
}
|
||||
continue;
|
||||
|
@ -370,7 +385,8 @@ int LoadSettings(int force, wchar_t *file) {
|
|||
int len = sscanf(string, " %u , %i , %i , %i , %i , %i , %i", &uid, &port, &command, &sensitivity, &turbo, &slot, &deadZone);
|
||||
if (len >= 5 && type) {
|
||||
VirtualControl *c = dev->GetVirtualControl(uid);
|
||||
if (!c) c = dev->AddVirtualControl(uid, -1);
|
||||
if (!c)
|
||||
c = dev->AddVirtualControl(uid, -1);
|
||||
if (c) {
|
||||
BindCommand(dev, uid, port, slot, command, sensitivity, turbo, deadZone);
|
||||
}
|
||||
|
@ -381,7 +397,8 @@ int LoadSettings(int force, wchar_t *file) {
|
|||
wsprintfW(temp, L"FF Binding %i", j++);
|
||||
if (!cfg.ReadStr(id, temp, temp2)) {
|
||||
if (j >= 10) {
|
||||
if (!last) break;
|
||||
if (!last)
|
||||
break;
|
||||
last = 0;
|
||||
}
|
||||
continue;
|
||||
|
@ -400,7 +417,8 @@ int LoadSettings(int force, wchar_t *file) {
|
|||
// whitespace without it.
|
||||
if (sscanf(string, " %s %i , %i , %i", effect, &port, &motor, &slot) == 4) {
|
||||
char *s = strchr(strchr(strchr(string, ',') + 1, ',') + 1, ',');
|
||||
if (!s) continue;
|
||||
if (!s)
|
||||
continue;
|
||||
s++;
|
||||
w = 0;
|
||||
while (effect[w]) {
|
||||
|
@ -448,14 +466,16 @@ int LoadSettings(int force, wchar_t *file) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void UnloadConfigs() {
|
||||
void UnloadConfigs()
|
||||
{
|
||||
if (dm) {
|
||||
delete dm;
|
||||
dm = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RefreshEnabledDevices(int updateDeviceList) {
|
||||
void RefreshEnabledDevices(int updateDeviceList)
|
||||
{
|
||||
// Clears all device state.
|
||||
static int lastXInputState = -1;
|
||||
if (updateDeviceList || lastXInputState != config.gameApis.xInput) {
|
||||
|
@ -499,7 +519,8 @@ void RefreshEnabledDevices(int updateDeviceList) {
|
|||
}
|
||||
}
|
||||
|
||||
void Configure() {
|
||||
void Configure()
|
||||
{
|
||||
// Can end up here without PADinit() being called first.
|
||||
LoadSettings();
|
||||
// Can also end up here after running emulator a bit, and possibly
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
extern void CfgSetSettingsDir(const char *dir);
|
||||
|
||||
class CfgHelper {
|
||||
class CfgHelper
|
||||
{
|
||||
wxFileConfig *m_config;
|
||||
static wxString m_path;
|
||||
|
||||
|
@ -44,5 +45,4 @@ class CfgHelper {
|
|||
float ReadFloat(const wchar_t *Section, const wchar_t *Name, float Default = 0.0f);
|
||||
|
||||
static void SetSettingsDir(const char *dir);
|
||||
|
||||
};
|
||||
|
|
|
@ -20,7 +20,10 @@
|
|||
#include "Linux/JoyEvdev.h"
|
||||
#include "Linux/bitmaskros.h"
|
||||
|
||||
JoyEvdev::JoyEvdev(int fd, bool ds3, const wchar_t *id) : Device(LNX_JOY, OTHER, id, id), m_fd(fd) {
|
||||
JoyEvdev::JoyEvdev(int fd, bool ds3, const wchar_t *id)
|
||||
: Device(LNX_JOY, OTHER, id, id)
|
||||
, m_fd(fd)
|
||||
{
|
||||
// XXX LNX_JOY => DS3 or ???
|
||||
|
||||
m_abs.clear();
|
||||
|
@ -91,11 +94,13 @@ JoyEvdev::JoyEvdev(int fd, bool ds3, const wchar_t *id) : Device(LNX_JOY, OTHER,
|
|||
fprintf(stderr, "New device created. Found axe:%zu, buttons:%zu, m_rel:%zu\n\n", m_abs.size(), m_btn.size(), m_rel.size());
|
||||
}
|
||||
|
||||
JoyEvdev::~JoyEvdev() {
|
||||
JoyEvdev::~JoyEvdev()
|
||||
{
|
||||
close(m_fd);
|
||||
}
|
||||
|
||||
int JoyEvdev::Activate(InitInfo* args) {
|
||||
int JoyEvdev::Activate(InitInfo *args)
|
||||
{
|
||||
AllocState();
|
||||
|
||||
uint16_t size = m_abs.size() + m_rel.size() + m_btn.size();
|
||||
|
@ -105,7 +110,8 @@ int JoyEvdev::Activate(InitInfo* args) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int JoyEvdev::Update() {
|
||||
int JoyEvdev::Update()
|
||||
{
|
||||
struct input_event events[32];
|
||||
int len;
|
||||
int status = 0;
|
||||
|
@ -117,8 +123,7 @@ int JoyEvdev::Update() {
|
|||
//fprintf(stderr, "Poll %d events available\n", evt_nb);
|
||||
for (int i = 0; i < evt_nb; i++) {
|
||||
switch (events[i].type) {
|
||||
case EV_ABS:
|
||||
{
|
||||
case EV_ABS: {
|
||||
for (size_t idx = 0; idx < m_abs.size(); idx++) {
|
||||
if (m_abs[idx].code == events[i].code) {
|
||||
// XXX strict or not ?
|
||||
|
@ -131,10 +136,8 @@ int JoyEvdev::Update() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EV_KEY:
|
||||
{
|
||||
} break;
|
||||
case EV_KEY: {
|
||||
for (size_t idx = 0; idx < m_btn.size(); idx++) {
|
||||
if (m_btn[idx] == events[i].code) {
|
||||
fprintf(stderr, "Event KEY:%d detected with value %d\n", events[i].code, events[i].value);
|
||||
|
@ -144,8 +147,7 @@ int JoyEvdev::Update() {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case EV_REL:
|
||||
// XXX
|
||||
break;
|
||||
|
@ -153,14 +155,14 @@ int JoyEvdev::Update() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static std::wstring CorrectJoySupport(int fd) {
|
||||
static std::wstring CorrectJoySupport(int fd)
|
||||
{
|
||||
struct input_id id;
|
||||
if (ioctl(fd, EVIOCGID, &id) < 0) {
|
||||
fprintf(stderr, "Invalid IOCTL EVIOCGID\n");
|
||||
|
@ -180,7 +182,8 @@ static std::wstring CorrectJoySupport(int fd) {
|
|||
return std::wstring(s.begin(), s.end());
|
||||
}
|
||||
|
||||
void EnumJoystickEvdev() {
|
||||
void EnumJoystickEvdev()
|
||||
{
|
||||
// Technically it must be done with udev but another lib for
|
||||
// avoid a loop is too much for me (even if udev is mandatory
|
||||
// so maybe later)
|
||||
|
@ -204,5 +207,4 @@ void EnumJoystickEvdev() {
|
|||
} else if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
#include <fcntl.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
struct abs_info {
|
||||
struct abs_info
|
||||
{
|
||||
uint16_t code;
|
||||
int32_t min;
|
||||
int32_t max;
|
||||
|
@ -31,7 +32,11 @@ struct abs_info {
|
|||
int32_t factor;
|
||||
int32_t translation;
|
||||
|
||||
abs_info(int32_t _code, int32_t _min, int32_t _max, ControlType type) : code(_code), min(_min), max(_max) {
|
||||
abs_info(int32_t _code, int32_t _min, int32_t _max, ControlType type)
|
||||
: code(_code)
|
||||
, min(_min)
|
||||
, max(_max)
|
||||
{
|
||||
translation = 0;
|
||||
// Note: ABSAXIS ranges from -64K to 64K
|
||||
// Note: PSHBTN ranges from 0 to 64K
|
||||
|
@ -56,12 +61,14 @@ struct abs_info {
|
|||
}
|
||||
}
|
||||
|
||||
int scale(int32_t value) {
|
||||
int scale(int32_t value)
|
||||
{
|
||||
return (value - translation) * factor;
|
||||
}
|
||||
};
|
||||
|
||||
class JoyEvdev : public Device {
|
||||
class JoyEvdev : public Device
|
||||
{
|
||||
int m_fd;
|
||||
std::vector<abs_info> m_abs;
|
||||
std::vector<uint16_t> m_btn;
|
||||
|
|
|
@ -20,15 +20,16 @@
|
|||
// actually it is even more but it is enough to distinguish different key
|
||||
#define MAX_KEYCODE (0xFF)
|
||||
|
||||
LinuxKeyboard::LinuxKeyboard() :
|
||||
Device(LNX_KEYBOARD, KEYBOARD, L"displayName", L"instanceID", L"deviceID")
|
||||
LinuxKeyboard::LinuxKeyboard()
|
||||
: Device(LNX_KEYBOARD, KEYBOARD, L"displayName", L"instanceID", L"deviceID")
|
||||
{
|
||||
for (int i = 0; i < MAX_KEYCODE; i++) {
|
||||
AddPhysicalControl(PSHBTN, i, i);
|
||||
}
|
||||
}
|
||||
|
||||
int LinuxKeyboard::Activate(InitInfo* args) {
|
||||
int LinuxKeyboard::Activate(InitInfo *args)
|
||||
{
|
||||
// Always active
|
||||
active = 1;
|
||||
|
||||
|
@ -50,7 +51,8 @@ int LinuxKeyboard::Activate(InitInfo* args) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int LinuxKeyboard::Update() {
|
||||
int LinuxKeyboard::Update()
|
||||
{
|
||||
keyEvent event;
|
||||
int status = 0;
|
||||
while (R_GetQueuedKeyEvent(&event)) {
|
||||
|
@ -73,6 +75,7 @@ int LinuxKeyboard::Update() {
|
|||
return status; // XXX ????
|
||||
}
|
||||
|
||||
void EnumLnx() {
|
||||
void EnumLnx()
|
||||
{
|
||||
dm->AddDevice(new LinuxKeyboard());
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#include "InputManager.h"
|
||||
#include "KeyboardQueue.h"
|
||||
|
||||
class LinuxKeyboard : public Device {
|
||||
class LinuxKeyboard : public Device
|
||||
{
|
||||
public:
|
||||
LinuxKeyboard();
|
||||
int Activate(InitInfo *args);
|
||||
|
|
|
@ -32,7 +32,8 @@ static u8 R_lastQueuedEvent = 0;
|
|||
static u8 R_nextQueuedEvent = 0;
|
||||
static keyEvent R_queuedEvents[R_EVENT_QUEUE_LEN];
|
||||
|
||||
void R_QueueKeyEvent(const keyEvent &evt) {
|
||||
void R_QueueKeyEvent(const keyEvent &evt)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(core_event);
|
||||
|
||||
R_queuedEvents[R_lastQueuedEvent] = evt;
|
||||
|
@ -41,8 +42,10 @@ void R_QueueKeyEvent(const keyEvent &evt) {
|
|||
assert(R_nextQueuedEvent != R_lastQueuedEvent);
|
||||
}
|
||||
|
||||
int R_GetQueuedKeyEvent(keyEvent *event) {
|
||||
if (R_lastQueuedEvent == R_nextQueuedEvent) return 0;
|
||||
int R_GetQueuedKeyEvent(keyEvent *event)
|
||||
{
|
||||
if (R_lastQueuedEvent == R_nextQueuedEvent)
|
||||
return 0;
|
||||
|
||||
std::lock_guard<std::mutex> lock(core_event);
|
||||
*event = R_queuedEvents[R_nextQueuedEvent];
|
||||
|
@ -50,11 +53,13 @@ int R_GetQueuedKeyEvent(keyEvent *event) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
void R_ClearKeyQueue() {
|
||||
void R_ClearKeyQueue()
|
||||
{
|
||||
R_lastQueuedEvent = R_nextQueuedEvent;
|
||||
}
|
||||
|
||||
EXPORT_C_(void) PADWriteEvent(keyEvent &evt)
|
||||
EXPORT_C_(void)
|
||||
PADWriteEvent(keyEvent &evt)
|
||||
{
|
||||
R_QueueKeyEvent(evt);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
|
||||
ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output);
|
||||
|
||||
int GetRawKeyboards(HWND hWnd) {
|
||||
int GetRawKeyboards(HWND hWnd)
|
||||
{
|
||||
RAWINPUTDEVICE Rid;
|
||||
Rid.hwndTarget = hWnd;
|
||||
|
||||
|
@ -36,7 +37,8 @@ int GetRawKeyboards(HWND hWnd) {
|
|||
return RegisterRawInputDevices(&Rid, 1, sizeof(Rid));
|
||||
}
|
||||
|
||||
void ReleaseRawKeyboards() {
|
||||
void ReleaseRawKeyboards()
|
||||
{
|
||||
RAWINPUTDEVICE Rid;
|
||||
Rid.hwndTarget = 0;
|
||||
|
||||
|
@ -46,7 +48,8 @@ void ReleaseRawKeyboards() {
|
|||
RegisterRawInputDevices(&Rid, 1, sizeof(Rid));
|
||||
}
|
||||
|
||||
int GetRawMice(HWND hWnd) {
|
||||
int GetRawMice(HWND hWnd)
|
||||
{
|
||||
RAWINPUTDEVICE Rid;
|
||||
Rid.hwndTarget = hWnd;
|
||||
|
||||
|
@ -56,7 +59,8 @@ int GetRawMice(HWND hWnd) {
|
|||
return RegisterRawInputDevices(&Rid, 1, sizeof(Rid));
|
||||
}
|
||||
|
||||
void ReleaseRawMice() {
|
||||
void ReleaseRawMice()
|
||||
{
|
||||
RAWINPUTDEVICE Rid;
|
||||
Rid.hwndTarget = 0;
|
||||
|
||||
|
@ -72,15 +76,19 @@ static int rawKeyboardActivatedCount = 0;
|
|||
// Same for mice.
|
||||
static int rawMouseActivatedCount = 0;
|
||||
|
||||
class RawInputKeyboard : public WindowsKeyboard {
|
||||
class RawInputKeyboard : public WindowsKeyboard
|
||||
{
|
||||
public:
|
||||
HANDLE hDevice;
|
||||
|
||||
RawInputKeyboard(HANDLE hDevice, wchar_t *name, wchar_t *instanceID=0) : WindowsKeyboard(RAW, name, instanceID) {
|
||||
RawInputKeyboard(HANDLE hDevice, wchar_t *name, wchar_t *instanceID = 0)
|
||||
: WindowsKeyboard(RAW, name, instanceID)
|
||||
{
|
||||
this->hDevice = hDevice;
|
||||
}
|
||||
|
||||
int Activate(InitInfo *initInfo) {
|
||||
int Activate(InitInfo *initInfo)
|
||||
{
|
||||
Deactivate();
|
||||
|
||||
hWndProc = initInfo->hWndProc;
|
||||
|
@ -100,7 +108,8 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
void Deactivate() {
|
||||
void Deactivate()
|
||||
{
|
||||
FreeState();
|
||||
if (active) {
|
||||
active = 0;
|
||||
|
@ -114,15 +123,19 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class RawInputMouse : public WindowsMouse {
|
||||
class RawInputMouse : public WindowsMouse
|
||||
{
|
||||
public:
|
||||
HANDLE hDevice;
|
||||
|
||||
RawInputMouse(HANDLE hDevice, wchar_t *name, wchar_t *instanceID=0, wchar_t *productID=0) : WindowsMouse(RAW, 0, name, instanceID, productID) {
|
||||
RawInputMouse(HANDLE hDevice, wchar_t *name, wchar_t *instanceID = 0, wchar_t *productID = 0)
|
||||
: WindowsMouse(RAW, 0, name, instanceID, productID)
|
||||
{
|
||||
this->hDevice = hDevice;
|
||||
}
|
||||
|
||||
int Activate(InitInfo *initInfo) {
|
||||
int Activate(InitInfo *initInfo)
|
||||
{
|
||||
Deactivate();
|
||||
|
||||
hWndProc = initInfo->hWndProc;
|
||||
|
@ -147,7 +160,8 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
void Deactivate() {
|
||||
void Deactivate()
|
||||
{
|
||||
FreeState();
|
||||
if (active) {
|
||||
active = 0;
|
||||
|
@ -163,7 +177,8 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) {
|
||||
ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output)
|
||||
{
|
||||
if (uMsg == WM_INPUT) {
|
||||
if (GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT) {
|
||||
RAWINPUT in;
|
||||
|
@ -171,18 +186,20 @@ ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, &in, &size, sizeof(RAWINPUTHEADER)) > 0) {
|
||||
for (int i = 0; i < dm->numDevices; i++) {
|
||||
Device *dev = dm->devices[i];
|
||||
if (dev->api != RAW || !dev->active) continue;
|
||||
if (dev->api != RAW || !dev->active)
|
||||
continue;
|
||||
if (in.header.dwType == RIM_TYPEKEYBOARD && dev->type == KEYBOARD) {
|
||||
RawInputKeyboard *rik = (RawInputKeyboard *)dev;
|
||||
if (rik->hDevice != in.header.hDevice) continue;
|
||||
if (rik->hDevice != in.header.hDevice)
|
||||
continue;
|
||||
|
||||
u32 uMsg = in.data.keyboard.Message;
|
||||
if (!(in.data.keyboard.VKey >> 8))
|
||||
rik->UpdateKey((u8)in.data.keyboard.VKey, (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN));
|
||||
}
|
||||
else if (in.header.dwType == RIM_TYPEMOUSE && dev->type == MOUSE) {
|
||||
} else if (in.header.dwType == RIM_TYPEMOUSE && dev->type == MOUSE) {
|
||||
RawInputMouse *rim = (RawInputMouse *)dev;
|
||||
if (rim->hDevice != in.header.hDevice) continue;
|
||||
if (rim->hDevice != in.header.hDevice)
|
||||
continue;
|
||||
if (in.data.mouse.usFlags) {
|
||||
// Never been set for me, and specs on what most of them
|
||||
// actually mean is sorely lacking. Also, specs erroneously
|
||||
|
@ -212,15 +229,14 @@ ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (uMsg == WM_ACTIVATE) {
|
||||
} else if (uMsg == WM_ACTIVATE) {
|
||||
for (int i = 0; i < dm->numDevices; i++) {
|
||||
Device *dev = dm->devices[i];
|
||||
if (dev->api != RAW || dev->physicalControlState == 0) continue;
|
||||
if (dev->api != RAW || dev->physicalControlState == 0)
|
||||
continue;
|
||||
memset(dev->physicalControlState, 0, sizeof(int) * dev->numPhysicalControls);
|
||||
}
|
||||
}
|
||||
else if (uMsg == WM_SIZE && rawMouseActivatedCount) {
|
||||
} else if (uMsg == WM_SIZE && rawMouseActivatedCount) {
|
||||
// Doesn't really matter for raw mice, as I disable legacy stuff, but shouldn't hurt.
|
||||
WindowsMouse::WindowResized(hWnd);
|
||||
}
|
||||
|
@ -228,7 +244,8 @@ ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
return CONTINUE_BLISSFULLY;
|
||||
}
|
||||
|
||||
void EnumRawInputDevices() {
|
||||
void EnumRawInputDevices()
|
||||
{
|
||||
int count = 0;
|
||||
if (GetRawInputDeviceList(0, (unsigned int *)&count, sizeof(RAWINPUTDEVICELIST)) != (UINT)-1 && count > 0) {
|
||||
wchar_t *instanceID = (wchar_t *)malloc(41000 * sizeof(wchar_t));
|
||||
|
@ -244,7 +261,8 @@ void EnumRawInputDevices() {
|
|||
// Not necessary, but reminder that count is -1 on failure.
|
||||
if (count > 0) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (list[i].dwType != RIM_TYPEKEYBOARD && list[i].dwType != RIM_TYPEMOUSE) continue;
|
||||
if (list[i].dwType != RIM_TYPEKEYBOARD && list[i].dwType != RIM_TYPEMOUSE)
|
||||
continue;
|
||||
|
||||
UINT bufferLen = 10000;
|
||||
int nameLen = GetRawInputDeviceInfo(list[i].hDevice, RIDI_DEVICENAME, instanceID, &bufferLen);
|
||||
|
@ -258,16 +276,19 @@ void EnumRawInputDevices() {
|
|||
wchar_t *temp = 0;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
wchar_t *s = wcschr(productID, '#');
|
||||
if (!s) break;
|
||||
if (!s)
|
||||
break;
|
||||
*s = '\\';
|
||||
if (j == 2) {
|
||||
*s = 0;
|
||||
}
|
||||
if (j==1) temp = s;
|
||||
if (j == 1)
|
||||
temp = s;
|
||||
}
|
||||
|
||||
wsprintfW(keyName, L"SYSTEM\\CurrentControlSet\\Enum%s", productID + 3);
|
||||
if (temp) *temp = 0;
|
||||
if (temp)
|
||||
*temp = 0;
|
||||
int haveDescription = 0;
|
||||
HKEY hKey;
|
||||
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_QUERY_VALUE, &hKey)) {
|
||||
|
@ -276,8 +297,10 @@ void EnumRawInputDevices() {
|
|||
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"DeviceDesc", 0, &type, (BYTE *)displayName, &len) &&
|
||||
len && type == REG_SZ) {
|
||||
wchar_t *temp2 = wcsrchr(displayName, ';');
|
||||
if (!temp2) temp2 = displayName;
|
||||
else temp2++;
|
||||
if (!temp2)
|
||||
temp2 = displayName;
|
||||
else
|
||||
temp2++;
|
||||
// Could do without this, but more effort than it's worth.
|
||||
wcscpy(keyName, temp2);
|
||||
haveDescription = 1;
|
||||
|
@ -285,13 +308,16 @@ void EnumRawInputDevices() {
|
|||
RegCloseKey(hKey);
|
||||
}
|
||||
if (list[i].dwType == RIM_TYPEKEYBOARD) {
|
||||
if (!haveDescription) wsprintfW(displayName, L"Raw Keyboard %i", keyboardCount++);
|
||||
else wsprintfW(displayName, L"Raw KB: %s", keyName);
|
||||
if (!haveDescription)
|
||||
wsprintfW(displayName, L"Raw Keyboard %i", keyboardCount++);
|
||||
else
|
||||
wsprintfW(displayName, L"Raw KB: %s", keyName);
|
||||
dm->AddDevice(new RawInputKeyboard(list[i].hDevice, displayName, instanceID));
|
||||
}
|
||||
else if (list[i].dwType == RIM_TYPEMOUSE) {
|
||||
if (!haveDescription) wsprintfW(displayName, L"Raw Mouse %i", mouseCount++);
|
||||
else wsprintfW(displayName, L"Raw MS: %s", keyName);
|
||||
} else if (list[i].dwType == RIM_TYPEMOUSE) {
|
||||
if (!haveDescription)
|
||||
wsprintfW(displayName, L"Raw Mouse %i", mouseCount++);
|
||||
else
|
||||
wsprintfW(displayName, L"Raw MS: %s", keyName);
|
||||
dm->AddDevice(new RawInputMouse(list[i].hDevice, displayName, instanceID, productID));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,15 @@
|
|||
#include "Global.h"
|
||||
#include "VKey.h"
|
||||
|
||||
wchar_t *GetVKStringW(unsigned char vk) {
|
||||
wchar_t *GetVKStringW(unsigned char vk)
|
||||
{
|
||||
int flag;
|
||||
static wchar_t t[20];
|
||||
switch (vk) {
|
||||
case 0x0C: return L"Clear";
|
||||
case 0x13: return L"Pause";
|
||||
case 0x0C:
|
||||
return L"Clear";
|
||||
case 0x13:
|
||||
return L"Pause";
|
||||
|
||||
case 0x21: // return "Page Up";
|
||||
case 0x22: // return "Page Down";
|
||||
|
@ -42,32 +45,54 @@ wchar_t *GetVKStringW(unsigned char vk) {
|
|||
flag = 1 << 24;
|
||||
break;
|
||||
|
||||
case 0x29: return L"Select";
|
||||
case 0x2A: return L"Print";
|
||||
case 0x2B: return L"Execute";
|
||||
case 0x2C: return L"Prnt Scrn";
|
||||
case 0x2F: return L"Help";
|
||||
case 0x29:
|
||||
return L"Select";
|
||||
case 0x2A:
|
||||
return L"Print";
|
||||
case 0x2B:
|
||||
return L"Execute";
|
||||
case 0x2C:
|
||||
return L"Prnt Scrn";
|
||||
case 0x2F:
|
||||
return L"Help";
|
||||
|
||||
case 0x6C: return L"|";
|
||||
case 0x90: return L"Num Lock";
|
||||
case 0x6C:
|
||||
return L"|";
|
||||
case 0x90:
|
||||
return L"Num Lock";
|
||||
|
||||
case 0xA0: return L"Left Shift";
|
||||
case 0xA1: return L"Right Shift";
|
||||
case 0xA2: return L"Left Ctrl";
|
||||
case 0xA3: return L"Right Ctrl";
|
||||
case 0xA4: return L"Left Alt";
|
||||
case 0xA5: return L"Right Alt";
|
||||
case 0xA0:
|
||||
return L"Left Shift";
|
||||
case 0xA1:
|
||||
return L"Right Shift";
|
||||
case 0xA2:
|
||||
return L"Left Ctrl";
|
||||
case 0xA3:
|
||||
return L"Right Ctrl";
|
||||
case 0xA4:
|
||||
return L"Left Alt";
|
||||
case 0xA5:
|
||||
return L"Right Alt";
|
||||
|
||||
case 0xA6: return L"Back";
|
||||
case 0xA7: return L"Forward";
|
||||
case 0xA8: return L"Refresh";
|
||||
case 0xA9: return L"Stop";
|
||||
case 0xAA: return L"Search";
|
||||
case 0xAB: return L"Favorites";
|
||||
case 0xAC: return L"Browser";
|
||||
case 0xA6:
|
||||
return L"Back";
|
||||
case 0xA7:
|
||||
return L"Forward";
|
||||
case 0xA8:
|
||||
return L"Refresh";
|
||||
case 0xA9:
|
||||
return L"Stop";
|
||||
case 0xAA:
|
||||
return L"Search";
|
||||
case 0xAB:
|
||||
return L"Favorites";
|
||||
case 0xAC:
|
||||
return L"Browser";
|
||||
|
||||
case 0xFA: return L"Play";
|
||||
case 0xFB: return L"Zoom";
|
||||
case 0xFA:
|
||||
return L"Play";
|
||||
case 0xFB:
|
||||
return L"Zoom";
|
||||
default:
|
||||
flag = 0;
|
||||
break;
|
||||
|
@ -76,10 +101,8 @@ wchar_t *GetVKStringW(unsigned char vk) {
|
|||
if (res && GetKeyNameText((res << 16) | flag, t, 20)) {
|
||||
// don't trust windows
|
||||
t[19] = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
wsprintfW(t, L"Key %i", vk);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,30 +21,35 @@
|
|||
#include "WindowsKeyboard.h"
|
||||
#include "KeyboardQueue.h"
|
||||
|
||||
WindowsKeyboard::WindowsKeyboard(DeviceAPI api, wchar_t *displayName, wchar_t *instanceID, wchar_t *deviceID) :
|
||||
Device(api, KEYBOARD, displayName, instanceID, deviceID) {
|
||||
WindowsKeyboard::WindowsKeyboard(DeviceAPI api, wchar_t *displayName, wchar_t *instanceID, wchar_t *deviceID)
|
||||
: Device(api, KEYBOARD, displayName, instanceID, deviceID)
|
||||
{
|
||||
for (int i = 0; i < 256; i++) {
|
||||
AddPhysicalControl(PSHBTN, i, i);
|
||||
}
|
||||
}
|
||||
|
||||
wchar_t *WindowsKeyboard::GetPhysicalControlName(PhysicalControl *control) {
|
||||
wchar_t *WindowsKeyboard::GetPhysicalControlName(PhysicalControl *control)
|
||||
{
|
||||
int id = control->id;
|
||||
if (control->type == PSHBTN && id >= 0 && id < 256) {
|
||||
wchar_t *w = GetVKStringW(id);
|
||||
if (w) return w;
|
||||
if (w)
|
||||
return w;
|
||||
}
|
||||
return Device::GetPhysicalControlName(control);
|
||||
}
|
||||
|
||||
void WindowsKeyboard::UpdateKey(int vkey, int state) {
|
||||
void WindowsKeyboard::UpdateKey(int vkey, int state)
|
||||
{
|
||||
if (vkey > 7 && vkey < 256) {
|
||||
int newState = state * FULLY_DOWN;
|
||||
if (newState != physicalControlState[vkey]) {
|
||||
// Check for alt-F4 to avoid toggling skip mode incorrectly.
|
||||
if (vkey != VK_F4 || !(physicalControlState[VK_MENU] || physicalControlState[VK_RMENU] || physicalControlState[VK_LMENU])) {
|
||||
int event = KEYPRESS;
|
||||
if (!newState) event = KEYRELEASE;
|
||||
if (!newState)
|
||||
event = KEYRELEASE;
|
||||
QueueKeyEvent(vkey, event);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +57,8 @@ void WindowsKeyboard::UpdateKey(int vkey, int state) {
|
|||
}
|
||||
}
|
||||
|
||||
void WindowsKeyboard::InitState() {
|
||||
void WindowsKeyboard::InitState()
|
||||
{
|
||||
AllocState();
|
||||
for (int vkey = 5; vkey < 256; vkey++) {
|
||||
int value = (unsigned short)(((short)GetAsyncKeyState(vkey)) >> 15);
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
*/
|
||||
|
||||
// Shared functionality for WM and RAW keyboards.
|
||||
class WindowsKeyboard : public Device {
|
||||
class WindowsKeyboard : public Device
|
||||
{
|
||||
public:
|
||||
WindowsKeyboard(DeviceAPI api, wchar_t *displayName, wchar_t *instanceID = 0, wchar_t *deviceID = 0);
|
||||
wchar_t *GetPhysicalControlName(PhysicalControl *control);
|
||||
|
|
|
@ -32,16 +32,20 @@ class WindowsMessagingMouse;
|
|||
static WindowsMessagingKeyboard *wmk = 0;
|
||||
static WindowsMessagingMouse *wmm = 0;
|
||||
|
||||
class WindowsMessagingKeyboard : public WindowsKeyboard {
|
||||
class WindowsMessagingKeyboard : public WindowsKeyboard
|
||||
{
|
||||
public:
|
||||
|
||||
WindowsMessagingKeyboard() : WindowsKeyboard(WM, L"WM Keyboard") {
|
||||
WindowsMessagingKeyboard()
|
||||
: WindowsKeyboard(WM, L"WM Keyboard")
|
||||
{
|
||||
}
|
||||
|
||||
int Activate(InitInfo *initInfo) {
|
||||
int Activate(InitInfo *initInfo)
|
||||
{
|
||||
// Redundant. Should match the next line.
|
||||
// Deactivate();
|
||||
if (wmk) wmk->Deactivate();
|
||||
if (wmk)
|
||||
wmk->Deactivate();
|
||||
|
||||
hWndProc = initInfo->hWndProc;
|
||||
|
||||
|
@ -55,7 +59,8 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
void Deactivate() {
|
||||
void Deactivate()
|
||||
{
|
||||
if (active) {
|
||||
if (!wmm)
|
||||
hWndProc->ReleaseExtraProc(WindowsMessagingWndProc);
|
||||
|
@ -66,21 +71,26 @@ public:
|
|||
}
|
||||
|
||||
|
||||
void CheckKey(int vkey) {
|
||||
void CheckKey(int vkey)
|
||||
{
|
||||
UpdateKey(vkey, 1 & (((unsigned short)GetAsyncKeyState(vkey)) >> 15));
|
||||
}
|
||||
};
|
||||
|
||||
class WindowsMessagingMouse : public WindowsMouse {
|
||||
class WindowsMessagingMouse : public WindowsMouse
|
||||
{
|
||||
public:
|
||||
|
||||
WindowsMessagingMouse() : WindowsMouse(WM, 1, L"WM Mouse") {
|
||||
WindowsMessagingMouse()
|
||||
: WindowsMouse(WM, 1, L"WM Mouse")
|
||||
{
|
||||
}
|
||||
|
||||
int Activate(InitInfo *initInfo) {
|
||||
int Activate(InitInfo *initInfo)
|
||||
{
|
||||
// Redundant. Should match the next line.
|
||||
// Deactivate();
|
||||
if (wmm) wmm->Deactivate();
|
||||
if (wmm)
|
||||
wmm->Deactivate();
|
||||
hWndProc = initInfo->hWndProc;
|
||||
|
||||
if (!wmk)
|
||||
|
@ -96,7 +106,8 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
void Deactivate() {
|
||||
void Deactivate()
|
||||
{
|
||||
if (active) {
|
||||
if (!wmk)
|
||||
hWndProc->ReleaseExtraProc(WindowsMessagingWndProc);
|
||||
|
@ -108,30 +119,27 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
ExtraWndProcResult WindowsMessagingWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) {
|
||||
ExtraWndProcResult WindowsMessagingWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output)
|
||||
{
|
||||
if (wmk) {
|
||||
if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN || uMsg == WM_KEYUP || uMsg == WM_SYSKEYUP) {
|
||||
if (wParam == VK_SHIFT) {
|
||||
wmk->CheckKey(VK_RSHIFT);
|
||||
wmk->CheckKey(VK_LSHIFT);
|
||||
}
|
||||
else if (wParam == VK_CONTROL) {
|
||||
} else if (wParam == VK_CONTROL) {
|
||||
wmk->CheckKey(VK_RCONTROL);
|
||||
wmk->CheckKey(VK_LCONTROL);
|
||||
}
|
||||
else if (wParam == VK_MENU) {
|
||||
} else if (wParam == VK_MENU) {
|
||||
wmk->CheckKey(VK_RMENU);
|
||||
wmk->CheckKey(VK_LMENU);
|
||||
}
|
||||
else
|
||||
} else
|
||||
wmk->UpdateKey(wParam, (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN));
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
// Needed to prevent default handling of keys in some situations.
|
||||
else if (uMsg == WM_CHAR || uMsg == WM_UNICHAR) {
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
else if (uMsg == WM_ACTIVATE) {
|
||||
} else if (uMsg == WM_ACTIVATE) {
|
||||
// Not really needed, but doesn't hurt.
|
||||
memset(wmk->physicalControlState, 0, sizeof(int) * wmk->numPhysicalControls);
|
||||
}
|
||||
|
@ -148,32 +156,25 @@ ExtraWndProcResult WindowsMessagingWndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
|
|||
SetCursorPos(wmm->center.x, wmm->center.y);
|
||||
}
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
else if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP) {
|
||||
} else if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP) {
|
||||
wmm->UpdateButton(0, uMsg == WM_LBUTTONDOWN);
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP) {
|
||||
} else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP) {
|
||||
wmm->UpdateButton(1, uMsg == WM_RBUTTONDOWN);
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP) {
|
||||
} else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP) {
|
||||
wmm->UpdateButton(2, uMsg == WM_MBUTTONDOWN);
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
else if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP) {
|
||||
} else if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP) {
|
||||
wmm->UpdateButton(3 + ((wParam >> 16) == XBUTTON2), uMsg == WM_XBUTTONDOWN);
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
else if (uMsg == WM_MOUSEWHEEL) {
|
||||
} else if (uMsg == WM_MOUSEWHEEL) {
|
||||
wmm->UpdateAxis(2, ((int)wParam >> 16) / WHEEL_DELTA);
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
else if (uMsg == WM_MOUSEHWHEEL) {
|
||||
} else if (uMsg == WM_MOUSEHWHEEL) {
|
||||
wmm->UpdateAxis(3, ((int)wParam >> 16) / WHEEL_DELTA);
|
||||
return NO_WND_PROC;
|
||||
}
|
||||
else if (uMsg == WM_SIZE && wmm->active) {
|
||||
} else if (uMsg == WM_SIZE && wmm->active) {
|
||||
WindowsMouse::WindowResized(hWnd);
|
||||
}
|
||||
// Taken care of elsewhere. When binding, killing focus means stop reading input.
|
||||
|
@ -185,7 +186,8 @@ ExtraWndProcResult WindowsMessagingWndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
|
|||
return CONTINUE_BLISSFULLY;
|
||||
}
|
||||
|
||||
void EnumWindowsMessagingDevices() {
|
||||
void EnumWindowsMessagingDevices()
|
||||
{
|
||||
dm->AddDevice(new WindowsMessagingKeyboard());
|
||||
dm->AddDevice(new WindowsMessagingMouse());
|
||||
}
|
||||
|
|
|
@ -23,8 +23,9 @@
|
|||
POINT WindowsMouse::origCursorPos;
|
||||
POINT WindowsMouse::center;
|
||||
|
||||
WindowsMouse::WindowsMouse(DeviceAPI api, int hWheel, wchar_t *displayName, wchar_t *instanceID, wchar_t *deviceID) :
|
||||
Device(api, MOUSE, displayName, instanceID, deviceID) {
|
||||
WindowsMouse::WindowsMouse(DeviceAPI api, int hWheel, wchar_t *displayName, wchar_t *instanceID, wchar_t *deviceID)
|
||||
: Device(api, MOUSE, displayName, instanceID, deviceID)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
AddPhysicalControl(PSHBTN, i, i);
|
||||
|
@ -35,7 +36,8 @@ Device(api, MOUSE, displayName, instanceID, deviceID) {
|
|||
}
|
||||
}
|
||||
|
||||
wchar_t *WindowsMouse::GetPhysicalControlName(PhysicalControl *control) {
|
||||
wchar_t *WindowsMouse::GetPhysicalControlName(PhysicalControl *control)
|
||||
{
|
||||
wchar_t *names[9] = {
|
||||
L"L Button",
|
||||
L"R Button",
|
||||
|
@ -45,24 +47,29 @@ wchar_t *WindowsMouse::GetPhysicalControlName(PhysicalControl *control) {
|
|||
L"X Axis",
|
||||
L"Y Axis",
|
||||
L"Y Wheel",
|
||||
L"X Wheel"
|
||||
};
|
||||
if (control->id < 9) return names[control->id];
|
||||
L"X Wheel"};
|
||||
if (control->id < 9)
|
||||
return names[control->id];
|
||||
return Device::GetPhysicalControlName(control);
|
||||
}
|
||||
|
||||
void WindowsMouse::UpdateButton(unsigned int button, int state) {
|
||||
if (button > 4) return;
|
||||
void WindowsMouse::UpdateButton(unsigned int button, int state)
|
||||
{
|
||||
if (button > 4)
|
||||
return;
|
||||
physicalControlState[button] = (state << 16);
|
||||
}
|
||||
|
||||
void WindowsMouse::UpdateAxis(unsigned int axis, int delta) {
|
||||
if (axis > 3) return;
|
||||
void WindowsMouse::UpdateAxis(unsigned int axis, int delta)
|
||||
{
|
||||
if (axis > 3)
|
||||
return;
|
||||
// 1 mouse pixel = 1/8th way down.
|
||||
physicalControlState[5 + axis] += (delta << (16 - 3 * (axis < 2)));
|
||||
}
|
||||
|
||||
void WindowsMouse::WindowResized(HWND hWnd) {
|
||||
void WindowsMouse::WindowResized(HWND hWnd)
|
||||
{
|
||||
RECT r;
|
||||
GetWindowRect(hWnd, &r);
|
||||
ClipCursor(&r);
|
||||
|
@ -71,7 +78,8 @@ void WindowsMouse::WindowResized(HWND hWnd) {
|
|||
SetCursorPos(center.x, center.y);
|
||||
}
|
||||
|
||||
void WindowsMouse::GetMouseCapture(HWND hWnd) {
|
||||
void WindowsMouse::GetMouseCapture(HWND hWnd)
|
||||
{
|
||||
SetCapture(hWnd);
|
||||
ShowCursor(0);
|
||||
|
||||
|
@ -85,7 +93,8 @@ void WindowsMouse::GetMouseCapture(HWND hWnd) {
|
|||
SetCursorPos(center.x, center.y);
|
||||
}
|
||||
|
||||
void WindowsMouse::ReleaseMouseCapture() {
|
||||
void WindowsMouse::ReleaseMouseCapture()
|
||||
{
|
||||
ClipCursor(0);
|
||||
ReleaseCapture();
|
||||
ShowCursor(1);
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
*/
|
||||
|
||||
// Shared functionality for WM and RAW keyboards.
|
||||
class WindowsMouse : public Device {
|
||||
class WindowsMouse : public Device
|
||||
{
|
||||
public:
|
||||
// Used by GetMouseCapture()/ReleaseMouseCapture()
|
||||
// Static because can have multiple raw mice active at once,
|
||||
|
|
|
@ -37,9 +37,11 @@ WndProcEater::~WndProcEater() throw()
|
|||
}
|
||||
}
|
||||
|
||||
void WndProcEater::ReleaseExtraProc(ExtraWndProc proc) {
|
||||
void WndProcEater::ReleaseExtraProc(ExtraWndProc proc)
|
||||
{
|
||||
// Probably isn't needed, but just in case...
|
||||
if (hMutex) WaitForSingleObject(hMutex, 100);
|
||||
if (hMutex)
|
||||
WaitForSingleObject(hMutex, 100);
|
||||
|
||||
//printf( "(Lilypad) Regurgitating! -> 0x%x\n", proc );
|
||||
|
||||
|
@ -57,8 +59,10 @@ void WndProcEater::ReleaseExtraProc(ExtraWndProc proc) {
|
|||
}
|
||||
}
|
||||
|
||||
void WndProcEater::Release() {
|
||||
while (numExtraProcs) ReleaseExtraProc(extraProcs[0].proc);
|
||||
void WndProcEater::Release()
|
||||
{
|
||||
while (numExtraProcs)
|
||||
ReleaseExtraProc(extraProcs[0].proc);
|
||||
if (hWndEaten && IsWindow(hWndEaten)) {
|
||||
RemoveProp(hWndEaten, L"LilyHaxxor");
|
||||
SetWindowLongPtr(hWndEaten, GWLP_WNDPROC, (LONG_PTR)eatenWndProc);
|
||||
|
@ -90,8 +94,8 @@ LRESULT WndProcEater::_OverrideWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
|||
if (res2 == CONTINUE_BLISSFULLY_AND_RELEASE_PROC) {
|
||||
ReleaseExtraProc(extraProcs[i].proc);
|
||||
i--;
|
||||
}
|
||||
else if (res2 > res) res = res2;
|
||||
} else if (res2 > res)
|
||||
res = res2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +121,8 @@ static LRESULT CALLBACK OverrideWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
|
|||
|
||||
bool WndProcEater::SetWndHandle(HWND hWnd)
|
||||
{
|
||||
if(hWnd == hWndEaten) return true;
|
||||
if (hWnd == hWndEaten)
|
||||
return true;
|
||||
|
||||
//printf( "(Lilypad) (Re)-Setting window handle! -> this=0x%08x, hWnd=0x%08x\n", this, hWnd );
|
||||
|
||||
|
@ -130,13 +135,16 @@ bool WndProcEater::SetWndHandle(HWND hWnd)
|
|||
return !!hWndEaten;
|
||||
}
|
||||
|
||||
void WndProcEater::Eat(ExtraWndProc proc, DWORD flags) {
|
||||
void WndProcEater::Eat(ExtraWndProc proc, DWORD flags)
|
||||
{
|
||||
|
||||
// check if Subclassing failed to init during SetWndHandle
|
||||
if (!hWndEaten) return;
|
||||
if (!hWndEaten)
|
||||
return;
|
||||
|
||||
// Probably isn't needed, but just in case...
|
||||
if (hMutex) WaitForSingleObject(hMutex, 100);
|
||||
if (hMutex)
|
||||
WaitForSingleObject(hMutex, 100);
|
||||
|
||||
//printf( "(Lilypad) EatingWndProc! -> 0x%x\n", proc );
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ enum ExtraWndProcResult {
|
|||
|
||||
typedef ExtraWndProcResult (*ExtraWndProc)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *out);
|
||||
|
||||
struct ExtraWndProcInfo {
|
||||
struct ExtraWndProcInfo
|
||||
{
|
||||
ExtraWndProc proc;
|
||||
DWORD flags;
|
||||
};
|
||||
|
|
|
@ -73,24 +73,29 @@ _XInputSetState pXInputSetState = 0;
|
|||
static int xInputActiveCount = 0;
|
||||
|
||||
// Completely unncessary, really.
|
||||
__forceinline int ShortToAxis(int v) {
|
||||
__forceinline int ShortToAxis(int v)
|
||||
{
|
||||
// If positive and at least 1 << 14, increment.
|
||||
v += (!((v >> 15) & 1)) & ((v >> 14) & 1);
|
||||
// Just double.
|
||||
return v * 2;
|
||||
}
|
||||
|
||||
class XInputDevice : public Device {
|
||||
class XInputDevice : public Device
|
||||
{
|
||||
// Cached last vibration values by pad and motor.
|
||||
// Need this, as only one value is changed at a time.
|
||||
int ps2Vibration[2][4][2];
|
||||
// Minor optimization - cache last set vibration values
|
||||
// When there's no change, no need to do anything.
|
||||
XINPUT_VIBRATION xInputVibration;
|
||||
|
||||
public:
|
||||
int index;
|
||||
|
||||
XInputDevice(int index, wchar_t *displayName) : Device(XINPUT, OTHER, displayName) {
|
||||
XInputDevice(int index, wchar_t *displayName)
|
||||
: Device(XINPUT, OTHER, displayName)
|
||||
{
|
||||
memset(ps2Vibration, 0, sizeof(ps2Vibration));
|
||||
memset(&xInputVibration, 0, sizeof(xInputVibration));
|
||||
this->index = index;
|
||||
|
@ -106,7 +111,8 @@ public:
|
|||
AddFFEffectType(L"Constant Effect", L"Constant", EFFECT_CONSTANT);
|
||||
}
|
||||
|
||||
wchar_t *GetPhysicalControlName(PhysicalControl *c) {
|
||||
wchar_t *GetPhysicalControlName(PhysicalControl *c)
|
||||
{
|
||||
const static wchar_t *names[] = {
|
||||
L"D-pad Up",
|
||||
L"D-pad Down",
|
||||
|
@ -137,8 +143,10 @@ public:
|
|||
return Device::GetPhysicalControlName(c);
|
||||
}
|
||||
|
||||
int Activate(InitInfo *initInfo) {
|
||||
if (active) Deactivate();
|
||||
int Activate(InitInfo *initInfo)
|
||||
{
|
||||
if (active)
|
||||
Deactivate();
|
||||
if (!xInputActiveCount) {
|
||||
pXInputEnable(1);
|
||||
}
|
||||
|
@ -148,8 +156,10 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
int Update() {
|
||||
if (!active) return 0;
|
||||
int Update()
|
||||
{
|
||||
if (!active)
|
||||
return 0;
|
||||
XINPUT_STATE state;
|
||||
if (ERROR_SUCCESS != pXInputGetStateEx(index, &state)) {
|
||||
Deactivate();
|
||||
|
@ -193,7 +203,8 @@ public:
|
|||
return 1;
|
||||
}
|
||||
|
||||
void SetEffects(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force) {
|
||||
void SetEffects(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force)
|
||||
{
|
||||
ps2Vibration[port][slot][motor] = force;
|
||||
int newVibration[2] = {0, 0};
|
||||
for (int p = 0; p < 2; p++) {
|
||||
|
@ -222,7 +233,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void SetEffect(ForceFeedbackBinding *binding, unsigned char force) {
|
||||
void SetEffect(ForceFeedbackBinding *binding, unsigned char force)
|
||||
{
|
||||
PadBindings pBackup = pads[0][0];
|
||||
pads[0][0].ffBindings = binding;
|
||||
pads[0][0].numFFBindings = 1;
|
||||
|
@ -230,7 +242,8 @@ public:
|
|||
pads[0][0] = pBackup;
|
||||
}
|
||||
|
||||
void Deactivate() {
|
||||
void Deactivate()
|
||||
{
|
||||
memset(&xInputVibration, 0, sizeof(xInputVibration));
|
||||
memset(ps2Vibration, 0, sizeof(ps2Vibration));
|
||||
pXInputSetState(index, &xInputVibration);
|
||||
|
@ -244,16 +257,19 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
~XInputDevice() {
|
||||
~XInputDevice()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void EnumXInputDevices() {
|
||||
void EnumXInputDevices()
|
||||
{
|
||||
wchar_t temp[30];
|
||||
if (!pXInputSetState) {
|
||||
// Also used as flag to indicute XInput not installed, so
|
||||
// don't repeatedly try to load it.
|
||||
if (pXInputEnable) return;
|
||||
if (pXInputEnable)
|
||||
return;
|
||||
|
||||
// Prefer XInput 1.3 since SCP only has an XInput 1.3 wrapper right now.
|
||||
// Also use LoadLibrary and not LoadLibraryEx for XInput 1.3, since some
|
||||
|
@ -284,4 +300,3 @@ void EnumXInputDevices() {
|
|||
}
|
||||
pXInputEnable(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,20 +97,23 @@
|
|||
|
||||
|
||||
/* All standard descriptors have these 2 fields in common */
|
||||
struct usb_descriptor_header {
|
||||
struct usb_descriptor_header
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
};
|
||||
|
||||
/* String descriptor */
|
||||
struct usb_string_descriptor {
|
||||
struct usb_string_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short wData[1];
|
||||
};
|
||||
|
||||
/* HID descriptor */
|
||||
struct usb_hid_descriptor {
|
||||
struct usb_hid_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short bcdHID;
|
||||
|
@ -120,7 +123,8 @@ struct usb_hid_descriptor {
|
|||
|
||||
/* Endpoint descriptor */
|
||||
#define USB_MAXENDPOINTS 32
|
||||
struct usb_endpoint_descriptor {
|
||||
struct usb_endpoint_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bEndpointAddress;
|
||||
|
@ -145,7 +149,8 @@ struct usb_endpoint_descriptor {
|
|||
|
||||
/* Interface descriptor */
|
||||
#define USB_MAXINTERFACES 32
|
||||
struct usb_interface_descriptor {
|
||||
struct usb_interface_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bInterfaceNumber;
|
||||
|
@ -164,7 +169,8 @@ struct usb_interface_descriptor {
|
|||
|
||||
#define USB_MAXALTSETTING 128 /* Hard limit */
|
||||
|
||||
struct usb_interface {
|
||||
struct usb_interface
|
||||
{
|
||||
struct usb_interface_descriptor *altsetting;
|
||||
|
||||
int num_altsetting;
|
||||
|
@ -172,7 +178,8 @@ struct usb_interface {
|
|||
|
||||
/* Configuration descriptor information.. */
|
||||
#define USB_MAXCONFIG 8
|
||||
struct usb_config_descriptor {
|
||||
struct usb_config_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short wTotalLength;
|
||||
|
@ -189,7 +196,8 @@ struct usb_config_descriptor {
|
|||
};
|
||||
|
||||
/* Device descriptor */
|
||||
struct usb_device_descriptor {
|
||||
struct usb_device_descriptor
|
||||
{
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned short bcdUSB;
|
||||
|
@ -206,7 +214,8 @@ struct usb_device_descriptor {
|
|||
unsigned char bNumConfigurations;
|
||||
};
|
||||
|
||||
struct usb_ctrl_setup {
|
||||
struct usb_ctrl_setup
|
||||
{
|
||||
unsigned char bRequestType;
|
||||
unsigned char bRequest;
|
||||
unsigned short wValue;
|
||||
|
@ -261,7 +270,8 @@ struct usb_ctrl_setup {
|
|||
/* struct usb_device; */
|
||||
/* struct usb_bus; */
|
||||
|
||||
struct usb_device {
|
||||
struct usb_device
|
||||
{
|
||||
struct usb_device *next, *prev;
|
||||
|
||||
char filename[LIBUSB_PATH_MAX];
|
||||
|
@ -279,7 +289,8 @@ struct usb_device {
|
|||
struct usb_device **children;
|
||||
};
|
||||
|
||||
struct usb_bus {
|
||||
struct usb_bus
|
||||
{
|
||||
struct usb_bus *next, *prev;
|
||||
|
||||
char dirname[LIBUSB_PATH_MAX];
|
||||
|
@ -291,14 +302,17 @@ struct usb_bus {
|
|||
};
|
||||
|
||||
/* Version information, Windows specific */
|
||||
struct usb_version {
|
||||
struct {
|
||||
struct usb_version
|
||||
{
|
||||
struct
|
||||
{
|
||||
int major;
|
||||
int minor;
|
||||
int micro;
|
||||
int nano;
|
||||
} dll;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
int major;
|
||||
int minor;
|
||||
int micro;
|
||||
|
@ -418,4 +432,3 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#endif /* __USB_H__ */
|
||||
|
||||
|
|
|
@ -53,5 +53,3 @@ void GamePad::UpdateGamePadState()
|
|||
SDL_JoystickUpdate(); // No need to make yet another function call for that
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,8 +13,15 @@
|
|||
class GamePad
|
||||
{
|
||||
public:
|
||||
GamePad() : devname(""), _id(-1), numbuttons(0), numaxes(0), numhats(0),
|
||||
deadzone(1500), pad(-1) {
|
||||
GamePad()
|
||||
: devname("")
|
||||
, _id(-1)
|
||||
, numbuttons(0)
|
||||
, numaxes(0)
|
||||
, numhats(0)
|
||||
, deadzone(1500)
|
||||
, pad(-1)
|
||||
{
|
||||
vbuttonstate.clear();
|
||||
vaxisstate.clear();
|
||||
vhatstate.clear();
|
||||
|
|
|
@ -102,28 +102,35 @@ void KeyStatus::analog_set(u32 pad, u32 index, u8 value)
|
|||
else
|
||||
m_internal_analog_ref = &m_internal_analog_joy[pad];
|
||||
|
||||
switch (index)
|
||||
{
|
||||
switch (index) {
|
||||
case PAD_R_LEFT:
|
||||
case PAD_R_RIGHT: m_internal_analog_ref->rx = value; break;
|
||||
case PAD_R_RIGHT:
|
||||
m_internal_analog_ref->rx = value;
|
||||
break;
|
||||
|
||||
case PAD_R_DOWN:
|
||||
case PAD_R_UP: m_internal_analog_ref->ry = value; break;
|
||||
case PAD_R_UP:
|
||||
m_internal_analog_ref->ry = value;
|
||||
break;
|
||||
|
||||
case PAD_L_LEFT:
|
||||
case PAD_L_RIGHT: m_internal_analog_ref->lx = value; break;
|
||||
case PAD_L_RIGHT:
|
||||
m_internal_analog_ref->lx = value;
|
||||
break;
|
||||
|
||||
case PAD_L_DOWN:
|
||||
case PAD_L_UP: m_internal_analog_ref->ly = value; break;
|
||||
case PAD_L_UP:
|
||||
m_internal_analog_ref->ly = value;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool KeyStatus::analog_is_reversed(u32 pad, u32 index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
switch (index) {
|
||||
case PAD_L_RIGHT:
|
||||
case PAD_L_LEFT:
|
||||
return (conf->pad_options[pad].reverse_lx);
|
||||
|
@ -140,27 +147,32 @@ bool KeyStatus::analog_is_reversed(u32 pad, u32 index)
|
|||
case PAD_R_UP:
|
||||
return (conf->pad_options[pad].reverse_ry);
|
||||
|
||||
default: return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
u8 KeyStatus::get(u32 pad, u32 index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
switch (index) {
|
||||
case PAD_R_LEFT:
|
||||
case PAD_R_RIGHT: return m_analog[pad].rx;
|
||||
case PAD_R_RIGHT:
|
||||
return m_analog[pad].rx;
|
||||
|
||||
case PAD_R_DOWN:
|
||||
case PAD_R_UP: return m_analog[pad].ry;
|
||||
case PAD_R_UP:
|
||||
return m_analog[pad].ry;
|
||||
|
||||
case PAD_L_LEFT:
|
||||
case PAD_L_RIGHT: return m_analog[pad].lx;
|
||||
case PAD_L_RIGHT:
|
||||
return m_analog[pad].lx;
|
||||
|
||||
case PAD_L_DOWN:
|
||||
case PAD_L_UP: return m_analog[pad].ly;
|
||||
case PAD_L_UP:
|
||||
return m_analog[pad].ly;
|
||||
|
||||
default: return m_button_pressure[pad][index];
|
||||
default:
|
||||
return m_button_pressure[pad][index];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,11 @@ class KeyStatus
|
|||
u8 analog_merge(u8 kbd, u8 joy);
|
||||
|
||||
public:
|
||||
KeyStatus() : m_analog_released_val(0x7F) { Init(); }
|
||||
KeyStatus()
|
||||
: m_analog_released_val(0x7F)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init();
|
||||
|
||||
void keyboard_state_acces(u32 pad) { m_state_acces[pad] = true; }
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "GamepadConfiguration.h"
|
||||
|
||||
// Construtor of GamepadConfiguration
|
||||
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxDialog(
|
||||
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent)
|
||||
: wxDialog(
|
||||
parent, // Parent
|
||||
wxID_ANY, // ID
|
||||
_T("Gamepad configuration"), // Title
|
||||
|
@ -30,8 +31,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxDialog
|
|||
wxSYSTEM_MENU |
|
||||
wxCAPTION |
|
||||
wxCLOSE_BOX |
|
||||
wxCLIP_CHILDREN
|
||||
)
|
||||
wxCLIP_CHILDREN)
|
||||
{
|
||||
|
||||
m_pad_id = pad;
|
||||
|
@ -137,23 +137,19 @@ void GamepadConfiguration::InitGamepadConfiguration()
|
|||
* if the pad id is 1, you need at least 2 gamepad connected,
|
||||
* Prevent to use a none initialized value on s_vgamePad (core dump)
|
||||
*/
|
||||
if(s_vgamePad.size() >= m_pad_id+1)
|
||||
{
|
||||
if (s_vgamePad.size() >= m_pad_id + 1) {
|
||||
/*
|
||||
* Determine if the device can use rumble
|
||||
* Use TestForce with a very low strength (can't be felt)
|
||||
* May be better to create a new function in order to check only that
|
||||
*/
|
||||
|
||||
if(!s_vgamePad[m_pad_id]->TestForce(0.001f))
|
||||
{
|
||||
if (!s_vgamePad[m_pad_id]->TestForce(0.001f)) {
|
||||
wxMessageBox(L"Rumble is not available for your device.");
|
||||
m_cb_rumble->Disable(); // disable the rumble checkbox
|
||||
m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
wxMessageBox(L"No gamepad detected.");
|
||||
m_sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider
|
||||
m_cb_rumble->Disable(); // disable the rumble checkbox
|
||||
|
@ -173,12 +169,9 @@ void GamepadConfiguration::OnButtonClicked(wxCommandEvent &event)
|
|||
// Affichage d'un message à chaque clic sur le bouton
|
||||
wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
|
||||
int bt_id = bt_tmp->GetId(); // get the real ID
|
||||
if(bt_id == m_bt_ok->GetId()) // If the button ID is equals to the Ok button ID
|
||||
{
|
||||
if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID
|
||||
Close(); // Close the window
|
||||
}
|
||||
else if(bt_id == m_bt_cancel->GetId()) // If the button ID is equals to the cancel button ID
|
||||
{
|
||||
} else if (bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID
|
||||
reset(); // reinitialize the value of each parameters
|
||||
Close(); // Close the window
|
||||
}
|
||||
|
@ -193,8 +186,7 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
|
|||
{
|
||||
wxSlider *sl_tmp = (wxSlider *)event.GetEventObject(); // get the slider object
|
||||
int sl_id = sl_tmp->GetId(); // slider id
|
||||
if(sl_id == m_sl_rumble_intensity->GetId()) // if this is the rumble intensity slider
|
||||
{
|
||||
if (sl_id == m_sl_rumble_intensity->GetId()) { // if this is the rumble intensity slider
|
||||
u32 intensity = m_sl_rumble_intensity->GetValue(); // get the new value
|
||||
conf->set_ff_intensity(intensity); // and set the force feedback intensity value with it
|
||||
// get the rumble intensity
|
||||
|
@ -211,9 +203,7 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
|
|||
* 1 : maximum value of the intensity for the sdl rumble test
|
||||
*/
|
||||
s_vgamePad[m_pad_id]->TestForce(strength / 0x7FFF);
|
||||
}
|
||||
else if(sl_id == m_sl_joystick_sensibility->GetId())
|
||||
{
|
||||
} else if (sl_id == m_sl_joystick_sensibility->GetId()) {
|
||||
u32 sensibility = m_sl_joystick_sensibility->GetValue(); // get the new value
|
||||
conf->set_sensibility(sensibility); // and set the joystick sensibility
|
||||
}
|
||||
|
@ -226,25 +216,17 @@ void GamepadConfiguration::OnCheckboxChange(wxCommandEvent& event)
|
|||
{
|
||||
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
|
||||
int cb_id = cb_tmp->GetId();
|
||||
if(cb_id == m_cb_rumble->GetId())
|
||||
{
|
||||
if (cb_id == m_cb_rumble->GetId()) {
|
||||
conf->pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
|
||||
if(m_cb_rumble->GetValue())
|
||||
{
|
||||
if (m_cb_rumble->GetValue()) {
|
||||
s_vgamePad[m_pad_id]->TestForce();
|
||||
m_sl_rumble_intensity->Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_sl_rumble_intensity->Disable();
|
||||
}
|
||||
}
|
||||
else if(cb_id == m_cb_hack_sixaxis_usb->GetId())
|
||||
{
|
||||
} else if (cb_id == m_cb_hack_sixaxis_usb->GetId()) {
|
||||
conf->pad_options[m_pad_id].sixaxis_usb = (m_cb_hack_sixaxis_usb->GetValue()) ? (u32)1 : (u32)0;
|
||||
}
|
||||
else if(cb_id == m_cb_hack_sixaxis_pressure->GetId())
|
||||
{
|
||||
} else if (cb_id == m_cb_hack_sixaxis_pressure->GetId()) {
|
||||
conf->pad_options[m_pad_id].sixaxis_pressure = (m_cb_hack_sixaxis_pressure->GetValue()) ? (u32)1 : (u32)0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "JoystickConfiguration.h"
|
||||
|
||||
// Construtor of JoystickConfiguration
|
||||
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent) : wxDialog(
|
||||
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent)
|
||||
: wxDialog(
|
||||
parent, // Parent
|
||||
wxID_ANY, // ID
|
||||
_T("Gamepad configuration"), // Title
|
||||
|
@ -30,8 +31,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
|
|||
wxSYSTEM_MENU |
|
||||
wxCAPTION |
|
||||
wxCLOSE_BOX |
|
||||
wxCLIP_CHILDREN
|
||||
)
|
||||
wxCLIP_CHILDREN)
|
||||
{
|
||||
|
||||
m_pad_id = pad;
|
||||
|
@ -43,8 +43,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
|
|||
wxSize(300, 200) // Size
|
||||
);
|
||||
|
||||
if(m_isForLeftJoystick)
|
||||
{
|
||||
if (m_isForLeftJoystick) {
|
||||
m_cb_reverse_Lx = new wxCheckBox(
|
||||
m_pan_joystick_config, // Parent
|
||||
wxID_ANY, // ID
|
||||
|
@ -65,9 +64,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
|
|||
_T("Use mouse for left analog joystick"), // Label
|
||||
wxPoint(20, 60) // Position
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_cb_reverse_Rx = new wxCheckBox(
|
||||
m_pan_joystick_config, // Parent
|
||||
wxID_ANY, // ID
|
||||
|
@ -123,17 +120,13 @@ void JoystickConfiguration::InitJoystickConfiguration()
|
|||
* if the pad id is 1, you need at least 2 gamepad connected,
|
||||
* Prevent to use a none initialized value on s_vgamePad (core dump)
|
||||
*/
|
||||
if(s_vgamePad.size() < m_pad_id+1)
|
||||
{
|
||||
if (s_vgamePad.size() < m_pad_id + 1) {
|
||||
wxMessageBox(L"No gamepad detected.");
|
||||
// disable all checkbox
|
||||
if(m_isForLeftJoystick)
|
||||
{
|
||||
if (m_isForLeftJoystick) {
|
||||
m_cb_reverse_Lx->Disable();
|
||||
m_cb_reverse_Ly->Disable();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_cb_reverse_Rx->Disable();
|
||||
m_cb_reverse_Ry->Disable();
|
||||
}
|
||||
|
@ -152,12 +145,9 @@ void JoystickConfiguration::OnButtonClicked(wxCommandEvent &event)
|
|||
// Affichage d'un message à chaque clic sur le bouton
|
||||
wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
|
||||
int bt_id = bt_tmp->GetId(); // get the real ID
|
||||
if(bt_id == m_bt_ok->GetId()) // If the button ID is equals to the Ok button ID
|
||||
{
|
||||
if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID
|
||||
Close(); // Close the window
|
||||
}
|
||||
else if(bt_id == m_bt_cancel->GetId()) // If the button ID is equals to the cancel button ID
|
||||
{
|
||||
} else if (bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID
|
||||
reset(); // reinitialize the value of each parameters
|
||||
Close(); // Close the window
|
||||
}
|
||||
|
@ -171,38 +161,25 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
|
|||
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
|
||||
int cb_id = cb_tmp->GetId();
|
||||
bool val;
|
||||
if(m_isForLeftJoystick)
|
||||
{
|
||||
if(cb_id == m_cb_reverse_Ly->GetId())
|
||||
{
|
||||
if (m_isForLeftJoystick) {
|
||||
if (cb_id == m_cb_reverse_Ly->GetId()) {
|
||||
val = m_cb_reverse_Ly->GetValue();
|
||||
conf->pad_options[m_pad_id].reverse_ly = val;
|
||||
}
|
||||
else if(cb_id == m_cb_reverse_Lx->GetId())
|
||||
{
|
||||
} else if (cb_id == m_cb_reverse_Lx->GetId()) {
|
||||
val = m_cb_reverse_Lx->GetValue();
|
||||
conf->pad_options[m_pad_id].reverse_lx = val;
|
||||
}
|
||||
else if(cb_id == m_cb_mouse_Ljoy->GetId())
|
||||
{
|
||||
} else if (cb_id == m_cb_mouse_Ljoy->GetId()) {
|
||||
val = m_cb_mouse_Ljoy->GetValue();
|
||||
conf->pad_options[m_pad_id].mouse_l = val;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cb_id == m_cb_reverse_Ry->GetId())
|
||||
{
|
||||
} else {
|
||||
if (cb_id == m_cb_reverse_Ry->GetId()) {
|
||||
val = m_cb_reverse_Ry->GetValue();
|
||||
conf->pad_options[m_pad_id].reverse_ry = val;
|
||||
}
|
||||
else if(cb_id == m_cb_reverse_Rx->GetId())
|
||||
{
|
||||
} else if (cb_id == m_cb_reverse_Rx->GetId()) {
|
||||
val = m_cb_reverse_Rx->GetValue();
|
||||
conf->pad_options[m_pad_id].reverse_rx = val;
|
||||
}
|
||||
else if(cb_id == m_cb_mouse_Rjoy->GetId())
|
||||
{
|
||||
} else if (cb_id == m_cb_mouse_Rjoy->GetId()) {
|
||||
val = m_cb_mouse_Rjoy->GetValue();
|
||||
conf->pad_options[m_pad_id].mouse_r = val;
|
||||
}
|
||||
|
@ -216,14 +193,11 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
|
|||
// Reset checkbox and slider values
|
||||
void JoystickConfiguration::reset()
|
||||
{
|
||||
if(m_isForLeftJoystick)
|
||||
{
|
||||
if (m_isForLeftJoystick) {
|
||||
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
|
||||
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
|
||||
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
|
||||
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
|
||||
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
|
||||
|
@ -234,8 +208,7 @@ void JoystickConfiguration::reset()
|
|||
void JoystickConfiguration::repopulate()
|
||||
{
|
||||
bool val;
|
||||
if(m_isForLeftJoystick)
|
||||
{
|
||||
if (m_isForLeftJoystick) {
|
||||
val = conf->pad_options[m_pad_id].reverse_lx;
|
||||
m_init_reverse_Lx = val;
|
||||
m_cb_reverse_Lx->SetValue(val);
|
||||
|
@ -247,9 +220,7 @@ void JoystickConfiguration::repopulate()
|
|||
val = conf->pad_options[m_pad_id].mouse_l;
|
||||
m_init_mouse_Ljoy = val;
|
||||
m_cb_mouse_Ljoy->SetValue(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
val = conf->pad_options[m_pad_id].reverse_rx;
|
||||
m_init_reverse_Rx = val;
|
||||
m_cb_reverse_Rx->SetValue(val);
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "dialog.h"
|
||||
|
||||
// Construtor of Dialog
|
||||
Dialog::Dialog() : wxDialog( NULL, // Parent
|
||||
Dialog::Dialog()
|
||||
: wxDialog(NULL, // Parent
|
||||
wxID_ANY, // ID
|
||||
_T("OnePad configuration"), // Title
|
||||
wxDefaultPosition, // Position
|
||||
|
@ -29,8 +30,7 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
|
|||
wxSYSTEM_MENU |
|
||||
wxCAPTION |
|
||||
wxCLOSE_BOX |
|
||||
wxCLIP_CHILDREN
|
||||
)
|
||||
wxCLIP_CHILDREN)
|
||||
{
|
||||
|
||||
/*
|
||||
|
@ -236,15 +236,13 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
|
|||
|
||||
// create a new Notebook
|
||||
m_tab_gamepad = new wxNotebook(this, wxID_ANY);
|
||||
for(int i=0; i<GAMEPAD_NUMBER; ++i)
|
||||
{
|
||||
for (int i = 0; i < GAMEPAD_NUMBER; ++i) {
|
||||
// Tabs panels
|
||||
m_pan_tabs[i] = new opPanel(
|
||||
m_tab_gamepad,
|
||||
wxID_ANY,
|
||||
wxDefaultPosition,
|
||||
wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT)
|
||||
);
|
||||
wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT));
|
||||
// Add new page
|
||||
// Define label
|
||||
std::stringstream sstm;
|
||||
|
@ -256,8 +254,7 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
|
|||
wxString(sstm.str().c_str(), wxConvUTF8) // Title
|
||||
);
|
||||
|
||||
for(int j=0; j<BUTTONS_LENGHT; ++j)
|
||||
{
|
||||
for (int j = 0; j < BUTTONS_LENGHT; ++j) {
|
||||
// Gamepad buttons
|
||||
m_bt_gamepad[i][j] = new wxButton(
|
||||
m_pan_tabs[i], // Parent
|
||||
|
@ -286,10 +283,8 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
|
|||
Bind(wxEVT_TIMER, &Dialog::JoystickEvent, this);
|
||||
m_time_update_gui.Start(UPDATE_TIME, wxTIMER_CONTINUOUS);
|
||||
|
||||
for(int i=0; i<GAMEPAD_NUMBER; ++i)
|
||||
{
|
||||
for(int j=0; j<NB_IMG; ++j)
|
||||
{
|
||||
for (int i = 0; i < GAMEPAD_NUMBER; ++i) {
|
||||
for (int j = 0; j < NB_IMG; ++j) {
|
||||
m_pressed[i][j] = false;
|
||||
}
|
||||
}
|
||||
|
@ -312,40 +307,29 @@ void Dialog::OnButtonClicked(wxCommandEvent &event)
|
|||
wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
|
||||
int bt_id = bt_tmp->GetId() - wxID_HIGHEST - 1; // get the real ID
|
||||
int gamepad_id = m_tab_gamepad->GetSelection(); // get the tab ID (equivalent to the gamepad id)
|
||||
if(bt_id >= 0 && bt_id <= PAD_R_LEFT) // if the button ID is a gamepad button
|
||||
{
|
||||
if (bt_id >= 0 && bt_id <= PAD_R_LEFT) { // if the button ID is a gamepad button
|
||||
bt_tmp->Disable(); // switch the button state to "Disable"
|
||||
config_key(gamepad_id, bt_id);
|
||||
bt_tmp->Enable(); // switch the button state to "Enable"
|
||||
}
|
||||
else if(bt_id == Gamepad_config) // If the button ID is equals to the Gamepad_config button ID
|
||||
{
|
||||
} else if (bt_id == Gamepad_config) { // If the button ID is equals to the Gamepad_config button ID
|
||||
GamepadConfiguration gamepad_config(gamepad_id, this);
|
||||
|
||||
gamepad_config.InitGamepadConfiguration();
|
||||
gamepad_config.ShowModal();
|
||||
}
|
||||
else if(bt_id == JoyL_config) // If the button ID is equals to the JoyL_config button ID
|
||||
{
|
||||
} else if (bt_id == JoyL_config) { // If the button ID is equals to the JoyL_config button ID
|
||||
JoystickConfiguration joystick_config(gamepad_id, true, this);
|
||||
|
||||
joystick_config.InitJoystickConfiguration();
|
||||
joystick_config.ShowModal();
|
||||
}
|
||||
else if(bt_id == JoyR_config) // If the button ID is equals to the JoyR_config button ID
|
||||
{
|
||||
} else if (bt_id == JoyR_config) { // If the button ID is equals to the JoyR_config button ID
|
||||
JoystickConfiguration joystick_config(gamepad_id, false, this);
|
||||
|
||||
joystick_config.InitJoystickConfiguration();
|
||||
joystick_config.ShowModal();
|
||||
}
|
||||
else if(bt_id == Set_all) // If the button ID is equals to the Set_all button ID
|
||||
{
|
||||
for(int i=0; i<MAX_KEYS; ++i)
|
||||
{
|
||||
} else if (bt_id == Set_all) { // If the button ID is equals to the Set_all button ID
|
||||
for (int i = 0; i < MAX_KEYS; ++i) {
|
||||
bt_tmp = m_bt_gamepad[gamepad_id][i];
|
||||
switch(i)
|
||||
{
|
||||
switch (i) {
|
||||
case PAD_L_UP: // Left joystick (Up) ↑
|
||||
m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_up);
|
||||
break;
|
||||
|
@ -377,8 +361,7 @@ void Dialog::OnButtonClicked(wxCommandEvent &event)
|
|||
m_pan_tabs[gamepad_id]->Refresh();
|
||||
m_pan_tabs[gamepad_id]->Update();
|
||||
config_key(gamepad_id, i);
|
||||
switch(i)
|
||||
{
|
||||
switch (i) {
|
||||
case PAD_L_UP: // Left joystick (Up) ↑
|
||||
m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_up);
|
||||
break;
|
||||
|
@ -411,18 +394,12 @@ void Dialog::OnButtonClicked(wxCommandEvent &event)
|
|||
m_pan_tabs[gamepad_id]->Update();
|
||||
usleep(500000); // give enough time to the user to release the button
|
||||
}
|
||||
}
|
||||
else if(bt_id == Ok) // If the button ID is equals to the Ok button ID
|
||||
{
|
||||
} else if (bt_id == Ok) { // If the button ID is equals to the Ok button ID
|
||||
SaveConfig(); // Save the configuration
|
||||
Close(); // Close the window
|
||||
}
|
||||
else if(bt_id == Apply) // If the button ID is equals to the Apply button ID
|
||||
{
|
||||
} else if (bt_id == Apply) { // If the button ID is equals to the Apply button ID
|
||||
SaveConfig(); // Save the configuration
|
||||
}
|
||||
else if(bt_id == Cancel) // If the button ID is equals to the cancel button ID
|
||||
{
|
||||
} else if (bt_id == Cancel) { // If the button ID is equals to the cancel button ID
|
||||
Close(); // Close the window
|
||||
}
|
||||
}
|
||||
|
@ -436,44 +413,32 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
|
|||
std::map<u32, int>::iterator it2;
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
SDL_Event events;
|
||||
while(SDL_PollEvent(&events))
|
||||
{
|
||||
switch(events.type)
|
||||
{
|
||||
while (SDL_PollEvent(&events)) {
|
||||
switch (events.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
if(events.jaxis.which < GAMEPAD_NUMBER)
|
||||
{
|
||||
if (events.jaxis.which < GAMEPAD_NUMBER) {
|
||||
key = axis_to_key(false, (events.jaxis.value < 0), events.jaxis.axis);
|
||||
it = m_map_images[events.jaxis.which].find(key);
|
||||
if(it != m_map_images[events.jaxis.which].end())
|
||||
{
|
||||
if (it != m_map_images[events.jaxis.which].end()) {
|
||||
map = m_map_images[events.jaxis.which][key];
|
||||
if(events.jaxis.value == 0)
|
||||
{
|
||||
if (events.jaxis.value == 0) {
|
||||
if (map >= PAD_L_UP && map <= PAD_L_LEFT)
|
||||
m_pan_tabs[events.jaxis.which]->HideImg(img_left_cursor);
|
||||
else if (map >= PAD_R_UP && map <= PAD_R_LEFT)
|
||||
m_pan_tabs[events.jaxis.which]->HideImg(img_right_cursor);
|
||||
else if (map < PAD_L_UP)
|
||||
m_pan_tabs[events.jaxis.which]->HideImg(map);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(map >= PAD_L_UP && map <= PAD_L_LEFT)
|
||||
{
|
||||
} else {
|
||||
if (map >= PAD_L_UP && map <= PAD_L_LEFT) {
|
||||
m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value);
|
||||
m_pan_tabs[events.jaxis.which]->ShowImg(img_left_cursor);
|
||||
}
|
||||
else if(map >= PAD_R_UP && map <= PAD_R_LEFT)
|
||||
{
|
||||
} else if (map >= PAD_R_UP && map <= PAD_R_LEFT) {
|
||||
m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value);
|
||||
m_pan_tabs[events.jaxis.which]->ShowImg(img_right_cursor);
|
||||
}
|
||||
else if(map < PAD_L_UP) // if this is not a joystick
|
||||
{
|
||||
} else if (map < PAD_L_UP) { // if this is not a joystick
|
||||
m_pan_tabs[events.jaxis.which]->ShowImg(map);
|
||||
}
|
||||
}
|
||||
|
@ -482,11 +447,9 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
|
|||
// Hack Dualshock 4 (L2, R2)
|
||||
key = axis_to_key(false, (events.jaxis.value > 0), events.jaxis.axis);
|
||||
it2 = m_map_images[events.jaxis.which].find(key);
|
||||
if(it2 != m_map_images[events.jaxis.which].end())
|
||||
{
|
||||
if (it2 != m_map_images[events.jaxis.which].end()) {
|
||||
map = m_map_images[events.jaxis.which][key];
|
||||
if(map < PAD_L_UP) // if this is not a joystick
|
||||
{
|
||||
if (map < PAD_L_UP) { // if this is not a joystick
|
||||
m_pan_tabs[events.jaxis.which]->HideImg(map);
|
||||
}
|
||||
break;
|
||||
|
@ -494,63 +457,53 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
|
|||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
if(events.jbutton.which < GAMEPAD_NUMBER)
|
||||
{
|
||||
if (events.jbutton.which < GAMEPAD_NUMBER) {
|
||||
key = button_to_key(events.jbutton.button);
|
||||
it = m_map_images[events.jbutton.which].find(key);
|
||||
if(it != m_map_images[events.jbutton.which].end())
|
||||
{
|
||||
if (it != m_map_images[events.jbutton.which].end()) {
|
||||
map = m_map_images[events.jbutton.which][key];
|
||||
m_pan_tabs[events.jbutton.which]->ShowImg(map);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
if(events.jbutton.which < GAMEPAD_NUMBER)
|
||||
{
|
||||
if (events.jbutton.which < GAMEPAD_NUMBER) {
|
||||
key = button_to_key(events.jbutton.button);
|
||||
it = m_map_images[events.jbutton.which].find(key);
|
||||
if(it != m_map_images[events.jbutton.which].end())
|
||||
{
|
||||
if (it != m_map_images[events.jbutton.which].end()) {
|
||||
map = m_map_images[events.jbutton.which][key];
|
||||
m_pan_tabs[events.jbutton.which]->HideImg(map);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
if(events.jhat.which < GAMEPAD_NUMBER)
|
||||
{
|
||||
switch(events.jhat.value)
|
||||
{
|
||||
if (events.jhat.which < GAMEPAD_NUMBER) {
|
||||
switch (events.jhat.value) {
|
||||
case SDL_HAT_UP:
|
||||
key = hat_to_key(events.jhat.value, events.jhat.hat);
|
||||
it = m_map_images[events.jhat.which].find(key);
|
||||
if(it != m_map_images[events.jhat.which].end())
|
||||
{
|
||||
if (it != m_map_images[events.jhat.which].end()) {
|
||||
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_up);
|
||||
}
|
||||
break;
|
||||
case SDL_HAT_DOWN:
|
||||
key = hat_to_key(events.jhat.value, events.jhat.hat);
|
||||
it = m_map_images[events.jhat.which].find(key);
|
||||
if(it != m_map_images[events.jhat.which].end())
|
||||
{
|
||||
if (it != m_map_images[events.jhat.which].end()) {
|
||||
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_bottom);
|
||||
}
|
||||
break;
|
||||
case SDL_HAT_RIGHT:
|
||||
key = hat_to_key(events.jhat.value, events.jhat.hat);
|
||||
it = m_map_images[events.jhat.which].find(key);
|
||||
if(it != m_map_images[events.jhat.which].end())
|
||||
{
|
||||
if (it != m_map_images[events.jhat.which].end()) {
|
||||
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_right);
|
||||
}
|
||||
break;
|
||||
case SDL_HAT_LEFT:
|
||||
key = hat_to_key(events.jhat.value, events.jhat.hat);
|
||||
it = m_map_images[events.jhat.which].find(key);
|
||||
if(it != m_map_images[events.jhat.which].end())
|
||||
{
|
||||
if (it != m_map_images[events.jhat.which].end()) {
|
||||
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_left);
|
||||
}
|
||||
break;
|
||||
|
@ -580,45 +533,34 @@ void Dialog::config_key(int pad, int key)
|
|||
|
||||
// I don't have any guarantee that not-yet-pressed state is egual to released state
|
||||
GamePad::UpdateReleaseState();
|
||||
while (!captured)
|
||||
{
|
||||
while (!captured) {
|
||||
vector<GamePad *>::iterator itjoy;
|
||||
if (PollX11KeyboardMouseEvent(key_pressed))
|
||||
{
|
||||
if (PollX11KeyboardMouseEvent(key_pressed)) {
|
||||
// special case for keyboard/mouse to handle multiple keys
|
||||
// Note: key_pressed == 0 when ESC is hit to abort the capture
|
||||
if (key_pressed > 0)
|
||||
{
|
||||
if (key_pressed > 0) {
|
||||
clear_key(pad, key);
|
||||
set_keyboad_key(pad, key_pressed, key);
|
||||
m_simulatedKeys[pad][key] = key_pressed;
|
||||
m_map_images[pad][key_pressed] = key;
|
||||
}
|
||||
captured = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
GamePad::UpdateGamePadState();
|
||||
|
||||
itjoy = s_vgamePad.begin();
|
||||
while ((itjoy != s_vgamePad.end()) && (!captured))
|
||||
{
|
||||
if ((*itjoy)->PollButtons(key_pressed))
|
||||
{
|
||||
while ((itjoy != s_vgamePad.end()) && (!captured)) {
|
||||
if ((*itjoy)->PollButtons(key_pressed)) {
|
||||
clear_key(pad, key);
|
||||
set_key(pad, key, key_pressed);
|
||||
m_map_images[pad][key_pressed] = key;
|
||||
captured = true;
|
||||
}
|
||||
else if((*itjoy)->PollAxes(key_pressed))
|
||||
{
|
||||
} else if ((*itjoy)->PollAxes(key_pressed)) {
|
||||
clear_key(pad, key);
|
||||
set_key(pad, key, key_pressed);
|
||||
m_map_images[pad][key_pressed] = key;
|
||||
captured = true;
|
||||
}
|
||||
else if((*itjoy)->PollHats(key_pressed))
|
||||
{
|
||||
} else if ((*itjoy)->PollHats(key_pressed)) {
|
||||
clear_key(pad, key);
|
||||
set_key(pad, key, key_pressed);
|
||||
m_map_images[pad][key_pressed] = key;
|
||||
|
@ -629,8 +571,7 @@ void Dialog::config_key(int pad, int key)
|
|||
}
|
||||
}
|
||||
m_bt_gamepad[pad][key]->SetLabel(
|
||||
KeyName(pad, key, m_simulatedKeys[pad][key]).c_str()
|
||||
);
|
||||
KeyName(pad, key, m_simulatedKeys[pad][key]).c_str());
|
||||
}
|
||||
|
||||
void Dialog::clear_key(int pad, int key)
|
||||
|
@ -649,8 +590,7 @@ void Dialog::clear_key(int pad, int key)
|
|||
int val = get_key(pad, key);
|
||||
std::map<u32, int>::iterator it2;
|
||||
it2 = m_map_images[pad].find(val);
|
||||
if(it2 != m_map_images[pad].end())
|
||||
{
|
||||
if (it2 != m_map_images[pad].end()) {
|
||||
m_map_images[pad].erase(it2);
|
||||
}
|
||||
|
||||
|
@ -664,15 +604,11 @@ void Dialog::clear_key(int pad, int key)
|
|||
// Set button values
|
||||
void Dialog::repopulate()
|
||||
{
|
||||
for(int gamepad_id=0; gamepad_id<GAMEPAD_NUMBER; ++gamepad_id)
|
||||
{
|
||||
for (int key = 0; key < MAX_KEYS; key++)
|
||||
{
|
||||
if (get_key(gamepad_id, key) != 0)
|
||||
{
|
||||
for (int gamepad_id = 0; gamepad_id < GAMEPAD_NUMBER; ++gamepad_id) {
|
||||
for (int key = 0; key < MAX_KEYS; key++) {
|
||||
if (get_key(gamepad_id, key) != 0) {
|
||||
m_bt_gamepad[gamepad_id][key]->SetLabel(
|
||||
KeyName(gamepad_id, key).c_str()
|
||||
);
|
||||
KeyName(gamepad_id, key).c_str());
|
||||
|
||||
m_map_images[gamepad_id][get_key(gamepad_id, key)] = key;
|
||||
}
|
||||
|
@ -681,14 +617,12 @@ void Dialog::repopulate()
|
|||
// keyboard/mouse key
|
||||
map<u32, u32>::iterator it;
|
||||
for (it = conf->keysym_map[gamepad_id].begin();
|
||||
it != conf->keysym_map[gamepad_id].end(); ++it)
|
||||
{
|
||||
it != conf->keysym_map[gamepad_id].end(); ++it) {
|
||||
int keysym = it->first;
|
||||
int key = it->second;
|
||||
|
||||
m_bt_gamepad[gamepad_id][key]->SetLabel(
|
||||
KeyName(gamepad_id, key, keysym).c_str()
|
||||
);
|
||||
KeyName(gamepad_id, key, keysym).c_str());
|
||||
|
||||
m_simulatedKeys[gamepad_id][key] = keysym;
|
||||
m_map_images[gamepad_id][keysym] = key;
|
||||
|
|
|
@ -37,41 +37,43 @@ string KeyName(int pad, int key, int keysym)
|
|||
if (keysym < 10) {
|
||||
// mouse
|
||||
switch (keysym) {
|
||||
case 1: sprintf(&tmp[0], "Mouse Left"); break;
|
||||
case 2: sprintf(&tmp[0], "Mouse Middle"); break;
|
||||
case 3: sprintf(&tmp[0], "Mouse Right"); break;
|
||||
case 1:
|
||||
sprintf(&tmp[0], "Mouse Left");
|
||||
break;
|
||||
case 2:
|
||||
sprintf(&tmp[0], "Mouse Middle");
|
||||
break;
|
||||
case 3:
|
||||
sprintf(&tmp[0], "Mouse Right");
|
||||
break;
|
||||
default: // Use only number for extra button
|
||||
sprintf(&tmp[0], "Mouse %d", keysym);
|
||||
}
|
||||
} else {
|
||||
// keyboard
|
||||
char *pstr = XKeysymToString(keysym);
|
||||
if (pstr != NULL) tmp = pstr;
|
||||
if (pstr != NULL)
|
||||
tmp = pstr;
|
||||
}
|
||||
} else {
|
||||
// joystick
|
||||
KeyType k = type_of_joykey(pad, key);
|
||||
switch (k)
|
||||
{
|
||||
case PAD_JOYBUTTONS:
|
||||
{
|
||||
switch (k) {
|
||||
case PAD_JOYBUTTONS: {
|
||||
int button = key_to_button(pad, key);
|
||||
sprintf(&tmp[0], "JBut %d", button);
|
||||
break;
|
||||
}
|
||||
case PAD_AXIS:
|
||||
{
|
||||
case PAD_AXIS: {
|
||||
if (key_to_axis_type(pad, key))
|
||||
sprintf(&tmp[0], "JAxis %d Full", key_to_axis(pad, key));
|
||||
else
|
||||
sprintf(&tmp[0], "JAxis %d Half%s", key_to_axis(pad, key), key_to_axis_sign(pad, key) ? "-" : "+");
|
||||
break;
|
||||
}
|
||||
case PAD_HAT:
|
||||
{
|
||||
case PAD_HAT: {
|
||||
int axis = key_to_axis(pad, key);
|
||||
switch(key_to_hat_dir(pad, key))
|
||||
{
|
||||
switch (key_to_hat_dir(pad, key)) {
|
||||
case HAT_UP:
|
||||
sprintf(&tmp[0], "JPOVU-%d", axis);
|
||||
break;
|
||||
|
@ -90,7 +92,8 @@ string KeyName(int pad, int key, int keysym)
|
|||
}
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,8 +124,7 @@ void SaveConfig()
|
|||
|
||||
const std::string iniFile(s_strIniPath + "OnePAD.ini");
|
||||
f = fopen(iniFile.c_str(), "w");
|
||||
if (f == NULL)
|
||||
{
|
||||
if (f == NULL) {
|
||||
printf("OnePAD: failed to save ini %s\n", iniFile.c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -133,10 +135,8 @@ void SaveConfig()
|
|||
fprintf(f, "joy_pad_map = %d\n", conf->joyid_map);
|
||||
fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity());
|
||||
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
|
||||
{
|
||||
for (int key = 0; key < MAX_KEYS; key++)
|
||||
{
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
|
||||
for (int key = 0; key < MAX_KEYS; key++) {
|
||||
fprintf(f, "[%d][%d] = 0x%x\n", pad, key, get_key(pad, key));
|
||||
}
|
||||
}
|
||||
|
@ -162,35 +162,39 @@ void LoadConfig()
|
|||
|
||||
const std::string iniFile(s_strIniPath + "OnePAD.ini");
|
||||
f = fopen(iniFile.c_str(), "r");
|
||||
if (f == NULL)
|
||||
{
|
||||
if (f == NULL) {
|
||||
printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
|
||||
SaveConfig(); //save and return
|
||||
return;
|
||||
}
|
||||
|
||||
u32 value;
|
||||
if (fscanf(f, "log = %u\n", &value) == 0) goto error;
|
||||
if (fscanf(f, "log = %u\n", &value) == 0)
|
||||
goto error;
|
||||
conf->log = value;
|
||||
if (fscanf(f, "options = %u\n", &value) == 0) goto error;
|
||||
if (fscanf(f, "options = %u\n", &value) == 0)
|
||||
goto error;
|
||||
conf->packed_options = value;
|
||||
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0) goto error;
|
||||
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0)
|
||||
goto error;
|
||||
conf->set_sensibility(value);
|
||||
if (fscanf(f, "joy_pad_map = %u\n", &value) == 0) goto error;
|
||||
if (fscanf(f, "joy_pad_map = %u\n", &value) == 0)
|
||||
goto error;
|
||||
conf->joyid_map = value;
|
||||
if (fscanf(f, "ff_intensity = %u\n", &value) == 0) goto error;
|
||||
if (fscanf(f, "ff_intensity = %u\n", &value) == 0)
|
||||
goto error;
|
||||
conf->set_ff_intensity(value);
|
||||
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
|
||||
{
|
||||
for (int key = 0; key < MAX_KEYS; key++)
|
||||
{
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
|
||||
for (int key = 0; key < MAX_KEYS; key++) {
|
||||
sprintf(str, "[%d][%d] = 0x%%x\n", pad, key);
|
||||
u32 temp = 0;
|
||||
|
||||
if (fscanf(f, str, &temp) == 0) temp = 0;
|
||||
if (fscanf(f, str, &temp) == 0)
|
||||
temp = 0;
|
||||
set_key(pad, key, temp);
|
||||
if (temp && pad == 0) have_user_setting = true;
|
||||
if (temp && pad == 0)
|
||||
have_user_setting = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,12 +203,13 @@ void LoadConfig()
|
|||
u32 index;
|
||||
while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) != EOF) {
|
||||
set_keyboad_key(pad & 1, keysym, index);
|
||||
if(pad == 0) have_user_setting = true;
|
||||
if (pad == 0)
|
||||
have_user_setting = true;
|
||||
}
|
||||
|
||||
if (!have_user_setting) DefaultKeyboardValues();
|
||||
if (!have_user_setting)
|
||||
DefaultKeyboardValues();
|
||||
|
||||
error:
|
||||
fclose(f);
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ void SysMessage(const char *fmt, ...)
|
|||
vsprintf(msg, fmt, list);
|
||||
va_end(list);
|
||||
|
||||
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
|
||||
if (msg[strlen(msg) - 1] == '\n')
|
||||
msg[strlen(msg) - 1] = 0;
|
||||
|
||||
GtkWidget *dialog;
|
||||
dialog = gtk_message_dialog_new(NULL,
|
||||
|
@ -52,12 +53,14 @@ void SysMessage(const char *fmt, ...)
|
|||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
|
||||
EXPORT_C_(void) PADabout()
|
||||
EXPORT_C_(void)
|
||||
PADabout()
|
||||
{
|
||||
SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42.");
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) PADtest()
|
||||
EXPORT_C_(s32)
|
||||
PADtest()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -78,8 +81,7 @@ void _PADclose()
|
|||
vector<GamePad *>::iterator it = s_vgamePad.begin();
|
||||
|
||||
// Delete everything in the vector vjoysticks.
|
||||
while (it != s_vgamePad.end())
|
||||
{
|
||||
while (it != s_vgamePad.end()) {
|
||||
delete *it;
|
||||
++it;
|
||||
}
|
||||
|
@ -90,17 +92,15 @@ void _PADclose()
|
|||
void PollForJoystickInput(int cpad)
|
||||
{
|
||||
int joyid = conf->get_joyid(cpad);
|
||||
if (!GamePadIdWithinBounds(joyid)) return;
|
||||
if (!GamePadIdWithinBounds(joyid))
|
||||
return;
|
||||
|
||||
GamePad::UpdateGamePadState();
|
||||
for (int i = 0; i < MAX_KEYS; i++)
|
||||
{
|
||||
for (int i = 0; i < MAX_KEYS; i++) {
|
||||
GamePad *gamePad = s_vgamePad[joyid];
|
||||
|
||||
switch (type_of_joykey(cpad, i))
|
||||
{
|
||||
case PAD_JOYBUTTONS:
|
||||
{
|
||||
switch (type_of_joykey(cpad, i)) {
|
||||
case PAD_JOYBUTTONS: {
|
||||
|
||||
int value = gamePad->GetButton(key_to_button(cpad, i));
|
||||
if (value)
|
||||
|
@ -110,8 +110,7 @@ void PollForJoystickInput(int cpad)
|
|||
|
||||
break;
|
||||
}
|
||||
case PAD_HAT:
|
||||
{
|
||||
case PAD_HAT: {
|
||||
int value = gamePad->GetHat(key_to_axis(cpad, i));
|
||||
|
||||
// key_to_hat_dir and SDL_JoystickGetHat are a 4 bits bitmap, one for each directions. Only 1 bit can be high for
|
||||
|
@ -124,8 +123,7 @@ void PollForJoystickInput(int cpad)
|
|||
|
||||
break;
|
||||
}
|
||||
case PAD_AXIS:
|
||||
{
|
||||
case PAD_AXIS: {
|
||||
int value = gamePad->GetAxisFromKey(cpad, i);
|
||||
bool sign = key_to_axis_sign(cpad, i);
|
||||
bool full_axis = key_to_axis_type(cpad, i);
|
||||
|
@ -154,12 +152,14 @@ void PollForJoystickInput(int cpad)
|
|||
}
|
||||
}
|
||||
}
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORT_C_(void) PADupdate(int pad)
|
||||
EXPORT_C_(void)
|
||||
PADupdate(int pad)
|
||||
{
|
||||
// Gamepad inputs don't count as an activity. Therefore screensaver will
|
||||
// be fired after a couple of minute.
|
||||
|
@ -193,7 +193,8 @@ EXPORT_C_(void) PADupdate(int pad)
|
|||
Pad::rumble_all();
|
||||
}
|
||||
|
||||
EXPORT_C_(void) PADconfigure()
|
||||
EXPORT_C_(void)
|
||||
PADconfigure()
|
||||
{
|
||||
LoadConfig();
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
opPanel::opPanel(wxWindow *parent,
|
||||
wxWindowID id = wxID_ANY,
|
||||
const wxPoint &pos = wxDefaultPosition,
|
||||
const wxSize &size=wxDefaultSize
|
||||
): wxPanel( parent, id, pos, size)
|
||||
const wxSize &size = wxDefaultSize)
|
||||
: wxPanel(parent, id, pos, size)
|
||||
{
|
||||
m_picture[img_background] = EmbeddedImage<res_dualshock2>().Get();
|
||||
|
||||
|
@ -85,8 +85,7 @@ opPanel::opPanel(wxWindow *parent,
|
|||
m_picture[img_r_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get();
|
||||
m_picture[img_r_arrow_left] = EmbeddedImage<res_arrow_left>().Get();
|
||||
|
||||
for(int i=0; i<NB_IMG; ++i)
|
||||
{
|
||||
for (int i = 0; i < NB_IMG; ++i) {
|
||||
m_show_image[i] = false;
|
||||
HideImg(i);
|
||||
}
|
||||
|
@ -101,8 +100,7 @@ opPanel::opPanel(wxWindow *parent,
|
|||
|
||||
void opPanel::HideImg(int id)
|
||||
{
|
||||
if(id < NB_IMG)
|
||||
{
|
||||
if (id < NB_IMG) {
|
||||
m_show_image[id] = false;
|
||||
Refresh();
|
||||
}
|
||||
|
@ -110,8 +108,7 @@ void opPanel::HideImg(int id)
|
|||
|
||||
void opPanel::ShowImg(int id)
|
||||
{
|
||||
if(id < NB_IMG)
|
||||
{
|
||||
if (id < NB_IMG) {
|
||||
m_show_image[id] = true;
|
||||
Refresh();
|
||||
}
|
||||
|
@ -119,20 +116,13 @@ void opPanel::ShowImg(int id)
|
|||
|
||||
void opPanel::MoveJoystick(int axe, int value)
|
||||
{
|
||||
if(axe == 0)
|
||||
{
|
||||
if (axe == 0) {
|
||||
m_left_cursor_x = value * 30 / 40000;
|
||||
}
|
||||
else if(axe == 1)
|
||||
{
|
||||
} else if (axe == 1) {
|
||||
m_left_cursor_y = value * 30 / 40000;
|
||||
}
|
||||
else if( axe == 2)
|
||||
{
|
||||
} else if (axe == 2) {
|
||||
m_right_cursor_x = value * 30 / 40000;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_right_cursor_y = value * 30 / 40000;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ void JoystickInfo::UpdateReleaseState()
|
|||
SDL_JoystickUpdate();
|
||||
|
||||
// Save everything in the vector s_vjoysticks.
|
||||
while (itjoy != s_vgamePad.end())
|
||||
{
|
||||
while (itjoy != s_vgamePad.end()) {
|
||||
(*itjoy)->SaveState();
|
||||
++itjoy;
|
||||
}
|
||||
|
@ -46,19 +45,20 @@ void JoystickInfo::UpdateReleaseState()
|
|||
void JoystickInfo::EnumerateJoysticks(vector<GamePad *> &vjoysticks)
|
||||
{
|
||||
|
||||
if (!s_bSDLInit)
|
||||
{
|
||||
if (!s_bSDLInit) {
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
// Tell SDL to catch event even if the windows isn't focussed
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_HAPTIC|SDL_INIT_EVENTS) < 0) return;
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_EVENTS) < 0)
|
||||
return;
|
||||
// WTF! Give me back the control of my system
|
||||
struct sigaction action = {0};
|
||||
action.sa_handler = SIG_DFL;
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
#else
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) return;
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
|
||||
return;
|
||||
#endif
|
||||
SDL_JoystickEventState(SDL_QUERY);
|
||||
s_bSDLInit = true;
|
||||
|
@ -67,16 +67,14 @@ void JoystickInfo::EnumerateJoysticks(vector<GamePad*>& vjoysticks)
|
|||
vector<GamePad *>::iterator it = vjoysticks.begin();
|
||||
|
||||
// Delete everything in the vector vjoysticks.
|
||||
while (it != vjoysticks.end())
|
||||
{
|
||||
while (it != vjoysticks.end()) {
|
||||
delete *it;
|
||||
++it;
|
||||
}
|
||||
|
||||
vjoysticks.resize(SDL_NumJoysticks());
|
||||
|
||||
for (int i = 0; i < (int)vjoysticks.size(); ++i)
|
||||
{
|
||||
for (int i = 0; i < (int)vjoysticks.size(); ++i) {
|
||||
vjoysticks[i] = new JoystickInfo();
|
||||
vjoysticks[i]->Init(i);
|
||||
}
|
||||
|
@ -85,8 +83,7 @@ void JoystickInfo::EnumerateJoysticks(vector<GamePad*>& vjoysticks)
|
|||
void JoystickInfo::GenerateDefaultEffect()
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
for(int i=0;i<NB_EFFECT;i++)
|
||||
{
|
||||
for (int i = 0; i < NB_EFFECT; i++) {
|
||||
SDL_HapticEffect effect;
|
||||
memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
|
||||
SDL_HapticDirection direction;
|
||||
|
@ -107,14 +104,16 @@ void JoystickInfo::GenerateDefaultEffect()
|
|||
|
||||
void JoystickInfo::Rumble(int type, int pad)
|
||||
{
|
||||
if (type > 1) return;
|
||||
if ( !(conf->pad_options[pad].forcefeedback) ) return;
|
||||
if (type > 1)
|
||||
return;
|
||||
if (!(conf->pad_options[pad].forcefeedback))
|
||||
return;
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
if (haptic == NULL) return;
|
||||
if (haptic == NULL)
|
||||
return;
|
||||
|
||||
if(first)
|
||||
{// If done multiple times, device memory will be filled
|
||||
if (first) { // If done multiple times, device memory will be filled
|
||||
first = 0;
|
||||
GenerateDefaultEffect();
|
||||
/** Sine and triangle are quite probably the best, don't change that lightly and if you do
|
||||
|
@ -126,24 +125,21 @@ void JoystickInfo::Rumble(int type, int pad)
|
|||
**/
|
||||
effects[0].type = SDL_HAPTIC_SINE;
|
||||
effects_id[0] = SDL_HapticNewEffect(haptic, &effects[0]);
|
||||
if(effects_id[0] < 0)
|
||||
{
|
||||
if (effects_id[0] < 0) {
|
||||
fprintf(stderr, "ERROR: Effect is not uploaded! %s, id is %d\n", SDL_GetError(), effects_id[0]);
|
||||
}
|
||||
|
||||
/** Effect for big motor **/
|
||||
effects[1].type = SDL_HAPTIC_TRIANGLE;
|
||||
effects_id[1] = SDL_HapticNewEffect(haptic, &effects[1]);
|
||||
if(effects_id[1] < 0)
|
||||
{
|
||||
if (effects_id[1] < 0) {
|
||||
fprintf(stderr, "ERROR: Effect is not uploaded! %s, id is %d\n", SDL_GetError(), effects_id[1]);
|
||||
}
|
||||
}
|
||||
|
||||
int id;
|
||||
id = effects_id[type];
|
||||
if(SDL_HapticRunEffect(haptic, id, 1) != 0)
|
||||
{
|
||||
if (SDL_HapticRunEffect(haptic, id, 1) != 0) {
|
||||
fprintf(stderr, "ERROR: Effect is not working! %s, id is %d\n", SDL_GetError(), id);
|
||||
}
|
||||
#endif
|
||||
|
@ -151,8 +147,7 @@ void JoystickInfo::Rumble(int type, int pad)
|
|||
|
||||
void JoystickInfo::Destroy()
|
||||
{
|
||||
if (joy != NULL)
|
||||
{
|
||||
if (joy != NULL) {
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
// Haptic must be closed before the joystick
|
||||
if (haptic != NULL) {
|
||||
|
@ -163,10 +158,12 @@ void JoystickInfo::Destroy()
|
|||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#if SDL_MINOR_VERSION >= 4 // Version before 2.0.4 are bugged, JoystickClose crashes randomly
|
||||
if (joy) SDL_JoystickClose(joy);
|
||||
if (joy)
|
||||
SDL_JoystickClose(joy);
|
||||
#endif
|
||||
#else
|
||||
if (SDL_JoystickOpened(_id)) SDL_JoystickClose(joy);
|
||||
if (SDL_JoystickOpened(_id))
|
||||
SDL_JoystickClose(joy);
|
||||
#endif
|
||||
joy = NULL;
|
||||
}
|
||||
|
@ -178,8 +175,7 @@ bool JoystickInfo::Init(int id)
|
|||
_id = id;
|
||||
|
||||
joy = SDL_JoystickOpen(id);
|
||||
if (joy == NULL)
|
||||
{
|
||||
if (joy == NULL) {
|
||||
PAD_LOG("failed to open joystick %d\n", id);
|
||||
return false;
|
||||
}
|
||||
|
@ -244,8 +240,7 @@ bool JoystickInfo::TestForce(float strength=0.60)
|
|||
return false; // Otherwise, core dump!
|
||||
SDL_HapticRumbleInit(haptic);
|
||||
// Make the haptic pad rumble 60% strength for half a second, shoudld be enough for user to see if it works or not
|
||||
if( SDL_HapticRumblePlay( haptic, strength, 400 ) != 0)
|
||||
{
|
||||
if (SDL_HapticRumblePlay(haptic, strength, 400) != 0) {
|
||||
fprintf(stderr, "ERROR: Rumble is not working! %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
@ -258,11 +253,9 @@ bool JoystickInfo::TestForce(float strength=0.60)
|
|||
bool JoystickInfo::PollButtons(u32 &pkey)
|
||||
{
|
||||
// MAKE sure to look for changes in the state!!
|
||||
for (int i = 0; i < GetNumButtons(); ++i)
|
||||
{
|
||||
for (int i = 0; i < GetNumButtons(); ++i) {
|
||||
int but = SDL_JoystickGetButton(GetJoy(), i);
|
||||
if (but != GetButtonState(i))
|
||||
{
|
||||
if (but != GetButtonState(i)) {
|
||||
// Pressure sensitive button are detected as both button (digital) and axes (analog). So better
|
||||
// drop the button to emulate the pressure sensiblity of the ds2 :)
|
||||
// Trick: detect the release of the button. It avoid all races condition between axes and buttons :)
|
||||
|
@ -285,8 +278,7 @@ bool JoystickInfo::PollAxes(u32 &pkey)
|
|||
{
|
||||
u32 found_hack = devname.find(string("PLAYSTATION(R)3"));
|
||||
|
||||
for (int i = 0; i < GetNumAxes(); ++i)
|
||||
{
|
||||
for (int i = 0; i < GetNumAxes(); ++i) {
|
||||
// Sixaxis, dualshock3 hack
|
||||
if (found_hack != string::npos) {
|
||||
// The analog mode of the hat button is quite erratic. Values can be in half- axis
|
||||
|
@ -304,8 +296,7 @@ bool JoystickInfo::PollAxes(u32 &pkey)
|
|||
if (abs(value - old_value) < 0x1000)
|
||||
continue;
|
||||
|
||||
if (value != old_value)
|
||||
{
|
||||
if (value != old_value) {
|
||||
PAD_LOG("Change in joystick %d: %d.\n", i, value);
|
||||
// There are several kinds of axes
|
||||
// Half+: 0 (release) -> 32768
|
||||
|
@ -317,15 +308,12 @@ bool JoystickInfo::PollAxes(u32 &pkey)
|
|||
// Normally, old_value contains the release state so it can be used to detect the types of axis.
|
||||
bool is_full_axis = (old_value < full_axis_ceil) ? true : false;
|
||||
|
||||
if ((!is_full_axis && abs(value) <= half_axis_ceil)
|
||||
|| (is_full_axis && value <= full_axis_ceil)) // we don't want this
|
||||
if ((!is_full_axis && abs(value) <= half_axis_ceil) || (is_full_axis && value <= full_axis_ceil)) // we don't want this
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((!is_full_axis && abs(value) > half_axis_ceil)
|
||||
|| (is_full_axis && value > full_axis_ceil))
|
||||
{
|
||||
if ((!is_full_axis && abs(value) > half_axis_ceil) || (is_full_axis && value > full_axis_ceil)) {
|
||||
bool sign = (value < 0);
|
||||
pkey = axis_to_key(is_full_axis, sign, i);
|
||||
|
||||
|
@ -339,14 +327,11 @@ bool JoystickInfo::PollAxes(u32 &pkey)
|
|||
|
||||
bool JoystickInfo::PollHats(u32 &pkey)
|
||||
{
|
||||
for (int i = 0; i < GetNumHats(); ++i)
|
||||
{
|
||||
for (int i = 0; i < GetNumHats(); ++i) {
|
||||
int value = SDL_JoystickGetHat(GetJoy(), i);
|
||||
|
||||
if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED))
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED)) {
|
||||
switch (value) {
|
||||
case SDL_HAT_UP:
|
||||
case SDL_HAT_RIGHT:
|
||||
case SDL_HAT_DOWN:
|
||||
|
|
|
@ -34,7 +34,10 @@
|
|||
class JoystickInfo : GamePad
|
||||
{
|
||||
public:
|
||||
JoystickInfo() : GamePad(), joy(NULL) {
|
||||
JoystickInfo()
|
||||
: GamePad()
|
||||
, joy(NULL)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
haptic = NULL;
|
||||
first = true;
|
||||
|
|
|
@ -52,10 +52,14 @@ __forceinline KeyType type_of_joykey(int pad, int index)
|
|||
{
|
||||
int key = get_key(pad, index);
|
||||
|
||||
if (key >= 0x10000 && key < 0x20000) return PAD_JOYBUTTONS;
|
||||
else if (key >= 0x20000 && key < 0x30000) return PAD_AXIS;
|
||||
else if (key >= 0x30000 && key < 0x40000) return PAD_HAT;
|
||||
else return PAD_NULL;
|
||||
if (key >= 0x10000 && key < 0x20000)
|
||||
return PAD_JOYBUTTONS;
|
||||
else if (key >= 0x20000 && key < 0x30000)
|
||||
return PAD_AXIS;
|
||||
else if (key >= 0x30000 && key < 0x40000)
|
||||
return PAD_HAT;
|
||||
else
|
||||
return PAD_NULL;
|
||||
}
|
||||
|
||||
__forceinline bool IsAnalogKey(int index)
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#include <string.h> // for memset
|
||||
#define MAX_KEYS 24
|
||||
|
||||
enum KeyType
|
||||
{
|
||||
enum KeyType {
|
||||
PAD_JOYBUTTONS = 0,
|
||||
PAD_AXIS,
|
||||
PAD_HAT,
|
||||
|
@ -54,9 +53,12 @@ class PADconf
|
|||
{
|
||||
u32 ff_intensity;
|
||||
u32 sensibility;
|
||||
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
u16 forcefeedback : 1;
|
||||
u16 reverse_lx : 1;
|
||||
u16 reverse_ly : 1;
|
||||
|
@ -78,25 +80,27 @@ class PADconf
|
|||
|
||||
PADconf() { init(); }
|
||||
|
||||
void init() {
|
||||
void init()
|
||||
{
|
||||
memset(&keys, 0, sizeof(keys));
|
||||
log = packed_options = joyid_map = 0;
|
||||
ff_intensity = 0x7FFF; // set it at max value by default
|
||||
sensibility = 500;
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER ; pad++)
|
||||
{
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
|
||||
keysym_map[pad].clear();
|
||||
set_joyid((u32)pad, (u32)pad); // define id mapping for each gamepad
|
||||
}
|
||||
}
|
||||
|
||||
void set_joyid(u32 pad, u32 joy_id) {
|
||||
void set_joyid(u32 pad, u32 joy_id)
|
||||
{
|
||||
int shift = 8 * pad;
|
||||
joyid_map &= ~(0xFF << shift); // clear
|
||||
joyid_map |= (joy_id & 0xFF) << shift; // set
|
||||
}
|
||||
|
||||
u32 get_joyid(u32 pad) {
|
||||
u32 get_joyid(u32 pad)
|
||||
{
|
||||
int shift = 8 * pad;
|
||||
return ((joyid_map >> shift) & 0xFF);
|
||||
}
|
||||
|
@ -115,8 +119,7 @@ class PADconf
|
|||
**/
|
||||
void set_ff_intensity(u32 new_intensity)
|
||||
{
|
||||
if(new_intensity <= 0x7FFF)
|
||||
{
|
||||
if (new_intensity <= 0x7FFF) {
|
||||
ff_intensity = new_intensity;
|
||||
}
|
||||
}
|
||||
|
@ -128,8 +131,7 @@ class PADconf
|
|||
**/
|
||||
void set_sensibility(u32 new_sensibility)
|
||||
{
|
||||
if(sensibility > 0)
|
||||
{
|
||||
if (sensibility > 0) {
|
||||
sensibility = new_sensibility;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,7 @@ char* KeysymToChar(int keysym)
|
|||
void SetAutoRepeat(bool autorep)
|
||||
{
|
||||
#if defined(__unix__)
|
||||
if (toggleAutoRepeat)
|
||||
{
|
||||
if (toggleAutoRepeat) {
|
||||
if (autorep)
|
||||
XAutoRepeatOn(GSdsp);
|
||||
else
|
||||
|
@ -70,15 +69,15 @@ void AnalyzeKeyEvent(keyEvent &evt)
|
|||
}
|
||||
}
|
||||
|
||||
switch (evt.evt)
|
||||
{
|
||||
switch (evt.evt) {
|
||||
case KeyPress:
|
||||
// Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input
|
||||
// I found it very handy vs the automatic fullscreen detection
|
||||
// 1/ Does not need to detect full-screen
|
||||
// 2/ Can use a debugger in full-screen
|
||||
// 3/ Can grab input in window without the need of a pixelated full-screen
|
||||
if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = true;
|
||||
if (key == XK_Shift_R || key == XK_Shift_L)
|
||||
s_Shift = true;
|
||||
if (key == XK_F12 && s_Shift) {
|
||||
if (!s_grab_input) {
|
||||
s_grab_input = true;
|
||||
|
@ -92,10 +91,8 @@ void AnalyzeKeyEvent(keyEvent &evt)
|
|||
}
|
||||
|
||||
// Analog controls.
|
||||
if (IsAnalogKey(index))
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
if (IsAnalogKey(index)) {
|
||||
switch (index) {
|
||||
case PAD_R_LEFT:
|
||||
case PAD_R_UP:
|
||||
case PAD_L_LEFT:
|
||||
|
@ -119,7 +116,8 @@ void AnalyzeKeyEvent(keyEvent &evt)
|
|||
break;
|
||||
|
||||
case KeyRelease:
|
||||
if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false;
|
||||
if (key == XK_Shift_R || key == XK_Shift_L)
|
||||
s_Shift = false;
|
||||
|
||||
if (index != -1)
|
||||
key_status->release(pad, index);
|
||||
|
@ -217,8 +215,7 @@ void PollForX11KeyboardInput()
|
|||
}
|
||||
|
||||
// keyboard input
|
||||
while (XPending(GSdsp) > 0)
|
||||
{
|
||||
while (XPending(GSdsp) > 0) {
|
||||
XNextEvent(GSdsp, &E);
|
||||
|
||||
// Change the format of the structure to be compatible with GSOpen2
|
||||
|
@ -244,8 +241,7 @@ bool PollX11KeyboardMouseEvent(u32 &pkey)
|
|||
{
|
||||
GdkEvent *ev = gdk_event_get();
|
||||
|
||||
if (ev != NULL)
|
||||
{
|
||||
if (ev != NULL) {
|
||||
if (ev->type == GDK_KEY_PRESS) {
|
||||
pkey = ev->key.keyval != GDK_KEY_Escape ? ev->key.keyval : 0;
|
||||
return true;
|
||||
|
@ -264,17 +260,14 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
static bool lbutton = false, rbutton = false;
|
||||
key_status->keyboard_state_acces(cpad);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_KEYDOWN:
|
||||
if (lParam & 0x40000000) return TRUE;
|
||||
if (lParam & 0x40000000)
|
||||
return TRUE;
|
||||
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
|
||||
{
|
||||
for (int i = 0; i < MAX_KEYS; i++)
|
||||
{
|
||||
if (wParam == get_key(pad, i))
|
||||
{
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
|
||||
for (int i = 0; i < MAX_KEYS; i++) {
|
||||
if (wParam == get_key(pad, i)) {
|
||||
key_status->press(pad, i);
|
||||
break;
|
||||
}
|
||||
|
@ -286,12 +279,9 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
break;
|
||||
|
||||
case WM_KEYUP:
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
|
||||
{
|
||||
for (int i = 0; i < MAX_KEYS; i++)
|
||||
{
|
||||
if (wParam == get_key(pad,i))
|
||||
{
|
||||
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
|
||||
for (int i = 0; i < MAX_KEYS; i++) {
|
||||
if (wParam == get_key(pad, i)) {
|
||||
key_status->release(pad, i);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -79,24 +79,27 @@ static void InitLibraryName()
|
|||
#elif defined(PCSX2_DEVBUILD)
|
||||
"-Dev"
|
||||
#endif
|
||||
, SVN_REV,
|
||||
SVN_MODS ? "m" : ""
|
||||
);
|
||||
,
|
||||
SVN_REV,
|
||||
SVN_MODS ? "m" : "");
|
||||
#endif
|
||||
}
|
||||
|
||||
EXPORT_C_(u32) PS2EgetLibType()
|
||||
EXPORT_C_(u32)
|
||||
PS2EgetLibType()
|
||||
{
|
||||
return PS2E_LT_PAD;
|
||||
}
|
||||
|
||||
EXPORT_C_(char*) PS2EgetLibName()
|
||||
EXPORT_C_(char *)
|
||||
PS2EgetLibName()
|
||||
{
|
||||
InitLibraryName();
|
||||
return libraryName;
|
||||
}
|
||||
|
||||
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
|
||||
EXPORT_C_(u32)
|
||||
PS2EgetLibVersion2(u32 type)
|
||||
{
|
||||
return (version << 16) | (revision << 8) | build;
|
||||
}
|
||||
|
@ -105,7 +108,8 @@ void __Log(const char *fmt, ...)
|
|||
{
|
||||
va_list list;
|
||||
|
||||
if (padLog == NULL) return;
|
||||
if (padLog == NULL)
|
||||
return;
|
||||
va_start(list, fmt);
|
||||
vfprintf(padLog, fmt, list);
|
||||
va_end(list);
|
||||
|
@ -117,7 +121,8 @@ void __LogToConsole(const char *fmt, ...)
|
|||
|
||||
va_start(list, fmt);
|
||||
|
||||
if (padLog != NULL) vfprintf(padLog, fmt, list);
|
||||
if (padLog != NULL)
|
||||
vfprintf(padLog, fmt, list);
|
||||
|
||||
printf("OnePAD: ");
|
||||
vprintf(fmt, list);
|
||||
|
@ -127,7 +132,8 @@ void __LogToConsole(const char *fmt, ...)
|
|||
void initLogging()
|
||||
{
|
||||
#ifdef PAD_LOG
|
||||
if (padLog) return;
|
||||
if (padLog)
|
||||
return;
|
||||
|
||||
const std::string LogFile(s_strLogPath + "padLog.txt");
|
||||
padLog = fopen(LogFile.c_str(), "w");
|
||||
|
@ -142,8 +148,7 @@ void initLogging()
|
|||
void CloseLogging()
|
||||
{
|
||||
#ifdef PAD_LOG
|
||||
if (padLog)
|
||||
{
|
||||
if (padLog) {
|
||||
fclose(padLog);
|
||||
padLog = NULL;
|
||||
}
|
||||
|
@ -157,7 +162,8 @@ void clearPAD(int pad)
|
|||
set_key(pad, key, 0);
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) PADinit(u32 flags)
|
||||
EXPORT_C_(s32)
|
||||
PADinit(u32 flags)
|
||||
{
|
||||
initLogging();
|
||||
|
||||
|
@ -175,7 +181,8 @@ EXPORT_C_(s32) PADinit(u32 flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(void) PADshutdown()
|
||||
EXPORT_C_(void)
|
||||
PADshutdown()
|
||||
{
|
||||
CloseLogging();
|
||||
|
||||
|
@ -186,12 +193,14 @@ EXPORT_C_(void) PADshutdown()
|
|||
key_status = nullptr;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) PADopen(void *pDsp)
|
||||
EXPORT_C_(s32)
|
||||
PADopen(void *pDsp)
|
||||
{
|
||||
memset(&event, 0, sizeof(event));
|
||||
key_status->Init();
|
||||
|
||||
while (!ev_fifo.empty()) ev_fifo.pop();
|
||||
while (!ev_fifo.empty())
|
||||
ev_fifo.pop();
|
||||
pthread_spin_init(&mutex_KeyEvent, PTHREAD_PROCESS_PRIVATE);
|
||||
mutex_WasInit = true;
|
||||
|
||||
|
@ -201,13 +210,15 @@ EXPORT_C_(s32) PADopen(void *pDsp)
|
|||
return _PADopen(pDsp);
|
||||
}
|
||||
|
||||
EXPORT_C_(void) PADsetSettingsDir(const char* dir)
|
||||
EXPORT_C_(void)
|
||||
PADsetSettingsDir(const char *dir)
|
||||
{
|
||||
// Get the path to the ini directory.
|
||||
s_strIniPath = (dir == NULL) ? "inis/" : dir;
|
||||
}
|
||||
|
||||
EXPORT_C_(void) PADsetLogDir(const char* dir)
|
||||
EXPORT_C_(void)
|
||||
PADsetLogDir(const char *dir)
|
||||
{
|
||||
// Get the path to the log directory.
|
||||
s_strLogPath = (dir == NULL) ? "logs/" : dir;
|
||||
|
@ -217,20 +228,24 @@ EXPORT_C_(void) PADsetLogDir(const char* dir)
|
|||
initLogging();
|
||||
}
|
||||
|
||||
EXPORT_C_(void) PADclose()
|
||||
EXPORT_C_(void)
|
||||
PADclose()
|
||||
{
|
||||
while (!ev_fifo.empty()) ev_fifo.pop();
|
||||
while (!ev_fifo.empty())
|
||||
ev_fifo.pop();
|
||||
mutex_WasInit = false;
|
||||
pthread_spin_destroy(&mutex_KeyEvent);
|
||||
_PADclose();
|
||||
}
|
||||
|
||||
EXPORT_C_(u32) PADquery()
|
||||
EXPORT_C_(u32)
|
||||
PADquery()
|
||||
{
|
||||
return 3; // both
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot)
|
||||
EXPORT_C_(s32)
|
||||
PADsetSlot(u8 port, u8 slot)
|
||||
{
|
||||
port--;
|
||||
slot--;
|
||||
|
@ -243,7 +258,8 @@ EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot)
|
|||
return 1;
|
||||
}
|
||||
|
||||
EXPORT_C_(s32) PADfreeze(int mode, freezeData *data)
|
||||
EXPORT_C_(s32)
|
||||
PADfreeze(int mode, freezeData *data)
|
||||
{
|
||||
if (!data)
|
||||
return -1;
|
||||
|
@ -283,7 +299,8 @@ EXPORT_C_(s32) PADfreeze(int mode, freezeData *data)
|
|||
}
|
||||
|
||||
} else if (mode == FREEZE_SAVE) {
|
||||
if (data->size != sizeof(PadPluginFreezeData)) return 0;
|
||||
if (data->size != sizeof(PadPluginFreezeData))
|
||||
return 0;
|
||||
|
||||
PadPluginFreezeData *pdata = (PadPluginFreezeData *)(data->data);
|
||||
|
||||
|
@ -310,18 +327,21 @@ EXPORT_C_(s32) PADfreeze(int mode, freezeData *data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_C_(u8) PADstartPoll(int pad)
|
||||
EXPORT_C_(u8)
|
||||
PADstartPoll(int pad)
|
||||
{
|
||||
return pad_start_poll(pad);
|
||||
}
|
||||
|
||||
EXPORT_C_(u8) PADpoll(u8 value)
|
||||
EXPORT_C_(u8)
|
||||
PADpoll(u8 value)
|
||||
{
|
||||
return pad_poll(value);
|
||||
}
|
||||
|
||||
// PADkeyEvent is called every vsync (return NULL if no event)
|
||||
EXPORT_C_(keyEvent*) PADkeyEvent()
|
||||
EXPORT_C_(keyEvent *)
|
||||
PADkeyEvent()
|
||||
{
|
||||
s_event = event;
|
||||
event.evt = 0;
|
||||
|
@ -330,7 +350,8 @@ EXPORT_C_(keyEvent*) PADkeyEvent()
|
|||
}
|
||||
|
||||
#if defined(__unix__)
|
||||
EXPORT_C_(void) PADWriteEvent(keyEvent &evt)
|
||||
EXPORT_C_(void)
|
||||
PADWriteEvent(keyEvent &evt)
|
||||
{
|
||||
// This function call be called before PADopen. Therefore we cann't
|
||||
// guarantee that the spin lock was initialized
|
||||
|
|
|
@ -62,8 +62,7 @@ using namespace std;
|
|||
#define EXPORT_C_(type) extern "C" __attribute__((stdcall, externally_visible, visibility("default"))) type
|
||||
#endif
|
||||
|
||||
enum PadOptions
|
||||
{
|
||||
enum PadOptions {
|
||||
PADOPTION_FORCEFEEDBACK = 0x1,
|
||||
PADOPTION_REVERSELX = 0x2,
|
||||
PADOPTION_REVERSELY = 0x4,
|
||||
|
@ -82,8 +81,7 @@ extern bool toggleAutoRepeat;
|
|||
#define PAD_LOG __Log
|
||||
//#define PAD_LOG __LogToConsole
|
||||
|
||||
enum PadCommands
|
||||
{
|
||||
enum PadCommands {
|
||||
CMD_SET_VREF_PARAM = 0x40,
|
||||
CMD_QUERY_DS2_ANALOG_MODE = 0x41,
|
||||
CMD_READ_DATA_AND_VIBRATE = 0x42,
|
||||
|
@ -97,8 +95,7 @@ enum PadCommands
|
|||
CMD_SET_DS2_NATIVE_MODE = 0x4F // SET_DS2_NATIVE_MODE
|
||||
};
|
||||
|
||||
enum gamePadValues
|
||||
{
|
||||
enum gamePadValues {
|
||||
PAD_L2 = 0, // L2 button
|
||||
PAD_R2, // R2 button
|
||||
PAD_L1, // L1 button
|
||||
|
|
|
@ -159,7 +159,8 @@ void Pad::rumble_all()
|
|||
// Pad implementation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline bool IsDualshock2() {
|
||||
inline bool IsDualshock2()
|
||||
{
|
||||
// FIXME
|
||||
#if 0
|
||||
return config.padConfigs[query.port][query.slot].type == Dualshock2Pad ||
|
||||
|
@ -197,8 +198,7 @@ u8 pad_poll(u8 value)
|
|||
}
|
||||
break;
|
||||
|
||||
case CMD_READ_DATA_AND_VIBRATE:
|
||||
{
|
||||
case CMD_READ_DATA_AND_VIBRATE: {
|
||||
query.response[2] = 0x5A;
|
||||
#if 0
|
||||
int i;
|
||||
|
@ -319,8 +319,7 @@ u8 pad_poll(u8 value)
|
|||
if (pad->mode == MODE_DIGITAL) {
|
||||
queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0;
|
||||
queryMaskMode[6] = 0x00;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
queryMaskMode[1] = pad->umask[0];
|
||||
queryMaskMode[2] = pad->umask[1];
|
||||
queryMaskMode[3] = 0x03;
|
||||
|
@ -415,7 +414,8 @@ u8 pad_poll(u8 value)
|
|||
|
||||
case CMD_QUERY_ACT:
|
||||
if (query.lastByte == 3) {
|
||||
if (value<2) query.set_result(queryAct[value]);
|
||||
if (value < 2)
|
||||
query.set_result(queryAct[value]);
|
||||
// bunch of 0's
|
||||
// else query.set_result(setMode);
|
||||
query.queryDone = 1;
|
||||
|
@ -435,8 +435,7 @@ u8 pad_poll(u8 value)
|
|||
if (query.lastByte >= 3) {
|
||||
if (value == 0) {
|
||||
pad->vibrateI[0] = (u8)query.lastByte;
|
||||
}
|
||||
else if (value == 1) {
|
||||
} else if (value == 1) {
|
||||
pad->vibrateI[1] = (u8)query.lastByte;
|
||||
}
|
||||
pad->vibrate[query.lastByte - 2] = value;
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
#define MODE_DS2_NATIVE 0x79
|
||||
|
||||
// The state of the PS2 bus
|
||||
struct QueryInfo {
|
||||
struct QueryInfo
|
||||
{
|
||||
u8 port;
|
||||
u8 slot;
|
||||
u8 lastByte;
|
||||
|
@ -55,7 +56,8 @@ struct QueryInfo {
|
|||
|
||||
// Freeze data, for a single pad. Basically has all pad state that
|
||||
// a PS2 can set.
|
||||
struct PadFreezeData {
|
||||
struct PadFreezeData
|
||||
{
|
||||
// Digital / Analog / DS2 Native
|
||||
u8 mode;
|
||||
|
||||
|
@ -81,7 +83,8 @@ struct PadFreezeData {
|
|||
u8 nextVibrate[2];
|
||||
};
|
||||
|
||||
class Pad : public PadFreezeData {
|
||||
class Pad : public PadFreezeData
|
||||
{
|
||||
public:
|
||||
// Lilypad store here the state of PC pad
|
||||
|
||||
|
@ -98,7 +101,8 @@ public:
|
|||
};
|
||||
|
||||
// Full state to manage save state
|
||||
struct PadPluginFreezeData {
|
||||
struct PadPluginFreezeData
|
||||
{
|
||||
char format[8];
|
||||
u32 version;
|
||||
// active slot for port
|
||||
|
|
Loading…
Reference in New Issue