diff --git a/build/win32/Cxbx.vcxproj b/build/win32/Cxbx.vcxproj index e5fddf549..2f63af725 100644 --- a/build/win32/Cxbx.vcxproj +++ b/build/win32/Cxbx.vcxproj @@ -367,6 +367,7 @@ + @@ -383,7 +384,7 @@ - + @@ -744,16 +745,6 @@ - - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) %(AdditionalIncludeDirectories) diff --git a/build/win32/Cxbx.vcxproj.filters b/build/win32/Cxbx.vcxproj.filters index 1030ad7c7..87dbdff57 100644 --- a/build/win32/Cxbx.vcxproj.filters +++ b/build/win32/Cxbx.vcxproj.filters @@ -293,7 +293,6 @@ Hardware\Usb - Hardware\Usb @@ -315,6 +314,9 @@ Shared\Input + + Cross Platform + @@ -599,9 +601,6 @@ Hardware\Usb - - Shared - Hardware\Usb @@ -617,6 +616,12 @@ Shared\Input + + Shared + + + Cross Platform + diff --git a/src/Common/CxbxCommon.cpp b/src/Common/CxbxCommon.cpp index cb85352ba..1bbc5aceb 100644 --- a/src/Common/CxbxCommon.cpp +++ b/src/Common/CxbxCommon.cpp @@ -9,7 +9,7 @@ // * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, // * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, // * -// * Cxbx->Common->Cxbx.cpp +// * Cxbx->Common->CxbxCommon.cpp // * // * This file is part of the Cxbx project. // * @@ -36,7 +36,8 @@ // The intent of this file is to add general functions which are not kernel specific (for those CxbxKrnl.h should be used instead) -#include "CxbxKrnl\CxbxKrnl.h" +#include "CxbxCommon.h" +#include "CxbxKrnl\CxbxKrnl.h" #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/src/Common/CxbxCommon.h b/src/Common/CxbxCommon.h new file mode 100644 index 000000000..5a8bf3e0e --- /dev/null +++ b/src/Common/CxbxCommon.h @@ -0,0 +1,74 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check it. +// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Common->CxbxCommon.h +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2018 ergo720 +// * +// * All rights reserved +// * +// ****************************************************************** + +#ifndef CXBX_COMMON_H +#define CXBX_COMMON_H + +#include "Cxbx.h" +#include +#include + +/* This is a linux struct for vectored I/O. See readv() and writev() */ +struct IoVec +{ + void* Iov_Base; // Starting address + size_t Iov_Len; // Number of bytes to transfer +}; + +struct IOVector +{ + IoVec* IoVecStruct; + int IoVecNumber; // number of I/O buffers supplied + int AllocNumber; // number of IoVec structs currently allocated + size_t Size; // total size of all I/O buffers supplied +}; + +uint64_t Muldiv64(uint64_t a, uint32_t b, uint32_t c); + +void IoVecReset(IOVector* qiov); +void IoVecAdd(IOVector* qiov, void* base, size_t len); +size_t IoVecTobuffer(const IoVec* iov, const unsigned int iov_cnt, size_t offset, void *buf, size_t bytes); +size_t IoVecFromBuffer(const IoVec* iov, unsigned int iov_cnt, size_t offset, void* buf, size_t bytes); + +void WriteDwords(xbaddr Paddr, uint32_t* Buffer, int Number); +void GetDwords(xbaddr Paddr, uint32_t* Buffer, int Number); +void GetWords(xbaddr Paddr, uint16_t* Buffer, int Number); +void WriteWords(xbaddr Paddr, uint16_t* Buffer, int Number); + +#define GET_WORD_LOW(value) (uint8_t)((value) & 0xFF) +#define GET_WORD_HIGH(value) (uint8_t)(((value) >> 8) & 0xFF) + +#endif diff --git a/src/Common/CxbxDebugger.cpp b/src/Common/CxbxDebugger.cpp index b0f940156..76673a685 100644 --- a/src/Common/CxbxDebugger.cpp +++ b/src/Common/CxbxDebugger.cpp @@ -32,7 +32,7 @@ // * // ****************************************************************** -#include "CxbxCommon.h" +#include "Cxbx.h" #include "CxbxKrnl/EmuShared.h" #include "CxbxDebugger.h" diff --git a/src/Common/EmuEEPROM.cpp b/src/Common/EmuEEPROM.cpp index 1a0f78c29..d12b537cf 100644 --- a/src/Common/EmuEEPROM.cpp +++ b/src/Common/EmuEEPROM.cpp @@ -44,7 +44,7 @@ namespace xboxkrnl #include // For printf #include // For HANDLE, CreateFile, CreateFileMapping, MapViewOfFile -#include "CxbxCommon.h" // For DbgPrintf +#include "Cxbx.h" // For DbgPrintf #include "EmuEEPROM.h" // For EEPROMInfo, EEPROMInfos #include "..\CxbxKrnl\Emu.h" // For EmuWarning #include "..\..\src\devices\LED.h" // For SetLEDSequence diff --git a/src/Common/Error.h b/src/Common/Error.h index 07b071700..428015ec2 100644 --- a/src/Common/Error.h +++ b/src/Common/Error.h @@ -34,7 +34,7 @@ #ifndef ERROR_H #define ERROR_H -#include "CxbxCommon.h" +#include "Cxbx.h" #include diff --git a/src/Common/Input/InputConfig.cpp b/src/Common/Input/InputConfig.cpp index 1c9843e6b..4e2deb882 100644 --- a/src/Common/Input/InputConfig.cpp +++ b/src/Common/Input/InputConfig.cpp @@ -34,7 +34,16 @@ // * // ****************************************************************** +#define _XBOXKRNL_DEFEXTRN_ + +// prevent name collisions +namespace xboxkrnl +{ + #include // For PKINTERRUPT, etc. +}; + #include "InputConfig.h" +#include "SDL2_Device.h" #include "..\devices\usb\XidGamepad.h" #include "..\..\CxbxKrnl\EmuKrnl.h" // For EmuWarning #include @@ -324,6 +333,7 @@ void InputDeviceManager::InputThread(InputDeviceManager* pVoid) } default: + break; } } } @@ -377,6 +387,7 @@ void InputDeviceManager::UpdateButtonState(SDL_JoystickID id, uint8_t button, ui break; } default: + break; } } diff --git a/src/Common/Input/InputConfig.h b/src/Common/Input/InputConfig.h index f04cbafff..1d6a28e1d 100644 --- a/src/Common/Input/InputConfig.h +++ b/src/Common/Input/InputConfig.h @@ -70,8 +70,6 @@ #define BUTTON_MASK(button) (1 << ((button) - GAMEPAD_DPAD_UP)) -#include "SDL2_Device.h" - /* enum indicating the device type to attach to the virtual xbox */ typedef enum { @@ -83,7 +81,10 @@ typedef enum { MEMORY_UNIT, IR_DONGLE, STEEL_BATTALION_CONTROLLER, -}; +} +XBOX_INPUT_DEVICE; + +class SDL2Devices; // forward declare class InputDeviceManager diff --git a/src/Common/Logging.h b/src/Common/Logging.h index def3b4a51..5f5e7bff3 100644 --- a/src/Common/Logging.h +++ b/src/Common/Logging.h @@ -40,7 +40,7 @@ #include // For std::stringstream #include // For std::cout #include // For std::setw -#include "CxbxCommon.h" // For g_bPrintfOn +#include "Cxbx.h" // For g_bPrintfOn // diff --git a/src/Common/Win32/XBAudio.h b/src/Common/Win32/XBAudio.h index 850d8d892..d4d28436c 100644 --- a/src/Common/Win32/XBAudio.h +++ b/src/Common/Win32/XBAudio.h @@ -34,7 +34,7 @@ #ifndef XBAUDIO_H #define XBAUDIO_H -#include "CxbxCommon.h" +#include "Cxbx.h" #include "Common/Error.h" #include "Mutex.h" diff --git a/src/Common/Win32/XBController.h b/src/Common/Win32/XBController.h index 742392abe..1758effd4 100644 --- a/src/Common/Win32/XBController.h +++ b/src/Common/Win32/XBController.h @@ -34,7 +34,7 @@ #ifndef XBCONTROLLER_H #define XBCONTROLLER_H -#include "CxbxCommon.h" +#include "Cxbx.h" #include "Common/Error.h" #include "Mutex.h" diff --git a/src/Common/Win32/XBVideo.h b/src/Common/Win32/XBVideo.h index 834065249..43630e44d 100644 --- a/src/Common/Win32/XBVideo.h +++ b/src/Common/Win32/XBVideo.h @@ -34,7 +34,7 @@ #ifndef XBVIDEO_H #define XBVIDEO_H -#include "CxbxCommon.h" +#include "Cxbx.h" #include "Common/Error.h" #include "Mutex.h" diff --git a/src/CxbxCommon.h b/src/Cxbx.h similarity index 80% rename from src/CxbxCommon.h rename to src/Cxbx.h index 1a1bd25cc..56b9ad612 100644 --- a/src/CxbxCommon.h +++ b/src/Cxbx.h @@ -34,10 +34,6 @@ #ifndef CXBX_H #define CXBX_H -#include -#include -#include - #define FUNC_EXPORTS __pragma(comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)) /*! \name primitive typedefs */ @@ -161,35 +157,4 @@ extern volatile bool g_bPrintfOn; #define CxbxSetThreadName(Name) #endif - -/* This is a linux struct for vectored I/O. See readv() and writev() */ -struct IoVec -{ - void* Iov_Base; // Starting address - size_t Iov_Len; // Number of bytes to transfer -}; - -struct IOVector -{ - IoVec* IoVecStruct; - int IoVecNumber; // number of I/O buffers supplied - int AllocNumber; // number of IoVec structs currently allocated - size_t Size; // total size of all I/O buffers supplied -}; - -inline uint64_t Muldiv64(uint64_t a, uint32_t b, uint32_t c); - -void IoVecReset(IOVector* qiov); -void IoVecAdd(IOVector* qiov, void* base, size_t len); -size_t IoVecTobuffer(const IoVec* iov, const unsigned int iov_cnt, size_t offset, void *buf, size_t bytes); -size_t IoVecFromBuffer(const IoVec* iov, unsigned int iov_cnt, size_t offset, void* buf, size_t bytes); - -void WriteDwords(xbaddr Paddr, uint32_t* Buffer, int Number); -void GetDwords(xbaddr Paddr, uint32_t* Buffer, int Number); -void GetWords(xbaddr Paddr, uint16_t* Buffer, int Number); -void WriteWords(xbaddr Paddr, uint16_t* Buffer, int Number); - -#define GET_WORD_LOW(value) (uint8_t)((value) & 0xFF) -#define GET_WORD_HIGH(value) (uint8_t)(((value) >> 8) & 0xFF) - #endif diff --git a/src/Cxbx/CxbxXbdm.cpp b/src/Cxbx/CxbxXbdm.cpp index e8804dfc9..c25878876 100644 --- a/src/Cxbx/CxbxXbdm.cpp +++ b/src/Cxbx/CxbxXbdm.cpp @@ -42,7 +42,7 @@ #include #include -#include "CxbxCommon.h" +#include "Cxbx.h" #include "Logging.h" namespace xbdm { diff --git a/src/CxbxKrnl/CxbxKrnl.h b/src/CxbxKrnl/CxbxKrnl.h index e3542e86d..9bf123098 100644 --- a/src/CxbxKrnl/CxbxKrnl.h +++ b/src/CxbxKrnl/CxbxKrnl.h @@ -34,7 +34,7 @@ #ifndef CXBXKRNL_H #define CXBXKRNL_H -#include "CxbxCommon.h" +#include "Cxbx.h" #include "Common/Xbe.h" #undef FIELD_OFFSET // prevent macro redefinition warnings diff --git a/src/CxbxKrnl/DbgConsole.h b/src/CxbxKrnl/DbgConsole.h index 589f2ca70..90e0379f8 100644 --- a/src/CxbxKrnl/DbgConsole.h +++ b/src/CxbxKrnl/DbgConsole.h @@ -34,7 +34,7 @@ #ifndef DBGCONSOLE_H #define DBGCONSOLE_H -#include "CxbxCommon.h" +#include "Cxbx.h" // debug console input class DbgConsole diff --git a/src/CxbxKrnl/EmuD3D8/PixelShader.h b/src/CxbxKrnl/EmuD3D8/PixelShader.h index 9d7364eda..28a80a604 100644 --- a/src/CxbxKrnl/EmuD3D8/PixelShader.h +++ b/src/CxbxKrnl/EmuD3D8/PixelShader.h @@ -36,7 +36,7 @@ #pragma once -#include "CxbxCommon.h" +#include "Cxbx.h" // dump pixel shader definition to file void DumpPixelShaderDefToFile( X_D3DPIXELSHADERDEF* pPSDef, const char* pszCode ); diff --git a/src/CxbxKrnl/EmuD3D8/VertexBuffer.h b/src/CxbxKrnl/EmuD3D8/VertexBuffer.h index 38bb60ad2..97c725af3 100755 --- a/src/CxbxKrnl/EmuD3D8/VertexBuffer.h +++ b/src/CxbxKrnl/EmuD3D8/VertexBuffer.h @@ -34,7 +34,7 @@ #ifndef VERTEXBUFFER_H #define VERTEXBUFFER_H -#include "CxbxCommon.h" +#include "Cxbx.h" //#include // Conflict with io.h #define MAX_NBR_STREAMS 16 diff --git a/src/CxbxKrnl/EmuD3D8/VertexShader.h b/src/CxbxKrnl/EmuD3D8/VertexShader.h index 525192b37..fff149950 100644 --- a/src/CxbxKrnl/EmuD3D8/VertexShader.h +++ b/src/CxbxKrnl/EmuD3D8/VertexShader.h @@ -34,7 +34,7 @@ #ifndef VERTEXSHADER_H #define VERTEXSHADER_H -#include "CxbxCommon.h" +#include "Cxbx.h" // nv2a microcode header typedef struct diff --git a/src/CxbxKrnl/EmuShared.h b/src/CxbxKrnl/EmuShared.h index 851d73fc2..3c78f8b40 100644 --- a/src/CxbxKrnl/EmuShared.h +++ b/src/CxbxKrnl/EmuShared.h @@ -34,7 +34,7 @@ #ifndef EMUSHARED_H #define EMUSHARED_H -#include "CxbxCommon.h" +#include "Cxbx.h" #include "Common/Win32/XBController.h" #include "Common/Win32/XBVideo.h" #include "Common/Win32/XBAudio.h" diff --git a/src/CxbxKrnl/EmuX86.h b/src/CxbxKrnl/EmuX86.h index f739a873e..6b2423c5a 100644 --- a/src/CxbxKrnl/EmuX86.h +++ b/src/CxbxKrnl/EmuX86.h @@ -34,7 +34,7 @@ #ifndef EMUX86_H #define EMUX86_H -#include "CxbxCommon.h" +#include "Cxbx.h" #include #include diff --git a/src/CxbxKrnl/KernelThunk.cpp b/src/CxbxKrnl/KernelThunk.cpp index 9c836519a..644003f92 100644 --- a/src/CxbxKrnl/KernelThunk.cpp +++ b/src/CxbxKrnl/KernelThunk.cpp @@ -41,7 +41,7 @@ namespace xboxkrnl #include }; -#include "CxbxCommon.h" // For CxbxKrnl_KernelThunkTable +#include "Cxbx.h" // For CxbxKrnl_KernelThunkTable #include "CxbxKrnl.h" // For UINT #define FUNC(f) f diff --git a/src/CxbxKrnl/ResourceTracker.h b/src/CxbxKrnl/ResourceTracker.h index 887b48830..799bfd833 100644 --- a/src/CxbxKrnl/ResourceTracker.h +++ b/src/CxbxKrnl/ResourceTracker.h @@ -34,7 +34,7 @@ #ifndef RESOURCETRACKER_H #define RESOURCETRACKER_H -#include "CxbxCommon.h" +#include "Cxbx.h" #include "Common/Win32/Mutex.h" extern class ResourceTracker : public Mutex diff --git a/src/CxbxKrnl/Timer.cpp b/src/CxbxKrnl/Timer.cpp index 70d23d4e4..782e5acdf 100644 --- a/src/CxbxKrnl/Timer.cpp +++ b/src/CxbxKrnl/Timer.cpp @@ -72,7 +72,7 @@ inline uint64_t GetTime_NS(TimerObject* Timer) clock_gettime(CLOCK_MONOTONIC_RAW, &ts); uint64_t Ret = Muldiv64(ts.tv_sec, SCALE_S, 1) + ts.tv_nsec; #else -#error +#error "Unsupported OS" #endif return Timer->Type == CLOCK_REALTIME ? Ret : Ret / Timer->SlowdownFactor; } @@ -162,6 +162,6 @@ void Timer_Init() #elif __linux__ ClockFrequency = 0; #else -#error +#error "Unsupported OS" #endif } diff --git a/src/devices/Xbox.cpp b/src/devices/Xbox.cpp index 302afff58..558db59c4 100644 --- a/src/devices/Xbox.cpp +++ b/src/devices/Xbox.cpp @@ -35,6 +35,7 @@ // ****************************************************************** #include "Xbox.h" // For HardwareModel +#include "Xbe.h" // Without this HLEIntercept complains about some undefined xbe variables #include "..\CxbxKrnl\HLEIntercept.h" PCIBus* g_PCIBus; diff --git a/src/devices/usb/Hub.cpp b/src/devices/usb/Hub.cpp index f985c3053..f13ceb72c 100644 --- a/src/devices/usb/Hub.cpp +++ b/src/devices/usb/Hub.cpp @@ -34,8 +34,17 @@ // * // ****************************************************************** +#define _XBOXKRNL_DEFEXTRN_ + +// prevent name collisions +namespace xboxkrnl +{ + #include // For PKINTERRUPT, etc. +}; + #include "OHCI.h" #include "Hub.h" +#include "CxbxKrnl\EmuKrnl.h" // For EmuWarning #define LOG_STR_HUB "Hub" @@ -96,62 +105,61 @@ struct USBHubState { USBHubPort ports[NUM_PORTS]; // downstream ports of the hub }; -USBDescIface::USBDescIface() -{ - std::memset(this, 0, sizeof(USBDescIface)); - eps = new USBDescEndpoint(); - bInterfaceNumber = 0; - bNumEndpoints = 1; - bInterfaceClass = USB_CLASS_HUB; - eps->bEndpointAddress = USB_DIR_IN | 0x01; - eps->bmAttributes = USB_ENDPOINT_XFER_INT; - eps->wMaxPacketSize = 1 + (NUM_PORTS + 7) / 8; - eps->bInterval = 0xFF; -} +static const USBDescEndpoint desc_endp_hub = { + USB_DIR_IN | 0x01, // bEndpointAddress; + USB_ENDPOINT_XFER_INT, // bmAttributes; + 1 + (NUM_PORTS + 7) / 8, // wMaxPacketSize; + 0xFF, // bInterval; + 0, // bRefresh; + 0, // bSynchAddress + 0, // is_audio + nullptr // extra +}; + +static const USBDescIface desc_iface_hub = { + 0, // bInterfaceNumber; + 0, // bAlternateSetting; + 1, // bNumEndpoints; + USB_CLASS_HUB, // bInterfaceClass; + 0, // bInterfaceSubClass + 0, // bInterfaceProtocol + 0, // iInterface + 0, // ndesc + nullptr, // descs + &desc_endp_hub +}; -USBDescIface::~USBDescIface() -{ - delete eps; -} - -static const USBDescIface desc_iface_hub; - -USBDescDevice::USBDescDevice() -{ - std::memset(this, 0, sizeof(USBDescDevice)); - USBDescConfig* pUSBDescConfig = new USBDescConfig(); - bcdUSB = 0x0110; - bDeviceClass = USB_CLASS_HUB; - bMaxPacketSize0 = 8; - bNumConfigurations = 1; - pUSBDescConfig->bNumInterfaces = 1; - pUSBDescConfig->bConfigurationValue = 1; - pUSBDescConfig->bmAttributes = 0xE0; - pUSBDescConfig->nif = 1; - pUSBDescConfig->ifs = &desc_iface_hub; - confs = pUSBDescConfig; -} - -USBDescDevice::~USBDescDevice() -{ - delete confs; -} - -static const USBDescDevice desc_device_hub; - -USBDesc::USBDesc() -{ - std::memset(this, 0, sizeof(USBDesc)); - id.idVendor = 0x0409; - id.idProduct = 0x55AA; - id.bcdDevice = 0x0101; - id.iManufacturer = STR_MANUFACTURER; - id.iProduct = STR_PRODUCT; - id.iSerialNumber = STR_SERIALNUMBER; - full = &desc_device_hub; -} - -static const USBDesc desc_hub; +static const USBDescConfig desc_config_hub = { + 1, // bNumInterfaces + 1, // bConfigurationValue + 0, // iConfiguration + 0xE0, // bmAttributes + 0, // bMaxPower + 1, // nif + &desc_iface_hub +}; + +static const USBDescDevice desc_device_hub = { + 0x0110, // bcdUSB + USB_CLASS_HUB, // bDeviceClass + 0, // bDeviceSubClass + 0, // bDeviceProtocol + 8, // bMaxPacketSize0 + 1, // bNumConfigurations + &desc_config_hub +}; + +static const USBDesc desc_hub = { + { + 0x0409, // idVendor + 0x55AA, // idProduct + 0x0101, // bcdDevice + STR_MANUFACTURER, // iManufacturer + STR_PRODUCT, // iProduct + STR_SERIALNUMBER // iSerialNumber + }, + &desc_device_hub +}; // Class-specific hub descriptor. Remember to update DeviceRemovable and PortPwrCtrlMask if you change NUM_PORTS since their values depend on // the number of downstream ports available on the hub! Also note that this descriptor cannot be put in the descs member of the interface descriptor diff --git a/src/devices/usb/OHCI.cpp b/src/devices/usb/OHCI.cpp index 386609b37..26d293849 100644 --- a/src/devices/usb/OHCI.cpp +++ b/src/devices/usb/OHCI.cpp @@ -33,9 +33,18 @@ // * All rights reserved // * // ****************************************************************** + +#define _XBOXKRNL_DEFEXTRN_ + +/* prevent name collisions */ +namespace xboxkrnl +{ + #include +}; #include "OHCI.h" -#include "CxbxKrnl\EmuKrnl.h" // For HalSystemInterrupt +#include "CxbxKrnl\EmuKrnl.h" // For HalSystemInterrupt +#include "CxbxCommon.h" #define LOG_STR_OHCI "Ohci" diff --git a/src/devices/usb/USBDevice.cpp b/src/devices/usb/USBDevice.cpp index af20dc099..0cbd8fd6b 100644 --- a/src/devices/usb/USBDevice.cpp +++ b/src/devices/usb/USBDevice.cpp @@ -33,10 +33,19 @@ // * All rights reserved // * // ****************************************************************** + +#define _XBOXKRNL_DEFEXTRN_ + +// prevent name collisions +namespace xboxkrnl +{ + #include // For PKINTERRUPT, etc. +}; #include "USBDevice.h" #include "OHCI.h" -#include "CxbxKrnl\EmuKrnl.h" // For EmuWarning +#include "CxbxKrnl\EmuKrnl.h" // For EmuWarning +#include "CxbxCommon.h" #define LOG_STR_USB "Usb" @@ -628,7 +637,7 @@ void USBDevice::USB_EPsetType(XboxDeviceState* dev, int pid, int ep, uint8_t typ uep->Type = type; } -uint8_t USBDevice::USB_EPsetIfnum(XboxDeviceState* dev, int pid, int ep, uint8_t ifnum) +void USBDevice::USB_EPsetIfnum(XboxDeviceState* dev, int pid, int ep, uint8_t ifnum) { USBEndpoint* uep = USB_GetEP(dev, pid, ep); uep->IfNum = ifnum; @@ -1031,7 +1040,7 @@ int USBDevice::USBDesc_HandleStandardGetDescriptor(XboxDeviceState* dev, USBPack break; } - // Dropped from XQEMU descriptor types USB_DT_DEVICE_QUALIFIER (6), USB_DT_OTHER_SPEED_CONFIG (7) -> usb 2.0 only and reserved on usb 3.0, + // Dropped from XQEMU descriptor types USB_DT_DEVICE_QUALIFIER (6), USB_DT_OTHER_SPEED_CONFIG (7) -> usb 2.0 only and reserved in usb 3.0, // USB_DT_BOS (15) and USB_DT_DEBUG (10) -> usb 3.0 only default: @@ -1168,9 +1177,9 @@ int USBDevice::USB_ReadInterfaceDesc(const USBDescIface* iface, int flags, uint8 return pos; } -int USBDevice::USB_ReadOtherDesc(const USBDescOther* desc, uint8_t* dest, size_t len) +size_t USBDevice::USB_ReadOtherDesc(const USBDescOther* desc, uint8_t* dest, size_t len) { - int bLength = desc->length ? desc->length : desc->data[0]; + size_t bLength = desc->length ? desc->length : desc->data[0]; if (len < bLength) { return -1; @@ -1182,15 +1191,15 @@ int USBDevice::USB_ReadOtherDesc(const USBDescOther* desc, uint8_t* dest, size_t int USBDevice::USB_ReadEndpointDesc(const USBDescEndpoint* ep, int flags, uint8_t* dest, size_t len) { - uint8_t bLength = ep->is_audio ? 0x09 : 0x07; // an endpoint descriptor is 7 bytes large (or 9 if it is an audio device) - uint8_t extralen = ep->extra ? ep->extra[0] : 0; + size_t bLength = ep->is_audio ? 0x09 : 0x07; // an endpoint descriptor is 7 bytes large (or 9 if it is an audio device) + size_t extralen = ep->extra ? ep->extra[0] : 0; USBDescriptor* d = reinterpret_cast(dest); if (len < bLength + extralen) { return -1; } - d->bLength = bLength; + d->bLength = static_cast(bLength); d->bDescriptorType = USB_DT_ENDPOINT; d->u.endpoint.bEndpointAddress = ep->bEndpointAddress; @@ -1214,7 +1223,8 @@ int USBDevice::USB_ReadEndpointDesc(const USBDescEndpoint* ep, int flags, uint8_ int USBDevice::USB_ReadStringDesc(XboxDeviceState* dev, int index, uint8_t* dest, size_t len) { - uint8_t bLength, pos, i; + size_t bLength, i; + unsigned int pos; const char* str; if (len < 4) { diff --git a/src/devices/usb/USBDevice.h b/src/devices/usb/USBDevice.h index f88cbdda3..401b2cb8f 100644 --- a/src/devices/usb/USBDevice.h +++ b/src/devices/usb/USBDevice.h @@ -57,7 +57,7 @@ class USBDevice : public PCIDevice { void Init(unsigned int address); void Reset() {} - uint32_t IORead(int barIndex, uint32_t port, unsigned size) {} + uint32_t IORead(int barIndex, uint32_t port, unsigned size) { return 0; } void IOWrite(int barIndex, uint32_t port, uint32_t value, unsigned size) {} uint32_t MMIORead(int barIndex, uint32_t addr, unsigned size); void MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size); @@ -146,7 +146,7 @@ class USBDevice : public PCIDevice { // set the type of the endpoint void USB_EPsetType(XboxDeviceState* dev, int pid, int ep, uint8_t type); // set the interface number of the endpoint - uint8_t USB_EPsetIfnum(XboxDeviceState* dev, int pid, int ep, uint8_t ifnum); + void USB_EPsetIfnum(XboxDeviceState* dev, int pid, int ep, uint8_t ifnum); // set the maximum packet size parameter of the endpoint void USB_EPsetMaxPacketSize(XboxDeviceState* dev, int pid, int ep, uint16_t raw); // assign port numbers (also for hubs) @@ -184,7 +184,7 @@ class USBDevice : public PCIDevice { // return the binary rapresentation of interface descriptors int USB_ReadInterfaceDesc(const USBDescIface* iface, int flags, uint8_t* dest, size_t len); // return the binary rapresentation of class-specific descriptors - int USB_ReadOtherDesc(const USBDescOther* desc, uint8_t* dest, size_t len); + size_t USB_ReadOtherDesc(const USBDescOther* desc, uint8_t* dest, size_t len); // return the binary rapresentation of endpoint descriptors int USB_ReadEndpointDesc(const USBDescEndpoint* ep, int flags, uint8_t* dest, size_t len); // return the binary rapresentation of string descriptors diff --git a/src/devices/usb/UsbCommon.h b/src/devices/usb/UsbCommon.h index 33e2837a3..3efe6135e 100644 --- a/src/devices/usb/UsbCommon.h +++ b/src/devices/usb/UsbCommon.h @@ -39,7 +39,6 @@ #include "CxbxCommon.h" #include "..\devices\video\queue.h" -#include "..\CxbxKrnl\EmuKrnl.h" // For EmuWarning #include #define USB_MAX_ENDPOINTS 15 @@ -157,10 +156,13 @@ typedef enum { STR_MANUFACTURER = 1, STR_PRODUCT, STR_SERIALNUMBER, -}; +} +STRING_DESC_INDEX; +// Forward declarations struct USBPacket; struct XboxDeviceState; +struct USBPortOps; /* String descriptor */ struct USBDescString { @@ -203,9 +205,7 @@ struct USBDescIface { uint8_t ndesc; // number of device-specific class descriptors (if any) USBDescOther* descs; // pointer to the extra class descriptors - USBDescEndpoint* eps; // endpoints supported by this interface - USBDescIface(); - ~USBDescIface(); + const USBDescEndpoint* eps; // endpoints supported by this interface }; /* @@ -234,8 +234,6 @@ struct USBDescDevice { uint8_t bMaxPacketSize0; // maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid) uint8_t bNumConfigurations; // number of possible configurations const USBDescConfig* confs; // configurations supported by this device - USBDescDevice(); - ~USBDescDevice(); }; /* Device descriptor part 2 */ @@ -252,7 +250,6 @@ struct USBDescID { struct USBDesc { USBDescID id; // id-specific info of the device descriptor const USBDescDevice* full; // remaining fields of the device descriptor - USBDesc(); }; #pragma pack(1) @@ -326,6 +323,63 @@ struct USBEndpoint { QTAILQ_HEAD(, USBPacket) Queue; // queue of packets to this endpoint }; +/* Struct describing the status of a usb port */ +struct USBPort { + XboxDeviceState* Dev; // usb device (if present) + USBPortOps* Operations; // functions to call when a port event happens + int SpeedMask; // usb speeds supported + std::string Path; // the number of the port + 1, used to create a serial number for this device + int PortIndex; // internal port index +}; + +/* Struct which stores general functions/variables regarding the peripheral */ +struct USBDeviceClass { + std::function init; + + // Walk (enabled) downstream ports, check for a matching device. + // Only hubs implement this. + std::function find_device; + + // Called when a packet is canceled. + std::function cancel_packet; + + // Called when device is destroyed. + std::function handle_destroy; + + // Attach the device + std::function handle_attach; + + // Reset the device + std::function handle_reset; + + // Process control request. + // Called from handle_packet(). + // Status gets stored in p->status, and if p->status == USB_RET_SUCCESS + // then the number of bytes transferred is stored in p->actual_length + std::function handle_control; + + // Process data transfers (both BULK and ISOC). + // Called from handle_packet(). + // Status gets stored in p->status, and if p->status == USB_RET_SUCCESS + // then the number of bytes transferred is stored in p->actual_length + std::function handle_data; + + std::function set_interface; + + // Called when the hcd is done queuing packets for an endpoint, only + // necessary for devices which can return USB_RET_ADD_TO_QUEUE. + std::function flush_ep_queue; + + // Called by the hcd to let the device know the queue for an endpoint + // has been unlinked / stopped. Optional may be NULL. + std::function ep_stopped; + + const char* product_desc; // friendly name of the device + const USBDesc* usb_desc; // device descriptor +}; + /* definition of an Xbox usb device */ struct XboxDeviceState { USBPort* Port; // usb port struct of this device @@ -402,61 +456,4 @@ struct USBPortOps { std::function complete; }; -/* Struct describing the status of a usb port */ -struct USBPort { - XboxDeviceState* Dev; // usb device (if present) - USBPortOps* Operations; // functions to call when a port event happens - int SpeedMask; // usb speeds supported - std::string Path; // the number of the port + 1, used to create a serial number for this device - int PortIndex; // internal port index -}; - -/* Struct which stores general functions/variables regarding the peripheral */ -struct USBDeviceClass { - std::function init; - - // Walk (enabled) downstream ports, check for a matching device. - // Only hubs implement this. - std::function find_device; - - // Called when a packet is canceled. - std::function cancel_packet; - - // Called when device is destroyed. - std::function handle_destroy; - - // Attach the device - std::function handle_attach; - - // Reset the device - std::function handle_reset; - - // Process control request. - // Called from handle_packet(). - // Status gets stored in p->status, and if p->status == USB_RET_SUCCESS - // then the number of bytes transferred is stored in p->actual_length - std::function handle_control; - - // Process data transfers (both BULK and ISOC). - // Called from handle_packet(). - // Status gets stored in p->status, and if p->status == USB_RET_SUCCESS - // then the number of bytes transferred is stored in p->actual_length - std::function handle_data; - - std::function set_interface; - - // Called when the hcd is done queuing packets for an endpoint, only - // necessary for devices which can return USB_RET_ADD_TO_QUEUE. - std::function flush_ep_queue; - - // Called by the hcd to let the device know the queue for an endpoint - // has been unlinked / stopped. Optional may be NULL. - std::function ep_stopped; - - const char* product_desc; // friendly name of the device - const USBDesc* usb_desc; // device descriptor -}; - #endif diff --git a/src/devices/usb/XidGamepad.cpp b/src/devices/usb/XidGamepad.cpp index 077490a4c..66d260b56 100644 --- a/src/devices/usb/XidGamepad.cpp +++ b/src/devices/usb/XidGamepad.cpp @@ -33,11 +33,21 @@ // * All rights reserved // * // ****************************************************************** + +#define _XBOXKRNL_DEFEXTRN_ + +// prevent name collisions +namespace xboxkrnl +{ + #include // For PKINTERRUPT, etc. +}; #include "XidGamepad.h" #include "USBDevice.h" #include "Common/Input/InputConfig.h" -#include "OHCI.h" +#include "Common/Input/SDL2_Device.h" +#include "OHCI.h" +#include "CxbxKrnl\EmuKrnl.h" // For EmuWarning #define LOG_STR_GAMEPAD "Gamepad:" @@ -63,7 +73,6 @@ struct XIDDesc { uint8_t bMaxInputReportSize; uint8_t bMaxOutputReportSize; uint16_t wAlternateProductIds[4]; - XIDDesc(); }; /* Struct used by the Get_Report request -> button's state */ @@ -98,88 +107,86 @@ struct USBXIDState { XIDGamepadReport in_state_capabilities; // Get_Capabilities struct (in) XIDGamepadOutputReport out_state; // Set_Report struct XIDGamepadOutputReport out_state_capabilities; // Get_Capabilities struct (out) +}; + +static const USBDescEndpoint desc_endp_xbox_gamepad[2] = { + { + USB_DIR_IN | 0x02, // bEndpointAddress; + USB_ENDPOINT_XFER_INT, // bmAttributes; + 0x20, // wMaxPacketSize; + 4, // bInterval; + 0, // bRefresh; + 0, // bSynchAddress + 0, // is_audio + nullptr // extra + }, + { + USB_DIR_OUT | 0x02, + USB_ENDPOINT_XFER_INT, + 0x20, + 4, + 0, + 0, + 0, + nullptr + } }; -USBDescIface::USBDescIface() -{ - std::memset(this, 0, sizeof(USBDescIface)); - eps = new USBDescEndpoint[2](); - bInterfaceNumber = 0; - bNumEndpoints = 2; - bInterfaceClass = USB_CLASS_XID; - bInterfaceSubClass = 0x42; - bInterfaceProtocol = 0x00; - eps->bEndpointAddress = USB_DIR_IN | 0x02; - eps->bmAttributes = USB_ENDPOINT_XFER_INT; - eps->wMaxPacketSize = 0x20; - eps->bInterval = 4; - eps++; - eps->bEndpointAddress = USB_DIR_OUT | 0x02; - eps->bmAttributes = USB_ENDPOINT_XFER_INT; - eps->wMaxPacketSize = 0x20; - eps->bInterval = 4; -} +static const USBDescIface desc_iface_xbox_gamepad = { + 0, // bInterfaceNumber; + 0, // bAlternateSetting; + 2, // bNumEndpoints; + USB_CLASS_XID, // bInterfaceClass; + 0x42, // bInterfaceSubClass + 0x00, // bInterfaceProtocol + 0, // iInterface + 0, // ndesc + nullptr, // descs + desc_endp_xbox_gamepad +}; + +static const USBDescConfig desc_config_xbox_gamepad = { + 1, // bNumInterfaces + 1, // bConfigurationValue + 0, // iConfiguration + 0x80, // bmAttributes + 50, // bMaxPower + 1, // nif + &desc_iface_xbox_gamepad +}; -USBDescIface::~USBDescIface() -{ - delete[] eps; -} +static const USBDescDevice desc_device_xbox_gamepad = { + 0x0110, // bcdUSB + 0, // bDeviceClass + 0, // bDeviceSubClass + 0, // bDeviceProtocol + 0x40, // bMaxPacketSize0 + 1, // bNumConfigurations + &desc_config_xbox_gamepad +}; -static const USBDescIface desc_iface_xbox_gamepad; +static const USBDesc desc_xbox_gamepad = { + { + 0x045E, // idVendor + 0x0202, // idProduct + 0x0100, // bcdDevice + STR_MANUFACTURER, // iManufacturer + STR_PRODUCT, // iProduct + STR_SERIALNUMBER // iSerialNumber + }, + &desc_device_xbox_gamepad +}; -USBDescDevice::USBDescDevice() -{ - std::memset(this, 0, sizeof(USBDescDevice)); - USBDescConfig* pUSBDescConfig = new USBDescConfig(); - bcdUSB = 0x0110; - bMaxPacketSize0 = 0x40; - bNumConfigurations = 1; - pUSBDescConfig->bNumInterfaces = 1; - pUSBDescConfig->bConfigurationValue = 1; - pUSBDescConfig->bmAttributes = 0x80; - pUSBDescConfig->bMaxPower = 50; - pUSBDescConfig->nif = 1; - pUSBDescConfig->ifs = &desc_iface_xbox_gamepad; - confs = pUSBDescConfig; -} - -USBDescDevice::~USBDescDevice() -{ - delete confs; -} - -static const USBDescDevice desc_device_xbox_gamepad; - -USBDesc::USBDesc() -{ - std::memset(this, 0, sizeof(USBDesc)); - id.idVendor = 0x045E; - id.idProduct = 0x0202; - id.bcdDevice = 0x0100; - id.iManufacturer = STR_MANUFACTURER; - id.iProduct = STR_PRODUCT; - id.iSerialNumber = STR_SERIALNUMBER; - full = &desc_device_xbox_gamepad; -} - -static const USBDesc desc_xbox_gamepad; - -XIDDesc::XIDDesc() -{ - bLength = 0x10; - bDescriptorType = USB_DT_XID; - bcdXid = 0x100; - bType = 1; - bSubType = 1; - bMaxInputReportSize = 20; - bMaxOutputReportSize = 6; - wAlternateProductIds[0] = 0xFFFF; - wAlternateProductIds[1] = 0xFFFF; - wAlternateProductIds[2] = 0xFFFF; - wAlternateProductIds[3] = 0xFFFF; -} - -static const XIDDesc desc_xid_xbox_gamepad; +static const XIDDesc desc_xid_xbox_gamepad = { + 0x10, // bLength + USB_DT_XID, // bDescriptorType + 0x100, // bcdXid + 1, // bType + 1, // bSubType + 20, // bMaxInputReportSize + 6, // bMaxOutputReportSize + { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF } // wAlternateProductIds +}; int XidGamepad::Init(int port) { @@ -229,7 +236,6 @@ XboxDeviceState* XidGamepad::ClassInitFn() int XidGamepad::UsbXidClaimPort(XboxDeviceState* dev, int port) { int i; - int port_offset; std::vector::iterator it; assert(dev->Port == nullptr); @@ -525,7 +531,7 @@ void XidGamepad::XidCleanUp() void XidGamepad::UpdateForceFeedback() { // JayFoxRox's remarks: "Xbox -> XID packets were not tested - // The handling out output packets / force feedback was not checked." + // The handling of output packets / force feedback was not checked." // For the above reason we don't implement vibration support for now since the current // implementation is untested and could potentially contain errors diff --git a/src/devices/video/nv2a.h b/src/devices/video/nv2a.h index 6d732f628..62d54f60d 100644 --- a/src/devices/video/nv2a.h +++ b/src/devices/video/nv2a.h @@ -40,7 +40,7 @@ #include "glib_compat.h" // For GHashTable, g_hash_table_new, g_hash_table_lookup, g_hash_table_insert #endif -#include "CxbxCommon.h" // For xbaddr +#include "Cxbx.h" // For xbaddr #include "devices\PCIDevice.h" // For PCIDevice #include