Play-/Source/ui_js/Main.cpp

76 lines
1.6 KiB
C++
Raw Normal View History

#include <cstdio>
#include <emscripten/bind.h>
#include "Ps2VmJs.h"
2021-12-14 14:59:12 -05:00
#include "GSH_OpenGLJs.h"
2021-12-27 16:41:23 -05:00
#include "PS2VM_Preferences.h"
#include "AppConfig.h"
CPs2VmJs* g_virtualMachine = nullptr;
2021-12-14 14:59:12 -05:00
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE g_context = 0;
int main(int argc, const char** argv)
{
return 0;
}
extern "C" void initVm()
{
2021-12-14 14:59:12 -05:00
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.majorVersion = 2;
attr.minorVersion = 0;
2021-12-27 19:45:31 -05:00
attr.alpha = false;
2021-12-14 14:59:12 -05:00
g_context = emscripten_webgl_create_context("#outputCanvas", &attr);
assert(g_context >= 0);
g_virtualMachine = new CPs2VmJs();
g_virtualMachine->Initialize();
2021-12-14 14:59:12 -05:00
g_virtualMachine->CreateGSHandler(CGSH_OpenGLJs::GetFactoryFunction(g_context));
2021-12-02 20:10:35 -05:00
//g_virtualMachine->Reset();
printf("Reset VM\r\n");
}
void loadElf(std::string path)
{
printf("Loading '%s'...\r\n", path.c_str());
2021-12-27 16:41:23 -05:00
try
{
g_virtualMachine->Reset();
g_virtualMachine->m_ee->m_os->BootFromFile(path);
}
catch(const std::exception& ex)
{
printf("Failed to start: %s.\r\n", ex.what());
return;
}
printf("Starting...\r\n");
g_virtualMachine->Resume();
}
2021-12-27 16:41:23 -05:00
void bootDiscImage(std::string path)
{
printf("Loading '%s'...\r\n", path.c_str());
try
{
CAppConfig::GetInstance().SetPreferencePath(PREF_PS2_CDROM0_PATH, path);
g_virtualMachine->Reset();
g_virtualMachine->m_ee->m_os->BootFromCDROM();
}
catch(const std::exception& ex)
{
printf("Failed to start: %s.\r\n", ex.what());
return;
}
printf("Starting...\r\n");
g_virtualMachine->Resume();
}
EMSCRIPTEN_BINDINGS(Play)
{
using namespace emscripten;
function("loadElf", &loadElf);
2021-12-27 16:41:23 -05:00
function("bootDiscImage", &bootDiscImage);
}