2009-03-29 21:00:26 +00:00
|
|
|
// Copyright (C) 2003-2009 Dolphin Project.
|
2009-03-23 09:10:32 +00:00
|
|
|
|
|
|
|
// 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/
|
|
|
|
|
|
|
|
|
|
|
|
#include "Common.h" // Common
|
|
|
|
#include "CommonTypes.h"
|
|
|
|
#include "Mixer.h"
|
|
|
|
|
|
|
|
#include "Globals.h" // Local
|
2009-06-28 10:24:44 +00:00
|
|
|
#include "DSPInterpreter.h"
|
|
|
|
#include "DSPHWInterface.h"
|
2009-03-23 09:10:32 +00:00
|
|
|
#include "disassemble.h"
|
2009-06-21 08:39:21 +00:00
|
|
|
#include "DSPSymbols.h"
|
2009-03-23 20:55:32 +00:00
|
|
|
#include "Config.h"
|
|
|
|
|
2009-03-26 09:29:14 +00:00
|
|
|
#include "AudioCommon.h"
|
|
|
|
#include "Logging/Logging.h" // For Logging
|
2009-03-23 09:10:32 +00:00
|
|
|
|
2009-03-26 09:29:14 +00:00
|
|
|
#include "Thread.h"
|
2009-03-23 09:10:32 +00:00
|
|
|
#include "ChunkFile.h"
|
|
|
|
|
2009-04-01 20:22:43 +00:00
|
|
|
#include "DSPTables.h"
|
2009-05-01 20:06:24 +00:00
|
|
|
#include "DSPCore.h"
|
2009-04-01 20:22:43 +00:00
|
|
|
|
2009-03-29 21:00:26 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
#include "DSPConfigDlgLLE.h"
|
2009-07-02 17:11:27 +00:00
|
|
|
DSPConfigDialogLLE* m_ConfigFrame = NULL;
|
|
|
|
#include "Debugger/Debugger.h"
|
2009-04-02 12:50:47 +00:00
|
|
|
DSPDebuggerLLE* m_DebuggerFrame = NULL;
|
2009-03-29 21:00:26 +00:00
|
|
|
#endif
|
|
|
|
|
2009-03-23 09:10:32 +00:00
|
|
|
PLUGIN_GLOBALS* globals = NULL;
|
|
|
|
DSPInitialize g_dspInitialize;
|
2009-03-30 06:28:15 +00:00
|
|
|
Common::Thread *g_hDSPThread = NULL;
|
2009-03-23 20:55:32 +00:00
|
|
|
SoundStream *soundStream = NULL;
|
|
|
|
|
2009-03-30 06:28:15 +00:00
|
|
|
bool bIsRunning = false;
|
2009-03-23 09:10:32 +00:00
|
|
|
|
2009-07-02 19:00:27 +00:00
|
|
|
// Standard crap to make wxWidgets happy
|
2009-07-02 17:11:27 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
|
2009-03-29 21:00:26 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
class wxDLLApp : public wxApp
|
|
|
|
{
|
|
|
|
bool OnInit()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2009-07-02 17:11:27 +00:00
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
2009-03-29 21:00:26 +00:00
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
|
|
|
#endif
|
|
|
|
|
2009-07-02 17:11:27 +00:00
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
|
|
|
|
DWORD dwReason, // reason called
|
|
|
|
LPVOID lpvReserved) // reserved
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
2009-03-29 21:00:26 +00:00
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
{
|
2009-07-02 17:11:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-03-29 21:00:26 +00:00
|
|
|
wxSetInstance((HINSTANCE)hinstDLL);
|
|
|
|
int argc = 0;
|
|
|
|
char **argv = NULL;
|
|
|
|
wxEntryStart(argc, argv);
|
2009-07-02 17:11:27 +00:00
|
|
|
if (!wxTheApp || !wxTheApp->CallOnInit())
|
2009-03-29 21:00:26 +00:00
|
|
|
return FALSE;
|
2009-07-02 17:11:27 +00:00
|
|
|
#endif
|
2009-03-29 21:00:26 +00:00
|
|
|
}
|
2009-07-02 17:11:27 +00:00
|
|
|
break;
|
2009-03-29 21:00:26 +00:00
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2009-07-02 17:11:27 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
wxEntryCleanup();
|
|
|
|
#endif
|
2009-03-29 21:00:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_hInstance = hinstDLL;
|
2009-07-02 17:11:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
wxWindow* GetParentedWxWindow(HWND Parent)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
wxSetInstance((HINSTANCE)g_hInstance);
|
|
|
|
#endif
|
|
|
|
wxWindow *win = new wxWindow();
|
|
|
|
#ifdef _WIN32
|
|
|
|
win->SetHWND((WXHWND)Parent);
|
|
|
|
win->AdoptAttributesFromHWND();
|
|
|
|
#endif
|
|
|
|
return win;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-03-29 21:00:26 +00:00
|
|
|
|
2009-03-23 09:10:32 +00:00
|
|
|
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_DSP;
|
|
|
|
|
|
|
|
#ifdef DEBUGFAST
|
2009-04-08 20:26:33 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin DSP-LLE Plugin (DebugFast)");
|
2009-03-23 09:10:32 +00:00
|
|
|
#else
|
|
|
|
#ifndef _DEBUG
|
2009-04-08 20:26:33 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin DSP-LLE Plugin");
|
2009-03-23 09:10:32 +00:00
|
|
|
#else
|
2009-04-08 20:26:33 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin DSP-LLE Plugin (Debug)");
|
2009-03-23 09:10:32 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
|
|
|
{
|
|
|
|
globals = _pPluginGlobals;
|
|
|
|
LogManager::SetInstance((LogManager *)globals->logManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DllConfig(HWND _hParent)
|
2009-03-23 20:55:32 +00:00
|
|
|
{
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-07-02 17:11:27 +00:00
|
|
|
if (!m_ConfigFrame)
|
|
|
|
m_ConfigFrame = new DSPConfigDialogLLE(GetParentedWxWindow(_hParent));
|
2009-07-03 03:01:58 +00:00
|
|
|
else if (!m_ConfigFrame->GetParent()->IsShown())
|
|
|
|
m_ConfigFrame->Close(true);
|
2009-03-23 20:55:32 +00:00
|
|
|
|
2009-03-27 14:26:44 +00:00
|
|
|
// add backends
|
|
|
|
std::vector<std::string> backends = AudioCommon::GetSoundBackends();
|
|
|
|
|
|
|
|
for (std::vector<std::string>::const_iterator iter = backends.begin();
|
|
|
|
iter != backends.end(); ++iter) {
|
2009-07-02 17:11:27 +00:00
|
|
|
m_ConfigFrame->AddBackend((*iter).c_str());
|
2009-03-27 14:26:44 +00:00
|
|
|
}
|
2009-03-23 20:55:32 +00:00
|
|
|
|
2009-07-02 17:11:27 +00:00
|
|
|
// Only allow one open at a time
|
|
|
|
if (!m_ConfigFrame->IsShown())
|
|
|
|
m_ConfigFrame->ShowModal();
|
|
|
|
else
|
|
|
|
m_ConfigFrame->Hide();
|
2009-03-23 20:55:32 +00:00
|
|
|
#endif
|
|
|
|
}
|
2009-03-23 09:10:32 +00:00
|
|
|
|
|
|
|
|
2009-03-29 21:00:26 +00:00
|
|
|
void DoState(unsigned char **ptr, int mode)
|
|
|
|
{
|
2009-03-23 09:10:32 +00:00
|
|
|
PointerWrap p(ptr, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DllDebugger(HWND _hParent, bool Show)
|
|
|
|
{
|
2009-03-30 13:21:22 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-06-21 08:39:21 +00:00
|
|
|
if (!m_DebuggerFrame)
|
2009-07-02 17:11:27 +00:00
|
|
|
m_DebuggerFrame = new DSPDebuggerLLE(GetParentedWxWindow(_hParent));
|
2009-04-18 19:06:47 +00:00
|
|
|
|
2009-06-21 08:39:21 +00:00
|
|
|
if (Show)
|
2009-04-18 19:06:47 +00:00
|
|
|
m_DebuggerFrame->Show();
|
|
|
|
else
|
|
|
|
m_DebuggerFrame->Hide();
|
2009-03-30 13:21:22 +00:00
|
|
|
#endif
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-29 09:35:40 +00:00
|
|
|
// Regular thread
|
2009-03-29 21:00:26 +00:00
|
|
|
THREAD_RETURN dsp_thread(void* lpParameter)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
2009-03-30 06:28:15 +00:00
|
|
|
while (bIsRunning)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
2009-05-01 22:17:22 +00:00
|
|
|
DSPInterpreter::Run();
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
2009-03-30 06:28:15 +00:00
|
|
|
return 0;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_DebugBreak()
|
|
|
|
{
|
2009-04-02 12:50:47 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-06-28 16:23:40 +00:00
|
|
|
// if (m_DebuggerFrame)
|
|
|
|
// m_DebuggerFrame->DebugBreak();
|
2009-04-02 12:50:47 +00:00
|
|
|
#endif
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Initialize(void *init)
|
|
|
|
{
|
2009-06-28 16:23:40 +00:00
|
|
|
bool bCanWork = true;
|
2009-03-23 09:10:32 +00:00
|
|
|
g_dspInitialize = *(DSPInitialize*)init;
|
|
|
|
|
2009-03-30 09:55:50 +00:00
|
|
|
g_Config.Load();
|
2009-04-05 15:46:47 +00:00
|
|
|
|
2009-06-07 11:06:40 +00:00
|
|
|
std::string irom_filename = File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + DSP_IROM;
|
|
|
|
std::string coef_filename = File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + DSP_COEF;
|
2009-07-02 23:36:15 +00:00
|
|
|
bCanWork = DSPCore_Init(irom_filename.c_str(), coef_filename.c_str());
|
2009-07-02 21:20:47 +00:00
|
|
|
|
2009-03-23 09:10:32 +00:00
|
|
|
g_dsp.cpu_ram = g_dspInitialize.pGetMemoryPointer(0);
|
2009-06-07 11:06:40 +00:00
|
|
|
DSPCore_Reset();
|
2009-04-05 15:46:47 +00:00
|
|
|
|
2009-04-08 20:26:33 +00:00
|
|
|
if (!bCanWork)
|
|
|
|
{
|
2009-07-02 21:20:47 +00:00
|
|
|
PanicAlert("DSPLLE: Failed to initialize plugin, exiting");
|
2009-06-07 11:06:40 +00:00
|
|
|
DSPCore_Shutdown();
|
2009-04-08 12:37:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-03-30 06:28:15 +00:00
|
|
|
|
|
|
|
bIsRunning = true;
|
2009-04-05 15:46:47 +00:00
|
|
|
|
2009-04-06 18:47:21 +00:00
|
|
|
InitInstructionTable();
|
|
|
|
|
2009-04-08 20:26:33 +00:00
|
|
|
if (g_dspInitialize.bOnThread)
|
|
|
|
{
|
|
|
|
g_hDSPThread = new Common::Thread(dsp_thread, NULL);
|
|
|
|
}
|
2009-03-30 09:55:50 +00:00
|
|
|
soundStream = AudioCommon::InitSoundStream();
|
2009-04-18 19:06:47 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2009-06-21 08:39:21 +00:00
|
|
|
if (m_DebuggerFrame)
|
2009-04-18 19:06:47 +00:00
|
|
|
m_DebuggerFrame->Refresh();
|
|
|
|
#endif
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_StopSoundStream()
|
|
|
|
{
|
2009-05-01 22:17:22 +00:00
|
|
|
DSPInterpreter::Stop();
|
2009-04-03 12:21:02 +00:00
|
|
|
bIsRunning = false;
|
2009-04-08 20:26:33 +00:00
|
|
|
if (g_dspInitialize.bOnThread)
|
|
|
|
{
|
|
|
|
delete g_hDSPThread;
|
|
|
|
g_hDSPThread = NULL;
|
|
|
|
}
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
2009-04-06 18:47:21 +00:00
|
|
|
void Shutdown()
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
2009-03-27 14:26:44 +00:00
|
|
|
AudioCommon::ShutdownSoundStream();
|
2009-06-07 11:06:40 +00:00
|
|
|
DSPCore_Shutdown();
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u16 DSP_WriteControlRegister(u16 _uFlag)
|
|
|
|
{
|
2009-05-01 22:17:22 +00:00
|
|
|
DSPInterpreter::WriteCR(_uFlag);
|
|
|
|
return DSPInterpreter::ReadCR();
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u16 DSP_ReadControlRegister()
|
|
|
|
{
|
2009-05-01 22:17:22 +00:00
|
|
|
return DSPInterpreter::ReadCR();
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u16 DSP_ReadMailboxHigh(bool _CPUMailbox)
|
|
|
|
{
|
|
|
|
if (_CPUMailbox)
|
2009-04-05 15:46:47 +00:00
|
|
|
return gdsp_mbox_read_h(GDSP_MBOX_CPU);
|
2009-03-23 09:10:32 +00:00
|
|
|
else
|
2009-04-05 15:46:47 +00:00
|
|
|
return gdsp_mbox_read_h(GDSP_MBOX_DSP);
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u16 DSP_ReadMailboxLow(bool _CPUMailbox)
|
|
|
|
{
|
|
|
|
if (_CPUMailbox)
|
2009-04-05 15:46:47 +00:00
|
|
|
return gdsp_mbox_read_l(GDSP_MBOX_CPU);
|
2009-03-23 09:10:32 +00:00
|
|
|
else
|
2009-04-05 15:46:47 +00:00
|
|
|
return gdsp_mbox_read_l(GDSP_MBOX_DSP);
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_WriteMailboxHigh(bool _CPUMailbox, u16 _uHighMail)
|
|
|
|
{
|
|
|
|
if (_CPUMailbox)
|
|
|
|
{
|
|
|
|
if (gdsp_mbox_peek(GDSP_MBOX_CPU) & 0x80000000)
|
|
|
|
{
|
2009-04-06 17:12:05 +00:00
|
|
|
ERROR_LOG(DSPLLE, "Mailbox isnt empty ... strange");
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if PROFILE
|
|
|
|
if ((_uHighMail) == 0xBABE)
|
|
|
|
{
|
|
|
|
ProfilerStart();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gdsp_mbox_write_h(GDSP_MBOX_CPU, _uHighMail);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-06 17:12:05 +00:00
|
|
|
ERROR_LOG(DSPLLE, "CPU cant write to DSP mailbox");
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_WriteMailboxLow(bool _CPUMailbox, u16 _uLowMail)
|
|
|
|
{
|
|
|
|
if (_CPUMailbox)
|
|
|
|
{
|
|
|
|
gdsp_mbox_write_l(GDSP_MBOX_CPU, _uLowMail);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-06 17:12:05 +00:00
|
|
|
ERROR_LOG(DSPLLE, "CPU cant write to DSP mailbox");
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_Update(int cycles)
|
|
|
|
{
|
2009-04-08 20:26:33 +00:00
|
|
|
// This gets called VERY OFTEN. The soundstream update might be expensive so only do it 200 times per second or something.
|
|
|
|
const int cycles_between_ss_update = 80000000 / 200;
|
|
|
|
static int cycle_count = 0;
|
|
|
|
cycle_count += cycles;
|
|
|
|
if (cycle_count > cycles_between_ss_update)
|
|
|
|
{
|
|
|
|
while (cycle_count > cycles_between_ss_update)
|
|
|
|
cycle_count -= cycles_between_ss_update;
|
|
|
|
soundStream->Update();
|
|
|
|
}
|
2009-04-02 12:50:47 +00:00
|
|
|
|
2009-04-08 20:26:33 +00:00
|
|
|
// If we're not on a thread, run cycles here.
|
|
|
|
if (!g_dspInitialize.bOnThread)
|
|
|
|
{
|
2009-06-28 16:23:40 +00:00
|
|
|
DSPCore_RunCycles(cycles);
|
2009-04-08 20:26:33 +00:00
|
|
|
}
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSP_SendAIBuffer(unsigned int address, int sample_rate)
|
|
|
|
{
|
2009-03-26 09:29:14 +00:00
|
|
|
if (soundStream->GetMixer())
|
|
|
|
{
|
|
|
|
short samples[16] = {0}; // interleaved stereo
|
|
|
|
if (address)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
samples[i] = Memory_Read_U16(address + i * 2);
|
|
|
|
}
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
2009-03-28 14:08:06 +00:00
|
|
|
soundStream->GetMixer()->PushSamples(samples, 32 / 4, sample_rate);
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 09:29:14 +00:00
|
|
|
// SoundStream is updated only when necessary (there is no 70 ms limit
|
|
|
|
// so each sample now triggers the sound stream)
|
|
|
|
|
|
|
|
// TODO: think about this.
|
2009-06-28 16:23:40 +00:00
|
|
|
// static int counter = 0;
|
|
|
|
// counter++;
|
2009-04-08 12:37:15 +00:00
|
|
|
if (/*(counter & 31) == 0 &&*/ soundStream)
|
2009-03-26 09:29:14 +00:00
|
|
|
soundStream->Update();
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|