ppsspp/Windows/WindowsHost.cpp
2012-12-03 07:57:28 -08:00

173 lines
3.5 KiB
C++

#include "../Core/Core.h"
#include "EmuThread.h"
#include "DSoundStream.h"
#include "WindowsHost.h"
#include "WndMainWindow.h"
#include "OpenGLBase.h"
#include "../Windows/Debugger/Debugger_Disasm.h"
#include "../Windows/Debugger/Debugger_MemoryDlg.h"
#include "../Core/Debugger/SymbolMap.h"
#include "main.h"
static PMixer *curMixer;
int MyMix(short *buffer, int numSamples, int bits, int rate, int channels)
{
if (curMixer && !Core_IsStepping())
return curMixer->Mix(buffer, numSamples);
else
{
memset(buffer,0,numSamples*sizeof(short)*2);
return numSamples;
}
}
void WindowsHost::InitGL()
{
GL_Init(MainWindow::GetDisplayHWND());
}
void WindowsHost::ShutdownGL()
{
GL_Shutdown();
}
void WindowsHost::SetWindowTitle(const char *message)
{
// Really need a better way to deal with versions.
std::string title = "PPSSPP v0.4 - ";
title += message;
int size = MultiByteToWideChar(CP_UTF8, 0, message, title.size(), NULL, 0);
if (size > 0)
{
wchar_t *utf16_title = new wchar_t[size + 1];
if (utf16_title)
size = MultiByteToWideChar(CP_UTF8, 0, message, title.size(), utf16_title, size);
else
size = 0;
if (size > 0)
{
utf16_title[size] = 0;
// Don't use SetWindowTextW because it will internally use DefWindowProcA.
DefWindowProcW(mainWindow_, WM_SETTEXT, 0, (LPARAM) utf16_title);
delete[] utf16_title;
}
}
// Something went wrong, fall back to using the local codepage.
if (size <= 0)
SetWindowTextA(mainWindow_, title.c_str());
}
void WindowsHost::InitSound(PMixer *mixer)
{
curMixer = mixer;
DSound::DSound_StartSound(MainWindow::GetHWND(), MyMix);
}
void WindowsHost::UpdateSound()
{
DSound::DSound_UpdateSound();
}
void WindowsHost::ShutdownSound()
{
DSound::DSound_StopSound();
delete curMixer;
curMixer = 0;
}
void WindowsHost::UpdateUI()
{
MainWindow::Update();
MainWindow::UpdateMenus();
}
void WindowsHost::UpdateMemView()
{
for (int i=0; i<numCPUs; i++)
if (memoryWindow[i])
memoryWindow[i]->Update();
}
void WindowsHost::UpdateDisassembly()
{
for (int i=0; i<numCPUs; i++)
if (disasmWindow[i])
disasmWindow[i]->Update();
}
void WindowsHost::SetDebugMode(bool mode)
{
for (int i=0; i<numCPUs; i++)
if (disasmWindow[i])
disasmWindow[i]->SetDebugMode(mode);
}
void WindowsHost::BeginFrame()
{
for (auto iter = this->input.begin(); iter != this->input.end(); iter++)
if ((*iter)->UpdateState() == 0)
break; // *iter is std::shared_ptr, **iter is InputDevice
GL_BeginFrame();
}
void WindowsHost::EndFrame()
{
GL_EndFrame();
}
void WindowsHost::BootDone()
{
symbolMap.SortSymbols();
SendMessage(MainWindow::GetHWND(), WM_USER+1, 0,0);
}
bool WindowsHost::AttemptLoadSymbolMap()
{
char filename[256];
strcpy(filename, GetCurrentFilename());
int len = strlen(filename);
int ptpos = len-1;
while (filename[ptpos]!='.' && ptpos>len-8)
ptpos--;
filename[ptpos+1] = 'm';
filename[ptpos+2] = 'a';
filename[ptpos+3] = 'p';
return symbolMap.LoadSymbolMap(filename);
}
void WindowsHost::PrepareShutdown()
{
char filename[256];
strcpy(filename, GetCurrentFilename());
int len = strlen(filename);
int ptpos = len-1;
while (filename[ptpos]!='.' && ptpos>len-8)
ptpos--;
filename[ptpos+1] = 'm';
filename[ptpos+2] = 'a';
filename[ptpos+3] = 'p';
symbolMap.SaveSymbolMap(filename);
}
void WindowsHost::AddSymbol(std::string name, u32 addr, u32 size, int type=0)
{
symbolMap.AddSymbol(name.c_str(), addr, size, (SymbolType)type);
}
bool WindowsHost::IsDebuggingEnabled()
{
#ifdef _DEBUG
return true;
#else
return false;
#endif
}