summaryrefslogtreecommitdiff
path: root/src/lib/web.cpp
blob: 0c9d3493998c9ced1fbf164372c2260b1ed9ca4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifdef __EMSCRIPTEN__
#include "Companion.h"

#include <emscripten/bind.h>
using namespace emscripten;

Companion* Companion::Instance;

void Bind(Companion* instance) {
    Companion::Instance = instance;
}

EMSCRIPTEN_BINDINGS(Torch) {
    register_vector<uint8_t>("VectorUInt8");

    function("Bind", &Bind, allow_raw_pointers());

    enum_<ExportType>("ExportType")
        .value("Header", ExportType::Header)
        .value("Code", ExportType::Code)
        .value("Binary", ExportType::Binary)
        .value("Modding", ExportType::Modding)
        .value("XML", ExportType::XML);

    enum_<ArchiveType>("ArchiveType")
        .value("None", ArchiveType::None)
        .value("OTR", ArchiveType::OTR)
        .value("O2R", ArchiveType::O2R);

    enum_<N64::CountryCode>("CountryCode")
        .value("Japan", N64::CountryCode::Japan)
        .value("NorthAmerica", N64::CountryCode::NorthAmerica)
        .value("Europe", N64::CountryCode::Europe)
        .value("Unknown", N64::CountryCode::Unknown);

    class_<N64::Cartridge>("Cartridge")
        .function("GetGameTitle", &N64::Cartridge::GetGameTitle)
        .function("GetCountryCode", &N64::Cartridge::GetCountryCode)
        .function("GetCountry", &N64::Cartridge::GetCountry)
        .function("GetVersion", &N64::Cartridge::GetVersion)
        .function("GetHash", &N64::Cartridge::GetHash)
        .function("GetCRC", &N64::Cartridge::GetCRC);

    class_<Companion>("Companion")
        .constructor<std::vector<uint8_t>, ArchiveType, bool, bool, std::string, std::string>()
        .constructor<std::vector<uint8_t>, ArchiveType, bool, bool, std::string>()
        .constructor<std::vector<uint8_t>, ArchiveType, bool, bool>()
        .function("Init", optional_override([](Companion& self, ExportType type) { self.Init(type); }))
        .function("GetCartridge", &Companion::GetCartridge, allow_raw_pointers())
        .function("Process", optional_override([](Companion& self) {
                      std::atomic<size_t> dummy{ 0 };
                      self.Process(dummy);
                  }))
        .function("GetRomData", &Companion::GetRomData, allow_raw_pointers());
}
#endif