summaryrefslogtreecommitdiff
path: root/plugins/dfsound/spu.c
diff options
context:
space:
mode:
authorSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2010-08-12 02:56:43 +0000
committerSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2010-08-12 02:56:43 +0000
commit8297a92012e3f42ed74d47fc3d11a3003c14b4ae (patch)
treefc781551eb9e024428de1c4b2a194c1e1c444be2 /plugins/dfsound/spu.c
parentd4840a37d9adf0b9124fad722a5ae5faae4bb639 (diff)
downloadpcsxr-8297a92012e3f42ed74d47fc3d11a3003c14b4ae.tar.gz
dfsound: readded windows support.
gtk gui: increased number of savestate slots. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@56022 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'plugins/dfsound/spu.c')
-rw-r--r--plugins/dfsound/spu.c201
1 files changed, 175 insertions, 26 deletions
diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c
index c086c06b..b11e5fac 100644
--- a/plugins/dfsound/spu.c
+++ b/plugins/dfsound/spu.c
@@ -23,6 +23,11 @@
#include "cfg.h"
#include "dsoundoss.h"
#include "regs.h"
+
+#ifdef _WINDOWS
+#include "debug.h"
+#include "record.h"
+#endif
#ifdef ENABLE_NLS
#include <libintl.h>
@@ -33,8 +38,10 @@
#define _(x) (x)
#define N_(x) (x)
#endif
-
-#if defined (USEMACOSX)
+
+#if defined (_WINDOWS)
+static char * libraryName = N_("DirectSound Driver");
+#elif defined (USEMACOSX)
static char * libraryName = N_("Mac OS X Sound");
#elif defined (USEALSA)
static char * libraryName = N_("ALSA Sound");
@@ -89,8 +96,15 @@ int bEndThread=0; // thread handlers
int bThreadEnded=0;
int bSpuInit=0;
int bSPUIsOpen=0;
-
+
+#ifdef _WINDOWS
+HWND hWMain=0; // window handle
+HWND hWDebug=0;
+HWND hWRecord=0;
+static HANDLE hMainThread;
+#else
static pthread_t thread = (pthread_t)-1; // thread id (linux)
+#endif
unsigned long dwNewChannel=0; // flags for faster testing, if new channel starts
@@ -438,7 +452,11 @@ INLINE int iGetInterpolationVal(int ch)
////////////////////////////////////////////////////////////////////////
-static void *MAINThread(void *arg)
+#ifdef _WINDOWS
+static VOID CALLBACK MAINProc(UINT nTimerId, UINT msg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2)
+#else
+static void *MAINThread(void *arg)
+#endif
{
int s_1,s_2,fa,ns;
#ifndef _MACOSX
@@ -471,8 +489,19 @@ static void *MAINThread(void *arg)
{
iSecureStart=0; // reset secure
- if(iUseTimer) return 0; // linux no-thread mode? bye
- usleep(PAUSE_L); // else sleep for x ms (linux)
+#ifdef _WINDOWS
+ if(iUseTimer) // no-thread mode?
+ {
+ if(iUseTimer==1) // -> ok, timer mode 1: setup a oneshot timer of x ms to wait
+ timeSetEvent(PAUSE_W,1,MAINProc,0,TIME_ONESHOT);
+ return; // -> and done this time (timer mode 1 or 2)
+ }
+ // win thread mode:
+ Sleep(PAUSE_W); // sleep for x ms (win)
+#else
+ if(iUseTimer) return 0; // linux no-thread mode? bye
+ usleep(PAUSE_L); // else sleep for x ms (linux)
+#endif
if(dwNewChannel) iSecureStart=1; // if a new channel kicks in (or, of course, sound buffer runs low), we will leave the loop
}
@@ -605,14 +634,22 @@ static void *MAINThread(void *arg)
while(iSpuAsyncWait && !bEndThread &&
timeGetTime_spu()<dwWatchTime)
- usleep(1000L);
+#ifdef _WINDOWS
+ Sleep(1);
+#else
+ usleep(1000L);
+#endif
}
else
{
lastch=ch;
lastns=ns;
-
- return 0;
+
+#ifdef _WINDOWS
+ return;
+#else
+ return 0;
+#endif
}
}
@@ -757,9 +794,25 @@ ENDX: ;
// end of big main loop...
bThreadEnded = 1;
-
- return 0;
+
+#ifndef _WINDOWS
+ return 0;
+#endif
}
+
+////////////////////////////////////////////////////////////////////////
+// WINDOWS THREAD... simply calls the timer func and stays forever :)
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+
+DWORD WINAPI MAINThreadEx(LPVOID lpParameter)
+{
+ MAINProc(0,0,0,0,0);
+ return 0;
+}
+
+#endif
// SPU ASYNC... even newer epsxe func
// 1 time every 'cycle' cycles... harhar
@@ -771,13 +824,30 @@ void CALLBACK SPUasync(unsigned long cycle)
iSpuAsyncWait++;
if(iSpuAsyncWait<=64) return;
iSpuAsyncWait=0;
- }
+ }
+
+#ifdef _WINDOWS
+ if(iDebugMode==2)
+ {
+ if(IsWindow(hWDebug)) DestroyWindow(hWDebug);
+ hWDebug=0;iDebugMode=0;
+ }
+ if(iRecordMode==2)
+ {
+ if(IsWindow(hWRecord)) DestroyWindow(hWRecord);
+ hWRecord=0;iRecordMode=0;
+ }
+#endif
if(iUseTimer==2) // special mode, only used in Linux by this spu (or if you enable the experimental Windows mode)
{
if(!bSpuInit) return; // -> no init, no call
- MAINThread(0); // -> linux high-compat mode
+#ifdef _WINDOWS
+ MAINProc(0,0,0,0,0); // -> experimental win mode... not really tested... don't like the drawbacks
+#else
+ MAINThread(0); // -> linux high-compat mode
+#endif
}
}
@@ -825,17 +895,50 @@ void SetupTimer(void)
bEndThread=0; // init thread vars
bThreadEnded=0;
bSpuInit=1; // flag: we are inited
-
+
+#ifdef _WINDOWS
+
+ if(iUseTimer==1) // windows: use timer
+ {
+ timeBeginPeriod(1);
+ timeSetEvent(1,1,MAINProc,0,TIME_ONESHOT);
+ }
+ else
+ if(iUseTimer==0) // windows: use thread
+ {
+ //_beginthread(MAINThread,0,NULL);
+ DWORD dw;
+ hMainThread=CreateThread(NULL,0,MAINThreadEx,0,0,&dw);
+ SetThreadPriority(hMainThread,
+ //THREAD_PRIORITY_TIME_CRITICAL);
+ THREAD_PRIORITY_HIGHEST);
+ }
+
+#else
+
if(!iUseTimer) // linux: use thread
{
pthread_create(&thread, NULL, MAINThread, NULL);
- }
+ }
+
+#endif
}
// REMOVETIMER: kill threads/timers
void RemoveTimer(void)
{
- bEndThread=1; // raise flag to end thread
+ bEndThread=1; // raise flag to end thread
+
+#ifdef _WINDOWS
+
+ if(iUseTimer!=2) // windows thread?
+ {
+ while(!bThreadEnded) {Sleep(5L);} // -> wait till thread has ended
+ Sleep(5L);
+ }
+ if(iUseTimer==1) timeEndPeriod(1); // windows timer? stop it
+
+#else
if(!iUseTimer) // linux tread?
{
@@ -843,6 +946,8 @@ void RemoveTimer(void)
while(!bThreadEnded && i<2000) {usleep(1000L);i++;} // -> wait until thread has ended
if(thread!=(pthread_t)-1) {pthread_cancel(thread);thread=(pthread_t)-1;} // -> cancel thread anyway
}
+
+#endif
bThreadEnded=0; // no more spu is running
bSpuInit=0;
@@ -933,14 +1038,44 @@ long CALLBACK SPUinit(void)
}
// SPUOPEN: called by main emu after init
-long CALLBACK SPUopen(void)
+#ifdef _WINDOWS
+long CALLBACK SPUopen(HWND hW)
+#else
+long SPUopen(void)
+#endif
{
- if (bSPUIsOpen) return 0; // security for some stupid main emus
+ if (bSPUIsOpen) return 0; // security for some stupid main emus
+
+#ifdef _WINDOWS
+ LastWrite=0xffffffff;LastPlay=0; // init some play vars
+ if(!IsWindow(hW)) hW=GetActiveWindow();
+ hWMain = hW; // store hwnd
+#endif
SetupSound(); // setup sound (before init!)
SetupTimer(); // timer for feeding data
- bSPUIsOpen = 1;
+ bSPUIsOpen = 1;
+
+#ifdef _WINDOWS
+ if(iDebugMode) // windows debug dialog
+ {
+ hWDebug=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DEBUG),
+ NULL,(DLGPROC)DebugDlgProc);
+ SetWindowPos(hWDebug,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
+ UpdateWindow(hWDebug);
+ SetFocus(hWMain);
+ }
+
+ if(iRecordMode) // windows recording dialog
+ {
+ hWRecord=CreateDialog(hInst,MAKEINTRESOURCE(IDD_RECORD),
+ NULL,(DLGPROC)RecordDlgProc);
+ SetWindowPos(hWRecord,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
+ UpdateWindow(hWRecord);
+ SetFocus(hWMain);
+ }
+#endif
return PSE_SPU_ERR_SUCCESS;
}
@@ -950,7 +1085,14 @@ long CALLBACK SPUclose(void)
{
if (!bSPUIsOpen) return 0; // some security
- bSPUIsOpen = 0; // no more open
+ bSPUIsOpen = 0; // no more open
+
+#ifdef _WINDOWS
+ if(IsWindow(hWDebug)) DestroyWindow(hWDebug);
+ hWDebug=0;
+ if(IsWindow(hWRecord)) DestroyWindow(hWRecord);
+ hWRecord=0;
+#endif
RemoveTimer(); // no more feeding
RemoveSound(); // no more sound handling
@@ -975,19 +1117,26 @@ long CALLBACK SPUtest(void)
// SPUCONFIGURE: call config dialog
long CALLBACK SPUconfigure(void)
-{
-#ifdef _MACOSX
+{
+#if defined (_WINDOWS)
+ DialogBox(hInst,MAKEINTRESOURCE(IDD_CFGDLG),
+ GetActiveWindow(),(DLGPROC)DSoundDlgProc);
+#elif defined (_MACOSX)
DoConfiguration();
#else
StartCfgTool("CFG");
-#endif
+#endif
+
return 0;
}
// SPUABOUT: show about window
void CALLBACK SPUabout(void)
-{
-#ifdef _MACOSX
+{
+#if defined (_WINDOWS)
+ DialogBox(hInst,MAKEINTRESOURCE(IDD_ABOUT),
+ GetActiveWindow(),(DLGPROC)AboutDlgProc);
+#elif defined (_MACOSX)
DoAbout();
#else
StartCfgTool("ABOUT");
@@ -1020,7 +1169,7 @@ unsigned long CALLBACK PSEgetLibType(void)
unsigned long CALLBACK PSEgetLibVersion(void)
{
- return (1 << 16) | (6 << 8);
+ return (1 << 16) | (1 << 8);
}
char * SPUgetLibInfos(void)