From 7e0f42e952c540d8d2b1fa9d81d9e7ef49689d8d Mon Sep 17 00:00:00 2001 From: Lywx Date: Fri, 21 Mar 2025 18:45:45 -0600 Subject: [PATCH] Implemented osSetTime to fix osGetTime not using boot time (#829) * Implemented osSetTime to fix osGetTime not using boot time * Fixed tidy --- include/libultraship/libultra/os.h | 1 + src/public/libultra/os.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/libultraship/libultra/os.h b/include/libultraship/libultra/os.h index 25d765d..bd11553 100644 --- a/include/libultraship/libultra/os.h +++ b/include/libultraship/libultra/os.h @@ -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*); diff --git a/src/public/libultra/os.cpp b/src/public/libultra/os.cpp index de17712..0891ad5 100644 --- a/src/public/libultra/os.cpp +++ b/src/public/libultra/os.cpp @@ -9,6 +9,7 @@ typedef std::chrono::duration 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(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(std::chrono::steady_clock::now().time_since_epoch()) - .count(); + .count() - + __osCurrentTime; } // Returns the CPU clock count matching the N64 46.875Mhz cycle rate