2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _DOLPHIN_OS
|
|
|
|
#define _DOLPHIN_OS
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-09-29 23:09:11 +00:00
|
|
|
#include <dolphin/gx.h>
|
2022-10-02 07:43:00 +00:00
|
|
|
#include <dolphin/types.h>
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-08-05 10:23:49 +00:00
|
|
|
// Upper words of the masks, since UIMM is only 16 bits
|
2022-09-10 20:32:26 +00:00
|
|
|
#define OS_CACHED_REGION_PREFIX 0x8000
|
|
|
|
#define OS_UNCACHED_REGION_PREFIX 0xC000
|
|
|
|
#define OS_PHYSICAL_MASK 0x3FFF
|
2022-08-05 10:23:49 +00:00
|
|
|
|
2022-09-10 20:32:26 +00:00
|
|
|
#define OS_BASE_CACHED (OS_CACHED_REGION_PREFIX << 16)
|
|
|
|
#define OS_BASE_UNCACHED (OS_UNCACHED_REGION_PREFIX << 16)
|
2022-08-05 10:23:49 +00:00
|
|
|
|
2022-08-26 03:46:24 +00:00
|
|
|
#ifdef __MWERKS__
|
2022-08-05 10:23:49 +00:00
|
|
|
#define AT_ADDRESS(xyz) : (xyz)
|
2022-08-26 03:46:24 +00:00
|
|
|
#else
|
|
|
|
#define AT_ADDRESS
|
|
|
|
#endif
|
2022-09-01 00:22:20 +00:00
|
|
|
typedef s64 OSTime;
|
|
|
|
typedef u32 OSTick;
|
2022-09-10 20:32:26 +00:00
|
|
|
u32 __OSBusClock AT_ADDRESS(OS_BASE_CACHED | 0x00F8); // sync with OSLoMem.h
|
|
|
|
u32 __OSCoreClock AT_ADDRESS(OS_BASE_CACHED | 0x00FC); // sync with OSLoMem.h
|
2023-02-13 18:07:42 +00:00
|
|
|
#define OS_BUS_CLOCK (u32)__OSBusClock
|
2022-09-10 20:32:26 +00:00
|
|
|
#define OS_CORE_CLOCK __OSCoreClock
|
|
|
|
#define OS_TIMER_CLOCK (OS_BUS_CLOCK / 4)
|
|
|
|
|
2022-09-14 05:24:41 +00:00
|
|
|
#define OSPhysicalToCached(paddr) ((void*)((u32)(paddr) + OS_BASE_CACHED))
|
|
|
|
#define OSPhysicalToUncached(paddr) ((void*)((u32)(paddr) + OS_BASE_UNCACHED))
|
|
|
|
#define OSCachedToPhysical(caddr) ((u32)((u8*)(caddr)-OS_BASE_CACHED))
|
|
|
|
#define OSUncachedToPhysical(ucaddr) ((u32)((u8*)(ucaddr)-OS_BASE_UNCACHED))
|
|
|
|
#define OSCachedToUncached(caddr) ((void*)((u8*)(caddr) + (OS_BASE_UNCACHED - OS_BASE_CACHED)))
|
|
|
|
#define OSUncachedToCached(ucaddr) ((void*)((u8*)(ucaddr) - (OS_BASE_UNCACHED - OS_BASE_CACHED)))
|
2022-09-10 20:32:26 +00:00
|
|
|
|
|
|
|
#define OSTicksToCycles(ticks) (((ticks) * ((OS_CORE_CLOCK * 2) / OS_TIMER_CLOCK)) / 2)
|
|
|
|
#define OSTicksToSeconds(ticks) ((ticks) / OS_TIMER_CLOCK)
|
|
|
|
#define OSTicksToMilliseconds(ticks) ((ticks) / (OS_TIMER_CLOCK / 1000))
|
|
|
|
#define OSTicksToMicroseconds(ticks) (((ticks)*8) / (OS_TIMER_CLOCK / 125000))
|
|
|
|
#define OSTicksToNanoseconds(ticks) (((ticks)*8000) / (OS_TIMER_CLOCK / 125000))
|
2023-02-13 18:07:42 +00:00
|
|
|
#define OSSecondsToTicks(sec) ((sec)*OS_TIMER_CLOCK)
|
2022-09-10 20:32:26 +00:00
|
|
|
#define OSMillisecondsToTicks(msec) ((msec) * (OS_TIMER_CLOCK / 1000))
|
|
|
|
#define OSMicrosecondsToTicks(usec) (((usec) * (OS_TIMER_CLOCK / 125000)) / 8)
|
|
|
|
#define OSNanosecondsToTicks(nsec) (((nsec) * (OS_TIMER_CLOCK / 125000)) / 8000)
|
|
|
|
|
|
|
|
#define OSDiffTick(tick1, tick0) ((s32)(tick1) - (s32)(tick0))
|
|
|
|
|
|
|
|
#define OSRoundUp32B(v) (((u32)(v + 31) & ~31))
|
2022-04-30 08:32:00 +00:00
|
|
|
|
2022-09-20 04:35:24 +00:00
|
|
|
void* OSGetArenaHi(void);
|
|
|
|
void* OSGetArenaLo(void);
|
|
|
|
void OSSetArenaHi(void* newHi);
|
|
|
|
void OSSetArenaLo(void* newLo);
|
|
|
|
|
|
|
|
void* OSAllocFromArenaLo(u32 size, u32 align);
|
|
|
|
void* OSAllocFromArenaHi(u32 size, u32 align);
|
|
|
|
|
2022-10-05 01:31:43 +00:00
|
|
|
void OSInit();
|
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
OSTime OSGetTime();
|
2022-09-20 04:35:24 +00:00
|
|
|
OSTick OSGetTick();
|
2022-10-02 07:43:00 +00:00
|
|
|
|
2022-10-11 13:41:20 +00:00
|
|
|
typedef struct OSCalendarTime {
|
2022-11-05 10:21:17 +00:00
|
|
|
int sec; // seconds after the minute [0, 61]
|
|
|
|
int min; // minutes after the hour [0, 59]
|
|
|
|
int hour; // hours since midnight [0, 23]
|
|
|
|
int mday; // day of the month [1, 31]
|
2022-10-26 05:00:49 +00:00
|
|
|
int mon; // month since January [0, 11]
|
|
|
|
int year; // years in AD [1, ...]
|
|
|
|
int wday; // days since Sunday [0, 6]
|
|
|
|
int yday; // days since January 1 [0, 365]
|
|
|
|
|
|
|
|
int msec; // milliseconds after the second [0,999]
|
|
|
|
int usec; // microseconds after the millisecond [0,999]
|
2022-10-11 13:41:20 +00:00
|
|
|
} OSCalendarTime;
|
|
|
|
|
2022-11-05 10:21:17 +00:00
|
|
|
OSTime OSCalendarTimeToTicks(OSCalendarTime* td);
|
|
|
|
void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime* td);
|
2022-10-11 13:41:20 +00:00
|
|
|
|
2022-10-02 07:43:00 +00:00
|
|
|
#define OS_CONSOLE_MASK 0xf0000000
|
|
|
|
#define OS_CONSOLE_RETAIL 0x00000000
|
|
|
|
#define OS_CONSOLE_DEVELOPMENT 0x10000000
|
|
|
|
#define OS_CONSOLE_TDEV 0x20000000
|
|
|
|
|
|
|
|
#define OS_CONSOLE_RETAIL4 0x00000004
|
|
|
|
#define OS_CONSOLE_RETAIL3 0x00000003
|
|
|
|
#define OS_CONSOLE_RETAIL2 0x00000002
|
|
|
|
#define OS_CONSOLE_RETAIL1 0x00000001
|
|
|
|
#define OS_CONSOLE_TDEVHW4 0x20000007
|
|
|
|
#define OS_CONSOLE_TDEVHW3 0x20000006
|
|
|
|
#define OS_CONSOLE_TDEVHW2 0x20000005
|
|
|
|
#define OS_CONSOLE_TDEVHW1 0x20000004
|
|
|
|
#define OS_CONSOLE_DEVHW4 0x10000007
|
|
|
|
#define OS_CONSOLE_DEVHW3 0x10000006
|
|
|
|
#define OS_CONSOLE_DEVHW2 0x10000005
|
|
|
|
#define OS_CONSOLE_DEVHW1 0x10000004
|
|
|
|
#define OS_CONSOLE_MINNOW 0x10000003
|
|
|
|
#define OS_CONSOLE_ARTHUR 0x10000002
|
|
|
|
#define OS_CONSOLE_PC_EMULATOR 0x10000001
|
|
|
|
#define OS_CONSOLE_EMULATOR 0x10000000
|
|
|
|
|
|
|
|
u32 OSGetConsoleType();
|
|
|
|
|
2022-10-05 01:31:43 +00:00
|
|
|
#define OS_SOUND_MODE_MONO 0u
|
|
|
|
#define OS_SOUND_MODE_STEREO 1u
|
|
|
|
|
|
|
|
u32 OSGetSoundMode(void);
|
|
|
|
void OSSetSoundMode(u32 mode);
|
|
|
|
|
|
|
|
#define OS_PROGRESSIVE_MODE_OFF 0u
|
|
|
|
#define OS_PROGRESSIVE_MODE_ON 1u
|
|
|
|
|
|
|
|
u32 OSGetProgressiveMode(void);
|
|
|
|
void OSSetProgressiveMode(u32 on);
|
|
|
|
|
|
|
|
#define OS_LANG_ENGLISH 0u
|
|
|
|
#define OS_LANG_GERMAN 1u
|
|
|
|
#define OS_LANG_FRENCH 2u
|
|
|
|
#define OS_LANG_SPANISH 3u
|
|
|
|
#define OS_LANG_ITALIAN 4u
|
|
|
|
#define OS_LANG_DUTCH 5u
|
|
|
|
|
|
|
|
u8 OSGetLanguage(void);
|
|
|
|
void OSSetLanguage(u8 language);
|
|
|
|
|
|
|
|
#define OS_EURGB60_OFF 0u
|
|
|
|
#define OS_EURGB60_ON 1u
|
|
|
|
|
|
|
|
u32 OSGetEuRgb60Mode(void);
|
|
|
|
void OSSetEuRgb60Mode(u32 on);
|
|
|
|
|
|
|
|
void OSRegisterVersion(const char* id);
|
|
|
|
|
|
|
|
BOOL OSDisableInterrupts(void);
|
|
|
|
BOOL OSEnableInterrupts(void);
|
|
|
|
BOOL OSRestoreInterrupts(BOOL level);
|
|
|
|
|
2023-02-05 19:12:16 +00:00
|
|
|
#define OSHalt(msg) OSPanic(__FILE__, __LINE__, msg)
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
|
|
|
#ifndef ASSERT
|
|
|
|
#define ASSERT(exp) (void)((exp) || (OSPanic(__FILE__, __LINE__, "Failed assertion " #exp), 0))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERTMSG
|
|
|
|
#if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__MWERKS__) || \
|
|
|
|
defined(__SN__)
|
|
|
|
#define ASSERTMSG(exp, ...) (void)((exp) || (OSPanic(__FILE__, __LINE__, __VA_ARGS__), 0))
|
|
|
|
#else
|
|
|
|
#define ASSERTMSG(exp, msg) (void)((exp) || (OSPanic(__FILE__, __LINE__, (msg)), 0))
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERTMSG1
|
|
|
|
#define ASSERTMSG1(exp, msg, param1) \
|
|
|
|
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1)), 0))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERTMSG2
|
|
|
|
#define ASSERTMSG2(exp, msg, param1, param2) \
|
|
|
|
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2)), 0))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERTMSG3
|
|
|
|
#define ASSERTMSG3(exp, msg, param1, param2, param3) \
|
|
|
|
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2), (param3)), 0))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERTMSG4
|
|
|
|
#define ASSERTMSG4(exp, msg, param1, param2, param3, param4) \
|
|
|
|
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2), (param3), (param4)), 0))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else // _DEBUG
|
|
|
|
|
|
|
|
#ifndef ASSERT
|
|
|
|
#define ASSERT(exp) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERTMSG
|
|
|
|
#if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__MWERKS__) || \
|
|
|
|
defined(__SN__)
|
|
|
|
#define ASSERTMSG(exp, ...) ((void)0)
|
|
|
|
#else
|
|
|
|
#define ASSERTMSG(exp, msg) ((void)0)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERTMSG1
|
|
|
|
#define ASSERTMSG1(exp, msg, param1) ((void)0)
|
|
|
|
#endif
|
|
|
|
#ifndef ASSERTMSG2
|
|
|
|
#define ASSERTMSG2(exp, msg, param1, param2) ((void)0)
|
|
|
|
#endif
|
|
|
|
#ifndef ASSERTMSG3
|
|
|
|
#define ASSERTMSG3(exp, msg, param1, param2, param3) ((void)0)
|
|
|
|
#endif
|
|
|
|
#ifndef ASSERTMSG4
|
|
|
|
#define ASSERTMSG4(exp, msg, param1, param2, param3, param4) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
2022-09-13 04:26:54 +00:00
|
|
|
void OSReport(const char* msg, ...);
|
2022-09-16 01:17:42 +00:00
|
|
|
void OSPanic(const char* file, int line, const char* msg, ...);
|
2022-09-29 23:09:11 +00:00
|
|
|
void OSFatal(GXColor fg, GXColor bg, const char* msg);
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-09-10 20:32:26 +00:00
|
|
|
#include <dolphin/os/OSAlarm.h>
|
2023-02-26 04:51:09 +00:00
|
|
|
#include <dolphin/os/OSAlloc.h>
|
2022-12-18 01:47:41 +00:00
|
|
|
#include <dolphin/os/OSArena.h>
|
2022-09-10 20:32:26 +00:00
|
|
|
#include <dolphin/os/OSCache.h>
|
|
|
|
#include <dolphin/os/OSContext.h>
|
2022-09-29 23:09:11 +00:00
|
|
|
#include <dolphin/os/OSError.h>
|
2022-10-08 05:53:41 +00:00
|
|
|
#include <dolphin/os/OSException.h>
|
2022-12-22 20:46:14 +00:00
|
|
|
#include <dolphin/os/OSExpansion.h>
|
2022-12-06 04:11:13 +00:00
|
|
|
#include <dolphin/os/OSFastCast.h>
|
2022-09-10 20:32:26 +00:00
|
|
|
#include <dolphin/os/OSFont.h>
|
2022-10-08 05:53:41 +00:00
|
|
|
#include <dolphin/os/OSInterrupt.h>
|
2022-12-18 18:32:00 +00:00
|
|
|
#include <dolphin/os/OSMemory.h>
|
2022-12-18 06:48:45 +00:00
|
|
|
#include <dolphin/os/OSMessage.h>
|
2022-12-18 04:08:25 +00:00
|
|
|
#include <dolphin/os/OSModule.h>
|
2022-11-05 10:21:17 +00:00
|
|
|
#include <dolphin/os/OSMutex.h>
|
2022-09-10 20:32:26 +00:00
|
|
|
#include <dolphin/os/OSReset.h>
|
2022-12-22 23:11:03 +00:00
|
|
|
#include <dolphin/os/OSResetSW.h>
|
2022-09-14 05:24:41 +00:00
|
|
|
#include <dolphin/os/OSSerial.h>
|
2022-09-10 20:32:26 +00:00
|
|
|
#include <dolphin/os/OSThread.h>
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _DOLPHIN_OS
|