2013-03-10 22:08:57 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP 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 or later versions.
|
|
|
|
|
|
|
|
// 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 git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2013-01-29 20:38:05 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Config.h"
|
2013-03-29 21:56:57 +00:00
|
|
|
#include "Core/CoreParameter.h"
|
2013-05-04 21:21:06 +00:00
|
|
|
#include "Core/System.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-10 22:08:57 +00:00
|
|
|
bool WindowsHost::InitGL(std::string *error_message)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-03-10 22:08:57 +00:00
|
|
|
return GL_Init(MainWindow::GetDisplayHWND(), error_message);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::ShutdownGL()
|
|
|
|
{
|
|
|
|
GL_Shutdown();
|
|
|
|
}
|
|
|
|
|
2012-11-30 20:49:59 +00:00
|
|
|
void WindowsHost::SetWindowTitle(const char *message)
|
|
|
|
{
|
2013-03-02 20:31:11 +00:00
|
|
|
std::string title = std::string("PPSSPP ") + PPSSPP_GIT_VERSION + " - " + message;
|
2012-12-03 15:44:29 +00:00
|
|
|
|
2013-03-13 02:49:59 +00:00
|
|
|
int size = MultiByteToWideChar(CP_UTF8, 0, title.c_str(), (int) title.size(), NULL, 0);
|
2012-12-03 15:44:29 +00:00
|
|
|
if (size > 0)
|
|
|
|
{
|
2013-03-13 02:49:59 +00:00
|
|
|
// VC++6.0 any more?
|
|
|
|
wchar_t *utf16_title = new(std::nothrow) wchar_t[size + 1];
|
2012-12-03 15:44:29 +00:00
|
|
|
if (utf16_title)
|
2013-03-13 02:49:59 +00:00
|
|
|
size = MultiByteToWideChar(CP_UTF8, 0, title.c_str(), (int) title.size(), utf16_title, size);
|
2012-12-03 15:44:29 +00:00
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
utf16_title[size] = 0;
|
2012-12-03 15:57:28 +00:00
|
|
|
// Don't use SetWindowTextW because it will internally use DefWindowProcA.
|
|
|
|
DefWindowProcW(mainWindow_, WM_SETTEXT, 0, (LPARAM) utf16_title);
|
2012-12-03 15:44:29 +00:00
|
|
|
delete[] utf16_title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Something went wrong, fall back to using the local codepage.
|
|
|
|
if (size <= 0)
|
|
|
|
SetWindowTextA(mainWindow_, title.c_str());
|
2012-11-30 20:49:59 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
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();
|
2013-05-13 02:51:16 +00:00
|
|
|
if (curMixer != NULL)
|
|
|
|
delete curMixer;
|
2012-11-01 15:19:01 +00:00
|
|
|
curMixer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::UpdateUI()
|
|
|
|
{
|
|
|
|
MainWindow::Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-04 21:21:06 +00:00
|
|
|
extern BOOL g_bFullScreen;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-03-30 22:32:34 +00:00
|
|
|
void WindowsHost::PollControllers(InputState &input_state)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-04-08 01:41:26 +00:00
|
|
|
bool doPad = true;
|
2012-11-12 17:32:35 +00:00
|
|
|
for (auto iter = this->input.begin(); iter != this->input.end(); iter++)
|
2013-04-08 01:41:26 +00:00
|
|
|
{
|
|
|
|
auto device = *iter;
|
|
|
|
if (!doPad && device->IsPad())
|
|
|
|
continue;
|
|
|
|
if (device->UpdateState(input_state) == InputDevice::UPDATESTATE_SKIP_PAD)
|
|
|
|
doPad = false;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::BootDone()
|
|
|
|
{
|
|
|
|
symbolMap.SortSymbols();
|
2013-04-05 07:57:43 +00:00
|
|
|
SendMessage(MainWindow::GetHWND(), WM_USER+1, 0,0);
|
|
|
|
|
|
|
|
SetDebugMode(!g_Config.bAutoRun);
|
|
|
|
Core_EnableStepping(!g_Config.bAutoRun);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 22:05:46 +00:00
|
|
|
static std::string SymbolMapFilename(const char *currentFilename)
|
|
|
|
{
|
|
|
|
std::string result = currentFilename;
|
|
|
|
size_t dot = result.rfind('.');
|
|
|
|
if (dot == result.npos)
|
|
|
|
return result + ".map";
|
|
|
|
|
|
|
|
result.replace(dot, result.npos, ".map");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
bool WindowsHost::AttemptLoadSymbolMap()
|
|
|
|
{
|
2013-03-31 04:42:43 +00:00
|
|
|
if (loadedSymbolMap_)
|
|
|
|
return true;
|
|
|
|
loadedSymbolMap_ = symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str()).c_str());
|
|
|
|
return loadedSymbolMap_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::SaveSymbolMap()
|
|
|
|
{
|
|
|
|
symbolMap.SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str()).c_str());
|
|
|
|
loadedSymbolMap_ = false;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2013-06-26 07:32:49 +00:00
|
|
|
|
|
|
|
void WindowsHost::SetConsolePosition()
|
|
|
|
{
|
|
|
|
HWND console = GetConsoleWindow();
|
|
|
|
if (console != NULL && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1)
|
|
|
|
SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::UpdateConsolePosition()
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
HWND console = GetConsoleWindow();
|
|
|
|
if (console != NULL && GetWindowRect(console, &rc))
|
|
|
|
{
|
|
|
|
g_Config.iConsoleWindowX = rc.left;
|
|
|
|
g_Config.iConsoleWindowY = rc.top;
|
|
|
|
}
|
|
|
|
}
|