X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fplugins.c;h=6e5cdbfec4a4fe7bbfd670e54cf51d444859f4ea;hb=9ece32be0b943bfc3cb0bf23dc08730431c01ec7;hp=93af3d02cd5ba7e4e4e13b6d2b0de595d2ae4c9d;hpb=f6eb0b1c75fd9103a1ad18aed5d00aa0c41fa24e;p=pcsx_rearmed.git diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 93af3d02..6e5cdbfe 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -23,6 +23,7 @@ #include "plugins.h" #include "cdriso.h" +#include "psxcounters.h" static char IsoFile[MAXPATHLEN] = ""; static s64 cdOpenCaseTime = 0; @@ -49,6 +50,7 @@ GPUfreeze GPU_freeze; GPUgetScreenPic GPU_getScreenPic; GPUshowScreenPic GPU_showScreenPic; GPUvBlank GPU_vBlank; +GPUgetScreenInfo GPU_getScreenInfo; CDRinit CDR_init; CDRshutdown CDR_shutdown; @@ -194,6 +196,7 @@ void CALLBACK GPU__keypressed(int key) {} long CALLBACK GPU__getScreenPic(unsigned char *pMem) { return -1; } long CALLBACK GPU__showScreenPic(unsigned char *pMem) { return -1; } void CALLBACK GPU__vBlank(int val) {} +void CALLBACK GPU__getScreenInfo(int *y, int *base_hres) {} #define LoadGpuSym1(dest, name) \ LoadSym(GPU_##dest, GPU##dest, name, TRUE); @@ -233,6 +236,7 @@ static int LoadGPUplugin(const char *GPUdll) { LoadGpuSym0(getScreenPic, "GPUgetScreenPic"); LoadGpuSym0(showScreenPic, "GPUshowScreenPic"); LoadGpuSym0(vBlank, "GPUvBlank"); + LoadGpuSym0(getScreenInfo, "GPUgetScreenInfo"); LoadGpuSym0(configure, "GPUconfigure"); LoadGpuSym0(test, "GPUtest"); LoadGpuSym0(about, "GPUabout"); @@ -361,24 +365,23 @@ static unsigned char buf[256]; static unsigned char stdpar[8] = { 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; //response for request 44, 45, 46, 47, 4C, 4D -static unsigned char resp45[8] = {0xF3, 0x5A, 0x01, 0x02, 0x00, 0x02, 0x01, 0x00}; -static unsigned char resp46_00[8] = {0xF3, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}; -static unsigned char resp46_01[8] = {0xF3, 0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14}; -static unsigned char resp47[8] = {0xF3, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}; -static unsigned char resp4C_00[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00}; -static unsigned char resp4C_01[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00}; -static unsigned char resp4D[8] = {0xF3, 0x5A, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF}; +static const u8 resp45[8] = {0xF3, 0x5A, 0x01, 0x02, 0x00, 0x02, 0x01, 0x00}; +static const u8 resp46_00[8] = {0xF3, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}; +static const u8 resp46_01[8] = {0xF3, 0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14}; +static const u8 resp47[8] = {0xF3, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}; +static const u8 resp4C_00[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00}; +static const u8 resp4C_01[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00}; //fixed reponse of request number 41, 48, 49, 4A, 4B, 4E, 4F -static unsigned char resp40[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp41[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp43[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp44[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp49[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp4A[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp4B[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp4E[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static unsigned char resp4F[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp40[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp41[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp43[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp44[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp49[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp4A[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp4B[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp4E[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const u8 resp4F[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Resquest of psx core enum { @@ -478,23 +481,44 @@ enum { static void initBufForRequest(int padIndex, char value) { - switch (value){ - //Pad keystate already in buffer + if (pads[padIndex].ds.configMode) { + buf[0] = 0xf3; buf[1] = 0x5a; + respSize = 8; + } + else if (value != 0x42 && value != 0x43) { + respSize = 1; + return; + } + + // switch to analog mode automatically after the game finishes init + if (value == 0x42 && pads[padIndex].ds.padMode == 0) + pads[padIndex].ds.digitalModeFrames++; + if (pads[padIndex].ds.digitalModeFrames == 60*4) { + pads[padIndex].ds.padMode = 1; + pads[padIndex].ds.digitalModeFrames = 0; + } + + if ((u32)(frame_counter - pads[padIndex].ds.lastUseFrame) > 60u) + pads[padIndex].ds.padMode = 0; // according to nocash + pads[padIndex].ds.lastUseFrame = frame_counter; + + switch (value) { + // keystate already in buffer, set by PADstartPoll_() //case CMD_READ_DATA_AND_VIBRATE : // break; case CMD_CONFIG_MODE : - if (pads[padIndex].configMode) { + if (pads[padIndex].ds.configMode) { memcpy(buf, resp43, 8); break; } - //else, not in config mode, pad keystate return (already in the buffer) + // else not in config mode, pad keystate return break; case CMD_SET_MODE_AND_LOCK : memcpy(buf, resp44, 8); break; case CMD_QUERY_MODEL_AND_MODE : memcpy(buf, resp45, 8); - buf[4] = pads[padIndex].PadMode; + buf[4] = pads[padIndex].ds.padMode; break; case CMD_QUERY_ACT : memcpy(buf, resp46_00, 8); @@ -505,8 +529,8 @@ static void initBufForRequest(int padIndex, char value) { case CMD_QUERY_MODE : memcpy(buf, resp4C_00, 8); break; - case CMD_VIBRATION_TOGGLE : - memcpy(buf, resp4D, 8); + case CMD_VIBRATION_TOGGLE: // 4d + memcpy(buf + 2, pads[padIndex].ds.cmd4dConfig, 6); break; case REQ40 : memcpy(buf, resp40, 8); @@ -532,22 +556,22 @@ static void initBufForRequest(int padIndex, char value) { } } -static void reqIndex2Treatment(int padIndex, char value) { +static void reqIndex2Treatment(int padIndex, u8 value) { switch (pads[padIndex].txData[0]) { case CMD_CONFIG_MODE : //0x43 if (value == 0) { - pads[padIndex].configMode = 0; + pads[padIndex].ds.configMode = 0; } else { - pads[padIndex].configMode = 1; + pads[padIndex].ds.configMode = 1; } break; case CMD_SET_MODE_AND_LOCK : //0x44 store the led state for change mode if the next value = 0x02 //0x01 analog ON //0x00 analog OFF - //ledStateReq44[padIndex] = value; - pads[padIndex].PadMode = value; + if ((value & ~1) == 0) + pads[padIndex].ds.padMode = value; break; case CMD_QUERY_ACT : //0x46 @@ -560,10 +584,6 @@ static void reqIndex2Treatment(int padIndex, char value) { memcpy(buf, resp4C_01, 8); } break; - case CMD_VIBRATION_TOGGLE : - //0x4D - memcpy(buf, resp4D, 8); - break; case CMD_READ_DATA_AND_VIBRATE: //mem the vibration value for small motor; pads[padIndex].Vib[0] = value; @@ -578,8 +598,23 @@ static void vibrate(int padIndex) { pad->VibF[0] = pad->Vib[0]; pad->VibF[1] = pad->Vib[1]; plat_trigger_vibrate(padIndex, pad->VibF[0], pad->VibF[1]); - //printf("vibration pad %i", padIndex); + //printf("vib%i %02x %02x\n", padIndex, pad->VibF[0], pad->VibF[1]); + } +} + +static void log_pad(int port, int pos) +{ +#if 0 + if (port == 0 && pos == respSize - 1) { + int i; + for (i = 0; i < respSize; i++) + printf("%02x ", pads[port].txData[i]); + printf("|"); + for (i = 0; i < respSize; i++) + printf(" %02x", buf[i]); + printf("\n"); } +#endif } // Build response for 0x42 request Pad in port @@ -613,9 +648,8 @@ static void PADstartPoll_(PadDataS *pad) { stdpar[2] = pad->buttonStatus & 0xff; stdpar[3] = pad->buttonStatus >> 8; - int absX = pad->absoluteX; + int absX = pad->absoluteX; // 0-1023 int absY = pad->absoluteY; - int xres = 256, yres = 240; if (absX == 65536 || absY == 65536) { stdpar[4] = 0x01; @@ -624,9 +658,13 @@ static void PADstartPoll_(PadDataS *pad) { stdpar[7] = 0x00; } else { - plat_get_psx_resolution(&xres, &yres); - int x = 0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * absX >> 10); - int y = 0x20 + (yres * absY >> 10); + int y_ofs = 0, yres = 240; + GPU_getScreenInfo(&y_ofs, &yres); + int y_top = (Config.PsxType ? 0x30 : 0x19) + y_ofs; + int w = Config.PsxType ? 385 : 378; + int x = 0x40 + (w * absX >> 10); + int y = y_top + (yres * absY >> 10); + //printf("%3d %3d %4x %4x\n", absX, absY, x, y); stdpar[4] = x; stdpar[5] = x >> 8; @@ -646,6 +684,8 @@ static void PADstartPoll_(PadDataS *pad) { respSize = 4; break; case PSE_PAD_TYPE_ANALOGPAD: // scph1150 + if (pad->ds.padMode == 0) + goto standard; stdpar[0] = 0x73; stdpar[1] = 0x5a; stdpar[2] = pad->buttonStatus & 0xff; @@ -670,6 +710,7 @@ static void PADstartPoll_(PadDataS *pad) { respSize = 8; break; case PSE_PAD_TYPE_STANDARD: + standard: stdpar[0] = 0x41; stdpar[1] = 0x5a; stdpar[2] = pad->buttonStatus & 0xff; @@ -700,6 +741,10 @@ static void PADpoll_dualshock(int port, unsigned char value, int pos) vibrate(port); } break; + case 7: + if (pads[port].txData[0] == CMD_VIBRATION_TOGGLE) + memcpy(pads[port].ds.cmd4dConfig, pads[port].txData + 2, 6); + break; } } @@ -721,6 +766,7 @@ static unsigned char PADpoll_(int port, unsigned char value, int pos, int *more_ if (pos >= respSize) return 0xff; // no response/HiZ + log_pad(port, pos); return buf[pos]; } @@ -808,6 +854,7 @@ long CALLBACK PAD1__keypressed() { return 0; } static int LoadPAD1plugin(const char *PAD1dll) { void *drv; + size_t p; hPAD1Driver = SysLoadLibrary(PAD1dll); if (hPAD1Driver == NULL) { @@ -829,6 +876,11 @@ static int LoadPAD1plugin(const char *PAD1dll) { LoadPad1Sym0(poll, "PADpoll"); LoadPad1SymN(setSensitive, "PADsetSensitive"); + memset(pads, 0, sizeof(pads)); + for (p = 0; p < sizeof(pads) / sizeof(pads[0]); p++) { + memset(pads[p].ds.cmd4dConfig, 0xff, sizeof(pads[p].ds.cmd4dConfig)); + } + return 0; } @@ -901,6 +953,20 @@ static int LoadPAD2plugin(const char *PAD2dll) { return 0; } +int padFreeze(void *f, int Mode) { + size_t i; + + for (i = 0; i < sizeof(pads) / sizeof(pads[0]); i++) { + pads[i].saveSize = sizeof(pads[i]); + gzfreeze(&pads[i], sizeof(pads[i])); + if (Mode == 0 && pads[i].saveSize != sizeof(pads[i])) + SaveFuncs.seek(f, pads[i].saveSize - sizeof(pads[i]), SEEK_CUR); + } + + return 0; +} + + void *hNETDriver = NULL; void CALLBACK NET__setInfo(netInfo *info) {}