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
|
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
|
#include "ConsoleWindow.h" // Common: For the Windows console
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "ChunkFile.h"
|
|
|
|
|
#include "WaveFile.h"
|
|
|
|
|
#include "PCHW/Mixer.h"
|
|
|
|
|
#include "DSPHandler.h"
|
|
|
|
|
#include "Config.h"
|
2009-02-14 01:07:20 +00:00
|
|
|
|
#include "Setup.h"
|
|
|
|
|
#include "StringUtil.h"
|
2009-01-17 14:28:09 +00:00
|
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
|
#include "PCHW/AOSoundStream.h"
|
|
|
|
|
#include "PCHW/DSoundStream.h"
|
|
|
|
|
#include "PCHW/NullSoundStream.h"
|
2009-01-17 14:28:09 +00:00
|
|
|
|
|
|
|
|
|
// Declarations and definitions
|
2008-12-08 05:25:12 +00:00
|
|
|
|
DSPInitialize g_dspInitialize;
|
|
|
|
|
u8* g_pMemory;
|
|
|
|
|
extern std::vector<std::string> sMailLog, sMailTime;
|
|
|
|
|
std::string gpName;
|
|
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
|
SoundStream *soundStream = NULL;
|
|
|
|
|
|
2009-02-14 01:07:20 +00:00
|
|
|
|
// Set this if you want to log audio. search for log_ai in this file to see the filename.
|
|
|
|
|
bool log_ai = false;
|
|
|
|
|
WaveFileWriter g_wave_writer;
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Open and close console
|
|
|
|
|
void OpenConsole()
|
|
|
|
|
{
|
2009-01-29 00:57:55 +00:00
|
|
|
|
#if defined (_WIN32)
|
2009-01-29 01:53:07 +00:00
|
|
|
|
Console::Open(155, 100, "Sound Debugging"); // give room for 100 rows
|
|
|
|
|
Console::Print("OpenConsole > Console opened\n");
|
|
|
|
|
MoveWindow(Console::GetHwnd(), 0,400, 1280,550, true); // move window, TODO: make this
|
|
|
|
|
// adjustable from the debugging window
|
2009-01-29 00:57:55 +00:00
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CloseConsole()
|
|
|
|
|
{
|
2009-01-29 00:57:55 +00:00
|
|
|
|
#if defined (_WIN32)
|
2009-01-29 01:53:07 +00:00
|
|
|
|
FreeConsole();
|
2009-01-29 00:57:55 +00:00
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
|
// Exported fuctions
|
|
|
|
|
|
2008-12-08 05:25:12 +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.
|
|
|
|
|
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-01-08 12:12:15 +00:00
|
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) {
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
// Add avaliable output options
|
2009-01-29 01:53:07 +00:00
|
|
|
|
if (DSound::isValid())
|
|
|
|
|
dlg.AddBackend("DSound");
|
|
|
|
|
if (AOSound::isValid())
|
|
|
|
|
dlg.AddBackend("AOSound");
|
|
|
|
|
dlg.AddBackend("NullSound");
|
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-01-15 06:48:15 +00:00
|
|
|
|
void Initialize(void *init)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-02-14 01:07:20 +00:00
|
|
|
|
//Console::Open(80, 5000);
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2009-01-29 01:53:07 +00:00
|
|
|
|
gpName = g_dspInitialize.pName(); // save the game name globally
|
|
|
|
|
for (u32 i = 0; i < gpName.length(); ++i) // and fix it
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
|
fprintf(stderr,"%c", gpName[i]);
|
|
|
|
|
std::cout << gpName[i];
|
|
|
|
|
if (gpName[i] == ':') gpName[i] = ' ';
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-29 01:53:07 +00:00
|
|
|
|
fprintf(stderr, "\n");
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2009-01-29 01:53:07 +00:00
|
|
|
|
CDSPHandler::CreateInstance();
|
|
|
|
|
|
2009-02-14 01:07:20 +00:00
|
|
|
|
if (g_Config.sBackend == "DSound")
|
|
|
|
|
{
|
|
|
|
|
if (DSound::isValid())
|
2009-01-29 01:53:07 +00:00
|
|
|
|
soundStream = new DSound(48000, Mixer, g_dspInitialize.hWnd);
|
2009-02-14 01:07:20 +00:00
|
|
|
|
}
|
2009-02-20 22:04:52 +00:00
|
|
|
|
else if (g_Config.sBackend == "AOSound")
|
2009-02-14 01:07:20 +00:00
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
|
if (AOSound::isValid())
|
|
|
|
|
soundStream = new AOSound(48000, Mixer);
|
2009-02-14 01:07:20 +00:00
|
|
|
|
}
|
2009-02-20 22:04:52 +00:00
|
|
|
|
else if (g_Config.sBackend == "NullSound")
|
2009-02-14 01:07:20 +00:00
|
|
|
|
{
|
2009-02-09 19:50:06 +00:00
|
|
|
|
soundStream = new NullSound(48000, Mixer_MixUCode);
|
2009-02-14 01:07:20 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
|
PanicAlert("Cannot recognize backend %s", g_Config.sBackend);
|
|
|
|
|
return;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-29 01:53:07 +00:00
|
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
|
#if defined(WIN32) && defined(_DEBUG)
|
2009-01-29 01:53:07 +00:00
|
|
|
|
int tmpflag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
|
|
|
|
tmpflag |= _CRTDBG_DELAY_FREE_MEM_DF;
|
|
|
|
|
_CrtSetDbgFlag(tmpflag);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#endif
|
2009-01-29 00:57:55 +00:00
|
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
|
if (soundStream)
|
|
|
|
|
{
|
|
|
|
|
if (!soundStream->Start())
|
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
|
PanicAlert("Could not initialize backend %s, falling back to NULL",
|
|
|
|
|
g_Config.sBackend);
|
|
|
|
|
delete soundStream;
|
|
|
|
|
soundStream = new NullSound(48000, Mixer);
|
|
|
|
|
soundStream->Start();
|
|
|
|
|
}
|
2009-02-20 22:04:52 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-01-29 01:53:07 +00:00
|
|
|
|
PanicAlert("Sound backend %s is not valid, falling back to NULL",
|
|
|
|
|
g_Config.sBackend);
|
|
|
|
|
delete soundStream;
|
|
|
|
|
soundStream = new NullSound(48000, Mixer);
|
|
|
|
|
soundStream->Start();
|
2009-01-29 00:57:55 +00:00
|
|
|
|
}
|
2009-01-29 01:53:07 +00:00
|
|
|
|
|
2009-02-14 01:07:20 +00:00
|
|
|
|
// Start the sound recording
|
|
|
|
|
if (log_ai)
|
|
|
|
|
{
|
|
|
|
|
g_wave_writer.Start("ai_log.wav");
|
|
|
|
|
g_wave_writer.SetSkipSilence(false);
|
|
|
|
|
}
|
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
|
|
|
|
if (!soundStream)
|
|
|
|
|
PanicAlert("Can't stop non running SoundStream!");
|
2009-01-29 01:53:07 +00:00
|
|
|
|
soundStream->Stop();
|
|
|
|
|
delete soundStream;
|
|
|
|
|
soundStream = NULL;
|
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()
|
|
|
|
|
{
|
|
|
|
|
// Check that soundstream already is stopped.
|
|
|
|
|
if (soundStream)
|
|
|
|
|
PanicAlert("SoundStream alive in DSP::Shutdown!");
|
|
|
|
|
|
|
|
|
|
// Stop the sound recording
|
|
|
|
|
if (log_ai)
|
|
|
|
|
g_wave_writer.Stop();
|
|
|
|
|
|
|
|
|
|
// 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
|
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
|
2009-02-14 01:07:20 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
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-02-14 01:07:20 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
2009-01-17 14:28:09 +00:00
|
|
|
|
// Other DSP fuctions
|
2009-02-14 01:07:20 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
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-01-29 01:53:07 +00:00
|
|
|
|
CDSPHandler::GetInstance().Update();
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-14 01:07:20 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (soundStream->usesMixer())
|
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
|
|
|
|
|
|
|
|
|
// Write the audio to a file
|
2009-02-20 22:04:52 +00:00
|
|
|
|
if (log_ai)
|
|
|
|
|
g_wave_writer.AddStereoSamples(samples, 8);
|
2009-01-29 01:53:07 +00:00
|
|
|
|
}
|
|
|
|
|
Mixer_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-02-14 01:07:20 +00:00
|
|
|
|
/////////////////////////////////////
|