2021-10-28 15:38:10 -04:00
|
|
|
#include "PsfVmJs.h"
|
2021-09-02 14:02:13 -04:00
|
|
|
#include <cstdio>
|
|
|
|
#include "filesystem_def.h"
|
|
|
|
#include "PsfArchive.h"
|
2022-12-25 15:16:12 -05:00
|
|
|
#include "PsfStreamProvider.h"
|
2021-10-25 10:08:59 -04:00
|
|
|
#include "SH_OpenALProxy.h"
|
2021-09-02 14:02:13 -04:00
|
|
|
#include "SH_FileOutput.h"
|
2021-09-14 09:45:20 -04:00
|
|
|
#include "../SH_OpenAL.h"
|
2021-09-09 15:18:31 -04:00
|
|
|
#include <emscripten/bind.h>
|
2021-09-02 14:02:13 -04:00
|
|
|
|
2021-10-28 15:38:10 -04:00
|
|
|
CPsfVmJs* g_virtualMachine = nullptr;
|
2021-10-25 10:08:59 -04:00
|
|
|
CSH_OpenAL* g_soundHandler = nullptr;
|
2021-09-22 11:26:06 -04:00
|
|
|
CPsfBase::TagMap g_tags;
|
2021-09-02 14:02:13 -04:00
|
|
|
|
|
|
|
int main(int argc, const char** argv)
|
|
|
|
{
|
2025-02-08 20:25:05 -05:00
|
|
|
printf("PsfPlayer - Version %s\r\n", PLAY_VERSION);
|
2021-09-02 14:02:13 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void initVm()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:38:10 -04:00
|
|
|
g_virtualMachine = new CPsfVmJs();
|
2021-09-02 14:02:13 -04:00
|
|
|
|
2021-10-21 13:16:02 -04:00
|
|
|
//g_soundHandler = new CSH_FileOutput();
|
|
|
|
g_soundHandler = new CSH_OpenAL();
|
2021-10-28 15:38:10 -04:00
|
|
|
g_virtualMachine->SetSpuHandler(CSH_OpenALProxy::GetFactoryFunction(g_soundHandler));
|
2021-09-02 14:02:13 -04:00
|
|
|
}
|
|
|
|
catch(const std::exception& ex)
|
|
|
|
{
|
|
|
|
printf("Exception: %s\r\n", ex.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 13:26:21 -04:00
|
|
|
void resumePsf()
|
2021-09-02 14:02:13 -04:00
|
|
|
{
|
2021-10-25 13:26:21 -04:00
|
|
|
assert(g_virtualMachine);
|
|
|
|
g_virtualMachine->Resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pausePsf()
|
|
|
|
{
|
|
|
|
assert(g_virtualMachine);
|
|
|
|
g_virtualMachine->Pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadPsf(std::string archivePath, std::string psfPath)
|
|
|
|
{
|
|
|
|
printf("Loading '%s' from '%s'.\r\n", psfPath.c_str(), archivePath.c_str());
|
2021-09-02 14:02:13 -04:00
|
|
|
try
|
|
|
|
{
|
2021-09-09 15:18:31 -04:00
|
|
|
assert(g_virtualMachine);
|
2021-10-04 10:00:49 -04:00
|
|
|
g_virtualMachine->Pause();
|
2021-10-28 15:38:10 -04:00
|
|
|
g_tags = g_virtualMachine->LoadPsf(archivePath, psfPath);
|
2021-09-02 14:02:13 -04:00
|
|
|
}
|
|
|
|
catch(const std::exception& ex)
|
|
|
|
{
|
|
|
|
printf("Exception: %s\r\n", ex.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 15:18:31 -04:00
|
|
|
std::vector<std::string> getPsfArchiveFileList(std::string rawArchivePath)
|
|
|
|
{
|
|
|
|
std::vector<std::string> result;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fs::path archivePath(rawArchivePath);
|
|
|
|
auto archive = std::unique_ptr<CPsfArchive>(CPsfArchive::CreateFromPath(archivePath));
|
|
|
|
auto files = archive->GetFiles();
|
|
|
|
for(const auto& file : files)
|
|
|
|
{
|
|
|
|
result.push_back(file.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const std::exception& ex)
|
|
|
|
{
|
|
|
|
printf("Exception: %s\r\n", ex.what());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-12-25 15:16:12 -05:00
|
|
|
CPsfBase::TagMap getPsfArchiveItemTags(std::string rawArchivePath, std::string psfPath)
|
|
|
|
{
|
|
|
|
fs::path archivePath(rawArchivePath);
|
|
|
|
auto streamProvider = CreatePsfStreamProvider(archivePath);
|
|
|
|
std::unique_ptr<Framework::CStream> inputStream(streamProvider->GetStreamForPath(psfPath));
|
|
|
|
CPsfBase psfFile(*inputStream);
|
|
|
|
return CPsfBase::TagMap(psfFile.GetTagsBegin(), psfFile.GetTagsEnd());
|
|
|
|
}
|
|
|
|
|
2021-09-22 11:26:06 -04:00
|
|
|
CPsfBase::TagMap getCurrentPsfTags()
|
|
|
|
{
|
|
|
|
return g_tags;
|
|
|
|
}
|
|
|
|
|
2021-09-09 15:18:31 -04:00
|
|
|
EMSCRIPTEN_BINDINGS(PsfPlayer)
|
|
|
|
{
|
|
|
|
using namespace emscripten;
|
|
|
|
|
|
|
|
register_vector<std::string>("StringList");
|
2021-09-22 11:26:06 -04:00
|
|
|
register_map<std::string, std::string>("StringMap");
|
2021-09-09 15:18:31 -04:00
|
|
|
|
2021-10-25 13:26:21 -04:00
|
|
|
function("pausePsf", &pausePsf);
|
|
|
|
function("resumePsf", &resumePsf);
|
|
|
|
function("loadPsf", &loadPsf);
|
2021-09-09 15:18:31 -04:00
|
|
|
function("getPsfArchiveFileList", &getPsfArchiveFileList);
|
2022-12-25 15:16:12 -05:00
|
|
|
function("getPsfArchiveItemTags", &getPsfArchiveItemTags);
|
2021-09-22 11:26:06 -04:00
|
|
|
function("getCurrentPsfTags", &getCurrentPsfTags);
|
2021-09-09 15:18:31 -04:00
|
|
|
}
|