metaforce/Runtime/CBasics.hpp

75 lines
2.1 KiB
C++
Raw Normal View History

2018-10-06 20:42:33 -07:00
#pragma once
2015-08-16 22:26:58 -07:00
#include <chrono>
2017-12-29 00:08:12 -08:00
#include <cstdint>
#include <cstdlib>
#include <algorithm>
#include <string>
#ifndef _WIN32
#include <sys/stat.h>
#else
struct _stat64;
#endif
2015-08-16 22:26:58 -07:00
#include "Runtime/GCNTypes.hpp"
2015-08-17 13:33:58 -07:00
2021-04-10 01:42:06 -07:00
namespace metaforce {
2016-10-09 14:41:23 -07:00
using OSTime = s64;
2018-12-07 21:30:43 -08:00
struct OSCalendarTime {
int x0_sec; // seconds after the minute [0, 61]
int x4_min; // minutes after the hour [0, 59]
int x8_hour; // hours since midnight [0, 23]
int xc_mday; // day of the month [1, 31]
int x10_mon; // month since January [0, 11]
int x14_year; // years in AD [1, ...]
int x18_wday; // days since Sunday [0, 6]
int x1c_yday; // days since January 1 [0, 365]
int x20_msec; // milliseconds after the second [0,999]
int x24_usec; // microseconds after the millisecond [0,999]
2016-12-22 22:41:39 -08:00
};
2018-12-07 21:30:43 -08:00
class CBasics {
2015-08-16 22:26:58 -07:00
public:
#if _WIN32
using Sstat = struct ::_stat64;
#else
using Sstat = struct stat;
#endif
2018-12-07 21:30:43 -08:00
static void Initialize();
2016-10-09 14:41:23 -07:00
2018-12-07 21:30:43 -08:00
static const u64 SECONDS_TO_2000;
static const u64 TICKS_PER_SECOND;
2016-10-09 14:41:23 -07:00
2018-12-07 21:30:43 -08:00
static OSTime ToWiiTime(std::chrono::system_clock::time_point time);
static std::chrono::system_clock::time_point FromWiiTime(OSTime wiiTime);
2016-12-22 22:41:39 -08:00
2022-01-30 12:07:24 -08:00
static OSTime GetTime() { return ToWiiTime(std::chrono::system_clock::now()); }
2018-12-07 21:30:43 -08:00
static u64 GetGCTicks();
static constexpr u64 GetGCTicksPerSec() { return 486000000ull; }
2016-12-31 22:46:52 -08:00
2018-12-07 21:30:43 -08:00
static OSCalendarTime ToCalendarTime(OSTime time) { return ToCalendarTime(FromWiiTime(time)); }
static OSCalendarTime ToCalendarTime(std::chrono::system_clock::time_point time);
static u16 SwapBytes(u16 v);
static u32 SwapBytes(u32 v);
static u64 SwapBytes(u64 v);
static s16 SwapBytes(s16 v);
static s32 SwapBytes(s32 v);
static s64 SwapBytes(s64 v);
static float SwapBytes(float v);
static double SwapBytes(double s);
static void Swap2Bytes(u8* v);
static void Swap4Bytes(u8* v);
static void Swap8Bytes(u8* v);
static int RecursiveMakeDir(const char* dir);
static void MakeDir(const char* dir);
2023-06-21 13:22:49 -07:00
static bool IsDir(const char* path);
static bool IsFile(const char* path);
static int Stat(const char* path, Sstat* statOut);
2015-08-16 22:26:58 -07:00
};
2021-04-10 01:42:06 -07:00
} // namespace metaforce