diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 7c938f751b..bc811f360b 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -364,7 +364,6 @@ set(pcsx2USBHeaders USB/proxybase.h USB/deviceproxy.h USB/configuration.h - USB/platcompat.h USB/osdebugout.h USB/helpers.h USB/readerwriterqueue/readerwriterqueue.h diff --git a/pcsx2/IopCounters.cpp b/pcsx2/IopCounters.cpp index 1e7dd6afcf..59a5316489 100644 --- a/pcsx2/IopCounters.cpp +++ b/pcsx2/IopCounters.cpp @@ -22,6 +22,7 @@ #include "IopCommon.h" #include "SPU2/spu2.h" #include "DEV9/DEV9.h" +#include "USB/USB.h" #include @@ -149,12 +150,9 @@ void psxRcntInit() psxCounters[6].CycleT = psxCounters[6].rate; psxCounters[6].mode = 0x8; - if (USBasync != NULL) - { - psxCounters[7].rate = PSXCLK / 1000; - psxCounters[7].CycleT = psxCounters[7].rate; - psxCounters[7].mode = 0x8; - } + psxCounters[7].rate = PSXCLK / 1000; + psxCounters[7].CycleT = psxCounters[7].rate; + psxCounters[7].mode = 0x8; for (i = 0; i < 8; i++) psxCounters[i].sCycleT = psxRegs.cycle; @@ -516,22 +514,19 @@ void psxRcntUpdate() c -= difference; psxNextCounter = c; DEV9async(1); - if(USBasync) - { - const s32 difference = psxRegs.cycle - psxCounters[7].sCycleT; - s32 c = psxCounters[7].CycleT; + const s32 diffusb = psxRegs.cycle - psxCounters[7].sCycleT; + s32 cusb = psxCounters[7].CycleT; - if (difference >= psxCounters[7].CycleT) - { - USBasync(difference); - psxCounters[7].sCycleT = psxRegs.cycle; - psxCounters[7].CycleT = psxCounters[7].rate; - } - else - c -= difference; - if (c < psxNextCounter) - psxNextCounter = c; - } + if (diffusb >= psxCounters[7].CycleT) + { + USBasync(diffusb); + psxCounters[7].sCycleT = psxRegs.cycle; + psxCounters[7].CycleT = psxCounters[7].rate; + } + else + cusb -= diffusb; + if (cusb < psxNextCounter) + psxNextCounter = cusb; for (i = 0; i < 6; i++) _rcntSet(i); diff --git a/pcsx2/IopIrq.cpp b/pcsx2/IopIrq.cpp index b28e0d87e1..7560bd1f58 100644 --- a/pcsx2/IopIrq.cpp +++ b/pcsx2/IopIrq.cpp @@ -16,6 +16,7 @@ #include "PrecompiledHeader.h" #include "IopCommon.h" #include "DEV9/DEV9.h" +#include "USB/USB.h" using namespace R3000A; @@ -33,8 +34,6 @@ void dev9Irq(int cycles) void usbInterrupt() { - if (usbHandler != NULL && (usbHandler() != 1)) return; - iopIntcIrq(22); } diff --git a/pcsx2/R5900.cpp b/pcsx2/R5900.cpp index 0c49a1c10c..7de0ee4bd6 100644 --- a/pcsx2/R5900.cpp +++ b/pcsx2/R5900.cpp @@ -32,6 +32,7 @@ #include "Elfheader.h" #include "CDVD/CDVD.h" +#include "USB/USB.h" #include "Patch.h" #include "GameDatabase.h" @@ -109,8 +110,7 @@ void cpuReset() ElfEntry = -1; // Probably not the right place, but it has to be done when the ram is actually initialized - if(USBsetRAM != 0) - USBsetRAM(iopMem->Main); + USBsetRAM(iopMem->Main); // FIXME: LastELF should be reset on media changes as well as on CPU resets, in // the very unlikely case that a user swaps to another media source that "looks" diff --git a/pcsx2/USB/USB.cpp b/pcsx2/USB/USB.cpp index 8553fce6c8..de5b7eb40f 100644 --- a/pcsx2/USB/USB.cpp +++ b/pcsx2/USB/USB.cpp @@ -22,9 +22,7 @@ #include #include -#include "version.h" //CMake generated #include "USB.h" -#include "platcompat.h" #include "osdebugout.h" #include "qemu-usb/USBinternal.h" #include "qemu-usb/desc.h" @@ -33,8 +31,6 @@ #define PSXCLK 36864000 /* 36.864 Mhz */ -static char libraryName[256]; - OHCIState *qemu_ohci = NULL; USBDevice *usb_device[2] = { NULL }; bool configChanged = false; @@ -195,14 +191,8 @@ s32 USBinit() { if (conf.Log && !usbLog) { - usbLog = -#if _UNICODE - _wfopen(LogDir.c_str(), L"wb");// L"wb,ccs=UNICODE"); -#else - fopen(LogDir.c_str(), "w"); -#endif + usbLog = wfopen(LogDir.c_str(), "wb");// L"wb,ccs=UNICODE"); //if(usbLog) setvbuf(usbLog, NULL, _IONBF, 0); - USB_LOG("usbqemu wheel mod plugin version %d.%d.%d\n", VER_REV, VER_BLD, VER_FIX); USB_LOG("USBinit\n"); } @@ -239,7 +229,6 @@ s32 USBopen(void *pDsp) { { usbLog = fopen("logs/usbLog.txt", "a"); //if(usbLog) setvbuf(usbLog, NULL, _IONBF, 0); - USB_LOG("usbqemu wheel mod plugin version %d.%d.%d\n", VER_REV, VER_BLD, VER_FIX); } USB_LOG("USBopen\n"); diff --git a/pcsx2/USB/USB.h b/pcsx2/USB/USB.h index 435c63e060..54abfeb042 100644 --- a/pcsx2/USB/USB.h +++ b/pcsx2/USB/USB.h @@ -23,7 +23,7 @@ #include #include -#include "platcompat.h" +#include "SaveState.h" #include "osdebugout.h" // --------------------------------------------------------------------- diff --git a/pcsx2/USB/configuration.cpp b/pcsx2/USB/configuration.cpp index 59bdc4fb92..5e2a3645d7 100644 --- a/pcsx2/USB/configuration.cpp +++ b/pcsx2/USB/configuration.cpp @@ -12,7 +12,7 @@ TSTDSTRING IniPath = TSTDSTRING(TEXT("./inis/")) + iniFile; // default path, jus TSTDSTRING LogDir; CIniFile ciniFile; -EXPORT_C_(void) USBsetSettingsDir( const char* dir ) +void USBsetSettingsDir( const char* dir ) { #ifdef _UNICODE OSDebugOut(L"USBsetSettingsDir: %S\n", dir); @@ -29,7 +29,7 @@ EXPORT_C_(void) USBsetSettingsDir( const char* dir ) #endif } -EXPORT_C_(void) USBsetLogDir( const char* dir ) +void USBsetLogDir( const char* dir ) { #ifdef _UNICODE OSDebugOut(L"USBsetLogDir: %S\n", dir); diff --git a/pcsx2/USB/configuration.h b/pcsx2/USB/configuration.h index 1bb7b5195c..88e1d0b97b 100644 --- a/pcsx2/USB/configuration.h +++ b/pcsx2/USB/configuration.h @@ -1,12 +1,54 @@ #pragma once -#ifndef CONFIGURATION_H -#define CONFIGURATION_H + +#ifdef _WIN32 +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#define wfopen _wfopen +#define fseeko64 _fseeki64 +#define ftello64 _ftelli64 +#define TSTDSTRING std::wstring +#define TSTDSTRINGSTREAM std::wstringstream +#define TSTDTOSTRING std::to_wstring + +#ifdef _MSC_VER +typedef SSIZE_T ssize_t; +#endif + +//FIXME narrow string fmt +#ifdef UNICODE +#define SFMTs "S" +#endif + +#define __builtin_constant_p(p) false + +#else //_WIN32 + +#define MAX_PATH PATH_MAX +#define __inline inline + +//#ifndef TEXT +//#define TEXT(x) L##x +//#endif +//FIXME narrow string fmt +#define SFMTs "s" +#define TEXT(val) val +#define TCHAR char +#define wfopen fopen +#define TSTDSTRING std::string +#define TSTDSTRINGSTREAM std::stringstream +#define TSTDTOSTRING std::to_string + +void SysMessage(const char *fmt, ...); + +#endif //_WIN32 + #include #include #include #include -#include "platcompat.h" #include "osdebugout.h" #define RESULT_CANCELED 0 @@ -71,6 +113,9 @@ bool LoadSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TC bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, const std::string& value); #endif +void USBsetSettingsDir( const char* dir ); +void USBsetLogDir( const char* dir ); + template bool LoadSetting(const char* dev_type, int port, const std::string& key, const TCHAR* name, Type& var) { @@ -163,4 +208,8 @@ bool SaveSetting(const TCHAR* section, const TCHAR* key, const Type var) return ret; } -#endif +template +constexpr std::size_t countof(const T (&)[N]) noexcept +{ + return N; +} diff --git a/pcsx2/USB/osdebugout.h b/pcsx2/USB/osdebugout.h index 544e8a11fc..ad3ea84604 100644 --- a/pcsx2/USB/osdebugout.h +++ b/pcsx2/USB/osdebugout.h @@ -8,7 +8,6 @@ void __Log(const char* fmt, ...); #ifdef _WIN32 -#include "platcompat.h" #include void _OSDebugOut(const TCHAR *psz_fmt, ...); diff --git a/pcsx2/USB/platcompat.h b/pcsx2/USB/platcompat.h deleted file mode 100644 index 09dbe991fb..0000000000 --- a/pcsx2/USB/platcompat.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef PLATCOMPAT_H -#define PLATCOMPAT_H - -// Annoying defines -// --------------------------------------------------------------------- -// make sure __POSIX__ is defined for all systems where we assume POSIX -// compliance -#if defined(__linux__) || defined(__APPLE__) || defined(__unix__) || defined(__CYGWIN__) || defined(__LINUX__) -#if !defined(__POSIX__) -#define __POSIX__ 1 -#endif -#endif - -#ifdef _WIN32 -# define CALLBACK __stdcall -#else -# define CALLBACK __attribute__((stdcall)) -#endif - -#ifndef EXPORT_C_ -#ifdef _MSC_VER -#define EXPORT_C_(type) extern "C" type CALLBACK -#else -#define EXPORT_C_(type) extern "C" __attribute__((stdcall,externally_visible,visibility("default"))) type -//#define EXPORT_C_(type) extern "C" __attribute__((stdcall,visibility("default"))) type -#endif -#endif - -#ifdef _WIN32 -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include -#define wfopen _wfopen -#define fseeko64 _fseeki64 -#define ftello64 _ftelli64 -#define TSTDSTRING std::wstring -#define TSTDSTRINGSTREAM std::wstringstream -#define TSTDTOSTRING std::to_wstring - -#ifdef _MSC_VER -typedef SSIZE_T ssize_t; -#endif - -//FIXME narrow string fmt -#ifdef UNICODE -#define SFMTs "S" -#else -#define SFMTs "s" -#endif - -#define __builtin_constant_p(p) false - -#if _UNICODE -void SysMessageW(const wchar_t *fmt, ...); -#define SysMessage SysMessageW -#else -void SysMessageA(const char *fmt, ...); -#define SysMessage SysMessageA -#endif - -#ifndef _T -#define _T(x) L##x -#endif - -#else //_WIN32 - -#define MAX_PATH PATH_MAX -#define __inline inline - -//#ifndef TEXT -//#define TEXT(x) L##x -//#endif -//FIXME narrow string fmt -#define SFMTs "s" -#define TEXT(val) val -#define _T(x) x -#define TCHAR char -#define wfopen fopen -#define TSTDSTRING std::string -#define TSTDSTRINGSTREAM std::stringstream -#define TSTDTOSTRING std::to_string - -void SysMessage(const char *fmt, ...); - -#endif //_WIN32 - -#if __MINGW32__ - -#define DBL_EPSILON 2.2204460492503131e-16 -#define FLT_EPSILON 1.1920928955078125e-7f - -template -errno_t mbstowcs_s( - size_t *pReturnValue, - wchar_t (&wcstr)[size], - const char *mbstr, - size_t count -) -{ - return mbstowcs_s(pReturnValue, wcstr, size, mbstr, count); -} - -template -errno_t wcstombs_s( - size_t *pReturnValue, - char (&mbstr)[size], - const wchar_t *wcstr, - size_t count -) -{ - return wcstombs_s(pReturnValue, mbstr, size, wcstr, count); -} - -#endif //__MINGW32__ - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0]))) -#endif - -#include - -template -constexpr std::size_t countof(const T (&)[N]) noexcept -{ - return N; -} - -template -constexpr std::size_t countof(const T N) -{ - return N.size(); -} - -//TODO Idk, used only in desc.h and struct USBDescriptor should be already packed anyway -#if defined(_WIN32) && !defined(__MINGW32__) -#define PACK(def,name) __pragma( pack(push, 1) ) def name __pragma( pack(pop) ) -#elif defined(__clang__) -#define PACK(def,name) def __attribute__((packed)) name -#else -#define PACK(def,name) def __attribute__((gcc_struct, packed)) name -#endif -#endif diff --git a/pcsx2/USB/qemu-usb/bus.cpp b/pcsx2/USB/qemu-usb/bus.cpp index 3728e16297..3e3ae548ed 100644 --- a/pcsx2/USB/qemu-usb/bus.cpp +++ b/pcsx2/USB/qemu-usb/bus.cpp @@ -1,4 +1,3 @@ -#include "platcompat.h" #include "USBinternal.h" #include "vl.h" @@ -128,4 +127,4 @@ void usb_device_free_streams(USBDevice *dev, USBEndpoint **eps, int nr_eps) if (klass->free_streams) { klass->free_streams(dev, eps, nr_eps); } -} \ No newline at end of file +} diff --git a/pcsx2/USB/qemu-usb/core.cpp b/pcsx2/USB/qemu-usb/core.cpp index f7c977cd2b..495a7eb32c 100644 --- a/pcsx2/USB/qemu-usb/core.cpp +++ b/pcsx2/USB/qemu-usb/core.cpp @@ -23,7 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "platcompat.h" #include "osdebugout.h" #include "vl.h" #include "iov.h" diff --git a/pcsx2/USB/qemu-usb/desc.cpp b/pcsx2/USB/qemu-usb/desc.cpp index 5edfafe53c..07e612f215 100644 --- a/pcsx2/USB/qemu-usb/desc.cpp +++ b/pcsx2/USB/qemu-usb/desc.cpp @@ -1,5 +1,3 @@ -#include "platcompat.h" - #include "vl.h" #include "desc.h" #include "glib.h" @@ -848,4 +846,4 @@ int usb_desc_handle_control(USBDevice *dev, USBPacket *p, break; } return ret; -} \ No newline at end of file +} diff --git a/pcsx2/USB/qemu-usb/desc.h b/pcsx2/USB/qemu-usb/desc.h index b23d4c437f..6cb2ed7862 100644 --- a/pcsx2/USB/qemu-usb/desc.h +++ b/pcsx2/USB/qemu-usb/desc.h @@ -1,10 +1,16 @@ -#ifndef QEMU_HW_USB_DESC_H -#define QEMU_HW_USB_DESC_H +#pragma once -#include "platcompat.h" #include #include +#if defined(_WIN32) && !defined(__MINGW32__) +#define PACK(def,name) __pragma( pack(push, 1) ) def name __pragma( pack(pop) ) +#elif defined(__clang__) +#define PACK(def,name) def __attribute__((packed)) name +#else +#define PACK(def,name) def __attribute__((gcc_struct, packed)) name +#endif + /* binary representation */ PACK(typedef struct USBDescriptor { uint8_t bLength; @@ -244,4 +250,3 @@ int usb_desc_handle_control(USBDevice *dev, USBPacket *p, int usb_desc_set_config(USBDevice *dev, int value); int usb_desc_set_interface(USBDevice *dev, int index, int value); -#endif /* QEMU_HW_USB_DESC_H */ \ No newline at end of file diff --git a/pcsx2/USB/qemu-usb/iov.cpp b/pcsx2/USB/qemu-usb/iov.cpp index b2a71e345d..6d343425eb 100644 --- a/pcsx2/USB/qemu-usb/iov.cpp +++ b/pcsx2/USB/qemu-usb/iov.cpp @@ -16,7 +16,6 @@ * GNU GPL, version 2 or (at your option) any later version. */ -#include "platcompat.h" #include "vl.h" //#include "qemu-common.h" #include "iov.h" diff --git a/pcsx2/USB/qemu-usb/iov.h b/pcsx2/USB/qemu-usb/iov.h index 082a41d915..3d843992b8 100644 --- a/pcsx2/USB/qemu-usb/iov.h +++ b/pcsx2/USB/qemu-usb/iov.h @@ -13,7 +13,6 @@ #ifndef IOV_H #define IOV_H -#include "platcompat.h" /* ssize_t */ #if !defined(_BITS_UIO_H) && !defined(__iovec_defined) /* /usr/include/bits/uio.h */ struct iovec { diff --git a/pcsx2/USB/qemu-usb/usb-ohci.cpp b/pcsx2/USB/qemu-usb/usb-ohci.cpp index aed8098f73..628241e5eb 100644 --- a/pcsx2/USB/qemu-usb/usb-ohci.cpp +++ b/pcsx2/USB/qemu-usb/usb-ohci.cpp @@ -31,7 +31,6 @@ #include "vl.h" #include "queue.h" #include "USBinternal.h" -#include "platcompat.h" #include "../osdebugout.h" #define DMA_DIRECTION_TO_DEVICE 0 diff --git a/pcsx2/USB/shared/rawinput.cpp b/pcsx2/USB/shared/rawinput.cpp index de98a2766b..2d97a49e90 100644 --- a/pcsx2/USB/shared/rawinput.cpp +++ b/pcsx2/USB/shared/rawinput.cpp @@ -2,7 +2,6 @@ #include #include #include -#include "platcompat.h" #include "osdebugout.h" extern HINSTANCE hInst; @@ -270,4 +269,4 @@ void Uninitialize() eatenWnd = nullptr; } -}} //namespace \ No newline at end of file +}} //namespace diff --git a/pcsx2/USB/shared/ringbuffer.cpp b/pcsx2/USB/shared/ringbuffer.cpp index 1809ba6f1e..87662e78b4 100644 --- a/pcsx2/USB/shared/ringbuffer.cpp +++ b/pcsx2/USB/shared/ringbuffer.cpp @@ -2,7 +2,6 @@ #include #include #include "osdebugout.h" -#include "platcompat.h" #if 0 #define DPRINTF OSDebugOut diff --git a/pcsx2/USB/usb-hid/usb-hid.h b/pcsx2/USB/usb-hid/usb-hid.h index c4b275a37c..40a1fc6276 100644 --- a/pcsx2/USB/usb-hid/usb-hid.h +++ b/pcsx2/USB/usb-hid/usb-hid.h @@ -1,6 +1,6 @@ #pragma once #include "../configuration.h" -#include "qemu-usb/hid.h" +#include "../qemu-usb/hid.h" #include #include @@ -73,4 +73,4 @@ public: static int Freeze(int mode, USBDevice *dev, void *data); }; -} \ No newline at end of file +}