Implemented osSetTime to fix osGetTime not using boot time (#829)

* Implemented osSetTime to fix osGetTime not using boot time

* Fixed tidy
This commit is contained in:
Lywx
2025-03-21 20:45:45 -04:00
committed by GitHub
parent 5d3d38e0cb
commit 7e0f42e952
2 changed files with 10 additions and 2 deletions
+1
View File
@@ -126,6 +126,7 @@ void osViSetEvent(OSMesgQueue*, OSMesg, u32);
void osCreateViManager(OSPri);
void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt);
void osSetTime(OSTime time);
uint64_t osGetTime(void);
uint32_t osGetCount(void);
s32 osEepromProbe(OSMesgQueue*);
+9 -2
View File
@@ -9,6 +9,7 @@ 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;
@@ -43,11 +44,17 @@ void osContGetReadData(OSContPad* pad) {
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
// LUSTODO: This should be adjusted to return the time since "boot"
uint64_t osGetTime() {
return std::chrono::duration_cast<n64CycleRateDuration>(std::chrono::steady_clock::now().time_since_epoch())
.count();
.count() -
__osCurrentTime;
}
// Returns the CPU clock count matching the N64 46.875Mhz cycle rate