2008-12-08 05:25:12 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-01-11 13:37:13 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
#include "Globals.h" // Local
|
2009-01-17 21:42:43 +00:00
|
|
|
|
2008-12-14 23:52:01 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-01-29 00:57:55 +00:00
|
|
|
#include "ConfigDlg.h"
|
|
|
|
#include "Debugger/File.h" // For file logging
|
|
|
|
#include "Debugger/Debugger.h" // For the CDebugger class
|
2009-02-02 22:31:31 +00:00
|
|
|
CDebugger* m_frame = NULL;
|
2008-12-14 23:52:01 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "ChunkFile.h"
|
2009-03-26 09:29:14 +00:00
|
|
|
#include "HLEMixer.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "DSPHandler.h"
|
|
|
|
#include "Config.h"
|
2009-02-14 01:07:20 +00:00
|
|
|
#include "Setup.h"
|
|
|
|
#include "StringUtil.h"
|
2009-03-26 09:29:14 +00:00
|
|
|
#include "AudioCommon.h"
|
2009-01-17 14:28:09 +00:00
|
|
|
|
2009-03-26 09:29:14 +00:00
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
// Declarations and definitions
|
2009-03-18 17:17:58 +00:00
|
|
|
PLUGIN_GLOBALS* globals = NULL;
|
2008-12-08 05:25:12 +00:00
|
|
|
DSPInitialize g_dspInitialize;
|
|
|
|
u8* g_pMemory;
|
|
|
|
extern std::vector<std::string> sMailLog, sMailTime;
|
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
SoundStream *soundStream = NULL;
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
// Mailbox utility
|
2008-12-08 05:25:12 +00:00
|
|
|
struct DSPState
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
u32 CPUMailbox;
|
|
|
|
bool CPUMailbox_Written[2];
|
|
|
|
|
|
|
|
u32 DSPMailbox;
|
|
|
|
bool DSPMailbox_Read[2];
|
|
|
|
|
|
|
|
DSPState()
|
|
|
|
{
|
|
|
|
CPUMailbox = 0x00000000;
|
|
|
|
CPUMailbox_Written[0] = false;
|
|
|
|
CPUMailbox_Written[1] = false;
|
|
|
|
|
|
|
|
DSPMailbox = 0x00000000;
|
|
|
|
DSPMailbox_Read[0] = true;
|
|
|
|
DSPMailbox_Read[1] = true;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
};
|
|
|
|
DSPState g_dspState;
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
// wxWidgets: Create the wxApp
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-12-08 05:25:12 +00:00
|
|
|
class wxDLLApp : public wxApp
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
bool OnInit()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
};
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
2008-12-08 05:25:12 +00:00
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
2008-12-14 23:52:01 +00:00
|
|
|
#endif
|
2009-01-17 14:28:09 +00:00
|
|
|
|
|
|
|
// DllMain
|
2008-12-08 05:25:12 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HINSTANCE g_hInstance = NULL;
|
|
|
|
|
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
|
2009-01-29 01:53:07 +00:00
|
|
|
DWORD dwReason, // reason called
|
|
|
|
LPVOID lpvReserved) // reserved
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
switch (dwReason)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 00:57:55 +00:00
|
|
|
case DLL_PROCESS_ATTACH:
|
2009-01-29 01:53:07 +00:00
|
|
|
{
|
2009-01-29 00:57:55 +00:00
|
|
|
|
2009-01-29 01:53:07 +00:00
|
|
|
// more stuff wx needs
|
|
|
|
wxSetInstance((HINSTANCE)hinstDLL);
|
|
|
|
int argc = 0;
|
|
|
|
char **argv = NULL;
|
|
|
|
wxEntryStart(argc, argv);
|
2009-01-29 00:57:55 +00:00
|
|
|
|
2009-01-29 01:53:07 +00:00
|
|
|
// This is for ?
|
|
|
|
if ( !wxTheApp || !wxTheApp->CallOnInit() )
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2009-01-29 00:57:55 +00:00
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2009-01-29 01:53:07 +00:00
|
|
|
wxEntryCleanup(); // use this or get a crash
|
|
|
|
break;
|
2009-01-29 00:57:55 +00:00
|
|
|
|
|
|
|
default:
|
2009-01-29 01:53:07 +00:00
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 01:53:07 +00:00
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
return(TRUE);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
// Exported fuctions
|
|
|
|
|
2009-03-23 20:55:32 +00:00
|
|
|
// Create debugging window - We could use use wxWindow win; new CDebugger(win)
|
|
|
|
// like nJoy but I don't know why it would be better. - There's a lockup
|
|
|
|
// problem with ShowModal(), but Show() doesn't work because then
|
|
|
|
// DLL_PROCESS_DETACH is called immediately after DLL_PROCESS_ATTACH.
|
2008-12-08 05:25:12 +00:00
|
|
|
void DllDebugger(HWND _hParent, bool Show)
|
|
|
|
{
|
2008-12-14 23:52:01 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-02-20 22:04:52 +00:00
|
|
|
if (m_frame && Show) // if we have created it, let us show it again
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
m_frame->DoShow();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-02-20 22:04:52 +00:00
|
|
|
else if (!m_frame && Show)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
m_frame = new CDebugger(NULL);
|
|
|
|
m_frame->Show();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-02-20 22:04:52 +00:00
|
|
|
else if (m_frame && !Show)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
m_frame->DoHide();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2008-12-14 23:52:01 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_DSP;
|
2009-01-15 06:48:15 +00:00
|
|
|
#ifdef DEBUGFAST
|
2009-01-29 01:53:07 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin DSP-HLE Plugin (DebugFast) ");
|
2008-12-08 05:25:12 +00:00
|
|
|
#else
|
|
|
|
#ifndef _DEBUG
|
2009-01-29 01:53:07 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin DSP-HLE Plugin ");
|
2008-12-08 05:25:12 +00:00
|
|
|
#else
|
2009-01-29 01:53:07 +00:00
|
|
|
sprintf(_PluginInfo ->Name, "Dolphin DSP-HLE Plugin (Debug) ");
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
|
|
|
{
|
|
|
|
globals = _pPluginGlobals;
|
|
|
|
LogManager::SetInstance((LogManager *)globals->logManager);
|
2009-01-08 12:12:15 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
void DllConfig(HWND _hParent)
|
|
|
|
{
|
2009-01-17 21:42:43 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-01-29 01:53:07 +00:00
|
|
|
// (shuffle2) TODO: reparent dlg with DolphinApp
|
|
|
|
ConfigDialog dlg(NULL);
|
2009-02-14 01:07:20 +00:00
|
|
|
|
2009-03-27 14:26:44 +00:00
|
|
|
// add backends
|
|
|
|
std::vector<std::string> backends = AudioCommon::GetSoundBackends();
|
2009-02-14 01:07:20 +00:00
|
|
|
|
2009-03-27 14:26:44 +00:00
|
|
|
for (std::vector<std::string>::const_iterator iter = backends.begin();
|
|
|
|
iter != backends.end(); ++iter) {
|
|
|
|
dlg.AddBackend((*iter).c_str());
|
|
|
|
}
|
2009-02-14 01:07:20 +00:00
|
|
|
// Show the window
|
2009-01-29 01:53:07 +00:00
|
|
|
dlg.ShowModal();
|
2008-12-08 05:25:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-03-26 09:29:14 +00:00
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
void Initialize(void *init)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
g_dspInitialize = *(DSPInitialize*)init;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
g_Config.Load();
|
2009-01-29 01:53:07 +00:00
|
|
|
g_pMemory = g_dspInitialize.pGetMemoryPointer(0);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-01-29 01:53:07 +00:00
|
|
|
CDSPHandler::CreateInstance();
|
|
|
|
|
2009-03-30 09:55:50 +00:00
|
|
|
soundStream = AudioCommon::InitSoundStream(new HLEMixer());
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
void DSP_StopSoundStream()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-02-20 22:04:52 +00:00
|
|
|
}
|
2009-01-29 00:57:55 +00:00
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
void Shutdown()
|
|
|
|
{
|
2009-03-27 14:26:44 +00:00
|
|
|
AudioCommon::ShutdownSoundStream();
|
2009-02-20 22:04:52 +00:00
|
|
|
|
|
|
|
// Delete the UCodes
|
2009-01-29 01:53:07 +00:00
|
|
|
CDSPHandler::Destroy();
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
// Reset mails
|
|
|
|
if (m_frame)
|
|
|
|
{
|
|
|
|
sMailLog.clear();
|
|
|
|
sMailTime.clear();
|
|
|
|
m_frame->sMail.clear();
|
|
|
|
m_frame->sMailEnd.clear();
|
|
|
|
}
|
|
|
|
#endif
|
2009-03-27 14:26:44 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 01:07:20 +00:00
|
|
|
void DoState(unsigned char **ptr, int mode)
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
PointerWrap p(ptr, mode);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-01-17 14:28:09 +00:00
|
|
|
|
2009-02-14 01:07:20 +00:00
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
// Mailbox fuctions
|
2008-12-08 05:25:12 +00:00
|
|
|
unsigned short DSP_ReadMailboxHigh(bool _CPUMailbox)
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
if (_CPUMailbox)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
return (g_dspState.CPUMailbox >> 16) & 0xFFFF;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-01-29 01:53:07 +00:00
|
|
|
else
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
return CDSPHandler::GetInstance().AccessMailHandler().ReadDSPMailboxHigh();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short DSP_ReadMailboxLow(bool _CPUMailbox)
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
if (_CPUMailbox)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
return g_dspState.CPUMailbox & 0xFFFF;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-01-29 01:53:07 +00:00
|
|
|
else
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
return CDSPHandler::GetInstance().AccessMailHandler().ReadDSPMailboxLow();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update_DSP_WriteRegister()
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
// check if the whole message is complete and if we can send it
|
|
|
|
if (g_dspState.CPUMailbox_Written[0] && g_dspState.CPUMailbox_Written[1])
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
CDSPHandler::GetInstance().SendMailToDSP(g_dspState.CPUMailbox);
|
|
|
|
g_dspState.CPUMailbox_Written[0] = g_dspState.CPUMailbox_Written[1] = false;
|
|
|
|
g_dspState.CPUMailbox = 0; // Mail sent so clear it to show that it is progressed
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_WriteMailboxHigh(bool _CPUMailbox, unsigned short _Value)
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
if (_CPUMailbox)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
g_dspState.CPUMailbox = (g_dspState.CPUMailbox & 0xFFFF) | (_Value << 16);
|
|
|
|
g_dspState.CPUMailbox_Written[0] = true;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-01-29 01:53:07 +00:00
|
|
|
Update_DSP_WriteRegister();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-01-29 01:53:07 +00:00
|
|
|
else
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_WriteMailboxLow(bool _CPUMailbox, unsigned short _Value)
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
if (_CPUMailbox)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
g_dspState.CPUMailbox = (g_dspState.CPUMailbox & 0xFFFF0000) | _Value;
|
|
|
|
g_dspState.CPUMailbox_Written[1] = true;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-01-29 01:53:07 +00:00
|
|
|
Update_DSP_WriteRegister();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-01-29 01:53:07 +00:00
|
|
|
else
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-14 01:07:20 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
// Other DSP fuctions
|
2008-12-08 05:25:12 +00:00
|
|
|
unsigned short DSP_WriteControlRegister(unsigned short _Value)
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
return CDSPHandler::GetInstance().WriteControlRegister(_Value);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short DSP_ReadControlRegister()
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
return CDSPHandler::GetInstance().ReadControlRegister();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_Update(int cycles)
|
|
|
|
{
|
2009-04-08 18:36:53 +00:00
|
|
|
// This is called OFTEN - better not do anything expensive!
|
|
|
|
CDSPHandler::GetInstance().Update(cycles);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-03-23 20:55:32 +00:00
|
|
|
/* Other Audio will pass through here. The kind of audio that sometimes are
|
|
|
|
used together with pre-drawn movies. This audio can be disabled further
|
|
|
|
inside Mixer_PushSamples(), the reason that we don't disable this entire
|
|
|
|
function when Other Audio is disabled is that then we can't turn it back on
|
|
|
|
again once the game has started. */
|
2008-12-08 05:25:12 +00:00
|
|
|
void DSP_SendAIBuffer(unsigned int address, int sample_rate)
|
|
|
|
{
|
2009-02-20 22:04:52 +00:00
|
|
|
// TODO: This is not yet fully threadsafe.
|
|
|
|
if (!soundStream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-27 15:33:35 +00:00
|
|
|
CMixer* pMixer = soundStream->GetMixer();
|
|
|
|
if (pMixer)
|
2009-02-14 01:07:20 +00:00
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
short samples[16] = {0}; // interleaved stereo
|
2009-02-14 01:07:20 +00:00
|
|
|
if (address)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
samples[i] = Memory_Read_U16(address + i * 2);
|
|
|
|
}
|
2009-02-14 01:07:20 +00:00
|
|
|
|
2009-03-27 14:26:44 +00:00
|
|
|
// FIXME: Write the audio to a file
|
|
|
|
//if (log_ai)
|
|
|
|
// g_wave_writer.AddStereoSamples(samples, 8);
|
2009-01-29 01:53:07 +00:00
|
|
|
}
|
2009-03-28 14:08:06 +00:00
|
|
|
|
|
|
|
// sample_rate is usually 32k here,
|
|
|
|
// see Core/DSP/DSP.cpp for better information
|
|
|
|
pMixer->PushSamples(samples, 32 / 4, sample_rate);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 01:53:07 +00:00
|
|
|
// SoundStream is updated only when necessary (there is no 70 ms limit
|
|
|
|
// so each sample now triggers the sound stream)
|
2009-02-20 22:04:52 +00:00
|
|
|
|
|
|
|
// TODO: think about this.
|
|
|
|
static int counter = 0;
|
|
|
|
counter++;
|
|
|
|
if ((counter & 31) == 0 && soundStream)
|
|
|
|
soundStream->Update();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-03-23 20:55:32 +00:00
|
|
|
|