0.6.1
[libretro-ppsspp.git] / Windows / WindowsHost.cpp
blob2b574d0a5bfbfa2f42fbc909606126b3898b6496
1 #include "Core/Core.h"
2 #include "Core/Config.h"
3 #include "EmuThread.h"
4 #include "DSoundStream.h"
5 #include "WindowsHost.h"
6 #include "WndMainWindow.h"
7 #include "OpenGLBase.h"
9 #include "../Windows/Debugger/Debugger_Disasm.h"
10 #include "../Windows/Debugger/Debugger_MemoryDlg.h"
11 #include "../Core/Debugger/SymbolMap.h"
13 #include "main.h"
16 static PMixer *curMixer;
18 int MyMix(short *buffer, int numSamples, int bits, int rate, int channels)
20 if (curMixer && !Core_IsStepping())
21 return curMixer->Mix(buffer, numSamples);
22 else
24 memset(buffer,0,numSamples*sizeof(short)*2);
25 return numSamples;
29 void WindowsHost::InitGL()
31 GL_Init(MainWindow::GetDisplayHWND());
34 void WindowsHost::ShutdownGL()
36 GL_Shutdown();
39 void WindowsHost::SetWindowTitle(const char *message)
41 // Really need a better way to deal with versions.
42 std::string title = PPSSPP_VERSION_STR " - ";
43 title += message;
45 int size = MultiByteToWideChar(CP_UTF8, 0, message, (int) title.size(), NULL, 0);
46 if (size > 0)
48 wchar_t *utf16_title = new wchar_t[size + 1];
49 if (utf16_title)
50 size = MultiByteToWideChar(CP_UTF8, 0, message, (int) title.size(), utf16_title, size);
51 else
52 size = 0;
54 if (size > 0)
56 utf16_title[size] = 0;
57 // Don't use SetWindowTextW because it will internally use DefWindowProcA.
58 DefWindowProcW(mainWindow_, WM_SETTEXT, 0, (LPARAM) utf16_title);
59 delete[] utf16_title;
63 // Something went wrong, fall back to using the local codepage.
64 if (size <= 0)
65 SetWindowTextA(mainWindow_, title.c_str());
68 void WindowsHost::InitSound(PMixer *mixer)
70 curMixer = mixer;
71 DSound::DSound_StartSound(MainWindow::GetHWND(), MyMix);
74 void WindowsHost::UpdateSound()
76 DSound::DSound_UpdateSound();
79 void WindowsHost::ShutdownSound()
81 DSound::DSound_StopSound();
82 delete curMixer;
83 curMixer = 0;
86 void WindowsHost::UpdateUI()
88 MainWindow::Update();
89 MainWindow::UpdateMenus();
93 void WindowsHost::UpdateMemView()
95 for (int i=0; i<numCPUs; i++)
96 if (memoryWindow[i])
97 memoryWindow[i]->Update();
100 void WindowsHost::UpdateDisassembly()
102 for (int i=0; i<numCPUs; i++)
103 if (disasmWindow[i])
104 disasmWindow[i]->Update();
107 void WindowsHost::SetDebugMode(bool mode)
109 for (int i=0; i<numCPUs; i++)
110 if (disasmWindow[i])
111 disasmWindow[i]->SetDebugMode(mode);
115 void WindowsHost::BeginFrame()
117 for (auto iter = this->input.begin(); iter != this->input.end(); iter++)
118 if ((*iter)->UpdateState() == 0)
119 break; // *iter is std::shared_ptr, **iter is InputDevice
120 GL_BeginFrame();
122 void WindowsHost::EndFrame()
124 GL_EndFrame();
127 void WindowsHost::BootDone()
129 symbolMap.SortSymbols();
130 SendMessage(MainWindow::GetHWND(), WM_USER+1, 0,0);
133 static std::string SymbolMapFilename(const char *currentFilename)
135 std::string result = currentFilename;
136 size_t dot = result.rfind('.');
137 if (dot == result.npos)
138 return result + ".map";
140 result.replace(dot, result.npos, ".map");
141 return result;
144 bool WindowsHost::AttemptLoadSymbolMap()
146 return symbolMap.LoadSymbolMap(SymbolMapFilename(GetCurrentFilename()).c_str());
149 void WindowsHost::PrepareShutdown()
151 symbolMap.SaveSymbolMap(SymbolMapFilename(GetCurrentFilename()).c_str());
154 void WindowsHost::AddSymbol(std::string name, u32 addr, u32 size, int type=0)
156 symbolMap.AddSymbol(name.c_str(), addr, size, (SymbolType)type);
159 bool WindowsHost::IsDebuggingEnabled()
161 #ifdef _DEBUG
162 return true;
163 #else
164 return false;
165 #endif