USB: continuing merge, platformcompat fixes

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2020-11-02 15:52:23 +01:00 committed by refractionpcsx2
parent de314d253e
commit 50969601bf
20 changed files with 90 additions and 207 deletions

View File

@ -364,7 +364,6 @@ set(pcsx2USBHeaders
USB/proxybase.h USB/proxybase.h
USB/deviceproxy.h USB/deviceproxy.h
USB/configuration.h USB/configuration.h
USB/platcompat.h
USB/osdebugout.h USB/osdebugout.h
USB/helpers.h USB/helpers.h
USB/readerwriterqueue/readerwriterqueue.h USB/readerwriterqueue/readerwriterqueue.h

View File

@ -22,6 +22,7 @@
#include "IopCommon.h" #include "IopCommon.h"
#include "SPU2/spu2.h" #include "SPU2/spu2.h"
#include "DEV9/DEV9.h" #include "DEV9/DEV9.h"
#include "USB/USB.h"
#include <math.h> #include <math.h>
@ -149,12 +150,9 @@ void psxRcntInit()
psxCounters[6].CycleT = psxCounters[6].rate; psxCounters[6].CycleT = psxCounters[6].rate;
psxCounters[6].mode = 0x8; psxCounters[6].mode = 0x8;
if (USBasync != NULL)
{
psxCounters[7].rate = PSXCLK / 1000; psxCounters[7].rate = PSXCLK / 1000;
psxCounters[7].CycleT = psxCounters[7].rate; psxCounters[7].CycleT = psxCounters[7].rate;
psxCounters[7].mode = 0x8; psxCounters[7].mode = 0x8;
}
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
psxCounters[i].sCycleT = psxRegs.cycle; psxCounters[i].sCycleT = psxRegs.cycle;
@ -516,22 +514,19 @@ void psxRcntUpdate()
c -= difference; c -= difference;
psxNextCounter = c; psxNextCounter = c;
DEV9async(1); DEV9async(1);
if(USBasync) const s32 diffusb = psxRegs.cycle - psxCounters[7].sCycleT;
{ s32 cusb = psxCounters[7].CycleT;
const s32 difference = psxRegs.cycle - psxCounters[7].sCycleT;
s32 c = psxCounters[7].CycleT;
if (difference >= psxCounters[7].CycleT) if (diffusb >= psxCounters[7].CycleT)
{ {
USBasync(difference); USBasync(diffusb);
psxCounters[7].sCycleT = psxRegs.cycle; psxCounters[7].sCycleT = psxRegs.cycle;
psxCounters[7].CycleT = psxCounters[7].rate; psxCounters[7].CycleT = psxCounters[7].rate;
} }
else else
c -= difference; cusb -= diffusb;
if (c < psxNextCounter) if (cusb < psxNextCounter)
psxNextCounter = c; psxNextCounter = cusb;
}
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
_rcntSet(i); _rcntSet(i);

View File

@ -16,6 +16,7 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "IopCommon.h" #include "IopCommon.h"
#include "DEV9/DEV9.h" #include "DEV9/DEV9.h"
#include "USB/USB.h"
using namespace R3000A; using namespace R3000A;
@ -33,8 +34,6 @@ void dev9Irq(int cycles)
void usbInterrupt() void usbInterrupt()
{ {
if (usbHandler != NULL && (usbHandler() != 1)) return;
iopIntcIrq(22); iopIntcIrq(22);
} }

View File

@ -32,6 +32,7 @@
#include "Elfheader.h" #include "Elfheader.h"
#include "CDVD/CDVD.h" #include "CDVD/CDVD.h"
#include "USB/USB.h"
#include "Patch.h" #include "Patch.h"
#include "GameDatabase.h" #include "GameDatabase.h"
@ -109,7 +110,6 @@ void cpuReset()
ElfEntry = -1; ElfEntry = -1;
// Probably not the right place, but it has to be done when the ram is actually initialized // 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 // FIXME: LastELF should be reset on media changes as well as on CPU resets, in

View File

@ -22,9 +22,7 @@
#include <cerrno> #include <cerrno>
#include <cassert> #include <cassert>
#include "version.h" //CMake generated
#include "USB.h" #include "USB.h"
#include "platcompat.h"
#include "osdebugout.h" #include "osdebugout.h"
#include "qemu-usb/USBinternal.h" #include "qemu-usb/USBinternal.h"
#include "qemu-usb/desc.h" #include "qemu-usb/desc.h"
@ -33,8 +31,6 @@
#define PSXCLK 36864000 /* 36.864 Mhz */ #define PSXCLK 36864000 /* 36.864 Mhz */
static char libraryName[256];
OHCIState *qemu_ohci = NULL; OHCIState *qemu_ohci = NULL;
USBDevice *usb_device[2] = { NULL }; USBDevice *usb_device[2] = { NULL };
bool configChanged = false; bool configChanged = false;
@ -195,14 +191,8 @@ s32 USBinit() {
if (conf.Log && !usbLog) if (conf.Log && !usbLog)
{ {
usbLog = usbLog = wfopen(LogDir.c_str(), "wb");// L"wb,ccs=UNICODE");
#if _UNICODE
_wfopen(LogDir.c_str(), L"wb");// L"wb,ccs=UNICODE");
#else
fopen(LogDir.c_str(), "w");
#endif
//if(usbLog) setvbuf(usbLog, NULL, _IONBF, 0); //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"); USB_LOG("USBinit\n");
} }
@ -239,7 +229,6 @@ s32 USBopen(void *pDsp) {
{ {
usbLog = fopen("logs/usbLog.txt", "a"); usbLog = fopen("logs/usbLog.txt", "a");
//if(usbLog) setvbuf(usbLog, NULL, _IONBF, 0); //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"); USB_LOG("USBopen\n");

View File

@ -23,7 +23,7 @@
#include <string> #include <string>
#include <limits.h> #include <limits.h>
#include "platcompat.h" #include "SaveState.h"
#include "osdebugout.h" #include "osdebugout.h"
// --------------------------------------------------------------------- // ---------------------------------------------------------------------

View File

@ -12,7 +12,7 @@ TSTDSTRING IniPath = TSTDSTRING(TEXT("./inis/")) + iniFile; // default path, jus
TSTDSTRING LogDir; TSTDSTRING LogDir;
CIniFile ciniFile; CIniFile ciniFile;
EXPORT_C_(void) USBsetSettingsDir( const char* dir ) void USBsetSettingsDir( const char* dir )
{ {
#ifdef _UNICODE #ifdef _UNICODE
OSDebugOut(L"USBsetSettingsDir: %S\n", dir); OSDebugOut(L"USBsetSettingsDir: %S\n", dir);
@ -29,7 +29,7 @@ EXPORT_C_(void) USBsetSettingsDir( const char* dir )
#endif #endif
} }
EXPORT_C_(void) USBsetLogDir( const char* dir ) void USBsetLogDir( const char* dir )
{ {
#ifdef _UNICODE #ifdef _UNICODE
OSDebugOut(L"USBsetLogDir: %S\n", dir); OSDebugOut(L"USBsetLogDir: %S\n", dir);

View File

@ -1,12 +1,54 @@
#pragma once #pragma once
#ifndef CONFIGURATION_H
#define CONFIGURATION_H #ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#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 <vector> #include <vector>
#include <string> #include <string>
#include <map> #include <map>
#include <sstream> #include <sstream>
#include "platcompat.h"
#include "osdebugout.h" #include "osdebugout.h"
#define RESULT_CANCELED 0 #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); bool SaveSettingValue(const TSTDSTRING& ini, const TSTDSTRING& section, const TCHAR* param, const std::string& value);
#endif #endif
void USBsetSettingsDir( const char* dir );
void USBsetLogDir( const char* dir );
template<typename Type> template<typename Type>
bool LoadSetting(const char* dev_type, int port, const std::string& key, const TCHAR* name, Type& var) 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; return ret;
} }
#endif template <class T, std::size_t N>
constexpr std::size_t countof(const T (&)[N]) noexcept
{
return N;
}

View File

@ -8,7 +8,6 @@
void __Log(const char* fmt, ...); void __Log(const char* fmt, ...);
#ifdef _WIN32 #ifdef _WIN32
#include "platcompat.h"
#include <vector> #include <vector>
void _OSDebugOut(const TCHAR *psz_fmt, ...); void _OSDebugOut(const TCHAR *psz_fmt, ...);

View File

@ -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 <windows.h>
#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 <size_t size>
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 <size_t size>
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 <cstddef>
template <class T, std::size_t N>
constexpr std::size_t countof(const T (&)[N]) noexcept
{
return N;
}
template <class T>
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

View File

@ -1,4 +1,3 @@
#include "platcompat.h"
#include "USBinternal.h" #include "USBinternal.h"
#include "vl.h" #include "vl.h"

View File

@ -23,7 +23,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "platcompat.h"
#include "osdebugout.h" #include "osdebugout.h"
#include "vl.h" #include "vl.h"
#include "iov.h" #include "iov.h"

View File

@ -1,5 +1,3 @@
#include "platcompat.h"
#include "vl.h" #include "vl.h"
#include "desc.h" #include "desc.h"
#include "glib.h" #include "glib.h"

View File

@ -1,10 +1,16 @@
#ifndef QEMU_HW_USB_DESC_H #pragma once
#define QEMU_HW_USB_DESC_H
#include "platcompat.h"
#include <wchar.h> #include <wchar.h>
#include <vector> #include <vector>
#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 */ /* binary representation */
PACK(typedef struct USBDescriptor { PACK(typedef struct USBDescriptor {
uint8_t bLength; 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_config(USBDevice *dev, int value);
int usb_desc_set_interface(USBDevice *dev, int index, int value); int usb_desc_set_interface(USBDevice *dev, int index, int value);
#endif /* QEMU_HW_USB_DESC_H */

View File

@ -16,7 +16,6 @@
* GNU GPL, version 2 or (at your option) any later version. * GNU GPL, version 2 or (at your option) any later version.
*/ */
#include "platcompat.h"
#include "vl.h" #include "vl.h"
//#include "qemu-common.h" //#include "qemu-common.h"
#include "iov.h" #include "iov.h"

View File

@ -13,7 +13,6 @@
#ifndef IOV_H #ifndef IOV_H
#define IOV_H #define IOV_H
#include "platcompat.h" /* ssize_t */
#if !defined(_BITS_UIO_H) && !defined(__iovec_defined) /* /usr/include/bits/uio.h */ #if !defined(_BITS_UIO_H) && !defined(__iovec_defined) /* /usr/include/bits/uio.h */
struct iovec { struct iovec {

View File

@ -31,7 +31,6 @@
#include "vl.h" #include "vl.h"
#include "queue.h" #include "queue.h"
#include "USBinternal.h" #include "USBinternal.h"
#include "platcompat.h"
#include "../osdebugout.h" #include "../osdebugout.h"
#define DMA_DIRECTION_TO_DEVICE 0 #define DMA_DIRECTION_TO_DEVICE 0

View File

@ -2,7 +2,6 @@
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include "platcompat.h"
#include "osdebugout.h" #include "osdebugout.h"
extern HINSTANCE hInst; extern HINSTANCE hInst;

View File

@ -2,7 +2,6 @@
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
#include "osdebugout.h" #include "osdebugout.h"
#include "platcompat.h"
#if 0 #if 0
#define DPRINTF OSDebugOut #define DPRINTF OSDebugOut

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../configuration.h" #include "../configuration.h"
#include "qemu-usb/hid.h" #include "../qemu-usb/hid.h"
#include <list> #include <list>
#include <string> #include <string>