This is a joined work of XK and me on improving the HLE plugin interface.

It allows run time selection of backends (AOSound, DSound and NullSound).
It replaces the DSP_NULL plugin (works even better!)
It also includes improved thread handling on asound, and using some common functions on both
asound and windows.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2027 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2009-01-29 00:57:55 +00:00
parent 121be22532
commit 7219bcd4d5
46 changed files with 705 additions and 4584 deletions

View File

@ -331,7 +331,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="dxguid.lib dsound.lib comctl32.lib"
AdditionalDependencies="dxguid.lib dsound.lib dxerr.lib comctl32.lib"
OutputFile="../../../Binary/x64/Plugins/Plugin_DSP_HLE.dll"
LinkIncremental="1"
GenerateManifest="false"
@ -551,6 +551,14 @@
<Filter
Name="PCHW"
>
<File
RelativePath=".\Src\PCHW\AOSoundStream.cpp"
>
</File>
<File
RelativePath=".\Src\PCHW\AOSoundStream.h"
>
</File>
<File
RelativePath=".\Src\Pchw\DSoundStream.cpp"
>
@ -567,6 +575,14 @@
RelativePath=".\Src\Pchw\Mixer.h"
>
</File>
<File
RelativePath=".\Src\PCHW\NullSoundStream.h"
>
</File>
<File
RelativePath=".\Src\PCHW\SoundStream.h"
>
</File>
</Filter>
<Filter
Name="UCodes"
@ -776,6 +792,10 @@
RelativePath=".\Src\main.cpp"
>
</File>
<File
RelativePath=".\Src\main.h"
>
</File>
<File
RelativePath=".\Src\SConscript"
>

View File

@ -26,22 +26,23 @@ CConfig::CConfig()
Load();
}
void CConfig::LoadDefaults()
{
m_EnableHLEAudio = true;
m_EnableDTKMusic = true;
}
void CConfig::Load()
{
// first load defaults
LoadDefaults();
std::string temp;
IniFile file;
file.Load(FULL_CONFIG_DIR "DSP.ini");
file.Get("Config", "EnableHLEAudio", &m_EnableHLEAudio, true); // Sound Settings
file.Get("Config", "EnableDTKMusic", &m_EnableDTKMusic, true);
file.Get("Config", "EnableThrottle", &m_EnableThrottle, true);
#ifdef _WIN32
file.Get("Config", "Backend", &temp, "DSound");
#else
file.Get("Config", "Backend", &temp, "AOSound");
#endif
strncpy(sBackend, temp.c_str(), 16);
}
void CConfig::Save()
@ -51,6 +52,7 @@ void CConfig::Save()
file.Set("Config", "EnableHLEAudio", m_EnableHLEAudio); // Sound Settings
file.Set("Config", "EnableDTKMusic", m_EnableDTKMusic);
file.Set("Config", "EnableThrottle", m_EnableThrottle);
file.Set("Config", "Backend", sBackend);
file.Save(FULL_CONFIG_DIR "DSP.ini");
}

View File

@ -22,17 +22,16 @@
struct CConfig
{
bool m_EnableHLEAudio;
bool m_EnableDTKMusic;
bool m_EnableThrottle;
CConfig();
void LoadDefaults();
void Load();
void Save();
bool m_EnableHLEAudio;
bool m_EnableDTKMusic;
bool m_EnableThrottle;
char sBackend[10];
CConfig();
void Load();
void Save();
};
extern CConfig g_Config;

View File

@ -41,11 +41,15 @@ ConfigDialog::ConfigDialog(wxWindow *parent, wxWindowID id, const wxString &titl
m_buttonEnableHLEAudio = new wxCheckBox(this, ID_ENABLE_HLE_AUDIO, wxT("Enable HLE Audio"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_buttonEnableDTKMusic = new wxCheckBox(this, ID_ENABLE_DTK_MUSIC, wxT("Enable DTK Music"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_buttonEnableThrottle = new wxCheckBox(this, ID_ENABLE_THROTTLE, wxT("Enable Other Audio (Throttle)"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
wxStaticText *BackendText = new wxStaticText(this, wxID_ANY, wxT("Audio Backend"), wxDefaultPosition, wxDefaultSize, 0);
m_BackendSelection = new wxComboBox(this, ID_BACKEND, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxArrayBackends, 0, wxDefaultValidator);
// Update checkboxes
// Update values
m_buttonEnableHLEAudio->SetValue(g_Config.m_EnableHLEAudio ? true : false);
m_buttonEnableDTKMusic->SetValue(g_Config.m_EnableDTKMusic ? true : false);
m_buttonEnableThrottle->SetValue(g_Config.m_EnableThrottle ? true : false);
m_BackendSelection->SetValue(wxString::FromAscii(g_Config.sBackend));
// Add tooltips
m_buttonEnableHLEAudio->SetToolTip(wxT("This is the most common sound type"));
@ -60,6 +64,11 @@ ConfigDialog::ConfigDialog(wxWindow *parent, wxWindowID id, const wxString &titl
sbSettings->Add(m_buttonEnableHLEAudio, 0, wxALL, 5);
sbSettings->Add(m_buttonEnableDTKMusic, 0, wxALL, 5);
sbSettings->Add(m_buttonEnableThrottle, 0, wxALL, 5);
wxBoxSizer *sBackend = new wxBoxSizer(wxHORIZONTAL);
sBackend->Add(BackendText, 0, wxALIGN_CENTRE_VERTICAL|wxALL, 5);
sBackend->Add(m_BackendSelection);
sbSettings->Add(sBackend);
sMain->Add(sbSettings, 0, wxEXPAND|wxALL, 5);
wxBoxSizer *sButtons = new wxBoxSizer(wxHORIZONTAL);
sButtons->Add(150, 0); // Lazy way to make the dialog as wide as we want it
@ -68,6 +77,10 @@ ConfigDialog::ConfigDialog(wxWindow *parent, wxWindowID id, const wxString &titl
this->SetSizerAndFit(sMain);
}
void ConfigDialog::AddBackend(const char* backend) {
m_BackendSelection->Append(wxString::FromAscii(backend));
}
ConfigDialog::~ConfigDialog()
{
}
@ -77,6 +90,7 @@ void ConfigDialog::SettingsChanged(wxCommandEvent& event)
g_Config.m_EnableHLEAudio = m_buttonEnableHLEAudio->GetValue();
g_Config.m_EnableDTKMusic = m_buttonEnableDTKMusic->GetValue();
g_Config.m_EnableThrottle = m_buttonEnableThrottle->GetValue();
strcpy(g_Config.sBackend, m_BackendSelection->GetValue().mb_str());
g_Config.Save();
if (event.GetId() == wxID_OK)

View File

@ -27,31 +27,35 @@ class ConfigDialog : public wxDialog
{
public:
ConfigDialog(wxWindow *parent,
wxWindowID id = 1,
const wxString &title = wxT("Dolphin DSP-HLE Plugin Settings"),
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE);
virtual ~ConfigDialog();
wxWindowID id = 1,
const wxString &title = wxT("Dolphin DSP-HLE Plugin Settings"),
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE);
virtual ~ConfigDialog();
void AddBackend(const char *backend);
private:
DECLARE_EVENT_TABLE();
DECLARE_EVENT_TABLE();
wxButton *m_OK;
wxCheckBox *m_buttonEnableHLEAudio;
wxCheckBox *m_buttonEnableDTKMusic;
wxCheckBox *m_buttonEnableThrottle;
wxArrayString wxArrayBackends;
wxComboBox *m_BackendSelection;
wxButton *m_OK;
wxCheckBox *m_buttonEnableHLEAudio;
wxCheckBox *m_buttonEnableDTKMusic;
wxCheckBox *m_buttonEnableThrottle;
enum
enum
{
wxID_OK,
ID_ENABLE_HLE_AUDIO,
ID_ENABLE_DTK_MUSIC,
ID_ENABLE_THROTTLE
wxID_OK,
ID_ENABLE_HLE_AUDIO,
ID_ENABLE_DTK_MUSIC,
ID_ENABLE_THROTTLE,
ID_BACKEND
};
void OnOK(wxCommandEvent& event);
void SettingsChanged(wxCommandEvent& event);
void OnOK(wxCommandEvent& event);
void SettingsChanged(wxCommandEvent& event);
};
#endif //__DSP_HLE_CONFIGDIALOG_h__

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003-2008 Dolphin Project.
// Copyright (C) 2003-2009 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
@ -15,78 +15,74 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include <ao/ao.h>
#include <pthread.h>
#include <string.h>
#include "AOSoundStream.h"
namespace AOSound
#if defined(HAVE_AO) && HAVE_AO
void AOSound::SoundLoop()
{
pthread_t thread;
StreamCallback callback;
int buf_size;
ao_device *device;
ao_sample_format format;
int default_driver;
int sampleRate;
volatile int threadData;
short realtimeBuffer[1024 * 1024];
int AOSound_GetSampleRate()
{
return sampleRate;
}
void *soundThread(void *)
{
ao_initialize();
default_driver = ao_default_driver_id();
format.bits = 16;
format.channels = 2;
format.rate = sampleRate;
format.byte_format = AO_FMT_LITTLE;
ao_initialize();
default_driver = ao_default_driver_id();
format.bits = 16;
format.channels = 2;
format.rate = sampleRate;
format.byte_format = AO_FMT_LITTLE;
device = ao_open_live(default_driver, &format, NULL /* no options */);
if (device == NULL)
{
fprintf(stderr, "DSP_HLE: Error opening AO device.\n");
return false;
}
buf_size = format.bits/8 * format.channels * format.rate;
device = ao_open_live(default_driver, &format, NULL /* no options */);
if (device == NULL) {
PanicAlert("DSP_HLE: Error opening AO device.\n");
ao_shutdown();
Stop();
return;
}
while (!threadData)
{
uint_32 numBytesToRender = 256;
(*callback)(realtimeBuffer, numBytesToRender >> 2, 16, sampleRate, 2);
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
}
buf_size = format.bits/8 * format.channels * format.rate;
ao_close(device);
device = 0;
ao_shutdown();
while (!threadData) {
soundCriticalSection->Enter();
uint_32 numBytesToRender = 256;
(*callback)(realtimeBuffer, numBytesToRender >> 2, 16, sampleRate, 2);
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
soundCriticalSection->Leave();
soundSyncEvent->Wait();
}
return 0;
}
bool AOSound_StartSound(int _sampleRate, StreamCallback _callback)
{
callback = _callback;
threadData = 0;
sampleRate = _sampleRate;
memset(realtimeBuffer, 0, sizeof(realtimeBuffer));
pthread_create(&thread, NULL, soundThread, (void *)NULL);
return true;
}
void AOSound_StopSound()
{
threadData = 1;
void *retval;
pthread_join(thread, &retval);
}
ao_close(device);
device = NULL;
ao_shutdown();
}
void *soundThread(void *args) {
((AOSound *)args)->SoundLoop();
return NULL;
}
bool AOSound::Start() {
memset(realtimeBuffer, 0, sizeof(realtimeBuffer));
soundCriticalSection = new Common::CriticalSection(1);
thread = new Common::Thread(soundThread, (void *)this);
soundSyncEvent = new Common::Event();
soundSyncEvent->Init();
return true;
}
void AOSound::Update() {
soundSyncEvent->Set();
}
void AOSound::Stop()
{
soundCriticalSection->Enter();
threadData = 1;
soundSyncEvent->Set();
soundCriticalSection->Leave();
soundSyncEvent->Shutdown();
delete soundCriticalSection;
delete thread;
delete soundSyncEvent;
}
#endif

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003-2008 Dolphin Project.
// Copyright (C) 2003-2009 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
@ -18,18 +18,69 @@
#ifndef __AOSOUNDSTREAM_H__
#define __AOSOUNDSTREAM_H__
namespace AOSound
#include "SoundStream.h"
#if defined(HAVE_AO) && HAVE_AO
#include <ao/ao.h>
#endif
#include "Thread.h"
class AOSound : public SoundStream
{
typedef void (*StreamCallback)(short* buffer, int numSamples, int bits, int rate, int channels);
bool AOSound_StartSound(int sampleRate, StreamCallback _callback);
void AOSound_UpdateSound();
void AOSound_StopSound();
#if defined(HAVE_AO) && HAVE_AO
Common::Thread *thread;
float AOSound_GetTimer();
int AOSound_GetCurSample();
int AOSound_GetSampleRate();
}
Common::CriticalSection *soundCriticalSection;
Common::Event *soundSyncEvent;
int buf_size;
ao_device *device;
ao_sample_format format;
int default_driver;
short realtimeBuffer[1024 * 1024];
public:
AOSound(int _sampleRate, StreamCallback _callback) :
SoundStream(_sampleRate, _callback) {}
virtual ~AOSound() {}
virtual bool Start();
virtual void SoundLoop();
virtual void Stop();
static bool isValid() {
return true;
}
virtual bool usesMixer() {
return true;
}
virtual void Update();
virtual int GetSampleRate() {
return sampleRate;
}
#else
public:
AOSound(int _sampleRate, StreamCallback _callback) :
SoundStream(_sampleRate, _callback) {}
#endif
};
#endif //__AOSOUNDSTREAM_H__

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003-2008 Dolphin Project.
// Copyright (C) 2003-2009 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
@ -15,53 +15,12 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "stdafx.h"
#include <mmsystem.h>
#include <dsound.h>
#include "DSoundStream.h"
#include "../main.h"
namespace DSound
{
#include <dxerr.h>
#define BUFSIZE 32768
#define MAXWAIT 70 //ms
CRITICAL_SECTION soundCriticalSection;
HANDLE soundSyncEvent;
HANDLE hThread;
StreamCallback callback;
IDirectSound8* ds;
IDirectSoundBuffer* dsBuffer;
int bufferSize; //i bytes
int totalRenderedBytes;
int sampleRate;
// playback position
int currentPos;
int lastPos;
short realtimeBuffer[1024 * 1024];
// We set this to shut down the sound thread.
// 0=keep playing, 1=stop playing NOW.
volatile int threadData;
inline int FIX128(int x)
{
return(x & (~127));
}
int DSound_GetSampleRate()
{
return(sampleRate);
}
bool CreateBuffer()
bool DSound::CreateBuffer()
{
PCMWAVEFORMAT pcmwf;
DSBUFFERDESC dsbdesc;
@ -80,22 +39,23 @@ bool CreateBuffer()
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STICKYFOCUS; //VIKTIGT //DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
dsbdesc.dwBufferBytes = bufferSize = BUFSIZE;
dsbdesc.lpwfxFormat = (WAVEFORMATEX*)&pcmwf;
dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&pcmwf;
if (SUCCEEDED(ds->CreateSoundBuffer(&dsbdesc, &dsBuffer, NULL)))
HRESULT res = ds->CreateSoundBuffer(&dsbdesc, &dsBuffer, NULL);
if (SUCCEEDED(res))
{
dsBuffer->SetCurrentPosition(0);
return(true);
return true;
}
else
{
else {
// Failed.
PanicAlert("Sound buffer creation failed: %s", DXGetErrorString(res));
dsBuffer = NULL;
return(false);
return false;
}
}
bool WriteDataToBuffer(DWORD dwOffset, // Our own write cursor.
bool DSound::WriteDataToBuffer(DWORD dwOffset, // Our own write cursor.
char* soundData, // Start of our data.
DWORD dwSoundBytes) // Size of block to copy.
{
@ -122,20 +82,22 @@ bool WriteDataToBuffer(DWORD dwOffset, // Our own write cursor.
// Release the data back to DirectSound.
dsBuffer->Unlock(ptr1, numBytes1, ptr2, numBytes2);
return(true);
return true;
}
return(false);
}
inline int ModBufferSize(int x)
{
return((x + bufferSize) % bufferSize);
return false;
}
// The audio thread.
DWORD WINAPI soundThread(void*)
DWORD WINAPI soundThread(void* args)
{
((DSound *)args)->SoundLoop();
return 0; //huzzah! :D
}
void DSound::SoundLoop() {
currentPos = 0;
lastPos = 0;
@ -144,18 +106,19 @@ DWORD WINAPI soundThread(void*)
// dsBuffer->Lock(0, bufferSize, (void **)&p1, &num1, (void **)&p2, &num2, 0);
dsBuffer->Play(0, 0, DSBPLAY_LOOPING);
while (!threadData)
{
while (!threadData) {
// No blocking inside the csection
EnterCriticalSection(&soundCriticalSection);
soundCriticalSection->Enter();
dsBuffer->GetCurrentPosition((DWORD*)&currentPos, 0);
int numBytesToRender = FIX128(ModBufferSize(currentPos - lastPos));
int numBytesToRender = FIX128(
ModBufferSize(currentPos - lastPos));
if (numBytesToRender >= 256)
{
if (numBytesToRender > sizeof(realtimeBuffer))
MessageBox(0,"soundThread: too big render call",0,0);
(*callback)(realtimeBuffer, numBytesToRender >> 2, 16, sampleRate, 2);
PanicAlert("soundThread: too big render call");
(*callback)(realtimeBuffer, numBytesToRender >> 2, 16,
sampleRate, 2);
WriteDataToBuffer(lastPos, (char*)realtimeBuffer, numBytesToRender);
currentPos = ModBufferSize(lastPos + numBytesToRender);
@ -164,36 +127,32 @@ DWORD WINAPI soundThread(void*)
lastPos = currentPos;
}
LeaveCriticalSection(&soundCriticalSection);
WaitForSingleObject(soundSyncEvent, MAXWAIT);
soundCriticalSection->Leave();
soundSyncEvent->Wait();
}
dsBuffer->Stop();
return(0); //hurra!
}
bool DSound_StartSound(HWND window, int _sampleRate, StreamCallback _callback)
bool DSound::Start()
{
callback = _callback;
threadData = 0;
sampleRate = _sampleRate;
//no security attributes, automatic resetting, init state nonset, untitled
soundSyncEvent = CreateEvent(0, false, false, 0);
soundSyncEvent = new Common::Event();
soundSyncEvent->Init();
//vi initierar den...........
InitializeCriticalSection(&soundCriticalSection);
soundCriticalSection = new Common::CriticalSection();
//vi vill ha access till DSOUND så...
if (FAILED(DirectSoundCreate8(0, &ds, 0)))
return false;
return false;
ds->SetCooperativeLevel(window, DSSCL_NORMAL);
if(hWnd)
ds->SetCooperativeLevel((HWND)hWnd, DSSCL_NORMAL);
if (!CreateBuffer())
{
return false;
}
DWORD num1;
short* p1;
@ -201,48 +160,43 @@ bool DSound_StartSound(HWND window, int _sampleRate, StreamCallback _callback)
memset(p1, 0, num1);
dsBuffer->Unlock(p1, num1, 0, 0);
totalRenderedBytes = -bufferSize;
DWORD h;
hThread = CreateThread(0, 0, soundThread, 0, 0, &h);
SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL);
thread = new Common::Thread(soundThread, (void *)this);
return true;
}
void DSound_UpdateSound()
void DSound::Update()
{
SetEvent(soundSyncEvent);
soundSyncEvent->Set();
}
void DSound_StopSound()
void DSound::Stop()
{
EnterCriticalSection(&soundCriticalSection);
soundCriticalSection->Enter();
threadData = 1;
// kick the thread if it's waiting
SetEvent(soundSyncEvent);
LeaveCriticalSection(&soundCriticalSection);
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
soundSyncEvent->Set();
soundCriticalSection->Leave();
delete soundCriticalSection;
delete thread;
dsBuffer->Release();
ds->Release();
CloseHandle(soundSyncEvent);
soundSyncEvent = INVALID_HANDLE_VALUE;
hThread = INVALID_HANDLE_VALUE;
soundSyncEvent->Shutdown();
delete soundSyncEvent;
soundSyncEvent = NULL;
thread = NULL;
}
int DSound_GetCurSample()
/* Unused, is it needed?
int DSound::GetCurSample()
{
EnterCriticalSection(&soundCriticalSection);
soundCriticalSection->Enter();
int playCursor;
dsBuffer->GetCurrentPosition((DWORD*)&playCursor, 0);
playCursor = ModBufferSize(playCursor - lastPos) + totalRenderedBytes;
LeaveCriticalSection(&soundCriticalSection);
return(playCursor);
soundCriticalSection->Leave();
return playCursor;
}
float DSound_GetTimer()
{
return((float)DSound_GetCurSample() * (1.0f / (4.0f * sampleRate)));
}
} // namespace
*/

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003-2008 Dolphin Project.
// Copyright (C) 2003-2009 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
@ -15,21 +15,90 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef __SOUNDSTREAM_H__
#define __SOUNDSTREAM_H__
#ifndef __DSOUNDSTREAM_H__
#define __DSOUNDSTREAM_H__
#include "SoundStream.h"
namespace DSound
#include "Thread.h"
#ifdef _WIN32
#include "stdafx.h"
#include <mmsystem.h>
#include <dsound.h>
#define BUFSIZE 32768
#define MAXWAIT 70 //ms
#endif
class DSound : public SoundStream
{
typedef void (*StreamCallback)(short* buffer, int numSamples, int bits, int rate, int channels);
#ifdef _WIN32
bool DSound_StartSound(HWND window, int sampleRate, StreamCallback _callback);
void DSound_UpdateSound();
void DSound_StopSound();
Common::Thread *thread;
Common::CriticalSection *soundCriticalSection;
Common::Event *soundSyncEvent;
void *hWnd;
float DSound_GetTimer();
int DSound_GetCurSample();
int DSound_GetSampleRate();
}
IDirectSound8* ds;
IDirectSoundBuffer* dsBuffer;
int bufferSize; //i bytes
int totalRenderedBytes;
// playback position
int currentPos;
int lastPos;
short realtimeBuffer[1024 * 1024];
inline int FIX128(int x) {
return x & (~127);
}
inline int ModBufferSize(int x) {
return (x + bufferSize) % bufferSize;
}
bool CreateBuffer();
bool WriteDataToBuffer(DWORD dwOffset, char* soundData,
DWORD dwSoundBytes);
public:
DSound(int _sampleRate, StreamCallback _callback) :
SoundStream(_sampleRate, _callback) {}
DSound(int _sampleRate, StreamCallback _callback, void *_hWnd) :
SoundStream(_sampleRate, _callback), hWnd(_hWnd) {}
virtual ~DSound() {}
virtual bool Start();
virtual void SoundLoop();
virtual void Stop();
static bool isValid() { return true; }
virtual bool usesMixer() { return true; }
virtual void Update();
#else
public:
DSound(int _sampleRate, StreamCallback _callback, void *hWnd = NULL) :
SoundStream(_sampleRate, _callback) {}
#endif //__SOUNDSTREAM_H__
#endif
};
#endif //__DSOUNDSTREAM_H__

View File

@ -16,9 +16,6 @@
// http://code.google.com/p/dolphin-emu/
//////////////////////////////////////////////////////////////////////////////////////////
// Includes
// -------------
// This queue solution is temporary. I'll implement something more efficient later.
#include <queue> // System
@ -29,14 +26,11 @@
#include "../Globals.h"
#include "../DSPHandler.h"
#include "../Debugger/File.h"
#include "../main.h"
#include "Mixer.h"
#include "FixedSizeQueue.h"
#ifdef _WIN32
#include "../PCHW/DSoundStream.h"
#endif
///////////////////////
namespace {
@ -52,6 +46,11 @@ FixedSizeQueue<s16, queue_maxlength> sample_queue;
volatile bool mixer_HLEready = false;
volatile int queue_size = 0;
bool bThrottling = false;
void UpdateThrottle(bool update) {
bThrottling = update;
}
void Mixer(short *buffer, int numSamples, int bits, int rate, int channels)
{
@ -111,87 +110,85 @@ void Mixer_PushSamples(short *buffer, int num_stereo_samples, int sample_rate) {
static int PV1l=0,PV2l=0,PV3l=0,PV4l=0;
static int PV1r=0,PV2r=0,PV3r=0,PV4r=0;
static int acc=0;
static int acc=0;
bThrottling = g_Config.m_EnableThrottle;
if(bThrottling) {
/* This is only needed for non-AX sound, currently directly
streamed and DTK sound. For AX we call SoundStream::Update in
AXTask() for example. */
while (queue_size > queue_maxlength / 2) {
soundStream->Update();
Common::SleepCurrentThread(0);
}
#ifdef _WIN32
if (! (GetAsyncKeyState(VK_TAB)) && g_Config.m_EnableThrottle) {
//convert into config option?
const int mode = 2;
/* This is only needed for non-AX sound, currently directly streamed and
DTK sound. For AX we call DSound_UpdateSound in AXTask() for example. */
while (queue_size > queue_maxlength / 2) {
DSound::DSound_UpdateSound();
Sleep(0);
}
} else {
return;
}
#else
while (queue_size > queue_maxlength) {
usleep(1000);
}
#endif
//convert into config option?
const int mode = 2;
push_sync.Enter();
while (num_stereo_samples)
{
acc += sample_rate;
while (num_stereo_samples && (acc >= 48000))
{
PV4l=PV3l;
PV3l=PV2l;
PV2l=PV1l;
PV1l=*(buffer++); //32bit processing
PV4r=PV3r;
PV3r=PV2r;
PV2r=PV1r;
PV1r=*(buffer++); //32bit processing
num_stereo_samples--;
acc-=48000;
}
push_sync.Enter();
while (num_stereo_samples)
{
acc += sample_rate;
while (num_stereo_samples && (acc >= 48000))
{
PV4l=PV3l;
PV3l=PV2l;
PV2l=PV1l;
PV1l=*(buffer++); //32bit processing
PV4r=PV3r;
PV3r=PV2r;
PV2r=PV1r;
PV1r=*(buffer++); //32bit processing
num_stereo_samples--;
acc-=48000;
}
// defaults to nearest
s32 DataL = PV1l;
s32 DataR = PV1r;
// defaults to nearest
s32 DataL = PV1l;
s32 DataR = PV1r;
if (mode == 1) //linear
{
DataL = PV1l + ((PV2l - PV1l)*acc)/48000;
DataR = PV1r + ((PV2r - PV1r)*acc)/48000;
}
else if (mode == 2) //cubic
{
s32 a0l = PV1l - PV2l - PV4l + PV3l;
s32 a0r = PV1r - PV2r - PV4r + PV3r;
s32 a1l = PV4l - PV3l - a0l;
s32 a1r = PV4r - PV3r - a0r;
s32 a2l = PV1l - PV4l;
s32 a2r = PV1r - PV4r;
s32 a3l = PV2l;
s32 a3r = PV2r;
if (mode == 1) //linear
{
DataL = PV1l + ((PV2l - PV1l)*acc)/48000;
DataR = PV1r + ((PV2r - PV1r)*acc)/48000;
}
else if (mode == 2) //cubic
{
s32 a0l = PV1l - PV2l - PV4l + PV3l;
s32 a0r = PV1r - PV2r - PV4r + PV3r;
s32 a1l = PV4l - PV3l - a0l;
s32 a1r = PV4r - PV3r - a0r;
s32 a2l = PV1l - PV4l;
s32 a2r = PV1r - PV4r;
s32 a3l = PV2l;
s32 a3r = PV2r;
s32 t0l = ((a0l )*acc)/48000;
s32 t0r = ((a0r )*acc)/48000;
s32 t1l = ((t0l+a1l)*acc)/48000;
s32 t1r = ((t0r+a1r)*acc)/48000;
s32 t2l = ((t1l+a2l)*acc)/48000;
s32 t2r = ((t1r+a2r)*acc)/48000;
s32 t3l = ((t2l+a3l));
s32 t3r = ((t2r+a3r));
s32 t0l = ((a0l )*acc)/48000;
s32 t0r = ((a0r )*acc)/48000;
s32 t1l = ((t0l+a1l)*acc)/48000;
s32 t1r = ((t0r+a1r)*acc)/48000;
s32 t2l = ((t1l+a2l)*acc)/48000;
s32 t2r = ((t1r+a2r)*acc)/48000;
s32 t3l = ((t2l+a3l));
s32 t3r = ((t2r+a3r));
DataL = t3l;
DataR = t3r;
}
DataL = t3l;
DataR = t3r;
}
int l = DataL, r = DataR;
if (l < -32767) l = -32767;
if (r < -32767) r = -32767;
if (l > 32767) l = 32767;
if (r > 32767) r = 32767;
sample_queue.push(l);
sample_queue.push(r);
queue_size += 2;
}
push_sync.Leave();
}
int l = DataL, r = DataR;
if (l < -32767) l = -32767;
if (r < -32767) r = -32767;
if (l > 32767) l = 32767;
if (r > 32767) r = 32767;
sample_queue.push(l);
sample_queue.push(r);
queue_size += 2;
}
push_sync.Leave();
}

View File

@ -0,0 +1,58 @@
// Copyright (C) 2003-2009 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/
#ifndef __SOUNDSTREAM_H__
#define __SOUNDSTREAM_H__
#include "Common.h"
typedef void (*StreamCallback)(short* buffer, int numSamples, int bits, int rate, int channels);
class SoundStream {
protected:
int sampleRate;
StreamCallback callback;
// We set this to shut down the sound thread.
// 0=keep playing, 1=stop playing NOW.
volatile int threadData;
public:
SoundStream(int _sampleRate, StreamCallback _callback) :
sampleRate(_sampleRate), callback(_callback), threadData(0) {}
virtual ~SoundStream() {}
static bool isValid() { return false; }
virtual bool usesMixer() { return false; }
virtual bool Start() { return false; }
virtual void SoundLoop() { }
virtual void Stop() {}
virtual void Update() {}
virtual int GetSampleRate() { return sampleRate; }
};
#endif

View File

@ -5,10 +5,6 @@ import sys
name = "Plugin_DSP_HLE"
if not env['HAVE_AO']:
print name + " must have AO to be build"
Return()
files = [
'DSPHandler.cpp',
'MailHandler.cpp',
@ -16,6 +12,7 @@ files = [
'Config.cpp',
'Globals.cpp',
'PCHW/AOSoundStream.cpp',
# 'PCHW/NullSoundStream.cpp',
'PCHW/Mixer.cpp',
'Debugger/File.cpp',
'UCodes/UCode_AX.cpp',
@ -32,7 +29,7 @@ dspenv = env.Clone()
if dspenv['HAVE_WX']:
files += [
'ConfigDlg.cpp',
'ConfigDlg.cpp',
'Debugger/Debugger.cpp',
'Debugger/PBView.cpp',
'Debugger/Mails.cpp',

View File

@ -24,11 +24,6 @@ extern CDebugger* m_frame;
#endif
#include <sstream>
#ifdef _WIN32
#include "../PCHW/DSoundStream.h"
#else
#include "../PCHW/AOSoundStream.h"
#endif
#include "../PCHW/Mixer.h"
#include "../MailHandler.h"
@ -525,10 +520,10 @@ bool CUCode_AX::AXTask(u32& _uMail)
mixer_HLEready = true;
SaveLog("%08x : AXLIST PB address: %08x", uAddress, m_addressPBs);
#ifdef _WIN32
SaveLog("Update the SoundThread to be in sync");
DSound::DSound_UpdateSound(); //do it in this thread to avoid sync problems
#endif
soundStream->Update(); //do it in this thread to avoid sync problems
}
break;

View File

@ -23,12 +23,6 @@
extern CDebugger * m_frame;
#endif
#ifdef _WIN32
#include "../PCHW/DSoundStream.h"
#else
#include "../PCHW/AOSoundStream.h"
#endif
#include "../PCHW/Mixer.h"
#include "../MailHandler.h"
@ -329,10 +323,7 @@ bool CUCode_AXWii::AXTask(u32& _uMail)
lCUCode_AX->m_addressPBs = m_addressPBs; // for the sake of logging
mixer_HLEready = true;
SaveLog("%08x : AXLIST PB address: %08x", uAddress, m_addressPBs);
#ifdef _WIN32
//DebugLog("Update the SoundThread to be in sync");
DSound::DSound_UpdateSound(); //do it in this thread to avoid sync problems
#endif
soundStream->Update();
uAddress += 4;
break;

View File

@ -22,11 +22,6 @@
#include "UCode_AX.h"
#include "../main.h"
#ifdef _WIN32
#include "../PCHW/DSoundStream.h"
#else
#include "../PCHW/AOSoundStream.h"
#endif
// ----------------------------------------------------
// Externals
@ -112,11 +107,7 @@ inline void WriteBackPBsWii(u32 pbs_address, ParamBlockType& _pPBs, int _num)
template<class ParamBlockType>
inline void MixAddVoice(ParamBlockType &pb, int *templbuffer, int *temprbuffer, int _iSize, bool Wii)
{
#ifdef _WIN32
ratioFactor = 32000.0f / (float)DSound::DSound_GetSampleRate();
#else
ratioFactor = 32000.0f / (float)AOSound::AOSound_GetSampleRate();
#endif
ratioFactor = 32000.0f / (float)soundStream->GetSampleRate();
DoVoiceHacks(pb, Wii);

View File

@ -23,9 +23,7 @@
#include "UCode_Zelda.h"
#include "../MailHandler.h"
#ifdef _WIN32
#include "../PCHW/DSoundStream.h"
#endif
#include "../main.h"
#include "../PCHW/Mixer.h"
@ -126,10 +124,10 @@ void CUCode_Zelda::ExecuteList()
// We're ready to mix
mixer_HLEready = true;
#ifdef _WIN32
DebugLog("Update the SoundThread to be in sync");
DSound::DSound_UpdateSound(); //do it in this thread to avoid sync problems
#endif
soundStream->Update(); //do it in this thread to avoid sync problems
DebugLog("DsyncFrame");
DebugLog("???: 0x%08x", tmp[0]);

View File

@ -15,25 +15,15 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
//////////////////////////////////////////////////////////////////////////////////////////
// Includes
// -------------
#include <iostream>
#include "Globals.h" // Local
#ifdef _WIN32
#include "PCHW/DSoundStream.h"
#else
#include "PCHW/AOSoundStream.h"
#endif
#if defined(HAVE_WX) && HAVE_WX
#include "ConfigDlg.h"
#include "Debugger/File.h" // For file logging
#include "Debugger/Debugger.h" // For the CDebugger class
CDebugger* m_frame;
#include "ConfigDlg.h"
#include "Debugger/File.h" // For file logging
#include "Debugger/Debugger.h" // For the CDebugger class
CDebugger* m_frame;
#endif
#include "ConsoleWindow.h" // Common: For the Windows console
@ -42,174 +32,156 @@
#include "PCHW/Mixer.h"
#include "DSPHandler.h"
#include "Config.h"
///////////////////////////////
#include "PCHW/AOSoundStream.h"
#include "PCHW/DSoundStream.h"
#include "PCHW/NullSoundStream.h"
//////////////////////////////////////////////////////////////////////////////////////////
// Declarations and definitions
// ¯¯¯¯¯¯¯¯¯¯¯¯¯
DSPInitialize g_dspInitialize;
u8* g_pMemory;
extern std::vector<std::string> sMailLog, sMailTime;
std::string gpName;
SoundStream *soundStream = NULL;
// 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;
// --------------------------------------
// Mailbox utility
// ----------
struct DSPState
{
u32 CPUMailbox;
bool CPUMailbox_Written[2];
u32 CPUMailbox;
bool CPUMailbox_Written[2];
u32 DSPMailbox;
bool DSPMailbox_Read[2];
u32 DSPMailbox;
bool DSPMailbox_Read[2];
DSPState()
{
CPUMailbox = 0x00000000;
CPUMailbox_Written[0] = false;
CPUMailbox_Written[1] = false;
DSPState()
{
CPUMailbox = 0x00000000;
CPUMailbox_Written[0] = false;
CPUMailbox_Written[1] = false;
DSPMailbox = 0x00000000;
DSPMailbox_Read[0] = true;
DSPMailbox_Read[1] = true;
}
DSPMailbox = 0x00000000;
DSPMailbox_Read[0] = true;
DSPMailbox_Read[1] = true;
}
};
DSPState g_dspState;
// -------------------
///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// wxWidgets: Create the wxApp
// ¯¯¯¯¯¯¯¯¯¯¯¯¯
#if defined(HAVE_WX) && HAVE_WX
class wxDLLApp : public wxApp
{
bool OnInit()
{
return true;
}
bool OnInit()
{
return true;
}
};
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
#endif
///////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// DllMain
// ¯¯¯¯¯¯¯¯¯¯¯¯¯
#ifdef _WIN32
HINSTANCE g_hInstance = NULL;
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
DWORD dwReason, // reason called
LPVOID lpvReserved) // reserved
DWORD dwReason, // reason called
LPVOID lpvReserved) // reserved
{
switch (dwReason)
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
case DLL_PROCESS_ATTACH:
{
// more stuff wx needs
wxSetInstance((HINSTANCE)hinstDLL);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);
// more stuff wx needs
wxSetInstance((HINSTANCE)hinstDLL);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);
// This is for ?
if ( !wxTheApp || !wxTheApp->CallOnInit() )
return FALSE;
}
break;
// This is for ?
if ( !wxTheApp || !wxTheApp->CallOnInit() )
return FALSE;
}
break;
case DLL_PROCESS_DETACH:
wxEntryCleanup(); // use this or get a crash
break;
case DLL_PROCESS_DETACH:
wxEntryCleanup(); // use this or get a crash
break;
default:
break;
default:
break;
}
g_hInstance = hinstDLL;
return(TRUE);
g_hInstance = hinstDLL;
return(TRUE);
}
#endif
///////////////////
// =======================================================================================
// Open and close console
// -------------------
void OpenConsole()
{
#if defined (_WIN32)
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
#endif
#if defined (_WIN32)
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
#endif
}
void CloseConsole()
{
#if defined (_WIN32)
FreeConsole();
#endif
#if defined (_WIN32)
FreeConsole();
#endif
}
// ===================
//////////////////////////////////////////////////////////////////////////////////////////
// Exported fuctions
// ¯¯¯¯¯¯¯¯¯¯¯¯¯
// =======================================================================================
// 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)
{
#if defined(HAVE_WX) && HAVE_WX
if(m_frame && Show) // if we have created it, let us show it again
if(m_frame && Show) // if we have created it, let us show it again
{
m_frame->DoShow();
m_frame->DoShow();
}
else if(!m_frame && Show)
else if(!m_frame && Show)
{
m_frame = new CDebugger(NULL);
m_frame->Show();
m_frame = new CDebugger(NULL);
m_frame->Show();
}
else if(m_frame && !Show)
else if(m_frame && !Show)
{
m_frame->DoHide();
m_frame->DoHide();
}
#endif
}
// ===================
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
{
_PluginInfo->Version = 0x0100;
_PluginInfo->Type = PLUGIN_TYPE_DSP;
_PluginInfo->Version = 0x0100;
_PluginInfo->Type = PLUGIN_TYPE_DSP;
#ifdef DEBUGFAST
sprintf(_PluginInfo->Name, "Dolphin DSP-HLE Plugin (DebugFast) ");
sprintf(_PluginInfo->Name, "Dolphin DSP-HLE Plugin (DebugFast) ");
#else
#ifndef _DEBUG
sprintf(_PluginInfo->Name, "Dolphin DSP-HLE Plugin ");
sprintf(_PluginInfo->Name, "Dolphin DSP-HLE Plugin ");
#else
sprintf(_PluginInfo ->Name, "Dolphin DSP-HLE Plugin (Debug) ");
sprintf(_PluginInfo ->Name, "Dolphin DSP-HLE Plugin (Debug) ");
#endif
#endif
}
@ -220,187 +192,207 @@ void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) {
void DllConfig(HWND _hParent)
{
#if defined(HAVE_WX) && HAVE_WX
// (shuffle2) TODO: reparent dlg with DolphinApp
ConfigDialog dlg(NULL);
dlg.ShowModal();
// (shuffle2) TODO: reparent dlg with DolphinApp
ConfigDialog dlg(NULL);
if (DSound::isValid())
dlg.AddBackend("DSound");
if (AOSound::isValid())
dlg.AddBackend("AOSound");
dlg.AddBackend("NullSound");
dlg.ShowModal();
#endif
}
void Initialize(void *init)
{
g_Config.LoadDefaults();
g_Config.Load();
g_Config.Load();
g_dspInitialize = *(DSPInitialize*)init;
g_dspInitialize = *(DSPInitialize*)init;
g_pMemory = g_dspInitialize.pGetMemoryPointer(0);
g_pMemory = g_dspInitialize.pGetMemoryPointer(0);
#if defined(_DEBUG) || defined(DEBUGFAST)
gpName = g_dspInitialize.pName(); // save the game name globally
for (u32 i = 0; i < gpName.length(); ++i) // and fix it
gpName = g_dspInitialize.pName(); // save the game name globally
for (u32 i = 0; i < gpName.length(); ++i) // and fix it
{
Console::Print("%c", gpName[i]);
std::cout << gpName[i];
if (gpName[i] == ':') gpName[i] = ' ';
fprintf(stderr,"%c", gpName[i]);
std::cout << gpName[i];
if (gpName[i] == ':') gpName[i] = ' ';
}
Console::Print("\n");
fprintf(stderr, "\n");
#endif
CDSPHandler::CreateInstance();
#ifdef _WIN32
#ifdef _DEBUG
int tmpflag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
tmpflag |= _CRTDBG_DELAY_FREE_MEM_DF;
_CrtSetDbgFlag(tmpflag);
#endif
if (log_ai) {
g_wave_writer.Start("D:\\ai_log.wav");
g_wave_writer.SetSkipSilence(false);
CDSPHandler::CreateInstance();
if (strncasecmp(g_Config.sBackend, "DSound", 10) == 0) {
if (DSound::isValid()) {
soundStream = new DSound(48000, Mixer, g_dspInitialize.hWnd);
}
DSound::DSound_StartSound((HWND)g_dspInitialize.hWnd, 48000, Mixer);
#else
AOSound::AOSound_StartSound(48000, Mixer);
} else if(strncasecmp(g_Config.sBackend, "AOSound", 10) == 0) {
if (AOSound::isValid())
soundStream = new AOSound(48000, Mixer);
} else if(strncasecmp(g_Config.sBackend, "NullSound", 10) == 0) {
soundStream = new NullSound(48000, Mixer);
} else {
PanicAlert("Cannot recognize backend %s", g_Config.sBackend);
return;
}
#if defined(WIN32) && defined(_DEBUG)
int tmpflag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
tmpflag |= _CRTDBG_DELAY_FREE_MEM_DF;
_CrtSetDbgFlag(tmpflag);
#endif
if (soundStream) {
if(!soundStream->Start()) {
PanicAlert("Could not initialize backend %s, falling back to NULL",
g_Config.sBackend);
delete soundStream;
soundStream = new NullSound(48000, Mixer);
soundStream->Start();
}
} else {
PanicAlert("Sound backend %s is not valid, falling back to NULL",
g_Config.sBackend);
delete soundStream;
soundStream = new NullSound(48000, Mixer);
soundStream->Start();
}
}
void Shutdown()
{
if (log_ai)
g_wave_writer.Stop();
// delete the UCodes
#ifdef _WIN32
DSound::DSound_StopSound();
#else
AOSound::AOSound_StopSound();
#endif
CDSPHandler::Destroy();
if (log_ai)
g_wave_writer.Stop();
// delete the UCodes
soundStream->Stop();
delete soundStream;
soundStream = NULL;
CDSPHandler::Destroy();
#if defined(HAVE_WX) && HAVE_WX
// Reset mails
if(m_frame)
// Reset mails
if(m_frame)
{
sMailLog.clear();
sMailTime.clear();
m_frame->sMail.clear();
m_frame->sMailEnd.clear();
sMailLog.clear();
sMailTime.clear();
m_frame->sMail.clear();
m_frame->sMailEnd.clear();
}
#endif
}
void DoState(unsigned char **ptr, int mode) {
PointerWrap p(ptr, mode);
PointerWrap p(ptr, mode);
}
///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// Mailbox fuctions
// ¯¯¯¯¯¯¯¯¯¯¯¯¯
unsigned short DSP_ReadMailboxHigh(bool _CPUMailbox)
{
if (_CPUMailbox)
if (_CPUMailbox)
{
return (g_dspState.CPUMailbox >> 16) & 0xFFFF;
return (g_dspState.CPUMailbox >> 16) & 0xFFFF;
}
else
else
{
return CDSPHandler::GetInstance().AccessMailHandler().ReadDSPMailboxHigh();
return CDSPHandler::GetInstance().AccessMailHandler().ReadDSPMailboxHigh();
}
}
unsigned short DSP_ReadMailboxLow(bool _CPUMailbox)
{
if (_CPUMailbox)
if (_CPUMailbox)
{
return g_dspState.CPUMailbox & 0xFFFF;
return g_dspState.CPUMailbox & 0xFFFF;
}
else
else
{
return CDSPHandler::GetInstance().AccessMailHandler().ReadDSPMailboxLow();
return CDSPHandler::GetInstance().AccessMailHandler().ReadDSPMailboxLow();
}
}
void Update_DSP_WriteRegister()
{
// check if the whole message is complete and if we can send it
if (g_dspState.CPUMailbox_Written[0] && g_dspState.CPUMailbox_Written[1])
// check if the whole message is complete and if we can send it
if (g_dspState.CPUMailbox_Written[0] && g_dspState.CPUMailbox_Written[1])
{
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
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
}
}
void DSP_WriteMailboxHigh(bool _CPUMailbox, unsigned short _Value)
{
if (_CPUMailbox)
if (_CPUMailbox)
{
g_dspState.CPUMailbox = (g_dspState.CPUMailbox & 0xFFFF) | (_Value << 16);
g_dspState.CPUMailbox_Written[0] = true;
g_dspState.CPUMailbox = (g_dspState.CPUMailbox & 0xFFFF) | (_Value << 16);
g_dspState.CPUMailbox_Written[0] = true;
Update_DSP_WriteRegister();
Update_DSP_WriteRegister();
}
else
else
{
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
}
}
void DSP_WriteMailboxLow(bool _CPUMailbox, unsigned short _Value)
{
if (_CPUMailbox)
if (_CPUMailbox)
{
g_dspState.CPUMailbox = (g_dspState.CPUMailbox & 0xFFFF0000) | _Value;
g_dspState.CPUMailbox_Written[1] = true;
g_dspState.CPUMailbox = (g_dspState.CPUMailbox & 0xFFFF0000) | _Value;
g_dspState.CPUMailbox_Written[1] = true;
Update_DSP_WriteRegister();
Update_DSP_WriteRegister();
}
else
else
{
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
}
}
///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// Other DSP fuctions
// ¯¯¯¯¯¯¯¯¯¯¯¯¯
unsigned short DSP_WriteControlRegister(unsigned short _Value)
{
return CDSPHandler::GetInstance().WriteControlRegister(_Value);
return CDSPHandler::GetInstance().WriteControlRegister(_Value);
}
unsigned short DSP_ReadControlRegister()
{
return CDSPHandler::GetInstance().ReadControlRegister();
return CDSPHandler::GetInstance().ReadControlRegister();
}
void DSP_Update(int cycles)
{
CDSPHandler::GetInstance().Update();
CDSPHandler::GetInstance().Update();
}
void DSP_SendAIBuffer(unsigned int address, int sample_rate)
{
if(soundStream->usesMixer()) {
short samples[16] = {0}; // interleaved stereo
if (address) {
for (int i = 0; i < 16; i++) {
samples[i] = Memory_Read_U16(address + i * 2);
}
if (log_ai)
g_wave_writer.AddStereoSamples(samples, 8);
for (int i = 0; i < 16; i++) {
samples[i] = Memory_Read_U16(address + i * 2);
}
if (log_ai)
g_wave_writer.AddStereoSamples(samples, 8);
}
Mixer_PushSamples(samples, 32 / 4, sample_rate);
}
static int counter = 0;
counter++;
#ifdef _WIN32
if ((counter & 255) == 0)
DSound::DSound_UpdateSound();
#endif
/*static int counter = 0;
counter++;
if ((counter & 255) == 0)*/
// SoundStream is updated only when necessary (there is no 70 ms limit
// so each sample now triggers the sound stream)
soundStream->Update();
}
///////////////////////////////

View File

@ -1,3 +1,31 @@
// Copyright (C) 2003-2009 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/
#ifndef __MAIN_H__
#define __MAIN_H__
#include "PCHW/SoundStream.h"
#include "Globals.h" // Local
#if defined(HAVE_WX) && HAVE_WX
#include "Debugger/Debugger.h"
extern CDebugger* m_frame;
#endif
extern SoundStream *soundStream;
#endif

View File

@ -1,696 +0,0 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="Plugin_DSP_NULL"
ProjectGUID="{C6CC7A52-0FDD-433A-B2CF-9C6F187DA807}"
RootNamespace="Plugin_DSP"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../Externals/WTL80;../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DSP_NULL_EXPORTS;_SECURE_SCL=0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
FloatingPointModel="0"
UsePrecompiledHeader="0"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
WarnAsError="false"
DebugInformationFormat="4"
ForcedIncludeFiles="stdafx.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="../../../Binary/Win32/Plugins/Plugin_DSP_NULLD.dll"
LinkIncremental="2"
GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/DSP_NULL.pdb"
SubSystem="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/DSP_NULL.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../Externals/WTL80;../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DSP_NULL_EXPORTS;_SECURE_SCL=0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
FloatingPointModel="0"
UsePrecompiledHeader="0"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
WarnAsError="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="../../../Binary/x64/Plugins/Plugin_DSP_NULLD.dll"
LinkIncremental="2"
GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/DSP_NULL.pdb"
SubSystem="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/DSP_NULL.lib"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../../Externals/WTL80;../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_NULL_EXPORTS;_SECURE_SCL=0"
RuntimeLibrary="0"
BufferSecurityCheck="false"
EnableEnhancedInstructionSet="2"
FloatingPointModel="0"
UsePrecompiledHeader="0"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
WarnAsError="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="../../../Binary/Win32/Plugins/Plugin_DSP_NULL.dll"
LinkIncremental="1"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/DSP_NULL.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../../Externals/WTL80;../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_NULL_EXPORTS;_SECURE_SCL=0"
RuntimeLibrary="0"
BufferSecurityCheck="false"
FloatingPointModel="0"
UsePrecompiledHeader="0"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
WarnAsError="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="../../../Binary/x64/Plugins/Plugin_DSP_NULL.dll"
LinkIncremental="1"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/DSP_NULL.lib"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="DebugFast|Win32"
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../../Externals/WTL80;../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="DEBUGFAST;WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_NULL_EXPORTS;_SECURE_SCL=0"
RuntimeLibrary="0"
BufferSecurityCheck="false"
EnableEnhancedInstructionSet="2"
FloatingPointModel="0"
UsePrecompiledHeader="0"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
WarnAsError="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="../../../Binary/Win32/Plugins/Plugin_DSP_NULLDF.dll"
LinkIncremental="1"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/DSP_NULL.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="DebugFast|x64"
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../../Externals/WTL80;../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DSP_NULL_EXPORTS;DEBUGFAST;_SECURE_SCL=0"
RuntimeLibrary="0"
BufferSecurityCheck="false"
FloatingPointModel="0"
UsePrecompiledHeader="0"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
WarnAsError="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="../../../Binary/x64/Plugins/Plugin_DSP_NULLDF.dll"
LinkIncremental="1"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/DSP_NULL.lib"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="UCodes"
>
<File
RelativePath=".\Src\UCodes\UCode_CARD.cpp"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_CARD.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_InitAudioSystem.cpp"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_InitAudioSystem.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_Jac.cpp"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_Jac.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_ROM.cpp"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_ROM.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_Zelda.cpp"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_Zelda.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCodes.cpp"
>
</File>
<File
RelativePath=".\Src\UCodes\UCodes.h"
>
</File>
<Filter
Name="UCode AX"
>
<File
RelativePath=".\Src\UCodes\UCode_AX.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AssemblerOutput="4"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AssemblerOutput="4"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|Win32"
>
<Tool
Name="VCCLCompilerTool"
AssemblerOutput="4"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|x64"
>
<Tool
Name="VCCLCompilerTool"
AssemblerOutput="4"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Src\UCodes\UCode_AX.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_AX_ADPCM.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_AX_Voice.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_AXStructs.h"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_AXWii.cpp"
>
</File>
<File
RelativePath=".\Src\UCodes\UCode_AXWii.h"
>
</File>
</Filter>
</Filter>
<File
RelativePath=".\Src\DSPHandler.cpp"
>
</File>
<File
RelativePath=".\Src\DSPHandler.h"
>
</File>
<File
RelativePath=".\Src\Globals.cpp"
>
</File>
<File
RelativePath=".\Src\Globals.h"
>
</File>
<File
RelativePath=".\Src\MailHandler.cpp"
>
</File>
<File
RelativePath=".\Src\MailHandler.h"
>
</File>
<File
RelativePath=".\Src\main.cpp"
>
</File>
<File
RelativePath=".\Src\SConscript"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -1,86 +0,0 @@
// 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/
#include "DSPHandler.h"
CDSPHandler* CDSPHandler::m_pInstance = NULL;
CDSPHandler::CDSPHandler()
: m_pUCode(NULL),
m_bHalt(false),
m_bAssertInt(false)
{
SetUCode(UCODE_ROM);
m_DSPControl.DSPHalt = 1;
m_DSPControl.DSPInit = 1;
}
CDSPHandler::~CDSPHandler()
{
delete m_pUCode;
m_pUCode = NULL;
}
void CDSPHandler::Update()
{
if (m_pUCode != NULL)
m_pUCode->Update();
}
unsigned short CDSPHandler::WriteControlRegister(unsigned short _Value)
{
UDSPControl Temp(_Value);
if (Temp.DSPReset)
{
SetUCode(UCODE_ROM);
Temp.DSPReset = 0;
}
if (Temp.DSPInit == 0)
{
// copy 128 byte from ARAM 0x000000 to IMEM
SetUCode(UCODE_INIT_AUDIO_SYSTEM);
Temp.DSPInitCode = 0;
// MessageBox(NULL, "UCODE_INIT_AUDIO_SYSTEM", "DSP-HLE", MB_OK);
}
m_DSPControl.Hex = Temp.Hex;
return m_DSPControl.Hex;
}
unsigned short CDSPHandler::ReadControlRegister()
{
return m_DSPControl.Hex;
}
void CDSPHandler::SendMailToDSP(u32 _uMail)
{
if (m_pUCode != NULL)
m_pUCode->HandleMail(_uMail);
}
IUCode* CDSPHandler::GetUCode()
{
return m_pUCode;
}
void CDSPHandler::SetUCode(u32 _crc)
{
delete m_pUCode;
m_pUCode = NULL;
m_MailHandler.Clear();
m_pUCode = UCodeFactory(_crc, m_MailHandler);
}

View File

@ -1,99 +0,0 @@
// 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/
#ifndef _DSPHANDLER_H
#define _DSPHANDLER_H
#include "Common.h"
#include "MailHandler.h"
#include "UCodes/UCodes.h"
class CDSPHandler
{
public:
void Update();
unsigned short WriteControlRegister(unsigned short _Value);
unsigned short ReadControlRegister();
void SendMailToDSP(u32 _uMail);
IUCode* GetUCode();
void SetUCode(u32 _crc);
CMailHandler& AccessMailHandler() { return m_MailHandler; }
static CDSPHandler& GetInstance()
{
return *m_pInstance;
}
static void Destroy()
{
delete m_pInstance;
m_pInstance = NULL;
}
static CDSPHandler& CreateInstance()
{
if (!m_pInstance)
m_pInstance = new CDSPHandler();
return *m_pInstance;
}
private:
CDSPHandler();
~CDSPHandler();
// UDSPControl
union UDSPControl
{
u16 Hex;
struct
{
unsigned DSPReset : 1; // Write 1 to reset and waits for 0
unsigned DSPAssertInt : 1;
unsigned DSPHalt : 1;
unsigned AI : 1;
unsigned AI_mask : 1;
unsigned ARAM : 1;
unsigned ARAM_mask : 1;
unsigned DSP : 1;
unsigned DSP_mask : 1;
unsigned ARAM_DMAState : 1; // DSPGetDMAStatus() uses this flag
unsigned DSPInitCode : 1;
unsigned DSPInit : 1; // DSPInit() writes to this flag
unsigned pad : 4;
};
UDSPControl(u16 _Hex = 0)
: Hex(_Hex)
{}
};
// singleton instance
static CDSPHandler* m_pInstance;
IUCode* m_pUCode;
UDSPControl m_DSPControl;
CMailHandler m_MailHandler;
bool m_bHalt;
bool m_bAssertInt;
};
#endif

View File

@ -1,63 +0,0 @@
#include <stdarg.h>
#include <stdio.h>
#include "Common.h"
#include "Globals.h"
// debugger externals that are needed even in Release builds
bool gSSBM = true;
bool gSSBMremedy1 = true;
bool gSSBMremedy2 = true;
bool gSequenced = true;
bool gVolume = true;
bool gReset = false;
float ratioFactor; // a global to get the ratio factor from MixAdd
void __Log(int, const char *fmt, ...)
{
DebugLog(fmt);
}
void DebugLog(const char* _fmt, ...)
{
#ifdef _DEBUG
char Msg[512];
va_list ap;
va_start(ap, _fmt);
vsprintf(Msg, _fmt, ap);
va_end(ap);
g_dspInitialize.pLog(Msg, FALSE);
#endif
}
extern u8* g_pMemory;
// TODO: Wii support? Most likely audio data still must be in the old 24MB TRAM.
#define RAM_MASK 0x1FFFFFF
u8 Memory_Read_U8(u32 _uAddress)
{
_uAddress &= RAM_MASK;
return g_pMemory[_uAddress];
}
u16 Memory_Read_U16(u32 _uAddress)
{
_uAddress &= RAM_MASK;
return Common::swap16(*(u16*)&g_pMemory[_uAddress]);
}
u32 Memory_Read_U32(u32 _uAddress)
{
_uAddress &= RAM_MASK;
return Common::swap32(*(u32*)&g_pMemory[_uAddress]);
}
float Memory_Read_Float(u32 _uAddress)
{
u32 uTemp = Memory_Read_U32(_uAddress);
return *(float*)&uTemp;
}

View File

@ -1,16 +0,0 @@
#ifndef _GLOBALS_H
#define _GLOBALS_H
#include "Common.h"
#include "pluginspecs_dsp.h"
extern DSPInitialize g_dspInitialize;
void DebugLog(const char* _fmt, ...);
u8 Memory_Read_U8(u32 _uAddress);
u16 Memory_Read_U16(u32 _uAddress);
u32 Memory_Read_U32(u32 _uAddress);
float Memory_Read_Float(u32 _uAddress);
#endif

View File

@ -1,96 +0,0 @@
// 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/
#include "MailHandler.h"
CMailHandler::CMailHandler()
{
}
CMailHandler::~CMailHandler()
{
Clear();
}
void CMailHandler::PushMail(u32 _Mail)
{
m_Mails.push(_Mail);
Update();
}
u16 CMailHandler::ReadDSPMailboxHigh()
{
// check if we have a mail for the core
if (!m_Mails.empty())
{
u16 result = (m_Mails.front() >> 16) & 0xFFFF;
Update();
return result;
}
return 0x00;
}
u16 CMailHandler::ReadDSPMailboxLow()
{
// check if we have a mail for the core
if (!m_Mails.empty())
{
u16 result = m_Mails.front() & 0xFFFF;
m_Mails.pop();
Update();
return(result);
}
return 0x00;
}
void CMailHandler::Clear()
{
while (!m_Mails.empty())
m_Mails.pop();
}
bool CMailHandler::IsEmpty()
{
return m_Mails.empty();
}
void CMailHandler::Halt(bool _Halt)
{
if (_Halt)
{
Clear();
m_Mails.push(0x80544348);
}
Update();
}
void CMailHandler::Update()
{
if (!IsEmpty())
{
// g_dspInitialize.pGenerateDSPInterrupt();
}
}

View File

@ -1,46 +0,0 @@
// 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/
#ifndef _MAILHANDLER_H
#define _MAILHANDLER_H
#include <queue>
#include "Common.h"
class CMailHandler
{
public:
CMailHandler();
~CMailHandler();
void PushMail(u32 _Mail);
void Clear();
void Halt(bool _Halt);
bool IsEmpty();
u16 ReadDSPMailboxHigh();
u16 ReadDSPMailboxLow();
void Update();
private:
// mail handler
std::queue<u32> m_Mails;
};
#endif

View File

@ -1,28 +0,0 @@
# -*- python -*-
Import('env')
import sys
name = "Plugin_DSP_NULL"
files = [
"DSPHandler.cpp",
"MailHandler.cpp",
"main.cpp",
"Globals.cpp",
"UCodes/UCode_AX.cpp",
"UCodes/UCode_AXWii.cpp",
"UCodes/UCode_CARD.cpp",
"UCodes/UCode_InitAudioSystem.cpp",
"UCodes/UCode_Jac.cpp",
"UCodes/UCode_ROM.cpp",
"UCodes/UCodes.cpp",
"UCodes/UCode_Zelda.cpp",
]
dspenv = env.Clone()
dspenv.Append(
CXXFLAGS = [ '-fPIC' ],
LIBS = [ 'common' ],
)
dspenv.SharedLibrary(env['plugin_dir']+name, files)

View File

@ -1,466 +0,0 @@
// 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/
#include "FileUtil.h" // For IsDirectory()
#include "StringUtil.h" // For StringFromFormat()
#include <sstream>
#include "../MailHandler.h"
#include "UCodes.h"
#include "UCode_AXStructs.h"
#include "UCode_AX.h"
#include "UCode_AX_Voice.h"
// ------------------------------------------------------------------
// Externals
// -----------
extern bool gSSBM;
extern bool gSSBMremedy1;
extern bool gSSBMremedy2;
extern bool gSequenced;
extern bool gVolume;
extern bool gReset;
extern std::string gpName;
std::vector<std::string> sMailLog, sMailTime;
// -----------
CUCode_AX::CUCode_AX(CMailHandler& _rMailHandler)
: IUCode(_rMailHandler)
, m_addressPBs(0xFFFFFFFF)
{
// we got loaded
m_rMailHandler.PushMail(0xDCD10000);
m_rMailHandler.PushMail(0x80000000); // handshake ??? only (crc == 0xe2136399) needs it ...
templbuffer = new int[1024 * 1024];
temprbuffer = new int[1024 * 1024];
}
CUCode_AX::~CUCode_AX()
{
m_rMailHandler.Clear();
delete [] templbuffer;
delete [] temprbuffer;
}
// ============================================
// Save file to harddrive
// ----------------
void CUCode_AX::SaveLogFile(std::string f, int resizeTo, bool type, bool Wii)
{
if (gpName.length() > 0) // this is currently off in the Release build
{
std::ostringstream ci;
std::ostringstream cType;
ci << (resizeTo - 1); // write ci
cType << type; // write cType
std::string FileName = FULL_MAIL_LOGS_DIR + gpName;
FileName += "_sep"; FileName += ci.str(); FileName += "_sep"; FileName += cType.str();
FileName += Wii ? "_sepWii_sep" : "_sepGC_sep"; FileName += ".log";
FILE* fhandle = fopen(FileName.c_str(), "w");
fprintf(fhandle, "%s", f.c_str());
fflush(fhandle); fhandle = NULL;
}
}
// ============================================
// Save the logged AX mail
// ----------------
void CUCode_AX::SaveLog_(bool Wii, const char* _fmt, va_list ap)
{
char Msg[512];
vsprintf(Msg, _fmt, ap);
TmpMailLog += Msg;
TmpMailLog += "\n";
}
// ----------------
// ============================================
// Save the whole AX mail
// ----------------
void CUCode_AX::SaveMail(bool Wii, u32 _uMail)
{
}
// ----------------
int ReadOutPBs(u32 pbs_address, AXParamBlock* _pPBs, int _num)
{
int count = 0;
u32 blockAddr = pbs_address;
// reading and 'halfword' swap
for (int i = 0; i < _num; i++)
{
const short *pSrc = (const short *)g_dspInitialize.pGetMemoryPointer(blockAddr);
if (pSrc != NULL)
{
short *pDest = (short *)&_pPBs[i];
for (size_t p = 0; p < sizeof(AXParamBlock) / 2; p++)
{
pDest[p] = Common::swap16(pSrc[p]);
}
blockAddr = (_pPBs[i].next_pb_hi << 16) | _pPBs[i].next_pb_lo;
count++;
// Detect the last mail by checking when next_pb = 0
u32 next_pb = (Common::swap16(pSrc[0]) << 16) | Common::swap16(pSrc[1]);
if(next_pb == 0) break;
}
else
break;
}
// return the number of read PBs
return count;
}
void WriteBackPBs(u32 pbs_address, AXParamBlock* _pPBs, int _num)
{
u32 blockAddr = pbs_address;
// write back and 'halfword'swap
for (int i = 0; i < _num; i++)
{
short* pSrc = (short*)&_pPBs[i];
short* pDest = (short*)g_dspInitialize.pGetMemoryPointer(blockAddr);
for (size_t p = 0; p < sizeof(AXParamBlock) / 2; p++)
{
pDest[p] = Common::swap16(pSrc[p]);
}
// next block
blockAddr = (_pPBs[i].next_pb_hi << 16) | _pPBs[i].next_pb_lo;
}
}
void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
{
AXParamBlock PBs[NUMBER_OF_PBS];
// read out pbs
int numberOfPBs = ReadOutPBs(m_addressPBs, PBs, NUMBER_OF_PBS);
if (_iSize > 1024 * 1024)
_iSize = 1024 * 1024;
memset(templbuffer, 0, _iSize * sizeof(int));
memset(temprbuffer, 0, _iSize * sizeof(int));
// ---------------------------------------------------------------------------------------
/* Make the updates we are told to do. When there are multiple updates for a block they
are placed in memory directly following updaddr. They are mostly for initial time
delays, sometimes for the FIR filter or channel volumes. We do all of them at once here.
If we get both an on and an off update we chose on. Perhaps that makes the RE1 music
work better. */
// ------------
for (int i = 0; i < numberOfPBs; i++)
{
u16 *pDest = (u16 *)&PBs[i];
u16 upd0 = pDest[34]; u16 upd1 = pDest[35]; u16 upd2 = pDest[36]; // num_updates
u16 upd3 = pDest[37]; u16 upd4 = pDest[38];
u16 upd_hi = pDest[39]; // update addr
u16 upd_lo = pDest[40];
int numupd = upd0 + upd1 + upd2 + upd3 + upd4;
if(numupd > 64) numupd = 64; // prevent crazy values
const u32 updaddr = (u32)(upd_hi << 16) | upd_lo;
int on = false, off = false;
for (int j = 0; j < numupd; j++)
{
const u16 updpar = Memory_Read_U16(updaddr + j);
const u16 upddata = Memory_Read_U16(updaddr + j + 2);
// some safety checks, I hope it's enough
if(updaddr > 0x80000000 && updaddr < 0x817fffff
&& updpar < 63 && updpar > 3 && upddata >= 0 // updpar > 3 because we don't want to change
// 0-3, those are important
//&& (upd0 || upd1 || upd2 || upd3 || upd4) // We should use these in some way to I think
// but I don't know how or when
&& gSequenced) // on and off option
{
pDest[updpar] = upddata;
}
if (updpar == 7 && upddata == 1) on++;
if (updpar == 7 && upddata == 1) off++;
}
// hack: if we get both an on and an off select on rather than off
if (on > 0 && off > 0) pDest[7] = 1;
}
//PrintFile(1, "%08x %04x %04x\n", updaddr, updpar, upddata);
// ------------
for (int i = 0; i < numberOfPBs; i++)
{
AXParamBlock& pb = PBs[i];
MixAddVoice(pb, templbuffer, temprbuffer, _iSize, false);
}
// write back out pbs
WriteBackPBs(m_addressPBs, PBs, numberOfPBs);
for (int i = 0; i < _iSize; i++)
{
// Clamp into 16-bit. Maybe we should add a volume compressor here.
int left = templbuffer[i] + _pBuffer[0];
int right = temprbuffer[i] + _pBuffer[1];
if (left < -32767) left = -32767;
if (left > 32767) left = 32767;
if (right < -32767) right = -32767;
if (right > 32767) right = 32767;
*_pBuffer++ = left;
*_pBuffer++ = right;
}
}
// ------------------------------------------------------------------------------
// Handle incoming mail
// -----------
void CUCode_AX::HandleMail(u32 _uMail)
{
if ((_uMail & 0xFFFF0000) == MAIL_AX_ALIST)
{
// a new List
DebugLog(" >>>> u32 MAIL : General Mail (%08x)", _uMail);
}
else
{
DebugLog(" >>>> u32 MAIL : AXTask Mail (%08x)", _uMail);
AXTask(_uMail);
}
}
// ------------------------------------------------------------------------------
// Update with DSP Interrupt
// -----------
void CUCode_AX::Update()
{
// check if we have to sent something
if (!m_rMailHandler.IsEmpty())
{
g_dspInitialize.pGenerateDSPInterrupt();
}
}
// -----------
// Shortcut to avoid having to write SaveLog(false, ...) every time
void CUCode_AX::SaveLog(const char* _fmt, ...)
{
}
// ============================================
// AX seems to bootup one task only and waits for resume-callbacks
// everytime the DSP has "spare time" it sends a resume-mail to the CPU
// and the __DSPHandler calls a AX-Callback which generates a new AXFrame
bool CUCode_AX::AXTask(u32& _uMail)
{
u32 uAddress = _uMail;
SaveLog("Begin");
SaveLog("=====================================================================");
SaveLog("%08x : AXTask - AXCommandList-Addr:", uAddress);
u32 Addr__AXStudio;
u32 Addr__AXOutSBuffer;
u32 Addr__AXOutSBuffer_1;
u32 Addr__AXOutSBuffer_2;
u32 Addr__A;
u32 Addr__12;
u32 Addr__4_1;
u32 Addr__4_2;
// u32 Addr__4_3;
// u32 Addr__4_4;
u32 Addr__5_1;
u32 Addr__5_2;
u32 Addr__6;
u32 Addr__9;
bool bExecuteList = true;
while (bExecuteList)
{
static int last_valid_command = 0;
u16 iCommand = Memory_Read_U16(uAddress);
uAddress += 2;
switch (iCommand)
{
case AXLIST_STUDIOADDR: //00
Addr__AXStudio = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST studio address: %08x", uAddress, Addr__AXStudio);
break;
case 0x001: // 2byte x 10
{
u32 address = Memory_Read_U32(uAddress);
uAddress += 4;
u16 param1 = Memory_Read_U16(uAddress);
uAddress += 2;
u16 param2 = Memory_Read_U16(uAddress);
uAddress += 2;
u16 param3 = Memory_Read_U16(uAddress);
uAddress += 2;
SaveLog("%08x : AXLIST 1: %08x, %04x, %04x, %04x", uAddress, address, param1, param2, param3);
}
break;
//
// Somewhere we should be getting a bitmask of AX_SYNC values
// that tells us what has been updated
// Dunno if important
//
case AXLIST_PBADDR: //02
{
m_addressPBs = Memory_Read_U32(uAddress);
uAddress += 4;
}
break;
case 0x0003:
SaveLog("%08x : AXLIST command 0x0003 ????");
break;
case 0x0004: // AUX?
Addr__4_1 = Memory_Read_U32(uAddress);
uAddress += 4;
Addr__4_2 = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST 4_1 4_2 addresses: %08x %08x", uAddress, Addr__4_1, Addr__4_2);
break;
case 0x0005:
Addr__5_1 = Memory_Read_U32(uAddress);
uAddress += 4;
Addr__5_2 = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST 5_1 5_2 addresses: %08x %08x", uAddress, Addr__5_1, Addr__5_2);
break;
case 0x0006:
Addr__6 = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST 6 address: %08x", uAddress, Addr__6);
break;
case AXLIST_SBUFFER:
Addr__AXOutSBuffer = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST OutSBuffer address: %08x", uAddress, Addr__AXOutSBuffer);
break;
case 0x0009:
Addr__9 = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST 6 address: %08x", Addr__9);
break;
case AXLIST_COMPRESSORTABLE: // 0xa
Addr__A = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST CompressorTable address: %08x", uAddress, Addr__A);
break;
case 0x000e:
Addr__AXOutSBuffer_1 = Memory_Read_U32(uAddress);
uAddress += 4;
// Addr__AXOutSBuffer_2 is the address in RAM that we are supposed to mix to.
// Although we don't, currently.
Addr__AXOutSBuffer_2 = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST sbuf2 addresses: %08x %08x", uAddress, Addr__AXOutSBuffer_1, Addr__AXOutSBuffer_2);
break;
case AXLIST_END:
bExecuteList = false;
SaveLog("%08x : AXLIST end", uAddress);
break;
case 0x0010: //Super Monkey Ball 2
SaveLog("%08x : AXLIST 0x0010", uAddress);
//should probably read/skip stuff here
uAddress += 8;
break;
case 0x0011:
uAddress += 4;
break;
case 0x0012:
Addr__12 = Memory_Read_U16(uAddress);
uAddress += 2;
break;
case 0x0013:
uAddress += 6 * 4; // 6 Addresses.
break;
default:
{
static bool bFirst = true;
if (bFirst == true)
{
char szTemp[2048];
sprintf(szTemp, "Unknown AX-Command 0x%x (address: 0x%08x). Last valid: %02x\n",
iCommand, uAddress - 2, last_valid_command);
int num = -32;
while (num < 64+32)
{
char szTemp2[128] = "";
sprintf(szTemp2, "%s0x%04x\n", num == 0 ? ">>" : " ", Memory_Read_U16(uAddress + num));
strcat(szTemp, szTemp2);
num += 2;
}
// Wii AX will always show this
PanicAlert(szTemp);
// bFirst = false;
}
// unknown command so stop the execution of this TaskList
bExecuteList = false;
}
break;
}
if (bExecuteList)
last_valid_command = iCommand;
}
SaveLog("AXTask - done, send resume");
SaveLog("=====================================================================");
SaveLog("End");
// i hope resume is okay AX
m_rMailHandler.PushMail(0xDCD10001);
return true;
}

View File

@ -1,78 +0,0 @@
// 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/
#ifndef _UCODE_AX
#define _UCODE_AX
#include <iostream>
#include "pluginspecs_dsp.h"
#include "UCode_AXStructs.h"
enum
{
NUMBER_OF_PBS = 128
};
class CUCode_AX : public IUCode
{
public:
CUCode_AX(CMailHandler& _rMailHandler);
virtual ~CUCode_AX();
void HandleMail(u32 _uMail);
void MixAdd(short* _pBuffer, int _iSize);
void Update();
// Logging
//template<class ParamBlockType>
//void Logging(short* _pBuffer, int _iSize, int a, bool Wii, ParamBlockType &PBs, int numberOfPBs);
void Logging(short* _pBuffer, int _iSize, int a, bool Wii);
void SaveLog_(bool Wii, const char* _fmt, va_list ap);
void SaveMail(bool Wii, u32 _uMail);
void SaveLogFile(std::string f, int resizeTo, bool type, bool Wii);
std::string TmpMailLog;
int saveNext;
// PBs
u32 m_addressPBs;
u32 _CRC;
private:
enum
{
MAIL_AX_ALIST = 0xBABE0000,
AXLIST_STUDIOADDR = 0x0000,
AXLIST_PBADDR = 0x0002,
AXLIST_SBUFFER = 0x0007,
AXLIST_COMPRESSORTABLE = 0x000A,
AXLIST_END = 0x000F
};
int *templbuffer;
int *temprbuffer;
// ax task message handler
bool AXTask(u32& _uMail);
void SaveLog(const char* _fmt, ...);
void SendMail(u32 _uMail);
};
int ReadOutPBs(u32 pbs_address, AXParamBlock* _pPBs, int _num);
void WriteBackPBs(u32 pbs_address, AXParamBlock* _pPBs, int _num);
#endif // _UCODE_AX

View File

@ -1,248 +0,0 @@
// 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/
#ifndef _UCODE_AX_STRUCTS_H
#define _UCODE_AX_STRUCTS_H
struct PBMixer
{
u16 volume_left;
u16 unknown;
u16 volume_right;
u16 unknown2;
u16 unknown3[8];
u16 unknown4[6];
};
struct PBMixerWii
{
u16 volume_left;
u16 unknown;
u16 volume_right;
u16 unknown2;
u16 unknown3[12];
u16 unknown4[8];
};
struct PBInitialTimeDelay
{
u16 on;
u16 addrMemHigh;
u16 addrMemLow;
u16 offsetLeft;
u16 offsetRight;
u16 targetLeft;
u16 targetRight;
};
// Update data - read these each 1ms subframe and use them!
// It seems that to provide higher time precisions for MIDI events, some games
// use this thing to update the parameter blocks per 1ms sub-block (a block is 5ms).
// Using this data should fix games that are missing MIDI notes.
struct PBUpdates
{
u16 num_updates[5];
u16 data_hi; // These point to main RAM. Not sure about the structure of the data.
u16 data_lo;
};
struct PBUpdatesWii
{
u16 num_updates[3];
u16 data_hi; // These point to main RAM. Not sure about the structure of the data.
u16 data_lo;
};
struct PBDpop
{
s16 unknown[9];
};
struct PBDpopWii
{
s16 unknown[12];
};
struct PBDpopWii_ // new CRC version
{
s16 unknown[7];
};
struct PBVolumeEnvelope
{
u16 cur_volume;
s16 cur_volume_delta;
};
struct PBUnknown2
{
u16 unknown_reserved[3];
};
struct PBAudioAddr
{
u16 looping;
u16 sample_format;
u16 loop_addr_hi; // Start of loop (this will point to a shared "zero" buffer if one-shot mode is active)
u16 loop_addr_lo;
u16 end_addr_hi; // End of sample (and loop), inclusive
u16 end_addr_lo;
u16 cur_addr_hi;
u16 cur_addr_lo;
};
struct PBADPCMInfo
{
s16 coefs[16];
u16 gain;
u16 pred_scale;
s16 yn1;
s16 yn2;
};
struct PBSampleRateConverter
{
u16 ratio_hi;
u16 ratio_lo;
u16 cur_addr_frac;
u16 last_samples[4];
};
struct PBADPCMLoopInfo
{
u16 pred_scale;
u16 yn1;
u16 yn2;
};
struct AXParamBlock
{
u16 next_pb_hi;
u16 next_pb_lo;
u16 this_pb_hi;
u16 this_pb_lo;
u16 src_type; // Type of sample rate converter (none, ?, linear)
u16 coef_select;
u16 mixer_control;
u16 running; // 1=RUN 0=STOP
u16 is_stream; // 1 = stream, 0 = one shot
/* 9 */ PBMixer mixer;
/* 27 */ PBInitialTimeDelay initial_time_delay;
/* 34 */ PBUpdates updates;
/* 41 */ PBDpop dpop;
/* 50 */ PBVolumeEnvelope vol_env;
/* 52 */ PBUnknown2 unknown3;
/* 55 */ PBAudioAddr audio_addr;
/* 63 */ PBADPCMInfo adpcm;
/* 83 */ PBSampleRateConverter src;
/* 90 */ PBADPCMLoopInfo adpcm_loop_info;
/* 93 */ u16 unknown_maybe_padding[3];
};
struct PBLpf
{
u16 enabled;
u16 yn1;
u16 a0;
u16 b0;
};
struct PBHpf
{
u16 enabled;
u16 yn1;
u16 a0;
u16 b0;
};
struct AXParamBlockWii
{
u16 next_pb_hi;
u16 next_pb_lo;
u16 this_pb_hi;
u16 this_pb_lo;
u16 src_type; // Type of sample rate converter (none, ?, linear)
u16 coef_select;
u32 mixer_control;
u16 running; // 1=RUN 0=STOP
u16 is_stream; // 1 = stream, 0 = one shot
/* 10 */ PBMixerWii mixer;
/* 34 */ PBInitialTimeDelay initial_time_delay;
/* 41 */ PBUpdatesWii updates;
/* 46 */ PBDpopWii dpop;
/* 58 */ PBVolumeEnvelope vol_env;
/* 60 */ PBAudioAddr audio_addr;
/* 68 */ PBADPCMInfo adpcm;
/* 88 */ PBSampleRateConverter src;
/* 95 */ PBADPCMLoopInfo adpcm_loop_info;
/* 98 */ PBLpf lpf;
/* 102 */ PBHpf hpf;
/* 106 */ u16 pad[22];
};
struct AXParamBlockWii_ // new CRC version
{
u16 next_pb_hi;
u16 next_pb_lo;
u16 this_pb_hi;
u16 this_pb_lo;
u16 src_type; // Type of sample rate converter (none, ?, linear)
u16 coef_select;
u32 mixer_control;
u16 running; // 1=RUN 0=STOP
u16 is_stream; // 1 = stream, 0 = one shot
/* 10 */ PBMixerWii mixer;
/* 34 */ PBInitialTimeDelay initial_time_delay;
/* 41 */ PBUpdatesWii updates;
/* 46 */ PBDpopWii_ dpop;
/* 53 */ PBVolumeEnvelope vol_env;
/* 55 */ PBAudioAddr audio_addr;
/* 63 */ PBADPCMInfo adpcm;
/* 83 */ PBSampleRateConverter src;
/* 90 */ PBADPCMLoopInfo adpcm_loop_info;
/* 93 */ PBLpf lpf;
/* 97 */ PBHpf hpf;
/* 101 */ u16 pad[27];
};
enum {
AUDIOFORMAT_ADPCM = 0,
AUDIOFORMAT_PCM8 = 0x19,
AUDIOFORMAT_PCM16 = 0xA,
};
enum {
SRCTYPE_LINEAR = 1,
SRCTYPE_NEAREST = 2,
MIXCONTROL_RAMPING = 8,
};
#endif // _UCODE_AX_STRUCTS_H

View File

@ -1,366 +0,0 @@
// 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/
#include "StringUtil.h"
#include "../MailHandler.h"
#include "UCodes.h"
#include "UCode_AXStructs.h"
#include "UCode_AX.h" // for some functions in CUCode_AX
#include "UCode_AXWii.h"
#include "UCode_AX_Voice.h"
// ------------------------------------------------------------------
// Declarations
// -----------
extern bool gSequenced;
// -----------
CUCode_AXWii::CUCode_AXWii(CMailHandler& _rMailHandler, u32 l_CRC)
: IUCode(_rMailHandler)
, m_addressPBs(0xFFFFFFFF)
, _CRC(l_CRC)
{
// we got loaded
m_rMailHandler.PushMail(0xDCD10000);
m_rMailHandler.PushMail(0x80000000); // handshake ??? only (crc == 0xe2136399) needs it ...
templbuffer = new int[1024 * 1024];
temprbuffer = new int[1024 * 1024];
lCUCode_AX = new CUCode_AX(_rMailHandler);
lCUCode_AX->_CRC = l_CRC;
}
CUCode_AXWii::~CUCode_AXWii()
{
m_rMailHandler.Clear();
delete [] templbuffer;
delete [] temprbuffer;
}
void CUCode_AXWii::HandleMail(u32 _uMail)
{
if ((_uMail & 0xFFFF0000) == MAIL_AX_ALIST)
{
// a new List
}
else
{
AXTask(_uMail);
}
}
void CUCode_AXWii::MixAdd(short* _pBuffer, int _iSize)
{
if(_CRC == 0xfa450138)
{
AXParamBlockWii PBs[NUMBER_OF_PBS];
MixAdd_( _pBuffer, _iSize, PBs);
}
else
{
AXParamBlockWii_ PBs[NUMBER_OF_PBS];
MixAdd_(_pBuffer, _iSize, PBs);
}
}
template<class ParamBlockType>
void CUCode_AXWii::MixAdd_(short* _pBuffer, int _iSize, ParamBlockType &PBs)
{
//AXParamBlockWii PBs[NUMBER_OF_PBS];
// read out pbs
int numberOfPBs = ReadOutPBsWii(m_addressPBs, PBs, NUMBER_OF_PBS);
if (_iSize > 1024 * 1024)
_iSize = 1024 * 1024;
// write zeroes to the beginning of templbuffer
memset(templbuffer, 0, _iSize * sizeof(int));
memset(temprbuffer, 0, _iSize * sizeof(int));
// -------------------------------------------
// write logging data to debugger
/* Make the updates we are told to do. See comments to the GC version in UCode_AX.cpp */
// ------------
for (int i = 0; i < numberOfPBs; i++)
{
u16 *pDest = (u16 *)&PBs[i];
u16 upd0 = pDest[41]; u16 upd1 = pDest[42]; u16 upd2 = pDest[43]; // num_updates
u16 upd_hi = pDest[44]; // update addr
u16 upd_lo = pDest[45];
int numupd = upd0 + upd1 + upd2;
if(numupd > 64) numupd = 64; // prevent to high values
const u32 updaddr = (u32)(upd_hi << 16) | upd_lo;
int on = false, off = false;
for (int j = 0; j < numupd; j++) // make alll updates
{
const u16 updpar = Memory_Read_U16(updaddr);
const u16 upddata = Memory_Read_U16(updaddr + 2);
// some safety checks, I hope it's enough
if( ( (updaddr > 0x80000000 && updaddr < 0x817fffff)
|| (updaddr > 0x90000000 && updaddr < 0x93ffffff) )
&& updpar < 127 && updpar > 3 && upddata >= 0 // updpar > 3 because we don't want to change
// 0-3, those are important
//&& (upd0 || upd1 || upd2) // We should use these in some way to I think
// but I don't know how or when
&& gSequenced) // on and off option
{
//PanicAlert("Update %i: %i = %04x", i, updpar, upddata);
//DebugLog("Update: %i = %04x", updpar, upddata);
pDest[updpar] = upddata;
}
if (updpar == 7 && upddata == 1) on++;
if (updpar == 7 && upddata == 1) off++;
}
// hack: if we get both an on and an off select on rather than off
if (on > 0 && off > 0) pDest[7] = 1;
}
//PrintFile(1, "%08x %04x %04x\n", updaddr, updpar, upddata);
// ------------
for (int i = 0; i < numberOfPBs; i++)
{
MixAddVoice(PBs[i], templbuffer, temprbuffer, _iSize, true);
}
WriteBackPBsWii(m_addressPBs, PBs, numberOfPBs);
// We write the sound to _pBuffer
for (int i = 0; i < _iSize; i++)
{
// Clamp into 16-bit. Maybe we should add a volume compressor here.
int left = templbuffer[i] + _pBuffer[0];
int right = temprbuffer[i] + _pBuffer[1];
if (left < -32767) left = -32767;
if (left > 32767) left = 32767;
if (right < -32767) right = -32767;
if (right > 32767) right = 32767;
*_pBuffer++ = left;
*_pBuffer++ = right;
}
}
void CUCode_AXWii::Update()
{
// check if we have to sent something
if (!m_rMailHandler.IsEmpty())
{
g_dspInitialize.pGenerateDSPInterrupt();
}
}
// Shortcut
void CUCode_AXWii::SaveLog(const char* _fmt, ...)
{
}
// AX seems to bootup one task only and waits for resume-callbacks
// everytime the DSP has "spare time" it sends a resume-mail to the CPU
// and the __DSPHandler calls a AX-Callback which generates a new AXFrame
bool CUCode_AXWii::AXTask(u32& _uMail)
{
u32 uAddress = _uMail;
SaveLog("Begin");
SaveLog("=====================================================================");
SaveLog("%08x: AXTask - AXCommandList-Addr", uAddress);
u32 Addr__AXStudio;
u32 Addr__AXOutSBuffer;
// u32 Addr__AXOutSBuffer_1;
// u32 Addr__AXOutSBuffer_2;
u32 Addr__A;
// u32 Addr__12;
u32 Addr__5_1;
u32 Addr__5_2;
u32 Addr__6;
// u32 Addr__9;
bool bExecuteList = true;
if (false)
{
// PanicAlert("%i", sizeof(AXParamBlockWii)); // 252 ??
FILE *f = fopen("D:\\axdump.txt", "a");
if (!f)
f = fopen("D:\\axdump.txt", "w");
u32 addr = uAddress;
for (int i = 0; i < 100; i++) {
fprintf(f, "%02x\n", Memory_Read_U16(addr + i * 2));
}
fprintf(f, "===========------------------------------------------------=\n");
fclose(f);
}
else
{
// PanicAlert("%i", sizeof(AXParamBlock)); // 192
}
while (bExecuteList)
{
static int last_valid_command = 0;
u16 iCommand = Memory_Read_U16(uAddress);
uAddress += 2;
switch (iCommand)
{
case 0x0000: //00
Addr__AXStudio = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST studio address: %08x", uAddress, Addr__AXStudio);
break;
case 0x0001:
{
u32 address = Memory_Read_U32(uAddress);
uAddress += 4;
}
break;
case 0x0003:
{
u32 address = Memory_Read_U32(uAddress);
uAddress += 4;
}
break;
case 0x0004: // PBs are here now
m_addressPBs = Memory_Read_U32(uAddress);
lCUCode_AX->m_addressPBs = m_addressPBs; // for the sake of logging
uAddress += 4;
break;
case 0x0005:
if(Memory_Read_U16(uAddress) > 25) // this occured in Wii Sports
{
Addr__5_1 = Memory_Read_U32(uAddress);
uAddress += 4;
Addr__5_2 = Memory_Read_U32(uAddress);
uAddress += 4;
uAddress += 2;
}
else
{
uAddress += 2;
SaveLog("%08x : AXLIST Empty 0x0005", uAddress);
}
break;
case 0x0006:
Addr__6 = Memory_Read_U32(uAddress);
uAddress += 10;
SaveLog("%08x : AXLIST 6 address: %08x", uAddress, Addr__6);
break;
/**/ case 0x0007: // AXLIST_SBUFFER
Addr__AXOutSBuffer = Memory_Read_U32(uAddress);
uAddress += 10;
// uAddress += 12;
SaveLog("%08x : AXLIST OutSBuffer (0x0007) address: %08x", uAddress, Addr__AXOutSBuffer);
break;
/* case 0x0009:
Addr__9 = Memory_Read_U32(uAddress);
uAddress += 4;
DebugLog("AXLIST 6 address: %08x", Addr__9);
break;*/
case 0x000a: // AXLIST_COMPRESSORTABLE
Addr__A = Memory_Read_U32(uAddress);
uAddress += 4;
//Addr__A = Memory_Read_U32(uAddress);
uAddress += 4;
SaveLog("%08x : AXLIST CompressorTable address: %08x", uAddress, Addr__A);
break;
case 0x000b:
uAddress += 2; // one 0x8000 in rabbids
uAddress += 4 * 2; // then two RAM addressses
break;
case 0x000c:
uAddress += 2; // one 0x8000 in rabbids
uAddress += 4 * 2; // then two RAM addressses
break;
case 0x000d:
uAddress += 4 * 4;
break;
case 0x000e:
// This is the end.
bExecuteList = false;
SaveLog("%08x : AXLIST end, wii stylee.", uAddress);
break;
default:
{
static bool bFirst = true;
if (bFirst == true)
{
// A little more descreet way to say that there is a problem, that also let you
// take a look at the mail (and possible previous mails) in the debugger
SaveLog("%08x : Unknown AX-Command 0x%04x", uAddress, iCommand);
bExecuteList = false;
break;
char szTemp[2048];
sprintf(szTemp, "Unknown AX-Command 0x%04x (address: 0x%08x). Last valid: %02x\n",
iCommand, uAddress - 2, last_valid_command);
int num = -32;
while (num < 64+32)
{
char szTemp2[128] = "";
sprintf(szTemp2, "%s0x%04x\n", num == 0 ? ">>" : " ", Memory_Read_U16(uAddress + num));
strcat(szTemp, szTemp2);
num += 2;
}
// Wii AX will always show this
PanicAlert(szTemp);
// bFirst = false;
}
// unknown command so stop the execution of this TaskList
bExecuteList = false;
}
break;
}
if (bExecuteList)
last_valid_command = iCommand;
}
SaveLog("AXTask - done, send resume");
SaveLog("=====================================================================");
SaveLog("End");
// i hope resume is okay AX
m_rMailHandler.PushMail(0xDCD10001);
return true;
}

View File

@ -1,64 +0,0 @@
// 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/
#ifndef _UCODE_AXWII
#define _UCODE_AXWII
#include "UCode_AXStructs.h"
#define NUMBER_OF_PBS 128
class CUCode_AXWii : public IUCode
{
public:
CUCode_AXWii(CMailHandler& _rMailHandler, u32 _CRC);
virtual ~CUCode_AXWii();
void HandleMail(u32 _uMail);
void MixAdd(short* _pBuffer, int _iSize);
template<class ParamBlockType>
//void Logging(short* _pBuffer, int _iSize, int a, bool Wii, ParamBlockType &PBs, int numberOfPBs);
void MixAdd_(short* _pBuffer, int _iSize, ParamBlockType &PBs);
void Update();
// The logging function for the debugger
void Logging(short* _pBuffer, int _iSize, int a);
CUCode_AX * lCUCode_AX; // we need the logging functions in there
private:
enum
{
MAIL_AX_ALIST = 0xBABE0000,
};
// PBs
u32 m_addressPBs;
u32 _CRC;
int *templbuffer;
int *temprbuffer;
// ax task message handler
bool AXTask(u32& _uMail);
void SaveLog(const char* _fmt, ...);
void SendMail(u32 _uMail);
};
//int ReadOutPBsWii(u32 pbs_address, AXParamBlockWii* _pPBs, int _num);
//void WriteBackPBsWii(u32 pbs_address, AXParamBlockWii* _pPBs, int _num);
#endif // _UCODE_AXWII

View File

@ -1,92 +0,0 @@
// 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/
#ifndef _UCODE_AX_ADPCM_H
#define _UCODE_AX_ADPCM_H
#include "../Globals.h"
inline s16 ADPCM_Step(PBADPCMInfo &adpcm, u32& samplePos, u32 newSamplePos, u16 frac)
{
while (samplePos < newSamplePos)
{
if ((samplePos & 15) == 0)
{
adpcm.pred_scale = g_dspInitialize.pARAM_Read_U8((samplePos & ~15) >> 1);
samplePos += 2;
newSamplePos += 2;
}
int scale = 1 << (adpcm.pred_scale & 0xF);
int coef_idx = adpcm.pred_scale >> 4;
s32 coef1 = adpcm.coefs[coef_idx * 2 + 0];
s32 coef2 = adpcm.coefs[coef_idx * 2 + 1];
int temp = (samplePos & 1) ?
(g_dspInitialize.pARAM_Read_U8(samplePos >> 1) & 0xF) :
(g_dspInitialize.pARAM_Read_U8(samplePos >> 1) >> 4);
if (temp >= 8)
temp -= 16;
// 0x400 = 0.5 in 11-bit fixed point
int val = (scale * temp) + ((0x400 + coef1 * adpcm.yn1 + coef2 * adpcm.yn2) >> 11);
if (val > 0x7FFF)
val = 0x7FFF;
else if (val < -0x7FFF)
val = -0x7FFF;
adpcm.yn2 = adpcm.yn1;
adpcm.yn1 = val;
samplePos++;
}
return adpcm.yn1;
}
// =======================================================================================
// Volume control (ramping)
// --------------
inline u16 ADPCM_Vol(u16 vol, u16 delta)
{
int x = vol;
if (delta && delta < 0x5000)
x += delta * 20 * 8; // unsure what the right step is
//x += 1 * 20 * 8;
else if (delta && delta > 0x5000)
//x -= (0x10000 - delta); // this is to small, it's often 1
x -= (0x10000 - delta) * 20 * 16; // if this was 20 * 8 the sounds in Fire Emblem and Paper Mario
// did not have time to go to zero before the were closed
//x -= 1 * 20 * 16;
// make lower limits
if (x < 0) x = 0;
//if (pb.mixer_control < 1000 && x < pb.mixer_control) x = pb.mixer_control; // does this make
// any sense?
// make upper limits
//if (mixer_control > 1000 && x > mixer_control) x = mixer_control; // maybe mixer_control also
// has a volume target?
//if (x >= 0x7fff) x = 0x7fff; // this seems a little high
if (x >= 0x4e20) x = 0x4e20; // add a definitive limit at 20 000
return x; // update volume
}
// ==============
#endif // _UCODE_AX_ADPCM_H

View File

@ -1,391 +0,0 @@
// 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/
#ifndef _UCODE_AX_VOICE_H
#define _UCODE_AX_VOICE_H
#include "UCode_AX_ADPCM.h"
#include "UCode_AX.h"
// ----------------------------------------------------
// Externals
// -----------
extern bool gSSBM;
extern bool gSSBMremedy1;
extern bool gSSBMremedy2;
extern bool gSequenced;
extern bool gVolume;
extern bool gReset;
extern bool gSequenced;
extern float ratioFactor;
template<class ParamBlockType>
inline int ReadOutPBsWii(u32 pbs_address, ParamBlockType& _pPBs, int _num)
{
int count = 0;
u32 blockAddr = pbs_address;
u32 pAddr = 0;
// reading and 'halfword' swap
for (int i = 0; i < _num; i++)
{
const short *pSrc = (const short *)g_dspInitialize.pGetMemoryPointer(blockAddr);
pAddr = blockAddr;
if (pSrc != NULL)
{
short *pDest = (short *)&_pPBs[i];
for (u32 p = 0; p < sizeof(AXParamBlockWii) / 2; p++)
{
if(p == 6 || p == 7) pDest[p] = pSrc[p]; // control for the u32
else pDest[p] = Common::swap16(pSrc[p]);
}
_pPBs[i].mixer_control = Common::swap32(_pPBs[i].mixer_control);
blockAddr = (_pPBs[i].next_pb_hi << 16) | _pPBs[i].next_pb_lo;
count++;
// Detect the last mail by checking when next_pb = 0
u32 next_pb = (Common::swap16(pSrc[0]) << 16) | Common::swap16(pSrc[1]);
if(next_pb == 0) break;
}
else
break;
}
// return the number of read PBs
return count;
}
template<class ParamBlockType>
inline void WriteBackPBsWii(u32 pbs_address, ParamBlockType& _pPBs, int _num)
//void WriteBackPBsWii(u32 pbs_address, AXParamBlockWii* _pPBs, int _num)
{
u32 blockAddr = pbs_address;
// write back and 'halfword'swap
for (int i = 0; i < _num; i++)
{
short* pSrc = (short*)&_pPBs[i];
short* pDest = (short*)g_dspInitialize.pGetMemoryPointer(blockAddr);
_pPBs[i].mixer_control = Common::swap32(_pPBs[i].mixer_control);
for (size_t p = 0; p < sizeof(AXParamBlockWii) / 2; p++)
{
if(p == 6 || p == 7) pDest[p] = pSrc[p]; // control for the u32
else pDest[p] = Common::swap16(pSrc[p]);
}
// next block
blockAddr = (_pPBs[i].next_pb_hi << 16) | _pPBs[i].next_pb_lo;
}
}
template<class ParamBlockType>
inline void MixAddVoice(ParamBlockType &pb, int *templbuffer, int *temprbuffer, int _iSize, bool Wii)
{
DoVoiceHacks(pb, Wii);
// =============
if (pb.running)
{
// =======================================================================================
// Read initial parameters
// ------------
//constants
const u32 ratio = (u32)(((pb.src.ratio_hi << 16) + pb.src.ratio_lo) * ratioFactor);
u32 sampleEnd = (pb.audio_addr.end_addr_hi << 16) | pb.audio_addr.end_addr_lo;
u32 loopPos = (pb.audio_addr.loop_addr_hi << 16) | pb.audio_addr.loop_addr_lo;
//variables
u32 samplePos = (pb.audio_addr.cur_addr_hi << 16) | pb.audio_addr.cur_addr_lo;
u32 frac = pb.src.cur_addr_frac;
// =============
// =======================================================================================
// Handle No-SRC streams - No src streams have pb.src_type == 2 and have pb.src.ratio_hi = 0
// and pb.src.ratio_lo = 0. We handle that by setting the sampling ratio integer to 1. This
// makes samplePos update in the correct way. I'm unsure how we are actually supposed to
// detect that this setting. Updates did not fix this automatically.
// ---------------------------------------------------------------------------------------
// Stream settings
// src_type = 2 (most other games have src_type = 0)
// ------------
// Affected games:
// Baten Kaitos - Eternal Wings (2003)
// Baten Kaitos - Origins (2006)?
// Soul Calibur 2: The movie music use src_type 2 but it needs no adjustment, perhaps
// the sound format plays in to, Baten use ADPCM, SC2 use PCM16
// ------------
//if (pb.src_type == 2 && (pb.src.ratio_hi == 0 && pb.src.ratio_lo == 0))
if (pb.running && (pb.src.ratio_hi == 0 && pb.src.ratio_lo == 0))
{
pb.src.ratio_hi = 1;
}
// =============
// =======================================================================================
// Games that use looping to play non-looping music streams - SSBM has info in all
// pb.adpcm_loop_info parameters but has pb.audio_addr.looping = 0. If we treat these streams
// like any other looping streams the music works. I'm unsure how we are actually supposed to
// detect that these kinds of blocks should be looping. It seems like pb.mixer_control == 0 may
// identify these types of blocks. Updates did not write any looping values.
// --------------
if (
(pb.adpcm_loop_info.pred_scale || pb.adpcm_loop_info.yn1 || pb.adpcm_loop_info.yn2)
&& pb.mixer_control == 0
)
{
pb.audio_addr.looping = 1;
}
// ==============
// Top Spin 3 Wii
if(pb.audio_addr.sample_format > 25) pb.audio_addr.sample_format = 0;
// =======================================================================================
// Walk through _iSize. _iSize = numSamples. If the game goes slow _iSize will be higher to
// compensate for that. _iSize can be as low as 100 or as high as 2000 some cases.
for (int s = 0; s < _iSize; s++)
{
int sample = 0;
frac += ratio;
u32 newSamplePos = samplePos + (frac >> 16); //whole number of frac
// =======================================================================================
// Process sample format
// --------------
switch (pb.audio_addr.sample_format)
{
case AUDIOFORMAT_PCM8:
// TODO - the linear interpolation code below is somewhat suspicious
pb.adpcm.yn2 = pb.adpcm.yn1; //save last sample
pb.adpcm.yn1 = ((s8)g_dspInitialize.pARAM_Read_U8(samplePos)) << 8;
if (pb.src_type == SRCTYPE_NEAREST)
{
sample = pb.adpcm.yn1;
}
else //linear interpolation
{
sample = (pb.adpcm.yn1 * (u16)frac + pb.adpcm.yn2 * (u16)(0xFFFF - frac)) >> 16;
}
samplePos = newSamplePos;
break;
case AUDIOFORMAT_PCM16:
// TODO - the linear interpolation code below is somewhat suspicious
pb.adpcm.yn2 = pb.adpcm.yn1; //save last sample
pb.adpcm.yn1 = (s16)(u16)((g_dspInitialize.pARAM_Read_U8(samplePos * 2) << 8) | (g_dspInitialize.pARAM_Read_U8((samplePos * 2 + 1))));
if (pb.src_type == SRCTYPE_NEAREST)
sample = pb.adpcm.yn1;
else //linear interpolation
sample = (pb.adpcm.yn1 * (u16)frac + pb.adpcm.yn2 * (u16)(0xFFFF - frac)) >> 16;
samplePos = newSamplePos;
break;
case AUDIOFORMAT_ADPCM:
sample = ADPCM_Step(pb.adpcm, samplePos, newSamplePos, frac);
break;
default:
break;
}
// ================
// ===================================================================
// Overall volume control. In addition to this there is also separate volume settings to
// different channels (left, right etc).
frac &= 0xffff;
int vol = pb.vol_env.cur_volume >> 9;
sample = sample * vol >> 8;
if (pb.mixer_control & MIXCONTROL_RAMPING)
{
int x = pb.vol_env.cur_volume;
x += pb.vol_env.cur_volume_delta; // I'm not sure about this, can anybody find a game
// that use this? Or how does it work?
if (x < 0) x = 0;
if (x >= 0x7fff) x = 0x7fff;
pb.vol_env.cur_volume = x; // maybe not per sample?? :P
}
int leftmix = pb.mixer.volume_left >> 5;
int rightmix = pb.mixer.volume_right >> 5;
int left = sample * leftmix >> 8;
int right = sample * rightmix >> 8;
//adpcm has to walk from oldSamplePos to samplePos here
templbuffer[s] += left;
temprbuffer[s] += right;
// ===============
// ===================================================================
// Control the behavior when we reach the end of the sample
if (samplePos >= sampleEnd)
{
if (pb.audio_addr.looping == 1)
{
samplePos = loopPos;
if (pb.audio_addr.sample_format == AUDIOFORMAT_ADPCM)
{
if (!pb.is_stream)
{
pb.adpcm.yn1 = pb.adpcm_loop_info.yn1;
pb.adpcm.yn2 = pb.adpcm_loop_info.yn2;
pb.adpcm.pred_scale = pb.adpcm_loop_info.pred_scale;
}
}
}
else
{
pb.running = 0;
break;
}
}
// ===============
} // end of the _iSize loop
// Update volume
//if (sizeof(ParamBlockType) == sizeof(AXParamBlock)) // this is not needed anymore I think
if (gVolume) // allow us to turn this off in the debugger
{
pb.mixer.volume_left = ADPCM_Vol(pb.mixer.volume_left, pb.mixer.unknown);
pb.mixer.volume_right = ADPCM_Vol(pb.mixer.volume_right, pb.mixer.unknown2);
}
pb.src.cur_addr_frac = (u16)frac;
pb.audio_addr.cur_addr_hi = samplePos >> 16;
pb.audio_addr.cur_addr_lo = (u16)samplePos;
} // if (pb.running)
}
// ================================================
// Voice hacks
// --------------
template<class ParamBlockType>
inline void DoVoiceHacks(ParamBlockType &pb, bool Wii)
{
// get necessary values
const u32 sampleEnd = (pb.audio_addr.end_addr_hi << 16) | pb.audio_addr.end_addr_lo;
const u32 loopPos = (pb.audio_addr.loop_addr_hi << 16) | pb.audio_addr.loop_addr_lo;
const u32 updaddr = (u32)(pb.updates.data_hi << 16) | pb.updates.data_lo;
const u16 updpar = Memory_Read_U16(updaddr);
const u16 upddata = Memory_Read_U16(updaddr + 2);
// =======================================================================================
/* Fix problems introduced with the SSBM fix. Sometimes when a music stream ended sampleEnd
would end up outside of bounds while the block was still playing resulting in noise
a strange noise. This should take care of that.
*/
// ------------
if (
(sampleEnd > (0x017fffff * 2) || loopPos > (0x017fffff * 2)) // ARAM bounds in nibbles
&& gSSBMremedy1
&& !Wii
)
{
pb.running = 0;
// also reset all values if it makes any difference
pb.audio_addr.cur_addr_hi = 0; pb.audio_addr.cur_addr_lo = 0;
pb.audio_addr.end_addr_hi = 0; pb.audio_addr.end_addr_lo = 0;
pb.audio_addr.loop_addr_hi = 0; pb.audio_addr.loop_addr_lo = 0;
pb.src.cur_addr_frac = 0; pb.src.ratio_hi = 0; pb.src.ratio_lo = 0;
pb.adpcm.pred_scale = 0; pb.adpcm.yn1 = 0; pb.adpcm.yn2 = 0;
pb.audio_addr.looping = 0;
pb.adpcm_loop_info.pred_scale = 0;
pb.adpcm_loop_info.yn1 = 0; pb.adpcm_loop_info.yn2 = 0;
}
/*
// the fact that no settings are reset (except running) after a SSBM type music stream or another
looping block (for example in Battle Stadium DON) has ended could cause loud garbled sound to be
played from one or more blocks. Perhaps it was in conjunction with the old sequenced music fix below,
I'm not sure. This was an attempt to prevent that anyway by resetting all. But I'm not sure if this
is needed anymore. Please try to play SSBM without it and see if it works anyway.
*/
if (
// detect blocks that have recently been running that we should reset
pb.running == 0 && pb.audio_addr.looping == 1
//pb.running == 0 && pb.adpcm_loop_info.pred_scale
// this prevents us from ruining sequenced music blocks, may not be needed
/*
&& !(pb.updates.num_updates[0] || pb.updates.num_updates[1] || pb.updates.num_updates[2]
|| pb.updates.num_updates[3] || pb.updates.num_updates[4])
*/
&& !(updpar || upddata)
&& pb.mixer_control == 0 // only use this in SSBM
&& gSSBMremedy2 // let us turn this fix on and off
&& !Wii
)
{
// reset the detection values
pb.audio_addr.looping = 0;
pb.adpcm_loop_info.pred_scale = 0;
pb.adpcm_loop_info.yn1 = 0; pb.adpcm_loop_info.yn2 = 0;
//pb.audio_addr.cur_addr_hi = 0; pb.audio_addr.cur_addr_lo = 0;
//pb.audio_addr.end_addr_hi = 0; pb.audio_addr.end_addr_lo = 0;
//pb.audio_addr.loop_addr_hi = 0; pb.audio_addr.loop_addr_lo = 0;
//pb.src.cur_addr_frac = 0; PBs[i].src.ratio_hi = 0; PBs[i].src.ratio_lo = 0;
//pb.adpcm.pred_scale = 0; pb.adpcm.yn1 = 0; pb.adpcm.yn2 = 0;
}
// =============
// =======================================================================================
// Reset all values
// ------------
if (gReset
&& (pb.running || pb.audio_addr.looping || pb.adpcm_loop_info.pred_scale)
)
{
pb.running = 0;
pb.audio_addr.cur_addr_hi = 0; pb.audio_addr.cur_addr_lo = 0;
pb.audio_addr.end_addr_hi = 0; pb.audio_addr.end_addr_lo = 0;
pb.audio_addr.loop_addr_hi = 0; pb.audio_addr.loop_addr_lo = 0;
pb.src.cur_addr_frac = 0; pb.src.ratio_hi = 0; pb.src.ratio_lo = 0;
pb.adpcm.pred_scale = 0; pb.adpcm.yn1 = 0; pb.adpcm.yn2 = 0;
pb.audio_addr.looping = 0;
pb.adpcm_loop_info.pred_scale = 0;
pb.adpcm_loop_info.yn1 = 0; pb.adpcm_loop_info.yn2 = 0;
}
}
#endif // _UCODE_AX_VOICE_H

View File

@ -1,62 +0,0 @@
// 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/
#include "../Globals.h"
#include "../DSPHandler.h"
#include "UCodes.h"
#include "UCode_CARD.h"
CUCode_CARD::CUCode_CARD(CMailHandler& _rMailHandler)
: IUCode(_rMailHandler)
{
DebugLog("CUCode_CARD - initialized");
m_rMailHandler.PushMail(DSP_INIT);
}
CUCode_CARD::~CUCode_CARD()
{
m_rMailHandler.Clear();
}
void CUCode_CARD::Update()
{
// check if we have to sent something
if (!m_rMailHandler.IsEmpty())
{
g_dspInitialize.pGenerateDSPInterrupt();
}
}
void CUCode_CARD::HandleMail(u32 _uMail)
{
if (_uMail == 0xFF000000) // unlock card
{
// m_Mails.push(0x00000001); // ACK (actualy anything != 0)
}
else
{
DebugLog("CUCode_CARD - unknown cmd: %x (size %i)", _uMail);
}
m_rMailHandler.PushMail(DSP_DONE);
CDSPHandler::GetInstance().SetUCode(UCODE_ROM);
}

View File

@ -1,45 +0,0 @@
// 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/
#ifndef _UCODE_CARD_H
#define _UCODE_CARD_H
#include "UCodes.h"
class CUCode_CARD : public IUCode
{
private:
enum EDSP_Codes
{
DSP_INIT = 0xDCD10000,
DSP_RESUME = 0xDCD10001,
DSP_YIELD = 0xDCD10002,
DSP_DONE = 0xDCD10003,
DSP_SYNC = 0xDCD10004,
DSP_UNKN = 0xDCD10005,
};
public:
CUCode_CARD(CMailHandler& _rMailHandler);
virtual ~CUCode_CARD();
void HandleMail(u32 _uMail);
void Update();
};
#endif

View File

@ -1,53 +0,0 @@
// 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/
#include "../Globals.h"
#include "../DSPHandler.h"
#include "UCodes.h"
#include "UCode_InitAudioSystem.h"
CUCode_InitAudioSystem::CUCode_InitAudioSystem(CMailHandler& _rMailHandler)
: IUCode(_rMailHandler)
, m_BootTask_numSteps(0)
, m_NextParameter(0)
, IsInitialized(false)
{
DebugLog("CUCode_InitAudioSystem - initialized");
}
CUCode_InitAudioSystem::~CUCode_InitAudioSystem()
{}
void CUCode_InitAudioSystem::Init()
{}
void CUCode_InitAudioSystem::Update()
{
if (m_rMailHandler.IsEmpty())
{
m_rMailHandler.PushMail(0x80544348);
// HALT
}
}
void CUCode_InitAudioSystem::HandleMail(u32 _uMail)
{}

View File

@ -1,54 +0,0 @@
// 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/
#ifndef _UCODE_INITAUDIOSYSTEM
#define _UCODE_INITAUDIOSYSTEM
#include "UCodes.h"
class CUCode_InitAudioSystem : public IUCode
{
public:
CUCode_InitAudioSystem(CMailHandler& _rMailHandler);
virtual ~CUCode_InitAudioSystem();
void HandleMail(u32 _uMail);
void Update();
void Init();
private:
struct SUCode
{
u32 m_RAMAddress;
u32 m_Length;
u32 m_IMEMAddress;
u32 m_Unk;
u32 m_StartPC;
};
SUCode m_CurrentUCode;
int m_BootTask_numSteps;
u32 m_NextParameter;
bool IsInitialized;
void BootUCode();
};
#endif

View File

@ -1,161 +0,0 @@
// 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/
#include "../Globals.h"
#include "UCodes.h"
#include "UCode_Jac.h"
#include "../MailHandler.h"
CUCode_Jac::CUCode_Jac(CMailHandler& _rMailHandler)
: IUCode(_rMailHandler)
, m_bListInProgress(false)
{
DebugLog("CUCode_Jac: init");
m_rMailHandler.PushMail(0xDCD10000);
m_rMailHandler.PushMail(0x80000000);
}
CUCode_Jac::~CUCode_Jac()
{
m_rMailHandler.Clear();
}
void CUCode_Jac::HandleMail(u32 _uMail)
{
// this is prolly totally bullshit and should work like the zelda one...
// but i am to lazy to change it atm
if (m_bListInProgress == false)
{
// get the command to find out how much steps it has
switch (_uMail & 0xFFFF)
{
// release halt
case 0x00:
// m_Mails.push(0x80000000);
g_dspInitialize.pGenerateDSPInterrupt();
break;
case 0x40:
m_step = 0;
((u32*)m_Buffer)[m_step++] = _uMail;
m_bListInProgress = true;
m_numSteps = 5;
break;
case 0x2000:
case 0x4000:
m_step = 0;
((u32*)m_Buffer)[m_step++] = _uMail;
m_bListInProgress = true;
m_numSteps = 3;
break;
default:
PanicAlert("UCode Jac");
DebugLog("UCode Jac - unknown cmd: %x", _uMail & 0xFFFF);
break;
}
}
else
{
((u32*)m_Buffer)[m_step] = _uMail;
m_step++;
if (m_step == m_numSteps)
{
ExecuteList();
m_bListInProgress = false;
}
}
}
void CUCode_Jac::Update()
{
// check if we have to sent something
/* if (!g_MailHandler.empty())
{
g_dspInitialize.pGenerateDSPInterrupt();
}*/
}
void CUCode_Jac::ExecuteList()
{
// begin with the list
m_readOffset = 0;
u16 cmd = Read16();
u16 sync = Read16();
DebugLog("==============================================================================");
DebugLog("UCode Jac - execute dlist (cmd: 0x%04x : sync: 0x%04x)", cmd, sync);
switch (cmd)
{
// ==============================================================================
// DsetupTable
// ==============================================================================
case 0x40:
{
u32 tmp[4];
tmp[0] = Read32();
tmp[1] = Read32();
tmp[2] = Read32();
tmp[3] = Read32();
DebugLog("DsetupTable");
DebugLog("???: 0x%08x", tmp[0]);
DebugLog("DSPRES_FILTER (size: 0x40): 0x%08x", tmp[1]);
DebugLog("DSPADPCM_FILTER (size: 0x500): 0x%08x", tmp[2]);
DebugLog("???: 0x%08x", tmp[3]);
}
break;
// ==============================================================================
// UpdateDSPChannel
// ==============================================================================
case 0x2000:
case 0x4000: // animal crossing
{
u32 tmp[3];
tmp[0] = Read32();
tmp[1] = Read32();
tmp[2] = Read32();
DebugLog("UpdateDSPChannel");
DebugLog("audiomemory: 0x%08x", tmp[0]);
DebugLog("audiomemory: 0x%08x", tmp[1]);
DebugLog("DSPADPCM_FILTER (size: 0x40): 0x%08x", tmp[2]);
}
break;
default:
PanicAlert("UCode Jac unknown cmd: %s (size %i)", cmd, m_numSteps);
DebugLog("Jac UCode - unknown cmd: %x (size %i)", cmd, m_numSteps);
break;
}
// sync, we are rdy
m_rMailHandler.PushMail(DSP_SYNC);
m_rMailHandler.PushMail(0xF3550000 | sync);
}

View File

@ -1,74 +0,0 @@
// 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/
#ifndef _UCODE_JAC
#define _UCODE_JAC
#include "UCodes.h"
class CUCode_Jac : public IUCode
{
private:
enum EDSP_Codes
{
DSP_INIT = 0xDCD10000,
DSP_RESUME = 0xDCD10001,
DSP_YIELD = 0xDCD10002,
DSP_DONE = 0xDCD10003,
DSP_SYNC = 0xDCD10004,
DSP_UNKN = 0xDCD10005,
};
bool m_bListInProgress;
int m_numSteps;
int m_step;
u8 m_Buffer[1024];
void ExecuteList();
u32 m_readOffset;
u8 Read8()
{
return(m_Buffer[m_readOffset++]);
}
// Hmm, don't these need bswaps?
u16 Read16()
{
u16 res = *(u16*)&m_Buffer[m_readOffset];
m_readOffset += 2;
return(res);
}
u32 Read32()
{
u32 res = *(u32*)&m_Buffer[m_readOffset];
m_readOffset += 4;
return(res);
}
public:
CUCode_Jac(CMailHandler& _rMailHandler);
virtual ~CUCode_Jac();
void HandleMail(u32 _uMail);
void Update();
};
#endif

View File

@ -1,112 +0,0 @@
// 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/
#include "../Globals.h"
#include "../DSPHandler.h"
#include "UCodes.h"
#include "UCode_ROM.h"
CUCode_Rom::CUCode_Rom(CMailHandler& _rMailHandler)
: IUCode(_rMailHandler)
, m_BootTask_numSteps(0)
, m_NextParameter(0)
{
DebugLog("UCode_Rom - initialized");
m_rMailHandler.Clear();
m_rMailHandler.PushMail(0x8071FEED);
}
CUCode_Rom::~CUCode_Rom()
{}
void CUCode_Rom::Update()
{}
void CUCode_Rom::HandleMail(u32 _uMail)
{
if (m_NextParameter == 0)
{
// wait for beginning of UCode
if ((_uMail & 0xFFFF0000) != 0x80F30000)
{
u32 Message = 0xFEEE0000 | (_uMail & 0xFFFF);
m_rMailHandler.PushMail(Message);
}
else
{
m_NextParameter = _uMail;
}
}
else
{
switch (m_NextParameter)
{
case 0x80F3A001:
m_CurrentUCode.m_RAMAddress = _uMail;
break;
case 0x80F3A002:
m_CurrentUCode.m_Length = _uMail;
break;
case 0x80F3C002:
m_CurrentUCode.m_IMEMAddress = _uMail;
break;
case 0x80F3B002:
m_CurrentUCode.m_Unk = _uMail;
break;
case 0x80F3D001:
{
m_CurrentUCode.m_StartPC = _uMail;
BootUCode();
return; // FIXES THE OVERWRITE
}
break;
}
// THE GODDAMN OVERWRITE WAS HERE. Without the return above, since BootUCode may delete "this", well ...
m_NextParameter = 0;
}
}
void CUCode_Rom::BootUCode()
{
// simple non-scientific crc invented by ector :P
// too annoying to change now, and probably good enough anyway
u32 crc = 0;
for (u32 i = 0; i < m_CurrentUCode.m_Length; i++)
{
crc ^= Memory_Read_U8(m_CurrentUCode.m_RAMAddress + i);
//let's rol
crc = (crc << 3) | (crc >> 29);
}
DebugLog("CurrentUCode SOURCE Addr: 0x%08x", m_CurrentUCode.m_RAMAddress);
DebugLog("CurrentUCode Length: 0x%08x", m_CurrentUCode.m_Length);
DebugLog("CurrentUCode DEST Addr: 0x%08x", m_CurrentUCode.m_IMEMAddress);
DebugLog("CurrentUCode ???: 0x%08x", m_CurrentUCode.m_Unk);
DebugLog("CurrentUCode init_vector: 0x%08x", m_CurrentUCode.m_StartPC);
DebugLog("CurrentUCode CRC: 0x%08x", crc);
DebugLog("BootTask - done");
CDSPHandler::GetInstance().SetUCode(crc);
}

View File

@ -1,51 +0,0 @@
// 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/
#ifndef _UCODE_ROM
#define _UCODE_ROM
#include "UCodes.h"
class CUCode_Rom : public IUCode
{
public:
CUCode_Rom(CMailHandler& _rMailHandler);
virtual ~CUCode_Rom();
void HandleMail(u32 _uMail);
void Update();
private:
struct SUCode
{
u32 m_RAMAddress;
u32 m_Length;
u32 m_IMEMAddress;
u32 m_Unk;
u32 m_StartPC;
};
SUCode m_CurrentUCode;
int m_BootTask_numSteps;
u32 m_NextParameter;
void BootUCode();
};
#endif

View File

@ -1,168 +0,0 @@
// 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/
// Games that uses this UCode:
// Zelda: The Windwaker, Mario Sunshine, Mario Kart, Twilight Princess
#include "../Globals.h"
#include "UCodes.h"
#include "UCode_Zelda.h"
#include "../MailHandler.h"
CUCode_Zelda::CUCode_Zelda(CMailHandler& _rMailHandler)
: IUCode(_rMailHandler)
, m_numSteps(0)
, m_bListInProgress(false)
, m_step(0)
, m_readOffset(0)
{
DebugLog("UCode_Zelda - add boot mails for handshake");
m_rMailHandler.PushMail(DSP_INIT);
m_rMailHandler.PushMail(0x80000000); // handshake
memset(m_Buffer, 0, sizeof(m_Buffer));
}
CUCode_Zelda::~CUCode_Zelda()
{
m_rMailHandler.Clear();
}
void CUCode_Zelda::Update()
{
// check if we have to sent something
if (!m_rMailHandler.IsEmpty())
g_dspInitialize.pGenerateDSPInterrupt();
}
void CUCode_Zelda::HandleMail(u32 _uMail)
{
if (m_bListInProgress == false)
{
m_bListInProgress = true;
m_numSteps = _uMail;
m_step = 0;
}
else
{
if (m_step < 0 || m_step >= sizeof(m_Buffer)/4)
PanicAlert("m_step out of range");
((u32*)m_Buffer)[m_step] = _uMail;
m_step++;
if (m_step == m_numSteps)
{
ExecuteList();
m_bListInProgress = false;
}
}
}
void CUCode_Zelda::MixAdd(short* buffer, int size)
{
//TODO(XK): Zelda UCode MixAdd?
}
void CUCode_Zelda::ExecuteList()
{
// begin with the list
m_readOffset = 0;
u32 Temp = Read32();
u32 Command = (Temp >> 24) & 0x7f;
u32 Sync = Temp >> 16;
DebugLog("==============================================================================");
DebugLog("Zelda UCode - execute dlist (cmd: 0x%04x : sync: 0x%04x)", Command, Sync);
switch (Command)
{
// DsetupTable ... zelda ww jumps to 0x0095
case 0x01:
{
u32 tmp[4];
tmp[0] = Read32();
tmp[1] = Read32();
tmp[2] = Read32();
tmp[3] = Read32();
DebugLog("DsetupTable");
DebugLog("???: 0x%08x", tmp[0]);
DebugLog("DSPRES_FILTER (size: 0x40): 0x%08x", tmp[1]);
DebugLog("DSPADPCM_FILTER (size: 0x500): 0x%08x", tmp[2]);
DebugLog("???: 0x%08x", tmp[3]);
}
break;
// SyncFrame ... zelda ww jumps to 0x0243
case 0x02:
{
u32 tmp[3];
tmp[0] = Read32();
tmp[1] = Read32();
tmp[2] = Read32();
DebugLog("DsyncFrame");
DebugLog("???: 0x%08x", tmp[0]);
DebugLog("???: 0x%08x", tmp[1]);
DebugLog("DSPADPCM_FILTER (size: 0x500): 0x%08x", tmp[2]);
}
break;
/*
case 0x03: break; // dunno ... zelda ww jmps to 0x0073
case 0x04: break; // dunno ... zelda ww jmps to 0x0580
case 0x05: break; // dunno ... zelda ww jmps to 0x0592
case 0x06: break; // dunno ... zelda ww jmps to 0x0469
case 0x07: break; // dunno ... zelda ww jmps to 0x044d
case 0x08: break; // Mixer ... zelda ww jmps to 0x0485
case 0x09: break; // dunno ... zelda ww jmps to 0x044d
*/
// DsetDolbyDelay ... zelda ww jumps to 0x00b2
case 0x0d:
{
u32 tmp[2];
tmp[0] = Read32();
tmp[1] = Read32();
DebugLog("DSetDolbyDelay");
DebugLog("DOLBY2_DELAY_BUF (size 0x960): 0x%08x", tmp[0]);
DebugLog("DSPRES_FILTER (size 0x500): 0x%08x", tmp[1]);
}
break;
// Set VARAM
case 0x0e:
// MessageBox(NULL, "Zelda VARAM", "cmd", MB_OK);
break;
// default ... zelda ww jumps to 0x0043
default:
PanicAlert("Zelda UCode - unknown cmd: %x (size %i)", Command, m_numSteps);
break;
}
// sync, we are rdy
m_rMailHandler.PushMail(DSP_SYNC);
m_rMailHandler.PushMail(0xF3550000 | Sync);
}

View File

@ -1,75 +0,0 @@
// 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/
#ifndef _UCODE_ZELDA_H
#define _UCODE_ZELDA_H
#include "Common.h"
#include "UCodes.h"
class CUCode_Zelda : public IUCode
{
private:
enum EDSP_Codes
{
DSP_INIT = 0xDCD10000,
DSP_RESUME = 0xDCD10001,
DSP_YIELD = 0xDCD10002,
DSP_DONE = 0xDCD10003,
DSP_SYNC = 0xDCD10004,
DSP_UNKN = 0xDCD10005,
};
// List in progress
u32 m_numSteps;
bool m_bListInProgress;
u32 m_step;
u8 m_Buffer[1024];
void ExecuteList();
u32 m_readOffset;
u8 Read8()
{
return m_Buffer[m_readOffset++];
}
u16 Read16()
{
u16 res = *(u16*)&m_Buffer[m_readOffset];
m_readOffset += 2;
return res;
}
u32 Read32()
{
u32 res = *(u32*)&m_Buffer[m_readOffset];
m_readOffset += 4;
return res;
}
public:
CUCode_Zelda(CMailHandler& _rMailHandler);
virtual ~CUCode_Zelda();
void HandleMail(u32 _uMail);
void Update();
void MixAdd(short* buffer, int size);
};
#endif

View File

@ -1,90 +0,0 @@
// 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/
#include "../Globals.h"
#include "UCodes.h"
#include "UCode_AX.h"
#include "UCode_AXWii.h"
#include "UCode_Zelda.h"
#include "UCode_Jac.h"
#include "UCode_ROM.h"
#include "UCode_CARD.h"
#include "UCode_InitAudioSystem.h"
IUCode* UCodeFactory(u32 _CRC, CMailHandler& _rMailHandler)
{
switch (_CRC)
{
case UCODE_ROM:
return new CUCode_Rom(_rMailHandler);
case UCODE_INIT_AUDIO_SYSTEM:
return new CUCode_InitAudioSystem(_rMailHandler);
case 0x65d6cc6f: // CARD
return new CUCode_CARD(_rMailHandler);
case 0x088e38a5: // IPL - JAP
case 0xd73338cf: // IPL
case 0x42f64ac4: // Luigi (after fix)
case 0x4be6a5cb: // AC, Pikmin (after fix)
printf("JAC ucode chosen");
return new CUCode_Jac(_rMailHandler);
case 0x3ad3b7ac: // Naruto3
case 0x3daf59b9: // Alien Hominid
case 0x4e8a8b21: // spdemo, ctaxi, 18 wheeler, disney, monkeyball2,cubivore,puzzlecollection,wario,
// capcom vs snk, naruto2, lost kingdoms, star fox, mario party 4, mortal kombat,
// smugglers run warzone, smash brothers, sonic mega collection, ZooCube
// nddemo, starfox
case 0x07f88145: // bustamove, ikaruga, fzero, robotech battle cry, star soldier, soul calibur2,
// Zelda:OOT, Tony hawk, viewtiful joe
case 0xe2136399: // billy hatcher, dragonballz, mario party 5, TMNT, ava1080
printf("AX ucode chosen, yay!");
return new CUCode_AX(_rMailHandler);
case 0x6CA33A6D: // DK Jungle Beat
case 0x86840740: // zelda
case 0x56d36052: // mario
case 0x2fcdf1ec: // mariokart, zelda 4 swords
printf("Zelda ucode chosen");
return new CUCode_Zelda(_rMailHandler);
// WII CRCs
case 0x6c3f6f94: // zelda - PAL
case 0xd643001f: // mario galaxy - PAL
printf("Zelda Wii ucode chosen");
return new CUCode_Zelda(_rMailHandler);
case 0x5ef56da3: // AX demo
case 0x347112ba: // raving rabbits
case 0xfa450138: // wii sports - PAL
case 0xadbc06bd: // Elebits
printf("Wii - AXWii chosen");
return new CUCode_AXWii(_rMailHandler, _CRC);
default:
PanicAlert("Unknown ucode (CRC = %08x) - forcing AX", _CRC);
return new CUCode_AX(_rMailHandler);
}
return NULL;
}

View File

@ -1,48 +0,0 @@
// 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/
#ifndef _UCODES_H
#define _UCODES_H
#include "Common.h"
#define UCODE_ROM 0x0000000
#define UCODE_INIT_AUDIO_SYSTEM 0x0000001
class CMailHandler;
class IUCode
{
public:
IUCode(CMailHandler& _rMailHandler)
: m_rMailHandler(_rMailHandler)
{}
virtual ~IUCode()
{}
virtual void HandleMail(u32 _uMail) = 0;
virtual void Update(void) = 0;
virtual void MixAdd(short* buffer, int size) {}
protected:
CMailHandler& m_rMailHandler;
};
extern IUCode* UCodeFactory(u32 _CRC, CMailHandler& _rMailHandler);
#endif

View File

@ -1,207 +0,0 @@
// 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/
//#include "Common.h"
#include "ChunkFile.h"
#include "pluginspecs_dsp.h"
#include "DSPHandler.h"
DSPInitialize g_dspInitialize;
u8* g_pMemory;
std::string gpName;
struct DSPState
{
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;
}
};
DSPState g_dspState;
#ifdef _WIN32
HINSTANCE g_hInstance = NULL;
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);
}
#endif
void DllDebugger(HWND _hParent, bool Show) {
}
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
{
_PluginInfo->Version = 0x0100;
_PluginInfo->Type = PLUGIN_TYPE_DSP;
#ifdef DEBUGFAST
sprintf(_PluginInfo->Name, "Dolphin DSP-NULL Plugin (DebugFast) ");
#else
#ifndef _DEBUG
sprintf(_PluginInfo->Name, "Dolphin DSP-NULL Plugin ");
#else
sprintf(_PluginInfo->Name, "Dolphin DSP-NULL Plugin (Debug) ");
#endif
#endif
}
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) {
}
void DllAbout(HWND _hParent)
{
}
void DllConfig(HWND _hParent)
{
}
void Initialize(void *init)
{
g_dspInitialize = *(DSPInitialize*)init;
g_pMemory = g_dspInitialize.pGetMemoryPointer(0);
CDSPHandler::CreateInstance();
}
void Shutdown()
{
CDSPHandler::Destroy();
}
void DoState(unsigned char **ptr, int mode) {
PointerWrap p(ptr, mode);
}
unsigned short DSP_ReadMailboxHigh(bool _CPUMailbox)
{
if (_CPUMailbox)
{
return (g_dspState.CPUMailbox >> 16) & 0xFFFF;
}
else
{
return CDSPHandler::GetInstance().AccessMailHandler().ReadDSPMailboxHigh();
}
}
unsigned short DSP_ReadMailboxLow(bool _CPUMailbox)
{
if (_CPUMailbox)
{
return g_dspState.CPUMailbox & 0xFFFF;
}
else
{
return CDSPHandler::GetInstance().AccessMailHandler().ReadDSPMailboxLow();
}
}
void Update_DSP_WriteRegister()
{
// check if the whole message is complete and if we can send it
if (g_dspState.CPUMailbox_Written[0] && g_dspState.CPUMailbox_Written[1])
{
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
}
}
void DSP_WriteMailboxHigh(bool _CPUMailbox, unsigned short _Value)
{
if (_CPUMailbox)
{
g_dspState.CPUMailbox = (g_dspState.CPUMailbox & 0xFFFF) | (_Value << 16);
g_dspState.CPUMailbox_Written[0] = true;
Update_DSP_WriteRegister();
}
else
{
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
}
}
void DSP_WriteMailboxLow(bool _CPUMailbox, unsigned short _Value)
{
if (_CPUMailbox)
{
g_dspState.CPUMailbox = (g_dspState.CPUMailbox & 0xFFFF0000) | _Value;
g_dspState.CPUMailbox_Written[1] = true;
Update_DSP_WriteRegister();
}
else
{
PanicAlert("CPU can't write %08x to DSP mailbox", _Value);
}
}
unsigned short DSP_WriteControlRegister(unsigned short _Value)
{
return CDSPHandler::GetInstance().WriteControlRegister(_Value);
}
unsigned short DSP_ReadControlRegister()
{
return CDSPHandler::GetInstance().ReadControlRegister();
}
void DSP_Update(int cycles)
{
CDSPHandler::GetInstance().Update();
}
void DSP_SendAIBuffer(unsigned int address, int sample_rate)
{
}