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/deviceproxy.h
USB/configuration.h
USB/platcompat.h
USB/osdebugout.h
USB/helpers.h
USB/readerwriterqueue/readerwriterqueue.h

View File

@ -22,6 +22,7 @@
#include "IopCommon.h"
#include "SPU2/spu2.h"
#include "DEV9/DEV9.h"
#include "USB/USB.h"
#include <math.h>
@ -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);

View File

@ -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);
}

View File

@ -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"

View File

@ -22,9 +22,7 @@
#include <cerrno>
#include <cassert>
#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");

View File

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

View File

@ -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);

View File

@ -1,12 +1,54 @@
#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 <string>
#include <map>
#include <sstream>
#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<typename Type>
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 <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, ...);
#ifdef _WIN32
#include "platcompat.h"
#include <vector>
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 "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);
}
}
}

View File

@ -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"

View File

@ -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;
}
}

View File

@ -1,10 +1,16 @@
#ifndef QEMU_HW_USB_DESC_H
#define QEMU_HW_USB_DESC_H
#pragma once
#include "platcompat.h"
#include <wchar.h>
#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 */
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 */

View File

@ -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"

View File

@ -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 {

View File

@ -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

View File

@ -2,7 +2,6 @@
#include <cstdio>
#include <vector>
#include <algorithm>
#include "platcompat.h"
#include "osdebugout.h"
extern HINSTANCE hInst;
@ -270,4 +269,4 @@ void Uninitialize()
eatenWnd = nullptr;
}
}} //namespace
}} //namespace

View File

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

View File

@ -1,6 +1,6 @@
#pragma once
#include "../configuration.h"
#include "qemu-usb/hid.h"
#include "../qemu-usb/hid.h"
#include <list>
#include <string>
@ -73,4 +73,4 @@ public:
static int Freeze(int mode, USBDevice *dev, void *data);
};
}
}