forked from hydra-emu/n64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.cxx
111 lines (100 loc) · 2.71 KB
/
core.cxx
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <cstdint>
#include <hydra/core.hxx>
#include <n64_impl.hxx>
class HydraCore : public hydra::IBase, public hydra::ISoftwareRendered, public hydra::IFrontendDriven, public hydra::IInput
{
HYDRA_CLASS
public:
HydraCore()
{
n64.SetAudioCallback([](const int16_t*, uint32_t, int) {});
}
// IBase
bool loadFile(const char* type, const char* rom) override
{
printf("Loading %s: %s\n", type, rom);
std::string stype = type;
if (stype == "rom")
{
n64.LoadCartridge(rom);
return true;
}
else if (stype == "bios")
{
n64.LoadIPL(rom);
return true;
}
return false;
}
void reset() override
{
n64.Reset();
}
hydra::Size getNativeSize() override
{
return { (uint32_t)n64.GetWidth(), (uint32_t)n64.GetHeight() };
}
void setOutputSize(hydra::Size size) override {}
// ISoftwareRendered
void setVideoCallback(void (*callback)(void* data, hydra::Size size)) override { video_callback = callback; };
// IFrontendDriven
void runFrame() override
{
n64.RunFrame();
std::vector<uint8_t> data;
n64.RenderVideo(data);
video_callback(data.data(), { (uint32_t)n64.GetWidth(), (uint32_t)n64.GetHeight() });
}
uint16_t getFps() override { return 60; };
void setPollInputCallback(void (*callback)()) override
{
n64.SetPollInputCallback(callback);
}
void setCheckButtonCallback(int32_t (*callback)(uint32_t, hydra::ButtonType)) override
{
n64.SetReadInputCallback(callback);
}
private:
hydra::N64::N64 n64;
void (*video_callback)(void* data, hydra::Size size) = nullptr;
};
HC_API hydra::IBase* createEmulator()
{
return new HydraCore;
}
HC_API void destroyEmulator(hydra::IBase* emulator)
{
delete emulator;
}
HC_API const char* getInfo(hydra::InfoType type)
{
switch (type)
{
case hydra::InfoType::CoreName:
return "Cerberus";
case hydra::InfoType::SystemName:
return "Nintendo 64";
case hydra::InfoType::Version:
return "1.0";
case hydra::InfoType::Author:
return "OFFTKP";
case hydra::InfoType::Website:
return "todo: add me";
case hydra::InfoType::Description:
return "An n64 emulator";
case hydra::InfoType::Extensions:
return "z64,N64";
case hydra::InfoType::License:
return "MIT";
case hydra::InfoType::Settings:
return R"(
[bios]
type = "filepicker"
name = "IPL3"
description = "The IPL is required to run games"
required = true
)";
default:
return nullptr;
}
}