2008-07-12 17:40:22 +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/
|
|
|
|
|
2008-09-17 22:39:30 +00:00
|
|
|
#include "Common.h"
|
2008-07-12 17:40:22 +00:00
|
|
|
#include "Globals.h"
|
2008-10-08 19:02:52 +00:00
|
|
|
#include "WaveFile.h"
|
2008-09-02 23:32:05 +00:00
|
|
|
#include "CommonTypes.h"
|
2008-10-04 00:16:19 +00:00
|
|
|
#include "Mixer.h"
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
#include "gdsp_interpreter.h"
|
|
|
|
#include "gdsp_interface.h"
|
|
|
|
#include "disassemble.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2008-10-02 22:00:20 +00:00
|
|
|
#include "DisAsmDlg.h"
|
|
|
|
#include "DSoundStream.h"
|
|
|
|
#include "Logging/Console.h" // For wprintf, ClearScreen
|
|
|
|
#include "Logging/Logging.h" // For Logging
|
|
|
|
|
|
|
|
HINSTANCE g_hInstance = NULL;
|
|
|
|
HANDLE g_hDSPThread = NULL;
|
|
|
|
CRITICAL_SECTION g_CriticalSection;
|
|
|
|
CDisAsmDlg g_Dialog;
|
2008-07-29 23:59:21 +00:00
|
|
|
#else
|
2008-10-02 22:00:20 +00:00
|
|
|
#define WINAPI
|
|
|
|
#define LPVOID void*
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include "AOSoundStream.h"
|
|
|
|
pthread_t g_hDSPThread = NULL;
|
2008-07-12 17:40:22 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-30 19:19:40 +00:00
|
|
|
#include "ChunkFile.h"
|
|
|
|
|
2008-10-03 01:31:11 +00:00
|
|
|
|
|
|
|
// =======================================================================================
|
|
|
|
// Globals
|
|
|
|
// --------------
|
2008-07-12 17:40:22 +00:00
|
|
|
DSPInitialize g_dspInitialize;
|
|
|
|
|
|
|
|
#define GDSP_MBOX_CPU 0
|
|
|
|
#define GDSP_MBOX_DSP 1
|
|
|
|
|
|
|
|
uint32 g_LastDMAAddress = 0;
|
|
|
|
uint32 g_LastDMASize = 0;
|
2008-10-03 01:31:11 +00:00
|
|
|
|
|
|
|
extern u32 m_addressPBs;
|
|
|
|
bool AXTask(u32& _uMail);
|
2008-10-04 13:39:38 +00:00
|
|
|
|
|
|
|
bool bCanWork = false;
|
2008-10-08 19:02:52 +00:00
|
|
|
|
|
|
|
// Set this if you want to log audio. search for log_ai in this file to see the filename.
|
|
|
|
static bool log_ai = false;
|
|
|
|
static WaveFileWriter g_wave_writer;
|
|
|
|
|
2008-10-03 01:31:11 +00:00
|
|
|
// ==============
|
|
|
|
|
|
|
|
|
2008-07-29 23:59:21 +00:00
|
|
|
#ifdef _WIN32
|
2008-07-12 17:40:22 +00:00
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
|
|
|
|
DWORD dwReason, // reason called
|
|
|
|
LPVOID lpvReserved) // reserved
|
|
|
|
{
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
return(TRUE);
|
|
|
|
}
|
2008-07-29 23:59:21 +00:00
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_DSP;
|
|
|
|
|
2008-07-16 12:17:20 +00:00
|
|
|
#ifdef DEBUGFAST
|
|
|
|
sprintf(_PluginInfo->Name, "Dolphin DSP-LLE Plugin (DebugFast)");
|
|
|
|
#else
|
2008-07-12 17:40:22 +00:00
|
|
|
#ifndef _DEBUG
|
2008-07-16 12:17:20 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin DSP-LLE Plugin");
|
2008-07-12 17:40:22 +00:00
|
|
|
#else
|
2008-07-16 12:17:20 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Dolphin DSP-LLE Plugin (Debug)");
|
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DllAbout(HWND _hParent)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void DllConfig(HWND _hParent)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-09-16 13:53:11 +00:00
|
|
|
void DSP_DoState(unsigned char **ptr, int mode) {
|
|
|
|
PointerWrap p(ptr, mode);
|
|
|
|
}
|
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
void DllDebugger(HWND _hParent)
|
|
|
|
{
|
2008-10-04 13:39:38 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#if defined (_DEBUG) || defined (DEBUGFAST)
|
|
|
|
if(bCanWork)
|
|
|
|
{
|
|
|
|
g_Dialog.Create(NULL); //_hParent);
|
|
|
|
g_Dialog.ShowWindow(SW_SHOW);
|
|
|
|
|
|
|
|
// Open the console window
|
|
|
|
startConsoleWin(155, 100, "Sound Debugging"); // give room for 100 rows
|
|
|
|
wprintf("DllDebugger > Console opened\n");
|
|
|
|
// TODO: Make this adjustable from the Debugging window
|
|
|
|
MoveWindow(GetConsoleHwnd(), 0,400, 1280,500, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: let us open the debugging window when we open the Dolphin-Debugger, fix the crash
|
|
|
|
// that currently occurs of you try to do that
|
|
|
|
MessageBox(0, "Can't open debugging window yet. Please start a game first", "DSP LLE", 0);
|
|
|
|
}
|
2008-10-04 21:31:20 +00:00
|
|
|
#else
|
2008-10-04 13:39:38 +00:00
|
|
|
MessageBox(0, "Can't open debugging window in Release build of this plugin.", "DSP LLE", 0);
|
2008-10-04 21:31:20 +00:00
|
|
|
#endif
|
2008-10-02 22:00:20 +00:00
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 22:00:20 +00:00
|
|
|
|
|
|
|
// =======================================================================================
|
|
|
|
// Regular thread
|
|
|
|
// --------------
|
2008-07-29 23:59:21 +00:00
|
|
|
#ifdef _WIN32
|
2008-07-12 17:40:22 +00:00
|
|
|
DWORD WINAPI dsp_thread(LPVOID lpParameter)
|
2008-07-29 23:59:21 +00:00
|
|
|
#else
|
|
|
|
void* dsp_thread(void* lpParameter)
|
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (!gdsp_run())
|
|
|
|
{
|
|
|
|
ErrorLog("*** DSP: CRITICAL ERROR ***\n");
|
|
|
|
//return 0;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-02 22:00:20 +00:00
|
|
|
// ==============
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
|
2008-10-02 22:00:20 +00:00
|
|
|
// =======================================================================================
|
|
|
|
// Debug thread
|
|
|
|
// --------------
|
2008-08-31 23:06:21 +00:00
|
|
|
#ifdef _WIN32
|
2008-07-12 17:40:22 +00:00
|
|
|
DWORD WINAPI dsp_thread_debug(LPVOID lpParameter)
|
2008-09-16 16:40:40 +00:00
|
|
|
#else
|
|
|
|
void* dsp_thread_debug(void* lpParameter)
|
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2008-09-16 16:40:40 +00:00
|
|
|
|
2008-09-30 01:09:02 +00:00
|
|
|
//if (g_hDSPThread)
|
|
|
|
//{
|
2008-10-02 22:00:20 +00:00
|
|
|
// return NULL; // enable this to disable the plugin
|
2008-09-30 01:09:02 +00:00
|
|
|
//}
|
2008-10-02 22:00:20 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2008-10-02 22:00:20 +00:00
|
|
|
Logging(); // logging
|
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
if (g_Dialog.CanDoStep())
|
|
|
|
{
|
|
|
|
gdsp_runx(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Sleep(100);
|
|
|
|
}
|
|
|
|
}
|
2008-09-16 16:40:40 +00:00
|
|
|
#endif
|
2008-09-16 20:24:34 +00:00
|
|
|
return NULL;
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
2008-10-02 22:00:20 +00:00
|
|
|
// ==============
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DSP_DebugBreak()
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2008-10-02 22:00:20 +00:00
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2008-07-12 17:40:22 +00:00
|
|
|
g_Dialog.DebugBreak();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dspi_req_dsp_irq()
|
|
|
|
{
|
|
|
|
g_dspInitialize.pGenerateDSPInterrupt();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DSP_Initialize(DSPInitialize _dspInitialize)
|
|
|
|
{
|
2008-10-04 13:39:38 +00:00
|
|
|
bCanWork = true;
|
2008-08-16 21:58:07 +00:00
|
|
|
g_dspInitialize = _dspInitialize;
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-08-16 21:58:07 +00:00
|
|
|
gdsp_init();
|
|
|
|
g_dsp.step_counter = 0;
|
|
|
|
g_dsp.cpu_ram = g_dspInitialize.pGetMemoryPointer(0);
|
|
|
|
g_dsp.irq_request = dspi_req_dsp_irq;
|
|
|
|
gdsp_reset();
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-16 16:40:40 +00:00
|
|
|
if (!gdsp_load_rom((char *)"data\\dsp_rom.bin"))
|
2008-08-16 21:58:07 +00:00
|
|
|
{
|
2008-09-16 13:53:11 +00:00
|
|
|
bCanWork = false;
|
|
|
|
PanicAlert("No DSP ROM");
|
2008-08-16 21:58:07 +00:00
|
|
|
ErrorLog("Cannot load DSP ROM\n");
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-16 16:40:40 +00:00
|
|
|
if (!gdsp_load_coef((char *)"data\\dsp_coef.bin"))
|
2008-08-16 21:58:07 +00:00
|
|
|
{
|
2008-09-16 13:53:11 +00:00
|
|
|
bCanWork = false;
|
|
|
|
PanicAlert("No DSP COEF");
|
2008-08-16 21:58:07 +00:00
|
|
|
ErrorLog("Cannot load DSP COEF\n");
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-16 13:53:11 +00:00
|
|
|
if(!bCanWork)
|
|
|
|
return; // TODO: Don't let it work
|
|
|
|
|
2008-10-02 22:00:20 +00:00
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
// First create DSP_UCode.bin by setting "#define DUMP_DSP_IMEM 1" in Globals.h. Then
|
|
|
|
// make the disassembled file here.
|
|
|
|
// --------------
|
2008-07-12 17:40:22 +00:00
|
|
|
/* Dump UCode to file...
|
|
|
|
FILE* t = fopen("e:\\hmm.txt", "wb");
|
|
|
|
gd_globals_t gdg;
|
|
|
|
gd_dis_file(&gdg, "D:\\DSP_UCode.bin", t);
|
|
|
|
fclose(t); */
|
2008-10-02 22:00:20 +00:00
|
|
|
// --------------
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-07-29 23:59:21 +00:00
|
|
|
#ifdef _WIN32
|
2008-10-02 22:00:20 +00:00
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2008-07-12 17:40:22 +00:00
|
|
|
g_hDSPThread = CreateThread(NULL, 0, dsp_thread_debug, 0, 0, NULL);
|
|
|
|
#else
|
|
|
|
g_hDSPThread = CreateThread(NULL, 0, dsp_thread, 0, 0, NULL);
|
2008-09-16 16:40:40 +00:00
|
|
|
#endif // DEBUG
|
|
|
|
#else
|
|
|
|
#if _DEBUG
|
|
|
|
pthread_create(&g_hDSPThread, NULL, dsp_thread_debug, (void *)NULL);
|
2008-07-29 23:59:21 +00:00
|
|
|
#else
|
|
|
|
pthread_create(&g_hDSPThread, NULL, dsp_thread, (void *)NULL);
|
2008-09-16 16:40:40 +00:00
|
|
|
#endif // DEBUG
|
|
|
|
#endif // WIN32
|
|
|
|
|
2008-10-08 19:02:52 +00:00
|
|
|
if (log_ai) {
|
|
|
|
g_wave_writer.Start("D:\\ai_log.wav");
|
|
|
|
g_wave_writer.SetSkipSilence(false);
|
|
|
|
}
|
|
|
|
|
2008-08-16 21:58:07 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
InitializeCriticalSection(&g_CriticalSection);
|
|
|
|
DSound::DSound_StartSound((HWND)g_dspInitialize.hWnd, 48000, Mixer);
|
|
|
|
#else
|
|
|
|
AOSound::AOSound_StartSound(48000, Mixer);
|
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DSP_Shutdown(void)
|
|
|
|
{
|
2008-10-08 19:02:52 +00:00
|
|
|
if (log_ai)
|
|
|
|
g_wave_writer.Stop();
|
2008-09-16 16:40:40 +00:00
|
|
|
#ifdef _WIN32
|
2008-07-12 17:40:22 +00:00
|
|
|
if (g_hDSPThread != NULL)
|
|
|
|
{
|
2008-09-16 16:40:40 +00:00
|
|
|
TerminateThread(g_hDSPThread, 0);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
pthread_cancel(g_hDSPThread);
|
|
|
|
#endif
|
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
2008-09-02 23:32:05 +00:00
|
|
|
u16 DSP_WriteControlRegister(u16 _uFlag)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
gdsp_write_cr(_uFlag);
|
|
|
|
return(gdsp_read_cr());
|
|
|
|
}
|
|
|
|
|
2008-09-02 23:32:05 +00:00
|
|
|
u16 DSP_ReadControlRegister()
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
return(gdsp_read_cr());
|
|
|
|
}
|
|
|
|
|
2008-09-02 23:32:05 +00:00
|
|
|
u16 DSP_ReadMailboxHigh(bool _CPUMailbox)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
if (_CPUMailbox)
|
|
|
|
{
|
|
|
|
return(gdsp_mbox_read_h(GDSP_MBOX_CPU));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return(gdsp_mbox_read_h(GDSP_MBOX_DSP));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-02 23:32:05 +00:00
|
|
|
u16 DSP_ReadMailboxLow(bool _CPUMailbox)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
if (_CPUMailbox)
|
|
|
|
{
|
|
|
|
return(gdsp_mbox_read_l(GDSP_MBOX_CPU));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return(gdsp_mbox_read_l(GDSP_MBOX_DSP));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-02 23:32:05 +00:00
|
|
|
void DSP_WriteMailboxHigh(bool _CPUMailbox, u16 _uHighMail)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
if (_CPUMailbox)
|
|
|
|
{
|
|
|
|
if (gdsp_mbox_peek(GDSP_MBOX_CPU) & 0x80000000)
|
|
|
|
{
|
|
|
|
ErrorLog("Mailbox isnt empty ... strange");
|
|
|
|
}
|
|
|
|
|
|
|
|
gdsp_mbox_write_h(GDSP_MBOX_CPU, _uHighMail);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ErrorLog("CPU cant write to DSP mailbox");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-02 23:32:05 +00:00
|
|
|
void DSP_WriteMailboxLow(bool _CPUMailbox, u16 _uLowMail)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
if (_CPUMailbox)
|
|
|
|
{
|
|
|
|
gdsp_mbox_write_l(GDSP_MBOX_CPU, _uLowMail);
|
|
|
|
|
2008-10-03 01:31:11 +00:00
|
|
|
u32 uAddress = gdsp_mbox_peek(GDSP_MBOX_CPU);
|
|
|
|
u16 errpc = g_dsp.err_pc;
|
|
|
|
|
|
|
|
DebugLog("Write CPU Mail: 0x%08x (pc=0x%04x)\n", uAddress, errpc);
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
// I couldn't find any better way to detect the AX mails so this had to do. Please feel free
|
|
|
|
// to change it.
|
|
|
|
// --------------
|
|
|
|
if ((errpc == 0x0054 || errpc == 0x0055) && m_addressPBs == 0)
|
|
|
|
{
|
|
|
|
DebugLog("AXTask ======== 0x%08x (pc=0x%04x)", uAddress, errpc);
|
|
|
|
AXTask(uAddress);
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ErrorLog("CPU cant write to DSP mailbox");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-16 21:58:07 +00:00
|
|
|
void DSP_Update(int cycles)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
|
|
|
if (g_hDSPThread)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-07-29 23:59:21 +00:00
|
|
|
#ifdef _WIN32
|
2008-07-12 17:40:22 +00:00
|
|
|
if (g_Dialog.CanDoStep())
|
|
|
|
{
|
2008-08-16 21:58:07 +00:00
|
|
|
gdsp_runx(100); // cycles
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
2008-07-29 23:59:21 +00:00
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
2008-10-04 00:16:19 +00:00
|
|
|
|
2008-08-16 21:58:07 +00:00
|
|
|
void DSP_SendAIBuffer(unsigned int address, int sample_rate)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2008-10-04 00:16:19 +00:00
|
|
|
short samples[16] = {0}; // interleaved stereo
|
|
|
|
if (address) {
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
samples[i] = Memory_Read_U16(address + i * 2);
|
|
|
|
}
|
2008-10-08 19:02:52 +00:00
|
|
|
if (log_ai)
|
|
|
|
g_wave_writer.AddStereoSamples(samples, 8);
|
2008-10-04 00:16:19 +00:00
|
|
|
}
|
|
|
|
Mixer_PushSamples(samples, 32 / 4, sample_rate);
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-04 00:16:19 +00:00
|
|
|
static int counter = 0;
|
|
|
|
counter++;
|
|
|
|
#ifdef _WIN32
|
|
|
|
if ((counter & 255) == 0)
|
|
|
|
DSound::DSound_UpdateSound();
|
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
2008-09-17 23:25:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void __Log(int, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
//DebugLog(fmt);
|
|
|
|
}
|