OS.h: more type elaboration (#21)

* move OS function decls to their own header, os.h

* os.h: OSReport (+related), OSMutex, OSThread; fixup uses

* os.h: OS{Mutex,Thread}{Link,Queue}, OSCond

* os.h: OSxx typedefs, OSMessageQueue

* os.h: fix time function decls

* os.h: retype misc sched fns, create u32 OSSoundMode enum (and fixup use)

* os.h: more retyping

* merge os.h into os/OS.h

@Julgodis did this in parallel to me and added some functions beyond
what was in functions.h, so I merged our versions together

* os.h: retype the rest of the (currently decl'd) thread functions

* d_save: move OS import

Co-authored-by: Pheenoh <pheenoh@gmail.com>
This commit is contained in:
Erin Moon 2020-12-07 14:05:20 -06:00 committed by GitHub
parent 81e70882bf
commit b8bd1bbab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 131 additions and 43 deletions

View File

@ -102,7 +102,6 @@ extern "C" {
void func_8036221C(void);
void countUsed__FP10JKRExpHeap(void);
void JUTReport(void);
void OSGetTime(void);
void func_803621D0(void);
void offEventBit__11dSv_event_cFUs(void);
void func_803621C0(void);

View File

@ -1,60 +1,148 @@
#ifndef __OS_H_
#define __OS_H_
// at some point: we should split this up into various OS/... headers. but not yet, since barely any files include this atm.
struct OSThread {
u8 unkn[0x318];
};
#ifndef __OS_H__
#define __OS_H__
struct OSMessageQueue {
u8 unkn[0x20];
};
/* TODO: more structs, and get rid of the ones that are faked! */
struct OSMutex {
u8 unkn[24];
u8 unk[24];
};
struct OSMutexLink {
struct OSMutex *prev;
struct OSMutex *next;
};
struct OSMutexQueue {
struct OSMutex *prev;
struct OSMutex *next;
};
struct OSThread {
u8 unk[792];
};
typedef void (*OSSwitchThreadCallback)(OSThread *from, OSThread *to);
struct OSThreadLink {
struct OSThread * prev;
struct OSThread * next;
};
struct OSThreadQueue {
struct OSThread * head;
struct OSThread * tail;
};
struct OSCond {
struct OSThreadQueue queue;
};
typedef void* OSMessage;
struct OSMessageQueue {
struct OSThreadQueue sending_queue;
struct OSThreadQueue receiving_queue;
void **message_array;
s32 num_messages;
s32 first_index;
s32 num_used;
};
typedef u32 OSTick;
typedef s64 OSTime;
struct OSCalendarTime {
s32 seconds;
s32 minutes;
s32 hours;
s32 day_of_month;
s32 month;
s32 year;
s32 week_day;
s32 year_day;
s32 milliseconds;
s32 microseconds;
};
typedef s32 OSHeapHandle;
typedef enum OSSoundMode {
SOUND_MODE_MONO=0,
SOUND_MODE_STEREO=1,
__SOUND_MODE_FORCE_ENUM_U32=0xffffffff,
} OSSoundMode;
extern "C" {
void OSInitMutex(OSMutex*);
void OSLockMutex(OSMutex*);
void OSUnlockMutex(OSMutex*);
void OSEnableScheduler(void);
void OSDisableScheduler(void);
void OSCheckActiveThreads(void);
void OSReport_Error(char*,...);
u32 OSGetSoundMode(void);
void OSSuspendThread(void);
void OSSetThreadPriority(void);
void OSResumeThread(void);
void OSGetThreadPriority(void);
void OSGetConsoleType(void);
void OSGetResetCode(void);
void OSAllocFromArenaLo(void);
void OSReportInit(void);
s32 OSEnableScheduler(void);
s32 OSDisableScheduler(void);
s32 OSCheckActiveThreads(void);
OSThread* OSGetCurrentThread(void);
void OSTicksToCalendarTime(void);
s32 OSSuspendThread(OSThread* thread);
s32 OSSetThreadPriority(OSThread* thread, u32 pri);
s32 OSGetThreadPriority(OSThread* thread);
s32 OSCreateThread(OSThread* thread, void* (*func)(void*), void* param,
void* stack, u32 stackSize, int param_6, int param_7);
void OSCancelThread(OSThread* thread);
void OSDetachThread(OSThread* thread);
s32 OSResumeThread(OSThread *thread);
void OSExitThread(void *exit_val);
bool OSIsThreadSuspended(OSThread* thread);
bool OSIsThreadTerminated(OSThread* thread);
OSSwitchThreadCallback OSSetSwitchThreadCallback(OSSwitchThreadCallback *callback);
void OSInitMessageQueue(OSMessageQueue *queue, OSMessage* messages, int message_count);
void OSReceiveMessage(OSMessageQueue *queue, OSMessage message, int flags);
void OSSendMessage(OSMessageQueue *queue, OSMessage message, int flags);
s32 OSGetConsoleType(void);
s32 OSGetResetCode(void);
OSSoundMode OSGetSoundMode(void);
void OSSetSoundMode(OSSoundMode mode);
void OSReportInit(void);
void OSAttention(char *msg);
void OSPanic(char *file, s32 line, char* fmt, ...);
void OSReport(char *fmt, ...);
void OSReport_Error(char* fmt, ...);
void OSReport_FatalError(char* fmt, ...);
void OSReport_System(char* fmt, ...);
void OSReport_Warning(char* fmt, ...);
void OSReportDisable(void);
void OSReportEnable(void);
void OSReportForceEnableOff(void);
void OSReportForceEnableOn(void);
void OSReportInit(void);
void OSSwitchFiberEx(u32, u32, u32, u32, u32, u32);
void OSVAttention(char *, /*__gnuc_va_list*/ void*);
void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime *out_time);
OSTime OSGetTime(void);
OSTick OSGetTick(void);
u32 OSGetArenaLo();
u32 OSGetArenaHi();
u32 OSInitAlloc(u32 low, u32 high, int param_3);
void OSSetArenaLo(u32 param_1);
void OSSetArenaHi(u32 param_1);
void OSAllocFromArenaLo(u32 size, int alignment);
void OSGetTick(void);
void OSRestoreInterrupts(void);
void OSReport(void);
// void OSCancelAlarm(OSAlarm *alarm);
void OSCreateThread(OSThread* thread, void* (*func)(void*), void* param,
void* stack, u32 stackSize, int param_6, int param_7);
void OSCancelThread(OSThread* thread);
void OSDetachThread(OSThread* thread);
bool OSIsThreadSuspended(OSThread* thread);
bool OSIsThreadTerminated(OSThread* thread);
void OSInitMessageQueue(OSMessageQueue *queue, OSMessage* messages, int message_count);
void OSSetSwitchThreadCallback(void);
void OSReceiveMessage(OSMessageQueue *queue, OSMessage message, int flags);
void OSSendMessage(OSMessageQueue *queue, OSMessage message, int flags);
}
void OSInitMutex(OSMutex *mutex);
void OSLockMutex(OSMutex *mutex);
void OSTryLockMutex(OSMutex *mutex);
void OSUnlockMutex(OSMutex *mutex);
s32 OSDisableInterrupts();
s32 OSEnableInterrupts();
s32 OSRestoreInterrupts(s32 level);
};
#endif

View File

@ -1,6 +1,7 @@
#include "d/d_save/d_save/d_save.h"
#include "d/d_com/d_com_inf_game/d_com_inf_game.h"
#include "os/OS.h"
u8 dSv_item_rename(u8 item_id) {
switch (item_id) {
@ -854,11 +855,11 @@ asm void dSv_player_info_c::init(void) {
#endif
void dSv_player_config_c::init(void) {
u32 os_sound_mode;
OSSoundMode os_sound_mode;
this->unk0 = 1;
os_sound_mode = OSGetSoundMode();
if (os_sound_mode == 0) {
if (os_sound_mode == SOUND_MODE_MONO) {
this->sound_mode = 0;
Z2AudioMgr_NS_setOutputMode(lbl_80451368, 0);
} else {