diff --git a/pcsx2_suite_2010.sln b/pcsx2_suite_2010.sln index 5dccebb743..077eea2fc1 100644 --- a/pcsx2_suite_2010.sln +++ b/pcsx2_suite_2010.sln @@ -117,6 +117,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZZOgl", "plugins\zzogl-pg\o EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL", "3rdparty\SDL-1.3.0-5387\VisualC\SDL\SDL_VS2010.vcxproj", "{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "USBqemu", "plugins\USBqemu\Win32\USBqemu.vcxproj", "{E613DA9F-41B4-4613-9911-E418EF5533BC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug AVX|Win32 = Debug AVX|Win32 @@ -1235,6 +1237,39 @@ Global {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|Win32.Build.0 = Release|Win32 {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.ActiveCfg = Release|x64 {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.Build.0 = Release|x64 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug AVX|Win32.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug AVX|Win32.Build.0 = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug AVX|x64.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSE2|Win32.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSE2|Win32.Build.0 = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSE2|x64.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSE4|Win32.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSE4|Win32.Build.0 = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSE4|x64.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSSE3|Win32.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSSE3|Win32.Build.0 = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug SSSE3|x64.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug|Win32.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug|Win32.Build.0 = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Debug|x64.ActiveCfg = Debug|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Devel|Win32.ActiveCfg = Devel|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Devel|Win32.Build.0 = Devel|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Devel|x64.ActiveCfg = Devel|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release AVX|Win32.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release AVX|Win32.Build.0 = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release AVX|x64.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSE2|Win32.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSE2|Win32.Build.0 = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSE2|x64.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSE4|Win32.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSE4|Win32.Build.0 = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSE4|x64.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSSE3|Win32.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSSE3|Win32.Build.0 = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release SSSE3|x64.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release|Win32.ActiveCfg = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release|Win32.Build.0 = Release|Win32 + {E613DA9F-41B4-4613-9911-E418EF5533BC}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1252,6 +1287,7 @@ Global {5CF88D5F-64DD-4EDC-9F1A-436BD502940A} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF} {6C8D28E4-447E-4856-BD9E-6B8F5E7C58C9} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF} {2D4E85B2-F47F-4D65-B091-701E5C031DAC} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF} + {E613DA9F-41B4-4613-9911-E418EF5533BC} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF} {E9B51944-7E6D-4BCD-83F2-7BBD5A46182D} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38} {2F6C0388-20CB-4242-9F6C-A6EBB6A83F47} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38} {F4EB4AB2-C595-4B05-8BC0-059024BC796C} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38} diff --git a/plugins/USBqemu/USB.cpp b/plugins/USBqemu/USB.cpp index 8a03032be4..88c0a934a1 100644 --- a/plugins/USBqemu/USB.cpp +++ b/plugins/USBqemu/USB.cpp @@ -1,5 +1,5 @@ -/* USBlinuz - * Copyright (C) 2002-2004 USBlinuz Team +/* USBqemu + * Copyright (C) 2002-2011 PCSX2 Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,32 +16,26 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include -#include +#include "qemu-usb/USBinternal.h" -#include "qemu-usb/vl.h" -#include "USB.h" +#ifdef _MSC_VER +# include "svnrev.h" +#endif const unsigned char version = PS2E_USB_VERSION; const unsigned char revision = 0; const unsigned char build = 1; // increase that with each version -static char *libraryName = "Qemu USB Driver by Gigaherz" -#ifdef _DEBUG -" (debug)" -#endif -; +// PCSX2 expects ASNI, not unicode, so this MUST always be char... +static char libraryName[256]; OHCIState *qemu_ohci; Config conf; -HWND gsWnd=NULL; +HWND gsWindowHandle=NULL; -u8 *usbR; u8 *ram; -usbStruct usb; USBcallback _USBirq; FILE *usbLog; int64_t usb_frame_time=0; @@ -65,11 +59,64 @@ void __Log(char *fmt, ...) { va_end(list); } +static void InitLibraryName() +{ +#ifdef SPU2X_PUBLIC_RELEASE + + // Public Release! + // Output a simplified string that's just our name: + + strcpy( libraryName, "USBqemu" ); + +#else + #ifdef SVN_REV_UNKNOWN + + // Unknown revision. + // Output a name that includes devbuild status but not + // subversion revision tags: + + strcpy( libraryName, "USBqemu" + #ifdef DEBUG_FAST + "-Debug" + #elif defined( PCSX2_DEBUG ) + "-Debug/Strict" // strict debugging is slow! + #elif defined( PCSX2_DEVBUILD ) + "-Dev" + #else + "" + #endif + ); + + #else + + // Use TortoiseSVN's SubWCRev utility's output + // to label the specific revision: + + sprintf_s( libraryName, "USBqemu r%d%s" + #ifdef DEBUG_FAST + "-Debug" + #elif defined( PCSX2_DEBUG ) + "-Debug/Strict" // strict debugging is slow! + #elif defined( PCSX2_DEVBUILD ) + "-Dev" + #else + "" + #endif + ,SVN_REV, + SVN_MODS ? "m" : "" + ); + #endif +#endif + +} + u32 CALLBACK PS2EgetLibType() { return PS2E_LT_USB; } -char* CALLBACK PS2EgetLibName() { +char* CALLBACK PS2EgetLibName() +{ + InitLibraryName(); return libraryName; } @@ -126,7 +173,7 @@ s32 CALLBACK USBopen(void *pDsp) { while (GetWindowLong (hWnd, GWL_STYLE) & WS_CHILD) hWnd = GetParent (hWnd); } - gsWnd = hWnd; + gsWindowHandle = hWnd; return 0; } diff --git a/plugins/USBqemu/USB.h b/plugins/USBqemu/USB.h index ba2fc287ce..d94311fd4a 100644 --- a/plugins/USBqemu/USB.h +++ b/plugins/USBqemu/USB.h @@ -1,5 +1,5 @@ -/* USBlinuz - * Copyright (C) 2002-2004 USBlinuz Team +/* USBqemu + * Copyright (C) 2002-2011 PCSX2 Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,46 +27,28 @@ #include "PS2Edefs.h" #ifdef __WIN32__ - -#define usleep(x) Sleep(x / 1000) -#include -#include - +# include +# include #else - -#include - -#define __inline inline - +# include +# define __inline inline #endif +#include +#include +#include +#include + #define USB_LOG __Log typedef struct { - int Log; + bool Log; } Config; extern Config conf; -extern u8 *usbR; -extern u8 *ram; - -typedef struct { - int unused; -} usbStruct; - -extern usbStruct usb; - -#define usbRs8(mem) usbR[(mem) & 0xffff] -#define usbRs16(mem) (*(s16*)&usbR[(mem) & 0xffff]) -#define usbRs32(mem) (*(s32*)&usbR[(mem) & 0xffff]) -#define usbRu8(mem) (*(u8*) &usbR[(mem) & 0xffff]) -#define usbRu16(mem) (*(u16*)&usbR[(mem) & 0xffff]) -#define usbRu32(mem) (*(u32*)&usbR[(mem) & 0xffff]) - #define PSXCLK 36864000 /* 36.864 Mhz */ -extern USBcallback _USBirq; void USBirq(int); void SaveConfig(); @@ -77,300 +59,6 @@ void __Log(char *fmt, ...); void SysMessage(char *fmt, ...); -#include "qemu-usb/vl.h" - -#define DEBUG_OHCI -/* Dump packet contents. */ -//#define DEBUG_PACKET -/* This causes frames to occur 1000x slower */ -//#define OHCI_TIME_WARP 1 - -/* Number of Downstream Ports on the root hub. */ - -#define OHCI_MAX_PORTS 15 - -extern int64_t usb_frame_time; -extern int64_t usb_bit_time; - -typedef struct OHCIPort { - USBPort port; - uint32_t ctrl; -} OHCIPort; - -typedef uint32_t target_phys_addr_t; - -typedef struct { - //USBBus bus; - //qemu_irq irq; - enum ohci_type type; - int mem; - int num_ports; - const char *name; - - //QEMUTimer *eof_timer; - int64_t eof_timer; - int64_t sof_time; - - /* OHCI state */ - /* Control partition */ - uint32_t ctl, status; - uint32_t intr_status; - uint32_t intr; - - /* memory pointer partition */ - uint32_t hcca; - uint32_t ctrl_head, ctrl_cur; - uint32_t bulk_head, bulk_cur; - uint32_t per_cur; - uint32_t done; - int done_count; - - /* Frame counter partition */ - uint32_t fsmps:15; - uint32_t fit:1; - uint32_t fi:14; - uint32_t frt:1; - uint16_t frame_number; - uint16_t padding; - uint32_t pstart; - uint32_t lst; - - /* Root Hub partition */ - uint32_t rhdesc_a, rhdesc_b; - uint32_t rhstatus; - OHCIPort rhport[OHCI_MAX_PORTS]; - - /* PXA27x Non-OHCI events */ - uint32_t hstatus; - uint32_t hmask; - uint32_t hreset; - uint32_t htest; - - /* SM501 local memory offset */ - target_phys_addr_t localmem_base; - - /* Active packets. */ - uint32_t old_ctl; - USBPacket usb_packet; - uint8_t usb_buf[8192]; - uint32_t async_td; - int async_complete; - -} OHCIState; - -/* Host Controller Communications Area */ -struct ohci_hcca { - uint32_t intr[32]; - uint16_t frame, pad; - uint32_t done; -}; - - -extern int64_t usb_frame_time; -extern int64_t usb_bit_time; - -enum ohci_type { - OHCI_TYPE_PCI, - OHCI_TYPE_PXA, - OHCI_TYPE_SM501, -}; - -int64_t get_ticks_per_sec(); - -static void ohci_bus_stop(OHCIState *ohci); - -/* Bitfields for the first word of an Endpoint Desciptor. */ -#define OHCI_ED_FA_SHIFT 0 -#define OHCI_ED_FA_MASK (0x7f<> OHCI_##field##_SHIFT) - -#define OHCI_SET_BM(val, field, newval) do { \ - val &= ~OHCI_##field##_MASK; \ - val |= ((newval) << OHCI_##field##_SHIFT) & OHCI_##field##_MASK; \ - } while(0) - -/* endpoint descriptor */ -struct ohci_ed { - uint32_t flags; - uint32_t tail; - uint32_t head; - uint32_t next; -}; - -/* General transfer descriptor */ -struct ohci_td { - uint32_t flags; - uint32_t cbp; - uint32_t next; - uint32_t be; -}; - -/* Isochronous transfer descriptor */ -struct ohci_iso_td { - uint32_t flags; - uint32_t bp; - uint32_t next; - uint32_t be; - uint16_t offset[8]; -}; - -#define USB_HZ 12000000 - -/* OHCI Local stuff */ -#define OHCI_CTL_CBSR ((1<<0)|(1<<1)) -#define OHCI_CTL_PLE (1<<2) -#define OHCI_CTL_IE (1<<3) -#define OHCI_CTL_CLE (1<<4) -#define OHCI_CTL_BLE (1<<5) -#define OHCI_CTL_HCFS ((1<<6)|(1<<7)) -#define OHCI_USB_RESET 0x00 -#define OHCI_USB_RESUME 0x40 -#define OHCI_USB_OPERATIONAL 0x80 -#define OHCI_USB_SUSPEND 0xc0 -#define OHCI_CTL_IR (1<<8) -#define OHCI_CTL_RWC (1<<9) -#define OHCI_CTL_RWE (1<<10) - -#define OHCI_STATUS_HCR (1<<0) -#define OHCI_STATUS_CLF (1<<1) -#define OHCI_STATUS_BLF (1<<2) -#define OHCI_STATUS_OCR (1<<3) -#define OHCI_STATUS_SOC ((1<<6)|(1<<7)) - -#define OHCI_INTR_SO (1<<0) /* Scheduling overrun */ -#define OHCI_INTR_WD (1<<1) /* HcDoneHead writeback */ -#define OHCI_INTR_SF (1<<2) /* Start of frame */ -#define OHCI_INTR_RD (1<<3) /* Resume detect */ -#define OHCI_INTR_UE (1<<4) /* Unrecoverable error */ -#define OHCI_INTR_FNO (1<<5) /* Frame number overflow */ -#define OHCI_INTR_RHSC (1<<6) /* Root hub status change */ -#define OHCI_INTR_OC (1<<30) /* Ownership change */ -#define OHCI_INTR_MIE (1<<31) /* Master Interrupt Enable */ - -#define OHCI_HCCA_SIZE 0x100 -#define OHCI_HCCA_MASK 0xffffff00 - -#define OHCI_EDPTR_MASK 0xfffffff0 - -#define OHCI_FMI_FI 0x00003fff -#define OHCI_FMI_FSMPS 0xffff0000 -#define OHCI_FMI_FIT 0x80000000 - -#define OHCI_FR_RT (1<<31) - -#define OHCI_LS_THRESH 0x628 - -#define OHCI_RHA_RW_MASK 0x00000000 /* Mask of supported features. */ -#define OHCI_RHA_PSM (1<<8) -#define OHCI_RHA_NPS (1<<9) -#define OHCI_RHA_DT (1<<10) -#define OHCI_RHA_OCPM (1<<11) -#define OHCI_RHA_NOCP (1<<12) -#define OHCI_RHA_POTPGT_MASK 0xff000000 - -#define OHCI_RHS_LPS (1<<0) -#define OHCI_RHS_OCI (1<<1) -#define OHCI_RHS_DRWE (1<<15) -#define OHCI_RHS_LPSC (1<<16) -#define OHCI_RHS_OCIC (1<<17) -#define OHCI_RHS_CRWE (1<<31) - -#define OHCI_PORT_CCS (1<<0) -#define OHCI_PORT_PES (1<<1) -#define OHCI_PORT_PSS (1<<2) -#define OHCI_PORT_POCI (1<<3) -#define OHCI_PORT_PRS (1<<4) -#define OHCI_PORT_PPS (1<<8) -#define OHCI_PORT_LSDA (1<<9) -#define OHCI_PORT_CSC (1<<16) -#define OHCI_PORT_PESC (1<<17) -#define OHCI_PORT_PSSC (1<<18) -#define OHCI_PORT_OCIC (1<<19) -#define OHCI_PORT_PRSC (1<<20) -#define OHCI_PORT_WTC (OHCI_PORT_CSC|OHCI_PORT_PESC|OHCI_PORT_PSSC \ - |OHCI_PORT_OCIC|OHCI_PORT_PRSC) - -#define OHCI_TD_DIR_SETUP 0x0 -#define OHCI_TD_DIR_OUT 0x1 -#define OHCI_TD_DIR_IN 0x2 -#define OHCI_TD_DIR_RESERVED 0x3 - -#define OHCI_CC_NOERROR 0x0 -#define OHCI_CC_CRC 0x1 -#define OHCI_CC_BITSTUFFING 0x2 -#define OHCI_CC_DATATOGGLEMISMATCH 0x3 -#define OHCI_CC_STALL 0x4 -#define OHCI_CC_DEVICENOTRESPONDING 0x5 -#define OHCI_CC_PIDCHECKFAILURE 0x6 -#define OHCI_CC_UNDEXPETEDPID 0x7 -#define OHCI_CC_DATAOVERRUN 0x8 -#define OHCI_CC_DATAUNDERRUN 0x9 -#define OHCI_CC_BUFFEROVERRUN 0xc -#define OHCI_CC_BUFFERUNDERRUN 0xd - -#define OHCI_HRESET_FSBIR (1 << 0) - - -int64_t get_clock(); - -OHCIState *ohci_create(uint32_t base, int ports); - -uint32_t ohci_mem_read(void *ptr, target_phys_addr_t addr); -void ohci_mem_write(void *ptr, target_phys_addr_t addr, uint32_t val); -void ohci_frame_boundary(void *opaque); - -int ohci_bus_start(OHCIState *ohci); -void ohci_bus_stop(OHCIState *ohci); - -USBDevice *usb_hub_init(int nb_ports); -USBDevice *usb_msd_init(const char *filename); -USBDevice *eyetoy_init(void); -USBDevice *usb_mouse_init(void); +extern HWND gsWindowHandle; #endif diff --git a/plugins/USBqemu/Win32/CfgHelpers.cpp b/plugins/USBqemu/Win32/CfgHelpers.cpp new file mode 100644 index 0000000000..509d87ccbb --- /dev/null +++ b/plugins/USBqemu/Win32/CfgHelpers.cpp @@ -0,0 +1,160 @@ +/* SPU2-X, A plugin for Emulating the Sound Processing Unit of the Playstation 2 + * Developed and maintained by the Pcsx2 Development Team. + * + * Original portions from SPU2ghz are (c) 2008 by David Quintana [gigaherz] + * + * SPU2-X is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * SPU2-X 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with SPU2-X. If not, see . + */ +#include "../USB.h" + +void SysMessage(const char *fmt, ...) +{ + va_list list; + char tmp[512]; + wchar_t wtmp[512]; + + va_start(list,fmt); + vsprintf_s(tmp,fmt,list); + va_end(list); + swprintf_s(wtmp, L"%S", tmp); + MessageBox( (!!gsWindowHandle) ? (HWND)gsWindowHandle : GetActiveWindow(), wtmp, + L"SPU2-X System Message", MB_OK | MB_SETFOREGROUND); +} + +void SysMessage(const wchar_t *fmt, ...) +{ + va_list list; + wchar_t tmp[512]; + + va_start(list,fmt); + vswprintf_s(tmp,fmt,list); + va_end(list); + + MessageBox( (!!gsWindowHandle) ? (HWND)gsWindowHandle : GetActiveWindow(), tmp, + L"SPU2-X System Message", MB_OK | MB_SETFOREGROUND); +} + +////// + +static TCHAR CfgFile[260] = L"inis/SPU2-X.ini"; + +void CfgSetSettingsDir( const char* dir ) +{ + if(dir == NULL) + { + wcscpy(CfgFile, L"inis/SPU2-X.ini"); + } + else + { + swprintf_s(CfgFile, L"%S", dir); + TCHAR term = CfgFile[wcslen(CfgFile)-1]; + if(term != L'\\' && term != L'/') + wcscat(CfgFile, L"\\"); + wcscat(CfgFile, L"USBQemu.ini" ); + } +} + + +/*| Config File Format: |ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ*\ ++--+---------------------+------------------------+ +| | +| Option=Value | +| | +| | +| Boolean Values: TRUE,YES,1,T,Y mean 'true', | +| everything else means 'false'. | +| | +| All Values are limited to 255 chars. | +| | ++-------------------------------------------------+ +\*_____________________________________________*/ + + +void CfgWriteBool(const TCHAR* Section, const TCHAR* Name, bool Value) +{ + const TCHAR *Data = Value ? L"TRUE" : L"FALSE"; + WritePrivateProfileString( Section, Name, Data, CfgFile ); +} + +void CfgWriteInt(const TCHAR* Section, const TCHAR* Name, int Value) +{ + TCHAR Data[32]; + _itow( Value, Data, 10 ); + WritePrivateProfileString(Section,Name,Data,CfgFile); +} + +void CfgWriteStr(const TCHAR* Section, const TCHAR* Name, const TCHAR *Data) +{ + WritePrivateProfileString( Section, Name, Data, CfgFile ); +} + + +/*****************************************************************************/ + +bool CfgReadBool(const TCHAR *Section,const TCHAR* Name, bool Default) +{ + TCHAR Data[255] = {0}; + + GetPrivateProfileString( Section, Name, L"", Data, 255, CfgFile ); + Data[254]=0; + if(wcslen(Data)==0) { + CfgWriteBool(Section,Name,Default); + return Default; + } + + if(wcscmp(Data,L"1")==0) return true; + if(wcscmp(Data,L"Y")==0) return true; + if(wcscmp(Data,L"T")==0) return true; + if(wcscmp(Data,L"YES")==0) return true; + if(wcscmp(Data,L"TRUE")==0) return true; + return false; +} + + +int CfgReadInt(const TCHAR* Section, const TCHAR* Name,int Default) +{ + TCHAR Data[255]={0}; + GetPrivateProfileString(Section,Name,L"",Data,255,CfgFile); + Data[254]=0; + + if(wcslen(Data)==0) { + CfgWriteInt(Section,Name,Default); + return Default; + } + + return _wtoi(Data); +} + +void CfgReadStr(const TCHAR* Section, const TCHAR* Name, TCHAR* Data, int DataSize, const TCHAR* Default) +{ + wchar_t workspace[512]; + int chars = GetPrivateProfileString(Section,Name,L"",Data,DataSize,CfgFile); + + if(!chars) + { + wcscpy(Data, Default); + CfgWriteStr( Section, Name, Default ); + } +} + +// Tries to read the requested value. +// Returns FALSE if the value isn't found. +bool CfgFindName( const TCHAR *Section, const TCHAR* Name) +{ + // Only load 24 characters. No need to load more. + TCHAR Data[24]={0}; + GetPrivateProfileString(Section,Name,L"",Data,24,CfgFile); + Data[23]=0; + + if(wcslen(Data)==0) return false; + return true; +} diff --git a/plugins/USBqemu/Win32/CfgHelpers.h b/plugins/USBqemu/Win32/CfgHelpers.h new file mode 100644 index 0000000000..5be8478c92 --- /dev/null +++ b/plugins/USBqemu/Win32/CfgHelpers.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +extern void CfgSetSettingsDir( const char* dir ); +extern void CfgSetLogDir( const char* dir ); + +extern bool CfgFindName( const TCHAR *Section, const TCHAR* Name); + +extern void CfgWriteBool(const TCHAR* Section, const TCHAR* Name, bool Value); +extern void CfgWriteInt(const TCHAR* Section, const TCHAR* Name, int Value); +extern void CfgWriteStr(const TCHAR* Section, const TCHAR* Name, const TCHAR *Data); + +extern bool CfgReadBool(const TCHAR *Section,const TCHAR* Name, bool Default); +extern void CfgReadStr(const TCHAR* Section, const TCHAR* Name, TCHAR* Data, int DataSize, const TCHAR* Default); +extern int CfgReadInt(const TCHAR* Section, const TCHAR* Name,int Default); diff --git a/plugins/USBqemu/Win32/Config.cpp b/plugins/USBqemu/Win32/Config.cpp index c46552a4a6..46bd9b4972 100644 --- a/plugins/USBqemu/Win32/Config.cpp +++ b/plugins/USBqemu/Win32/Config.cpp @@ -1,51 +1,21 @@ #include -#include "USB.h" +#include "../USB.h" + +#include "CfgHelpers.h" + +void CALLBACK USBsetSettingsDir( const char* dir ) +{ + CfgSetSettingsDir(dir); +} -extern HINSTANCE hInst; void SaveConfig() { - - Config *Conf1 = &conf; - char *szTemp; - char szIniFile[256], szValue[256]; - - GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); - szTemp = strrchr(szIniFile, '\\'); - - if(!szTemp) return; - strcpy(szTemp, "\\inis\\usblinuz.ini"); - sprintf(szValue,"%u",Conf1->Log); - WritePrivateProfileString("Interface", "Logging",szValue,szIniFile); - + CfgWriteBool(L"Interface", L"Logging", conf.Log); } -void LoadConfig() { - FILE *fp; - - - Config *Conf1 = &conf; - char *szTemp; - char szIniFile[256], szValue[256]; - - GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); - szTemp = strrchr(szIniFile, '\\'); - - if(!szTemp) return ; - strcpy(szTemp, "\\inis\\usblinuz.ini"); - fp=fopen("inis\\usblinuz.ini","rt");//check if usbnull.ini really exists - if (!fp) - { - CreateDirectory("inis",NULL); - memset(&conf, 0, sizeof(conf)); - conf.Log = 0;//default value - SaveConfig();//save and return - return ; - } - fclose(fp); - GetPrivateProfileString("Interface", "Logging", NULL, szValue, 20, szIniFile); - Conf1->Log = strtoul(szValue, NULL, 10); - return ; - +void LoadConfig() +{ + conf.Log = CfgReadBool(L"Interface", L"Logging", false); } diff --git a/plugins/USBqemu/Win32/ProjectRootDir.props b/plugins/USBqemu/Win32/ProjectRootDir.props new file mode 100644 index 0000000000..5e4da28bf9 --- /dev/null +++ b/plugins/USBqemu/Win32/ProjectRootDir.props @@ -0,0 +1,16 @@ +ïğż + + + $(ProjectDir).. + $(ProjectRootDir)\..\.. + $(SvnRootDir)\common + + + <_ProjectFileVersion>10.0.30128.1 + + + + $(SvnRootDir) + + + \ No newline at end of file diff --git a/plugins/USBqemu/Win32/USBqemu.sln b/plugins/USBqemu/Win32/USBqemu.sln deleted file mode 100644 index 0ebe0428f4..0000000000 --- a/plugins/USBqemu/Win32/USBqemu.sln +++ /dev/null @@ -1,19 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "USBqemu", "USBqemu.vcxproj", "{BF7B81A5-E348-4F7C-A69F-F74C8EEEAD70}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {BF7B81A5-E348-4F7C-A69F-F74C8EEEAD70}.Debug|Win32.ActiveCfg = Debug|Win32 - {BF7B81A5-E348-4F7C-A69F-F74C8EEEAD70}.Debug|Win32.Build.0 = Debug|Win32 - {BF7B81A5-E348-4F7C-A69F-F74C8EEEAD70}.Release|Win32.ActiveCfg = Release|Win32 - {BF7B81A5-E348-4F7C-A69F-F74C8EEEAD70}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/plugins/USBqemu/Win32/USBqemu.vcxproj b/plugins/USBqemu/Win32/USBqemu.vcxproj index 7d9c05094e..bc5ad66301 100644 --- a/plugins/USBqemu/Win32/USBqemu.vcxproj +++ b/plugins/USBqemu/Win32/USBqemu.vcxproj @@ -5,107 +5,113 @@ Debug Win32 + + Devel + Win32 + Release Win32 - {BF7B81A5-E348-4F7C-A69F-F74C8EEEAD70} + USBqemu + {E613DA9F-41B4-4613-9911-E418EF5533BC} USBlinuz Win32Proj DynamicLibrary - MultiByte true + Unicode + + + DynamicLibrary + false + Unicode DynamicLibrary - MultiByte - false + Unicode + + + + + + + + + - + + + + + - + + + + + + <_ProjectFileVersion>10.0.40219.1 - true - ..\..\..\bin\plugins\ - true - AllRules.ruleset - - - AllRules.ruleset - - - $(ProjectName)-dbg - ..\..\..\bin\plugins\ + $(ProjectName)-dev + + + + + + + USBqemu.def + Windows + + + MachineX86 + + + + - Disabled - false - ..\;h:\pcsx2-trunk\common\include\;%(AdditionalIncludeDirectories) - __WIN32__;_DEBUG;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - NotUsing - Level4 - EditAndContinue + + USBqemu.def - true Windows MachineX86 - + - MaxSpeed - AnySuitable - true - Speed - true - false - ..\;h:\pcsx2-trunk\common\include\;%(AdditionalIncludeDirectories) - __WIN32__;NDEBUG;%(PreprocessorDefinitions) - false - Default - MultiThreadedDebug - NotSet - Level4 - - USBqemu.def - true Windows - false - $(OutDir)USBlinuz.lib MachineX86 + @@ -113,16 +119,19 @@ true true + true true true + true true true + true @@ -132,6 +141,8 @@ + + diff --git a/plugins/USBqemu/Win32/USBqemu.vcxproj.filters b/plugins/USBqemu/Win32/USBqemu.vcxproj.filters index 418d5b0e48..9979482e52 100644 --- a/plugins/USBqemu/Win32/USBqemu.vcxproj.filters +++ b/plugins/USBqemu/Win32/USBqemu.vcxproj.filters @@ -54,6 +54,9 @@ Source Files\qemu-usb + + Source Files + @@ -79,6 +82,12 @@ Header Files\qemu-usb + + Header Files + + + Header Files\qemu-usb + diff --git a/plugins/USBqemu/Win32/Win32.cpp b/plugins/USBqemu/Win32/Win32.cpp index 7647d9702b..0c30fb3eca 100644 --- a/plugins/USBqemu/Win32/Win32.cpp +++ b/plugins/USBqemu/Win32/Win32.cpp @@ -2,19 +2,19 @@ #include #include -#include "USB.h" +#include "../USB.h" #include "resource.h" HINSTANCE hInst; -void SysMessage(char *fmt, ...) { +void SysMessage(TCHAR *fmt, ...) { va_list list; - char tmp[512]; + TCHAR tmp[512]; va_start(list,fmt); - vsprintf(tmp,fmt,list); + _vswprintf(tmp,fmt,list); va_end(list); - MessageBox(0, tmp, "USBlinuz Msg", 0); + MessageBox(0, tmp, L"USBqemu Msg", 0); } BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { diff --git a/plugins/USBqemu/Win32/resource.h b/plugins/USBqemu/Win32/resource.h index ad8f21c11d..890edd5a7a 100644 --- a/plugins/USBqemu/Win32/resource.h +++ b/plugins/USBqemu/Win32/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by USBlinuz.rc +// Used by USBqemu.rc // #define IDD_CONFDLG 101 #define IDD_CONFIG 101 diff --git a/plugins/USBqemu/qemu-usb/USBinternal.h b/plugins/USBqemu/qemu-usb/USBinternal.h new file mode 100644 index 0000000000..0b417f82c3 --- /dev/null +++ b/plugins/USBqemu/qemu-usb/USBinternal.h @@ -0,0 +1,300 @@ +#pragma once + +#include "../USB.h" +#include "vl.h" + +#ifdef PCSX2_DEVBUILD +# define DEBUG_OHCI +#endif +/* Dump packet contents. */ +//#define DEBUG_PACKET +/* This causes frames to occur 1000x slower */ +//#define OHCI_TIME_WARP 1 + +/* Number of Downstream Ports on the root hub. */ + +#define OHCI_MAX_PORTS 2 + +extern int64_t usb_frame_time; +extern int64_t usb_bit_time; + +typedef struct OHCIPort { + USBPort port; + uint32_t ctrl; +} OHCIPort; + +typedef uint32_t target_phys_addr_t; + +typedef struct { + //USBBus bus; + //qemu_irq irq; + enum ohci_type type; + int mem; + int num_ports; + const char *name; + + //QEMUTimer *eof_timer; + int64_t eof_timer; + int64_t sof_time; + + /* OHCI state */ + /* Control partition */ + uint32_t ctl, status; + uint32_t intr_status; + uint32_t intr; + + /* memory pointer partition */ + uint32_t hcca; + uint32_t ctrl_head, ctrl_cur; + uint32_t bulk_head, bulk_cur; + uint32_t per_cur; + uint32_t done; + int done_count; + + /* Frame counter partition */ + uint32_t fsmps:15; + uint32_t fit:1; + uint32_t fi:14; + uint32_t frt:1; + uint16_t frame_number; + uint16_t padding; + uint32_t pstart; + uint32_t lst; + + /* Root Hub partition */ + uint32_t rhdesc_a, rhdesc_b; + uint32_t rhstatus; + OHCIPort rhport[OHCI_MAX_PORTS]; + + /* PXA27x Non-OHCI events */ + uint32_t hstatus; + uint32_t hmask; + uint32_t hreset; + uint32_t htest; + + /* SM501 local memory offset */ + target_phys_addr_t localmem_base; + + /* Active packets. */ + uint32_t old_ctl; + USBPacket usb_packet; + uint8_t usb_buf[8192]; + uint32_t async_td; + int async_complete; + +} OHCIState; + +/* Host Controller Communications Area */ +struct ohci_hcca { + uint32_t intr[32]; + uint16_t frame, pad; + uint32_t done; +}; + + +extern int64_t usb_frame_time; +extern int64_t usb_bit_time; + +enum ohci_type { + OHCI_TYPE_PCI, + OHCI_TYPE_PXA, + OHCI_TYPE_SM501, +}; + +int64_t get_ticks_per_sec(); + +static void ohci_bus_stop(OHCIState *ohci); + +/* Bitfields for the first word of an Endpoint Desciptor. */ +#define OHCI_ED_FA_SHIFT 0 +#define OHCI_ED_FA_MASK (0x7f<> OHCI_##field##_SHIFT) + +#define OHCI_SET_BM(val, field, newval) do { \ + val &= ~OHCI_##field##_MASK; \ + val |= ((newval) << OHCI_##field##_SHIFT) & OHCI_##field##_MASK; \ + } while(0) + +/* endpoint descriptor */ +struct ohci_ed { + uint32_t flags; + uint32_t tail; + uint32_t head; + uint32_t next; +}; + +/* General transfer descriptor */ +struct ohci_td { + uint32_t flags; + uint32_t cbp; + uint32_t next; + uint32_t be; +}; + +/* Isochronous transfer descriptor */ +struct ohci_iso_td { + uint32_t flags; + uint32_t bp; + uint32_t next; + uint32_t be; + uint16_t offset[8]; +}; + +#define USB_HZ 12000000 + +/* OHCI Local stuff */ +#define OHCI_CTL_CBSR ((1<<0)|(1<<1)) +#define OHCI_CTL_PLE (1<<2) +#define OHCI_CTL_IE (1<<3) +#define OHCI_CTL_CLE (1<<4) +#define OHCI_CTL_BLE (1<<5) +#define OHCI_CTL_HCFS ((1<<6)|(1<<7)) +#define OHCI_USB_RESET 0x00 +#define OHCI_USB_RESUME 0x40 +#define OHCI_USB_OPERATIONAL 0x80 +#define OHCI_USB_SUSPEND 0xc0 +#define OHCI_CTL_IR (1<<8) +#define OHCI_CTL_RWC (1<<9) +#define OHCI_CTL_RWE (1<<10) + +#define OHCI_STATUS_HCR (1<<0) +#define OHCI_STATUS_CLF (1<<1) +#define OHCI_STATUS_BLF (1<<2) +#define OHCI_STATUS_OCR (1<<3) +#define OHCI_STATUS_SOC ((1<<6)|(1<<7)) + +#define OHCI_INTR_SO (1<<0) /* Scheduling overrun */ +#define OHCI_INTR_WD (1<<1) /* HcDoneHead writeback */ +#define OHCI_INTR_SF (1<<2) /* Start of frame */ +#define OHCI_INTR_RD (1<<3) /* Resume detect */ +#define OHCI_INTR_UE (1<<4) /* Unrecoverable error */ +#define OHCI_INTR_FNO (1<<5) /* Frame number overflow */ +#define OHCI_INTR_RHSC (1<<6) /* Root hub status change */ +#define OHCI_INTR_OC (1<<30) /* Ownership change */ +#define OHCI_INTR_MIE (1<<31) /* Master Interrupt Enable */ + +#define OHCI_HCCA_SIZE 0x100 +#define OHCI_HCCA_MASK 0xffffff00 + +#define OHCI_EDPTR_MASK 0xfffffff0 + +#define OHCI_FMI_FI 0x00003fff +#define OHCI_FMI_FSMPS 0xffff0000 +#define OHCI_FMI_FIT 0x80000000 + +#define OHCI_FR_RT (1<<31) + +#define OHCI_LS_THRESH 0x628 + +#define OHCI_RHA_RW_MASK 0x00000000 /* Mask of supported features. */ +#define OHCI_RHA_PSM (1<<8) +#define OHCI_RHA_NPS (1<<9) +#define OHCI_RHA_DT (1<<10) +#define OHCI_RHA_OCPM (1<<11) +#define OHCI_RHA_NOCP (1<<12) +#define OHCI_RHA_POTPGT_MASK 0xff000000 + +#define OHCI_RHS_LPS (1<<0) +#define OHCI_RHS_OCI (1<<1) +#define OHCI_RHS_DRWE (1<<15) +#define OHCI_RHS_LPSC (1<<16) +#define OHCI_RHS_OCIC (1<<17) +#define OHCI_RHS_CRWE (1<<31) + +#define OHCI_PORT_CCS (1<<0) +#define OHCI_PORT_PES (1<<1) +#define OHCI_PORT_PSS (1<<2) +#define OHCI_PORT_POCI (1<<3) +#define OHCI_PORT_PRS (1<<4) +#define OHCI_PORT_PPS (1<<8) +#define OHCI_PORT_LSDA (1<<9) +#define OHCI_PORT_CSC (1<<16) +#define OHCI_PORT_PESC (1<<17) +#define OHCI_PORT_PSSC (1<<18) +#define OHCI_PORT_OCIC (1<<19) +#define OHCI_PORT_PRSC (1<<20) +#define OHCI_PORT_WTC (OHCI_PORT_CSC|OHCI_PORT_PESC|OHCI_PORT_PSSC \ + |OHCI_PORT_OCIC|OHCI_PORT_PRSC) + +#define OHCI_TD_DIR_SETUP 0x0 +#define OHCI_TD_DIR_OUT 0x1 +#define OHCI_TD_DIR_IN 0x2 +#define OHCI_TD_DIR_RESERVED 0x3 + +#define OHCI_CC_NOERROR 0x0 +#define OHCI_CC_CRC 0x1 +#define OHCI_CC_BITSTUFFING 0x2 +#define OHCI_CC_DATATOGGLEMISMATCH 0x3 +#define OHCI_CC_STALL 0x4 +#define OHCI_CC_DEVICENOTRESPONDING 0x5 +#define OHCI_CC_PIDCHECKFAILURE 0x6 +#define OHCI_CC_UNDEXPETEDPID 0x7 +#define OHCI_CC_DATAOVERRUN 0x8 +#define OHCI_CC_DATAUNDERRUN 0x9 +#define OHCI_CC_BUFFEROVERRUN 0xc +#define OHCI_CC_BUFFERUNDERRUN 0xd + +#define OHCI_HRESET_FSBIR (1 << 0) + + +int64_t get_clock(); + +OHCIState *ohci_create(uint32_t base, int ports); + +uint32_t ohci_mem_read(void *ptr, target_phys_addr_t addr); +void ohci_mem_write(void *ptr, target_phys_addr_t addr, uint32_t val); +void ohci_frame_boundary(void *opaque); + +int ohci_bus_start(OHCIState *ohci); +void ohci_bus_stop(OHCIState *ohci); + +USBDevice *usb_hub_init(int nb_ports); +USBDevice *usb_msd_init(const char *filename); +USBDevice *eyetoy_init(void); +USBDevice *usb_mouse_init(void); diff --git a/plugins/USBqemu/qemu-usb/usb-base.cpp b/plugins/USBqemu/qemu-usb/usb-base.cpp index 03d8a38300..285af3ff15 100644 --- a/plugins/USBqemu/qemu-usb/usb-base.cpp +++ b/plugins/USBqemu/qemu-usb/usb-base.cpp @@ -23,7 +23,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "vl.h" +#include "USBinternal.h" //#include "usb.h" void usb_attach(USBPort *port, USBDevice *dev) diff --git a/plugins/USBqemu/qemu-usb/usb-hub.cpp b/plugins/USBqemu/qemu-usb/usb-hub.cpp index 4d62c9ef92..6d1099d11e 100644 --- a/plugins/USBqemu/qemu-usb/usb-hub.cpp +++ b/plugins/USBqemu/qemu-usb/usb-hub.cpp @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "vl.h" +#include "USBinternal.h" //#define DEBUG diff --git a/plugins/USBqemu/qemu-usb/usb-kbd.cpp b/plugins/USBqemu/qemu-usb/usb-kbd.cpp index 6c4d427b24..2e64e79e05 100644 --- a/plugins/USBqemu/qemu-usb/usb-kbd.cpp +++ b/plugins/USBqemu/qemu-usb/usb-kbd.cpp @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "vl.h" +#include "USBinternal.h" /* HID interface requests */ #define GET_REPORT 0xa101 @@ -40,7 +40,6 @@ typedef struct USBKeyboardState { USBDeviceInfo devinfo; -extern HWND gsWnd; #define VK_BASED @@ -624,7 +623,7 @@ static int usb_keyboard_poll(USBKeyboardState *s, uint8_t *buf, int len) s->keyboard_grabbed = 1; } - if(gsWnd != GetForegroundWindow()) + if(gsWindowHandle != GetForegroundWindow()) { for(int i=0;i<256;i++) { diff --git a/plugins/USBqemu/qemu-usb/usb-ohci.cpp b/plugins/USBqemu/qemu-usb/usb-ohci.cpp index d2a00e1f30..5fa1662be6 100644 --- a/plugins/USBqemu/qemu-usb/usb-ohci.cpp +++ b/plugins/USBqemu/qemu-usb/usb-ohci.cpp @@ -28,8 +28,7 @@ //typedef CPUReadMemoryFunc -#include "vl.h" -#include "../USB.h" +#include "USBinternal.h" s64 last_cycle = 0; #define MIN_IRQ_INTERVAL 64 /* hack */ diff --git a/plugins/USBqemu/qemu-usb/vl.h b/plugins/USBqemu/qemu-usb/vl.h index 59ebea45c7..b8d3d9984b 100644 --- a/plugins/USBqemu/qemu-usb/vl.h +++ b/plugins/USBqemu/qemu-usb/vl.h @@ -58,7 +58,7 @@ typedef unsigned __int64 uint64_t; #ifdef _WIN32 #include #define fsync _commit -#define lseek _lseeki64 +//#define lseek _lseeki64 //#define ENOTSUP 4096 extern int qemu_ftruncate64(int, int64_t); #define ftruncate qemu_ftruncate64