-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathos.cpp
More file actions
106 lines (85 loc) · 3.04 KB
/
os.cpp
File metadata and controls
106 lines (85 loc) · 3.04 KB
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
#include "libultraship/libultraship.h"
#include <SDL2/SDL.h>
#include <ratio>
// Establish a chrono duration for the N64 46.875MHz clock rate
typedef std::ratio<3000, 64> n64ClockRatio;
typedef std::ratio_divide<std::micro, n64ClockRatio> n64CycleRate;
typedef std::chrono::duration<long long, n64CycleRate> n64CycleRateDuration;
extern "C" {
uint8_t __osMaxControllers = MAXCONTROLLERS;
uint64_t __osCurrentTime = 0;
int32_t osContInit(OSMesgQueue* mq, uint8_t* controllerBits, OSContStatus* status) {
*controllerBits = 0;
status->status |= 1;
std::string controllerDb = Ship::Context::LocateFileAcrossAppDirs("gamecontrollerdb.txt");
int mappingsAdded = SDL_GameControllerAddMappingsFromFile(controllerDb.c_str());
if (mappingsAdded >= 0) {
SPDLOG_INFO("Added SDL game controllers from \"{}\" ({})", controllerDb, mappingsAdded);
} else {
SPDLOG_ERROR("Failed add SDL game controller mappings from \"{}\" ({})", controllerDb, SDL_GetError());
}
SDL_SetHint(SDL_HINT_JOYSTICK_THREAD, "1");
if (SDL_Init(SDL_INIT_GAMECONTROLLER) != 0) {
SPDLOG_ERROR("Failed to initialize SDL game controllers ({})", SDL_GetError());
exit(EXIT_FAILURE);
}
Ship::Context::GetInstance()->GetControlDeck()->Init(controllerBits);
return 0;
}
int32_t osContStartReadData(OSMesgQueue* mesg) {
if (mesg != nullptr) {
osSendMesg(mesg, nullptr, OS_MESG_NOBLOCK);
}
return 0;
}
void osContGetReadData(OSContPad* pad) {
memset(pad, 0, sizeof(OSContPad) * __osMaxControllers);
Ship::Context::GetInstance()->GetControlDeck()->WriteToPad(pad);
}
void osSetTime(OSTime time) {
__osCurrentTime =
std::chrono::duration_cast<n64CycleRateDuration>(std::chrono::steady_clock::now().time_since_epoch()).count() +
time;
}
// Returns the OS time matching the N64 46.875MHz cycle rate
uint64_t osGetTime() {
return std::chrono::duration_cast<n64CycleRateDuration>(std::chrono::steady_clock::now().time_since_epoch())
.count() -
__osCurrentTime;
}
// Returns the CPU clock count matching the N64 46.875Mhz cycle rate
uint32_t osGetCount() {
return std::chrono::duration_cast<n64CycleRateDuration>(std::chrono::steady_clock::now().time_since_epoch())
.count();
}
OSPiHandle* osCartRomInit() {
return NULL;
}
int osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg) {
return 0;
}
int32_t osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, int32_t direction) {
return 0;
}
uint32_t osAiGetLength() {
// TODO: Implement
return 0;
}
int32_t osAiSetNextBuffer(void* buff, size_t len) {
// TODO: Implement
return 0;
}
int32_t __osMotorAccess(OSPfs* pfs, uint32_t vibrate) {
auto io = Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(pfs->channel)->GetRumble();
if (vibrate) {
io->StartRumble();
} else {
io->StopRumble();
}
return 0;
}
int32_t osMotorInit(OSMesgQueue* ctrlrqueue, OSPfs* pfs, int32_t channel) {
pfs->channel = channel;
return 0;
}
}