diff --git a/Makefile b/Makefile index 264b142930..8fcb64978b 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,10 @@ OPTIMIZATION := -O2 -g3 build/src/libultra/os/%: OPTIMIZATION := -O1 build/src/libultra/io/%: OPTIMIZATION := -O2 build/src/libultra/libc/%: OPTIMIZATION := -O2 +build/src/libultra/libc/ll%: OPTIMIZATION := -O1 +build/src/libultra/libc/ll%: MIPS_VERSION := -mips3 -32 build/src/libultra/gu/%: OPTIMIZATION := -O2 +build/src/libultra/rmon/%: OPTIMIZATION := -O2 build/src/libultra/%: CC := $(QEMU_IRIX) -L $(IRIX_53_ROOT) $(IRIX_53_ROOT)/usr/bin/cc build/src/libultra/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul build/src/boot_O1/%: OPTIMIZATION := -O1 @@ -25,8 +28,8 @@ build/src/boot_O2_g3_trapuv/%: OPTIMIZATION := -O2 -g3 build/src/code/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul build/src/actors/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul build/src/boot_O2_g3_trapuv/%: CFLAGS := $(CFLAGS) -trapuv -test.txt: OPTIMIZATION := -O2 -test.txt: CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc +test.txt: OPTIMIZATION := -O1 +test.txt: CC := $(QEMU_IRIX) -L $(IRIX_53_ROOT) $(IRIX_53_ROOT)/usr/bin/cc test.txt: CFLAGS := $(CFLAGS) -Wab,-r4300_mul CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc @@ -56,6 +59,7 @@ C_FILES := $(wildcard src/libultra/*) \ $(wildcard src/libultra/io/*) \ $(wildcard src/libultra/libc/*) \ $(wildcard src/libultra/gu/*) \ + $(wildcard src/libultra/rmon/*) \ $(wildcard src/code/*) \ $(wildcard src/boot_O2/*) \ $(wildcard src/boot_O2_g3/*) \ @@ -84,6 +88,7 @@ $(shell mkdir -p $(BUILD_DIR)/src/libultra/os) $(shell mkdir -p $(BUILD_DIR)/src/libultra/io) $(shell mkdir -p $(BUILD_DIR)/src/libultra/libc) $(shell mkdir -p $(BUILD_DIR)/src/libultra/gu) +$(shell mkdir -p $(BUILD_DIR)/src/libultra/rmon) $(shell mkdir -p $(BUILD_DIR)/src/code) $(shell mkdir -p $(BUILD_DIR)/src/boot_O2) $(shell mkdir -p $(BUILD_DIR)/src/boot_O2_g3) @@ -187,6 +192,14 @@ build/src/actors/%.o: src/actors/%.c include/* build/src/%.o: src/%.c include/* $(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $< +build/src/libultra/libc/ll.o: src/libultra/libc/ll.c include/* + $(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $< + ./tools/set_o32abi_bit.py $@ + +build/src/libultra/libc/llcvt.o: src/libultra/libc/llcvt.c include/* + $(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $< + ./tools/set_o32abi_bit.py $@ + build/decomp/%: build/decomp_pre_dmadata/% cp $< $@ diff --git a/include/functions.h b/include/functions.h index ae04b5d054..9741deed81 100644 --- a/include/functions.h +++ b/include/functions.h @@ -234,7 +234,7 @@ void* __osRealloc(Heap* heap, void* oldPtr, u32 newSize); // func_800875E4 void __osAnalyzeArena(Heap* heap, u32* maxFreeBlock, u32* bytesFree, u32* bytesAllocated); // func_80087714 s32 __osCheckArena(Heap* heap); // func_800877C4 void* proutSprintf(void* s, char* buf, size_t n); // func_80087830 -void func_80087854(void); // func_80087854 +int vsprintf(char* dst, char* fmt, va_list args); // func_80087854 int sprintf(char* s, char* fmt, ...); // func_800878A4 void func_80087900(void); // func_80087900 void func_80087934(void); // func_80087934 @@ -254,20 +254,20 @@ OSIntMask osGetIntMask(void); // func_800880B0 void func_80088110(void); // func_80088110 void func_800882A0(void); // func_800882A0 f32 __sinf(f32 __x); // func_80088350 -s32 sins(u16 angle); // func_80088510 +short sins(unsigned short x); // func_80088510 OSTask* _VirtualToPhysicalTask(OSTask* intp); // func_80088580 void osSpTaskLoad(OSTask* intp); // func_8008868C void osSpTaskStartGo(OSTask* tp); // func_800887F4 -void __ull_rshift(void); // func_80088840 -void __ull_rem(void); // func_8008886C -u64 __ull_div(u64 param_1, u64 param_2); // func_800888A8 -void __ll_lshift(void); // func_800888E4 -void __ll_rem(void); // func_80088910 -void __ll_div(void); // func_8008894C -u64 __ll_mul(u64 param_1, u64 param_2); // func_800889A8 -void __ull_divremi(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE2 param_5); // func_800889D8 -void __ll_mod(void); // func_80088A38 -void __ll_rshift(void); // func_80088AD4 +long long __ull_rshift(unsigned long long left, unsigned long long right); // func_80088840 +unsigned long long __ull_rem(unsigned long long left, unsigned long long right); // func_8008886C +unsigned long long __ull_div(unsigned long long left, unsigned long long right); // func_800888A8 +long long __ll_lshift(long long left, long long right); // func_800888E4 +long long __ll_rem(long long left, unsigned long long right); // func_80088910 +long long __ll_div(long long left, long long right); // func_8008894C +long long __ll_mul(long long left, long long right); // func_800889A8 +void __ull_divremi(unsigned long long* quotient, unsigned long long* remainder, unsigned long long dividend, unsigned short divisor); // func_800889D8 +long long __ll_mod(long long left, long long right); // func_80088A38 +long long __ll_rshift(long long left, long long right); // func_80088AD4 void __osExceptionPreamble(void); // func_80088B00 void __osException(void); // func_80088B10 void func_80088D48(void); // func_80088D48 @@ -301,8 +301,8 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data); // func_800 void __osContGetInitData(u8* pattern, OSContStatus* data); // func_80089CBC void __osPackRequestData(u8 cmd); // func_80089D68 void osCreateThread(OSThread* t, OSId id, osCreateThread_func entry, void* arg, void* sp, OSPri p); // func_80089E40 -void osContStartReadData(void); // func_80089F90 -void osContGetReadData(void); // func_8008A014 +s32 osContStartReadData(OSMesgQueue* mq); // func_80089F90 +void osContGetReadData(OSContPad* data); // func_8008A014 void __osPackReadData(void); // func_8008A0A0 void func_8008A170(void); // func_8008A170 u32 osVirtualToPhysical(void* vaddr); // func_8008A540 @@ -322,8 +322,8 @@ void osViRepeatLine(u8 active); // func_8008AE70 s32 __osSiRawReadIo(u32 devAddr, u32* data); // func_8008AEE0 OSId osGetThreadId(OSThread* t); // func_8008AF30 void osSpTaskYield(void); // func_8008AF50 -void func_8008AF70(void); // func_8008AF70 -void func_8008B044(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // func_8008B044 +s32 __osPfsRWInode(OSPfs* param_1, __OSInode* param_2, u8 param_3, u8 param_4); // func_8008AF70 +s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in_bytes, u8* data_buffer); // func_8008B044 void func_8008B3C0(void); // func_8008B3C0 void func_8008B490(void); // func_8008B490 void func_8008B554(void); // func_8008B554 @@ -341,8 +341,9 @@ void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgC void __osPiCreateAccessQueue(void); // func_8008C190 void __osPiGetAccess(void); // func_8008C1E0 void __osPiRelAccess(void); // func_8008C224 -void func_8008C260(s32 param_1); // func_8008C260 -void func_8008C670(void); // func_8008C670 +void __osDevMgrMain(void* arg); // func_8008C260 +void func_8008C640(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE1 param_5, UNK_TYPE1 param_6, UNK_TYPE1 param_7, UNK_TYPE1 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11, UNK_TYPE4 param_12, UNK_TYPE4 param_13, UNK_TYPE4 param_14, UNK_TYPE4 param_15, UNK_TYPE4 param_16, UNK_TYPE4 param_17, UNK_TYPE4 param_18); // func_8008C640 +s32 osPiRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size); // func_8008C670 void func_8008C740(void); // func_8008C740 void func_8008C7B4(void); // func_8008C7B4 void func_8008C8B0(void); // func_8008C8B0 @@ -350,9 +351,9 @@ void func_8008CC00(void); // func_8008CC00 void func_8008CD64(void); // func_8008CD64 void func_8008CF10(void); // func_8008CF10 void func_8008CFE4(void); // func_8008CFE4 -void osGetCount(void); // func_8008D2C0 +u32 osGetCount(void); // func_8008D2C0 void func_8008D2E0(void); // func_8008D2E0 -u32 calculate_mem_size(void); // func_8008D350 +u32 osGetMemSize(void); // func_8008D350 void func_8008D470(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // func_8008D470 void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg m); // func_8008D640 f32 sqrtf(f32 __x); // func_8008D700 @@ -361,8 +362,8 @@ s32 osContStartQuery(OSMesgQueue* mq); // func_8008D730 void osContGetQuery(OSContStatus* data); // func_8008D7AC void guLookAtHiliteF(float mf[4][4], UNK_PTR l, int* h, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp, float xl1, float yl1, float zl1, float xl2, float yl2, float zl2, int twidth, int theight); // func_8008D7D0 void guLookAtHilite(Mtx* m, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 twidth, s32 theight); // func_8008DF90 -int _Printf(printf_func pfn, void* arg, char* fmt, char* ap); // func_8008E050 -void func_8008E698(void); // func_8008E698 +int _Printf(printf_func pfn, void* arg, char* fmt, va_list ap); // func_8008E050 +void _Putfld(_Pft* px, va_list* pap, unsigned char code, unsigned char* ac); // func_8008E698 void func_8008ED30(void); // func_8008ED30 void osUnmapTLBAll(void); // func_8008EDE0 s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction); // func_8008EE30 @@ -377,7 +378,7 @@ void osInvalDCache(void* vaddr, s32 nbytes); // func_8008F2F0 void __osTimerServicesInit(void); // func_8008F3A0 void __osTimerInterrupt(void); // func_8008F42C void __osSetTimerIntr(OSTime tim); // func_8008F5A4 -void __osInsertTimer(OSTimer* t); // func_8008F644 +OSTime __osInsertTimer(OSTimer* t); // func_8008F644 void func_8008F7D0(void); // func_8008F7D0 int __osSpDeviceBusy(void); // func_8008FA00 int __osSiDeviceBusy(void); // func_8008FA30 @@ -387,10 +388,10 @@ void osSetThreadPri(OSThread* t, OSPri pri); // func_8008FC00 OSPri osGetThreadPri(OSThread* t); // func_8008FCE0 void func_8008FD00(void); // func_8008FD00 void osViSwapBuffer(void* frameBufPtr); // func_8008FE60 -void func_8008FEB0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); // func_8008FEB0 -void func_80090058(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); // func_80090058 +void guPositionF(float mf[4][4], float r, float p, float h, float s, float x, float y, float z); // func_8008FEB0 +void guPosition(Mtx* m, float r, float p, float h, float s, float x, float y, float z); // func_80090058 void func_800900C0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // func_800900C0 -void osSpTaskYielded(void); // func_800902A0 +OSYieldResult osSpTaskYielded(OSTask* task); // func_800902A0 s32 memcmp(void* __s1, void* __s2, size_t __n); // func_80090300 OSTime osGetTime(void); // func_80090420 void guRotateF(float mf[4][4], float a, float x, float y, float z); // func_800904B0 @@ -400,42 +401,42 @@ void func_800906D0(void); // func_800906D0 void func_80090810(void); // func_80090810 void func_80090900(void); // func_80090900 s32 osAiSetFrequency(u32 frequency); // func_80090AF0 -void func_80090C40(void); // func_80090C40 +s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer); // func_80090C40 void func_80090E70(void); // func_80090E70 -void func_800910A0(void); // func_800910A0 -void func_80091170(void); // func_80091170 +u8 __osContAddressCrc(u16 addr); // func_800910A0 +u8 __osContDataCrc(u8* data); // func_80091170 OSThread* __osGetActiveQueue(void); // func_80091210 void guNormalize(float* x, float* y, float* z); // func_80091220 void __osSetCompare(u32 value); // func_80091280 u32 __osGetCompare(void); // func_80091290 u32 osDpGetStatus(void); // func_800912A0 -void osDpSetStatus(u32 status); // func_800912B0 +void osDpSetStatus(u32 data); // func_800912B0 void _bcopy(void* __src, void* __dest, size_t __n); // func_800912C0 void __osResetGlobalIntMask(void); // func_800915D0 void func_80091630(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // func_80091630 void func_80091808(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // func_80091808 -void guOrthoF(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); // func_800918A0 -void guOrtho(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); // func_800919F4 +void guOrthoF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale); // func_800918A0 +void guOrtho(Mtx* m, float l, float r, float b, float t, float n, float f, float scale); // func_800919F4 OSIntMask __osDisableInt(void); // func_80091A60 void __osRestoreInt(OSIntMask im); // func_80091AD0 void __osViInit(void); // func_80091AF0 void __osViSwapContext(void); // func_80091C10 -void osPiGetCmdQueue(void); // func_80091F10 +OSMesgQueue* osPiGetCmdQueue(void); // func_80091F10 f32 __cosf(f32 __x); // func_80091F40 void func_800920B0(void); // func_800920B0 void osViSetSpecialFeatures(u32 func); // func_80092100 -s32 coss(u16 angle); // func_80092260 -void osSetTime(void); // func_80092290 +short coss(unsigned short x); // func_80092260 +void osSetTime(OSTime ticks); // func_80092290 void func_800922C0(void); // func_800922C0 -void osViSetEvent(OSMesgQueue* param_1, OSMesg param_2, u32 retraceCount); // func_800923E0 +void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount); // func_800923E0 void func_80092440(void); // func_80092440 void func_800925CC(void); // func_800925CC void func_80092680(void); // func_80092680 void func_80092730(void); // func_80092730 -OSPiHandle* func_80092920(void); // func_80092920 +OSPiHandle* osCartRomInit(void); // func_80092920 void func_80092A80(void); // func_80092A80 -void func_80092C00(void); // func_80092C00 -void osContSetCh(void); // func_80092C80 +s32 __osPfsSelectBank(OSPfs* pfs, UNK_TYPE4 param_2); // func_80092C00 +s32 osContSetCh(u8 ch); // func_80092C80 u32 __osSetFpcCsr(u32 value); // func_80092CE0 u32 __osGetFpcCsr(void); // func_80092CF0 void func_80092D00(void); // func_80092D00 @@ -444,21 +445,21 @@ void func_800930E8(void); // func_800930E8 void func_800931F0(void); // func_800931F0 void func_80093728(void); // func_80093728 void func_80093A00(void); // func_80093A00 -void osAiGetLength(void); // func_80093BA0 +u32 osAiGetLength(void); // func_80093BA0 void func_80093BB0(void); // func_80093BB0 void osMapTLBRdb(void); // func_80093C00 void osYieldThread(void); // func_80093C60 void func_80093CC0(void); // func_80093CC0 u32 __osGetCause(void); // func_80093D90 -void func_80093DA0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // func_80093DA0 +s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force); // func_80093DA0 void func_80093FF0(void); // func_80093FF0 -s32 osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg); // func_80094150 -void _Ldtob(void); // func_800942E0 -void func_80094770(void); // func_80094770 -void func_80094828(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE2 param_5); // func_80094828 -ldiv_t ldiv(s32 __numer, s32 __denom); // func_80094DF0 -lldiv_t* lldiv(s64 __numer, s64 __denom); // func_80094E74 -void _Litob(void); // func_80094F80 +int osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg); // func_80094150 +void _Ldtob(_Pft* px, unsigned char code); // func_800942E0 +void _Ldunscale(void); // func_80094770 +void _Genld(_Pft* px, unsigned char code, unsigned char* p, short nsig, short xexp); // func_80094828 +ldiv_t ldiv(long numer, long denom); // func_80094DF0 +lldiv_t lldiv(long long numer, long long denom); // func_80094E74 +void _Litob(_Pft* px, unsigned char code); // func_80094F80 s32 __osSiRawWriteIo(u32 devAddr, u32 data); // func_80095220 u32 __osSpGetStatus(void); // func_80095270 void __osSpSetStatus(u32 value); // func_80095280 @@ -470,22 +471,23 @@ OSThread* __osGetCurrFaultedThread(void); // func_800955F0 void func_80095600(void); // func_80095600 void guMtxF2L(float mf[4][4], Mtx* m); // func_80095740 void osStartThread(OSThread* param_1); // func_800957B0 -void osViSetYScale(f32 param_1); // func_80095900 -void osViSetXScale(f32 xscale); // func_80095950 -void __d_to_ll(void); // func_80095A60 -void __f_to_ll(void); // func_80095A7C -void __d_to_ull(void); // func_80095A98 -void __f_to_ull(void); // func_80095B38 -void __ll_to_d(void); // func_80095BD4 -void __ll_to_f(void); // func_80095BEC -void __ull_to_d(void); // func_80095C04 -void __ull_to_f(void); // func_80095C38 +void osViSetYScale(f32 value); // func_80095900 +void osViSetXScale(f32 value); // func_80095950 +long long __d_to_ll(double d); // func_80095A60 +long long __f_to_ll(float f); // func_80095A7C +unsigned long long __d_to_ull(double d); // func_80095A98 +unsigned long long __f_to_ull(float f); // func_80095B38 +double __ll_to_d(long long l); // func_80095BD4 +float __ll_to_f(long long l); // func_80095BEC +double __ull_to_d(unsigned long long l); // func_80095C04 +float __ull_to_f(unsigned long long l); // func_80095C38 void func_80095C70(void); // func_80095C70 void func_80096360(void); // func_80096360 void func_80096410(void); // func_80096410 void func_800964D0(void); // func_800964D0 s32 __osSpSetPc(u32 data); // func_80096510 void func_80096540(void); // func_80096540 +// UNK_RET func_80096770(UNK_ARGS); void func_800967A0(void); // func_800967A0 u32 __osGetWatchLo(void); // func_80096810 void __osSetWatchLo(u32 value); // func_80096820 @@ -3737,6 +3739,8 @@ void func_8019AB40(void); // func_8019AB40 void func_8019AC10(void); // func_8019AC10 void func_8019ACEC(void); // func_8019ACEC void func_8019ADBC(void); // func_8019ADBC +// UNK_RET func_8019AE40(UNK_ARGS); +// UNK_RET func_8019AEC0(UNK_ARGS); void func_8019AF00(void); // func_8019AF00 void func_8019AF58(void); // func_8019AF58 void func_8019AFE8(void); // func_8019AFE8 diff --git a/include/os.h b/include/os.h index 978999ddb1..bc882d32d7 100644 --- a/include/os.h +++ b/include/os.h @@ -161,6 +161,7 @@ typedef struct { /* 0x8 */ void* dramAddr; /* 0xC */ u32 devAddr; /* 0x10 */ u32 size; + /* 0x14 */ OSPiHandle* piHandle; } OSIoMesg; @@ -170,7 +171,8 @@ typedef struct { /* 0x8 */ OSMesgQueue* cmdQueue; /* 0xC */ OSMesgQueue* evtQueue; /* 0x10 */ OSMesgQueue* acsQueue; - /* 0x14 */ s32 (*dma)(... /* ECOFF does not store param types */); + /* 0x14 */ s32 (*dma)(void); + /* 0x14 */ s32 (*unk18)(void); } OSDevMgr; @@ -244,12 +246,15 @@ typedef struct { /* 0x4 */ OSMesgQueue* queue; /* 0x8 */ int channel; /* 0xC */ u8 id[32]; - /* 0x2C */ u8 backup_id[32]; /* 0x4C */ u8 label[32]; - /* 0x6C */ int pack_size; - /* 0x70 */ int version; - /* 0x74 */ int dir_size; - /* 0x78 */ int inode_start_page; + /* 0x6C */ int version; + /* 0x70 */ int dir_size; + /* 0x74 */ int inode_table; + /* 0x78 */ int minode_table; + /* 0x7C */ int dir_table; + /* 0x80 */ int inode_start_page; + /* 0x84 */ u8 banks; + /* 0x88 */ u8 activebank; } OSPfs; diff --git a/include/stdarg.h b/include/stdarg.h index a7c9afa8c9..3303fdcb83 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -1,6 +1,45 @@ #ifndef _STDARG_H_ #define _STDARG_H_ -typedef unsigned char* va_list; +#include + +// When building with GCC, use the official vaarg macros to avoid warnings +// and possibly bad codegen. +#ifdef __GNUC__ +#define va_list __builtin_va_list +#define va_start __builtin_va_start +#define va_arg __builtin_va_arg +#define va_end __builtin_va_end +#else + +typedef char *va_list; +#define _FP 1 +#define _INT 0 +#define _STRUCT 2 + +#define _VA_FP_SAVE_AREA 0x10 +#define _VA_ALIGN(p, a) (((unsigned int)(((char *)p) + ((a) > 4 ? (a) : 4) - 1)) & -((a) > 4 ? (a) : 4)) +#define va_start(vp, parmN) (vp = ((va_list)&parmN + sizeof(parmN))) + +#define __va_stack_arg(list, mode) \ + ( \ + ((list) = (char *)_VA_ALIGN(list, __builtin_alignof(mode)) + \ + _VA_ALIGN(sizeof(mode), 4)), \ + (((char *)list) - (_VA_ALIGN(sizeof(mode), 4) - sizeof(mode)))) + +#define __va_double_arg(list, mode) \ + ( \ + (((long)list & 0x1) /* 1 byte aligned? */ \ + ? (list = (char *)((long)list + 7), (char *)((long)list - 6 - _VA_FP_SAVE_AREA)) \ + : (((long)list & 0x2) /* 2 byte aligned? */ \ + ? (list = (char *)((long)list + 10), (char *)((long)list - 24 - _VA_FP_SAVE_AREA)) \ + : __va_stack_arg(list, mode)))) + +#define va_arg(list, mode) ((mode *)(((__builtin_classof(mode) == _FP && \ + __builtin_alignof(mode) == sizeof(double)) \ + ? __va_double_arg(list, mode) \ + : __va_stack_arg(list, mode))))[-1] +#define va_end(__list) #endif +#endif diff --git a/include/variables.h b/include/variables.h index 26809e83f7..161060b1cc 100644 --- a/include/variables.h +++ b/include/variables.h @@ -35,8 +35,8 @@ extern UNK_TYPE1 D_80096CF8; // D_80096CF8 extern UNK_TYPE4 D_80097500; // D_80097500 extern UNK_TYPE4 D_80097524; // D_80097524 extern u32 randSeed; // D_80097530 -extern UNK_TYPE1 osViModeNtscHpf1; // D_80097540 -extern UNK_TYPE1 D_80097590; // D_80097590 +extern OSViMode osViModeNtscHpf1; // D_80097540 +extern OSViMode osViModePalLan1; // D_80097590 extern s16 sintable[1024]; // D_800975E0 extern UNK_TYPE1 D_80097DE0; // D_80097DE0 extern UNK_TYPE1 D_80097DE4; // D_80097DE4 @@ -46,33 +46,32 @@ extern OSThread* __osRunQueue; // D_80097E18 extern OSThread* __osActiveQueue; // D_80097E1C extern OSThread* __osRunningThread; // D_80097E20 extern OSThread* __osFaultedThread; // D_80097E24 -extern UNK_TYPE4 __osSiAccessQueueEnabled; // D_80097E30 +extern u32 __osSiAccessQueueEnabled; // D_80097E30 extern UNK_TYPE4 D_80097E40; // D_80097E40 extern u64 osClockRate; // D_80097E50 extern s32 osViClock; // D_80097E58 extern UNK_TYPE4 __osShutdown; // D_80097E5C extern UNK_TYPE4 __OSGlobalIntMask; // D_80097E60 -extern UNK_TYPE4 __osPiDevMgr; // D_80097E70 -extern OSPiHandle* osPiHandleListHead; // D_80097E8C +extern OSDevMgr __osPiDevMgr; // D_80097E70 +extern OSPiHandle* __osPiTable; // D_80097E8C extern UNK_PTR D_80097E90; // D_80097E90 extern UNK_TYPE4 __osPiAccessQueueEnabled; // D_80097EA0 -extern UNK_TYPE1 osViModeNtscHpn1; // D_80097EB0 +extern OSViMode osViModeNtscHpn1; // D_80097EB0 extern UNK_TYPE4 D_80097F00; // D_80097F00 extern UNK_TYPE1 D_80097F04; // D_80097F04 extern UNK_TYPE4 D_80097F10; // D_80097F10 extern char spaces[]; // D_80097F20 -extern char zeros[]; // D_80097F44 +extern char zeroes[]; // D_80097F44 extern OSTimer* __osTimerList; // D_80097F70 extern UNK_TYPE4 D_80097F80; // D_80097F80 -extern UNK_TYPE4 D_80097F90; // D_80097F90 +extern float D_80097F90; // D_80097F90 extern UNK_TYPE1 D_80097FA0; // D_80097FA0 extern UNK_TYPE1 D_80097FA4; // D_80097FA4 extern UNK_TYPE1 D_80097FA5; // D_80097FA5 extern UNK_TYPE4 D_80097FB0; // D_80097FB0 extern OSViMode osViModeNtscLan1; // D_80097FC0 extern OSViMode osViModeMpalLan1; // D_80098010 -extern __OSViContext D_80098060; // D_80098060 -extern UNK_TYPE2 D_80098090; // D_80098090 +extern __OSViContext D_80098060[2]; // D_80098060 extern __OSViContext* __osViCurr; // D_800980C0 extern __OSViContext* __osViNext; // D_800980C4 extern UNK_TYPE4 D_800980D0; // D_800980D0 @@ -256,7 +255,7 @@ extern f64 D_800992F0; // D_800992F0 extern f64 D_800992F8; // D_800992F8 extern char D_80099300[]; // D_80099300 extern char D_80099304[]; // D_80099304 -extern UNK_TYPE1 D_8009930C; // D_8009930C +extern unsigned int D_8009930C[6]; // D_8009930C extern f32 D_80099400; // D_80099400 extern f64 D_80099428; // D_80099428 extern f64 D_80099430; // D_80099430 @@ -314,8 +313,8 @@ extern f32 randLast; // D_8009CD50 extern UNK_TYPE4 heapLockMessageBuffer; // D_8009CD60 extern OSTask tmp_task; // D_8009CD70 extern UNK_TYPE1 D_8009CDB0; // D_8009CDB0 -extern UNK_TYPE1 D_8009CEB0; // D_8009CEB0 -extern UNK_TYPE1 __osSiAccessQueue; // D_8009CEB8 +extern OSMesg siAccessBuf[1]; // D_8009CEB0 +extern OSMesgQueue __osSiAccessQueue; // D_8009CEB8 extern OSPifRam __osContPifRam; // D_8009CED0 extern UNK_TYPE1 D_8009CF0C; // D_8009CF0C extern u8 __osContLastCmd; // D_8009CF10 @@ -325,33 +324,23 @@ extern OSMesg D_8009CF50[1]; // D_8009CF50 extern UNK_TYPE1 D_8009CF60; // D_8009CF60 extern UNK_TYPE4 D_8009CF70; // D_8009CF70 extern UNK_TYPE1 __osThreadSave; // D_8009CF80 -extern UNK_TYPE1 D_8009D130; // D_8009D130 -extern u8 D_8009D134; // D_8009D134 -extern u8 D_8009D135; // D_8009D135 -extern u8 D_8009D136; // D_8009D136 -extern u8 D_8009D137; // D_8009D137 -extern u8 D_8009D138; // D_8009D138 -extern UNK_TYPE1 D_8009D1A8; // D_8009D1A8 -extern u8 D_8009D1AC; // D_8009D1AC -extern u8 D_8009D1AD; // D_8009D1AD -extern u8 D_8009D1AE; // D_8009D1AE -extern u8 D_8009D1AF; // D_8009D1AF -extern u8 D_8009D1B0; // D_8009D1B0 +extern OSPiHandle D_8009D130; // D_8009D130 +extern OSPiHandle D_8009D1A8; // D_8009D1A8 extern OSThread D_8009D220; // D_8009D220 extern u8 piManagerStack[4096]; // D_8009D3D0 extern OSMesgQueue D_8009E3D0; // D_8009E3D0 -extern UNK_TYPE1 D_8009E3E8; // D_8009E3E8 -extern UNK_TYPE1 D_8009E3F0; // D_8009E3F0 +extern OSMesg D_8009E3E8[1]; // D_8009E3E8 +extern OSMesg D_8009E3F0[1]; // D_8009E3F0 extern OSMesgQueue __osPiAccessQueue; // D_8009E3F8 extern UNK_TYPE1 D_8009E410; // D_8009E410 extern __OSEventState __osEventStateTab[16]; // D_8009E510 extern OSTimer D_8009E590; // D_8009E590 extern OSTime __osCurrentTime; // D_8009E5B0 extern u32 __osBaseCounter; // D_8009E5B8 -extern UNK_TYPE4 __osViIntrCount; // D_8009E5BC -extern UNK_TYPE4 __osTimerCounter; // D_8009E5C0 -extern UNK_TYPE1 D_8009E5D0; // D_8009E5D0 -extern OSPiHandle D_8009E610; // D_8009E610 +extern u32 __osViIntrCount; // D_8009E5BC +extern u32 __osTimerCounter; // D_8009E5C0 +extern OSPifRam __osPfsPifRam; // D_8009E5D0 +extern OSPiHandle CartRomHandle; // D_8009E610 extern OSThread viThread; // D_8009E690 extern u8 viThreadStack[4096]; // D_8009E840 extern OSMesgQueue viEventQueue; // D_8009F840 @@ -3689,7 +3678,7 @@ extern char padmgrThreadName[]; // D_801DFD80 extern char graphThreadName[]; // D_801DFD88 extern char D_801DFD90[]; // D_801DFD90 extern char D_801DFD9C[]; // D_801DFD9C -extern UNK_TYPE1 D_801DFDA8; // D_801DFDA8 +extern char D_801DFDA8[]; // D_801DFDA8 extern char D_801DFDE0[]; // D_801DFDE0 extern char D_801DFDFC[]; // D_801DFDFC extern char D_801DFE18[]; // D_801DFE18 diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index c464623c82..97b5ef9d0c 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -2,6 +2,7 @@ SECTIONS { /* Objects with .gptab.data sections error if they are not referenced, for some reason */ /DISCARD/ : { *(.gptab.data) } + /DISCARD/ : { *(.gptab.bss) } boot 0x80080060: { @@ -26,7 +27,7 @@ SECTIONS build/asm/boot_0x800862E0.o(.text) build/asm/boot_0x80086760.o(.text) build/asm/__osMalloc.o(.text) - build/asm/sprintf.o(.text) + build/src/libultra/rmon/sprintf.o(.text) build/asm/boot_0x80087900.o(.text) build/asm/setcause.o(.text) build/src/libultra/os/sendmesg.o(.text) @@ -41,137 +42,141 @@ SECTIONS build/src/libultra/gu/sinf.o(.text) build/src/libultra/gu/sins.o(.text) build/src/libultra/io/sptask.o(.text) - build/asm/ll.o(.text) + build/src/libultra/libc/ll.o(.text) build/asm/exceptasm.o(.text) build/src/libultra/os/thread.o(.text) build/src/libultra/os/destroythread.o(.text) build/asm/boot_0x80089580.o(.text) build/asm/bzero.o(.text) build/asm/boot_0x800896D0.o(.text) - build/asm/siacs.o(.text) + build/src/libultra/io/siacs.o(.text) build/src/libultra/io/controller.o(.text) build/src/libultra/os/createthread.o(.text) - build/asm/contreaddata.o(.text) + build/src/libultra/io/contreaddata.o(.text) build/asm/boot_0x8008A170.o(.text) build/src/libultra/os/virtualtophysical.o(.text) build/asm/getsr.o(.text) build/asm/setsr.o(.text) build/asm/writebackdcache.o(.text) build/asm/initialize.o(.text) - build/asm/vigetnextframebuf.o(.text) + build/src/libultra/io/vigetnextframebuf.o(.text) build/src/libultra/gu/perspective.o(.text) build/src/libultra/io/sprawdma.o(.text) - build/asm/sirawdma.o(.text) + build/src/libultra/io/sirawdma.o(.text) build/asm/boot_0x8008AE20.o(.text) - build/asm/virepeatline.o(.text) - build/asm/sirawread.o(.text) + build/src/libultra/io/virepeatline.o(.text) + build/src/libultra/io/sirawread.o(.text) build/src/libultra/os/getthreadid.o(.text) - build/asm/sptaskyield.o(.text) - build/asm/boot_0x8008AF70.o(.text) + build/src/libultra/io/sptaskyield.o(.text) + build/asm/pfsreadwritefile.o(.text) build/asm/boot_0x8008B3C0.o(.text) build/asm/boot_0x8008B600.o(.text) - build/asm/visetmode.o(.text) + build/src/libultra/io/visetmode.o(.text) build/asm/getconfig.o(.text) build/asm/setconfig.o(.text) build/asm/lookat.o(.text) build/asm/boot_0x8008B9F0.o(.text) build/src/libultra/os/stoptimer.o(.text) build/asm/probetlb.o(.text) - build/asm/pimgr.o(.text) - build/asm/piacs.o(.text) - build/asm/boot_0x8008C260.o(.text) + build/src/libultra/io/pimgr.o(.text) + build/src/libultra/io/piacs.o(.text) + . += 0x10; + build/asm/devmgr.o(.text) + build/asm/boot_0x8008C640.o(.text) + build/src/libultra/io/pirawdma.o(.text) build/asm/boot_0x8008C740.o(.text) build/asm/getcount.o(.text) build/asm/boot_0x8008D2E0.o(.text) - build/src/boot_O1/boot_0x8008D350.o(.text) + build/src/libultra/os/getmemsize.o(.text) build/asm/boot_0x8008D470.o(.text) build/src/libultra/os/seteventmesg.o(.text) build/asm/sqrtf.o(.text) build/asm/boot_0x8008D710.o(.text) build/src/libultra/io/contquery.o(.text) build/asm/lookathil.o(.text) - build/asm/xprintf.o(.text) + build/src/libultra/rmon/xprintf.o(.text) build/asm/boot_0x8008ED30.o(.text) build/asm/unmaptlball.o(.text) - build/asm/pidma.o(.text) + build/src/libultra/io/epidma.o(.text) build/asm/boot_0x8008EED0.o(.text) build/asm/boot_0x8008F100.o(.text) build/src/libultra/libc/string.o(.text) - build/asm/createmesgqueue.o(.text) + build/src/libultra/os/createmesgqueue.o(.text) build/asm/invalicache.o(.text) build/asm/invaldcache.o(.text) - build/asm/timerintr.o(.text) + build/src/libultra/os/timerintr.o(.text) build/asm/boot_0x8008F7D0.o(.text) build/asm/boot_0x8008FA00.o(.text) - build/asm/si.o(.text) + build/src/libultra/io/si.o(.text) build/asm/boot_0x8008FA60.o(.text) build/src/libultra/os/jammesg.o(.text) build/src/libultra/os/setthreadpri.o(.text) build/src/libultra/os/getthreadpri.o(.text) build/asm/boot_0x8008FD00.o(.text) - build/asm/viswapbuf.o(.text) - build/asm/boot_0x8008FEB0.o(.text) + build/src/libultra/io/viswapbuf.o(.text) + build/asm/position.o(.text) build/asm/boot_0x800900C0.o(.text) - build/asm/sptaskyielded.o(.text) + build/src/libultra/io/sptaskyielded.o(.text) build/asm/memcmp.o(.text) - build/asm/gettime.o(.text) - build/asm/rotate.o(.text) + build/src/libultra/os/gettime.o(.text) + build/src/libultra/gu/rotate.o(.text) build/asm/setglobalintmask.o(.text) build/asm/boot_0x800906D0.o(.text) build/asm/boot_0x80090810.o(.text) build/asm/boot_0x80090900.o(.text) build/asm/aisetfreq.o(.text) - build/asm/boot_0x80090C40.o(.text) + build/asm/contramread.o(.text) build/asm/boot_0x80090E70.o(.text) - build/asm/boot_0x800910A0.o(.text) - build/asm/getactivequeue.o(.text) + build/asm/crc.o(.text) + build/src/libultra/os/getactivequeue.o(.text) build/asm/normalize.o(.text) build/asm/setcompare.o(.text) build/asm/getcompare.o(.text) - build/asm/dpgetstat.o(.text) - build/asm/dpsetstat.o(.text) + build/src/libultra/io/dpgetstat.o(.text) + build/src/libultra/io/dpsetstat.o(.text) build/asm/bcopy.o(.text) build/asm/resetglobalintmask.o(.text) build/asm/boot_0x80091630.o(.text) - build/asm/ortho.o(.text) + build/src/libultra/gu/ortho.o(.text) build/asm/interrupt.o(.text) - build/asm/vi.o(.text) + build/src/libultra/io/vi.o(.text) build/asm/viswapcontext.o(.text) - build/asm/pigetcmdq.o(.text) + build/src/libultra/io/pigetcmdq.o(.text) build/asm/cosf.o(.text) build/asm/boot_0x800920B0.o(.text) - build/asm/visetspecial.o(.text) - build/asm/coss.o(.text) - build/asm/settime.o(.text) + build/src/libultra/io/visetspecial.o(.text) + build/src/libultra/gu/coss.o(.text) + build/src/libultra/os/settime.o(.text) build/asm/boot_0x800922C0.o(.text) - build/asm/visetevent.o(.text) + build/src/libultra/gu/visetevent.o(.text) build/asm/boot_0x80092440.o(.text) build/asm/boot_0x80092730.o(.text) - build/asm/boot_0x80092920.o(.text) + build/asm/cartrominit.o(.text) build/asm/boot_0x80092A80.o(.text) build/asm/boot_0x80092C00.o(.text) - build/asm/contsetch.o(.text) + build/src/libultra/io/contsetch.o(.text) build/asm/setfpccsr.o(.text) build/asm/getfpccsr.o(.text) build/asm/boot_0x80092D00.o(.text) build/asm/boot_0x80092EE0.o(.text) build/asm/boot_0x800931F0.o(.text) - build/asm/aigetlen.o(.text) + build/src/libultra/io/aigetlen.o(.text) build/asm/boot_0x80093BB0.o(.text) build/asm/maptlbrdb.o(.text) - build/asm/yieldthread.o(.text) + build/src/libultra/os/yieldthread.o(.text) + . += 0x10; build/asm/boot_0x80093CC0.o(.text) build/asm/getcause.o(.text) - build/asm/boot_0x80093DA0.o(.text) + build/asm/contramwrite.o(.text) build/asm/boot_0x80093FF0.o(.text) - build/asm/settimer.o(.text) + build/src/libultra/os/settimer.o(.text) build/asm/xldtob.o(.text) - build/asm/ldiv.o(.text) + build/src/libultra/libc/ldiv.o(.text) build/asm/xlitob.o(.text) build/src/libultra/io/sirawwrite.o(.text) build/src/libultra/io/spgetstat.o(.text) build/src/libultra/io/spsetstat.o(.text) - . = ALIGN(0x20); /* XXX insert NOPs to pad the file */ + . += 0x10; build/asm/vimgr.o(.text) build/src/libultra/io/vigetcurrcontext.o(.text) build/asm/writebackdcacheall.o(.text) @@ -180,8 +185,8 @@ SECTIONS build/asm/boot_0x80095740.o(.text) build/src/libultra/os/startthread.o(.text) build/src/libultra/io/visetyscale.o(.text) - build/asm/visetxscale.o(.text) - build/asm/llcvt.o(.text) + build/src/libultra/io/visetxscale.o(.text) + build/src/libultra/libc/llcvt.o(.text) build/asm/boot_0x80095C70.o(.text) build/asm/boot_0x80096360.o(.text) build/asm/boot_0x80096410.o(.text) @@ -221,11 +226,11 @@ SECTIONS build/src/libultra/gu/perspective.o(.rodata) build/asm/boot_rodata_0x8008C260.o(.text) build/asm/boot_rodata_lookathil.o(.text) - build/asm/boot_rodata_xprintf.o(.text) + build/src/libultra/rmon/xprintf.o(.rodata) build/asm/boot_rodata_cosf.o(.text) build/asm/boot_rodata___libm_qnan_f.o(.text) build/asm/boot_rodata_xldtob.o(.text) - build/asm/boot_rodata_llcvt.o(.text) + build/src/libultra/libc/llcvt.o(.rodata) build/asm/boot_rodata_build_date.o(.text) boot_rodata_end = .; } diff --git a/src/boot_O2_g3/boot_0x80080060.c b/src/boot_O2_g3/boot_0x80080060.c index ba916f4e24..6989e32589 100644 --- a/src/boot_O2_g3/boot_0x80080060.c +++ b/src/boot_O2_g3/boot_0x80080060.c @@ -3,11 +3,11 @@ void start(void) { StackCheck_Init(&bootStackEntry, (u32)bootStack, (u32)&bootStack[1024], 0, -1, "boot"); - osMemSize = func_8008D350(); + osMemSize = osGetMemSize(); func_800818F4(); osInitialize(); osUnmapTLBAll(); - D_80096B40 = func_80092920(); + D_80096B40 = osCartRomInit(); StackCheck_Init(&idleStackEntry, (u32)idleStack, (u32)&idleStack[1024], 0, 256, "idle"); osCreateThread(&idleOSThread, 1, (osCreateThread_func)Idle_ThreadEntry, 0, &idleStack[1024], 12); osStartThread(&idleOSThread); diff --git a/src/boot_O2_g3/boot_0x800805E0.c b/src/boot_O2_g3/boot_0x800805E0.c index 9c46c4411c..81c7e43616 100644 --- a/src/boot_O2_g3/boot_0x800805E0.c +++ b/src/boot_O2_g3/boot_0x800805E0.c @@ -10,7 +10,7 @@ UNK_RET func_800805E0(UNK_TYPE a0) { osViSetMode(&osViModeMpalLan1); break; case 0: - osViSetMode(&D_80097590); + osViSetMode(&osViModePalLan1); break; case 1: default: diff --git a/src/boot_O2_g3/z_std_dma.c b/src/boot_O2_g3/z_std_dma.c index 3906ddedeb..a7cf044d56 100644 --- a/src/boot_O2_g3/z_std_dma.c +++ b/src/boot_O2_g3/z_std_dma.c @@ -2,7 +2,6 @@ #include s32 Dmamgr_DoDmaTransfer(u32 a0, void* a1, u32 a2) { - u32 spPad; OSIoMesg sp60; OSMesgQueue sp48; OSMesg sp44; diff --git a/src/libultra/gu/coss.c b/src/libultra/gu/coss.c new file mode 100644 index 0000000000..fa7a29faf0 --- /dev/null +++ b/src/libultra/gu/coss.c @@ -0,0 +1,6 @@ +#include +#include + +short coss(unsigned short x) { + return sins(x + 0x4000); +} diff --git a/src/libultra/gu/ortho.c b/src/libultra/gu/ortho.c new file mode 100644 index 0000000000..31ae521ebe --- /dev/null +++ b/src/libultra/gu/ortho.c @@ -0,0 +1,26 @@ +#include +#include + +void guOrthoF(float m[4][4], float l, float r, float b, float t, float n, float f, float scale) { + int i; + int j; + guMtxIdentF(m); + m[0][0] = 2 / (r - l); + m[1][1] = 2 / (t - b); + m[2][2] = -2 / (f - n); + m[3][0] = -(r + l) / (r - l); + m[3][1] = -(t + b) / (t - b); + m[3][2] = -(f + n) / (f - n); + m[3][3] = 1; + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + m[i][j] *= scale; + } + } +} + +void guOrtho(Mtx *m, float l, float r, float b, float t, float n, float f, float scale) { + float mf[4][4]; + guOrthoF(mf, l, r, b, t, n, f, scale); + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/rotate.c b/src/libultra/gu/rotate.c new file mode 100644 index 0000000000..0975a4ac6e --- /dev/null +++ b/src/libultra/gu/rotate.c @@ -0,0 +1,52 @@ +#include +#include + +void guRotateF(float m[4][4], float a, float x, float y, float z) { +// TODO move in .data section +// static float dtor; + float sine; + float cosine; + float ab; + float bc; + float ca; + float t; + float xs; + float ys; + float zs; + + guNormalize(&x, &y, &z); + + a = a * D_80097F90; + + sine = __sinf(a); + cosine = __cosf(a); + + ab = x * y * (1 - cosine); + bc = y * z * (1 - cosine); + ca = z * x * (1 - cosine); + + guMtxIdentF(m); + + xs = x * sine; + ys = y * sine; + zs = z * sine; + + t = x * x; + m[0][0] = (1 - t) * cosine + t; + m[2][1] = bc - xs; + m[1][2] = bc + xs; + t = y * y; + m[1][1] = (1 - t) * cosine + t; + m[2][0] = ca + ys; + m[0][2] = ca - ys; + t = z * z; + m[2][2] = (1 - t) * cosine + t; + m[1][0] = ab - zs; + m[0][1] = ab + zs; +} + +void guRotate(Mtx *m, float a, float x, float y, float z) { + float mf[4][4]; + guRotateF(mf, a, x, y, z); + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/visetevent.c b/src/libultra/gu/visetevent.c new file mode 100644 index 0000000000..954965836e --- /dev/null +++ b/src/libultra/gu/visetevent.c @@ -0,0 +1,12 @@ +#include +#include + +void osViSetEvent(OSMesgQueue *mq, OSMesg m, u32 retraceCount) { + register u32 saveMask = __osDisableInt(); + + __osViNext->msgq = mq; + __osViNext->msg = m; + __osViNext->retraceCount = retraceCount; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/aigetlen.c b/src/libultra/io/aigetlen.c new file mode 100644 index 0000000000..c992c5dab1 --- /dev/null +++ b/src/libultra/io/aigetlen.c @@ -0,0 +1,6 @@ +#include +#include + +u32 osAiGetLength(void) { + return *(u32*)0xA4500004; +} diff --git a/src/libultra/io/contreaddata.c b/src/libultra/io/contreaddata.c new file mode 100644 index 0000000000..80945047f5 --- /dev/null +++ b/src/libultra/io/contreaddata.c @@ -0,0 +1,64 @@ +#include +#include + +s32 osContStartReadData(OSMesgQueue* mq) { + s32 ret; + int i; + + __osSiGetAccess(); + + if (__osContLastCmd != 1) { + __osPackReadData(); + __osSiRawStartDma(1, &__osContPifRam); + osRecvMesg(mq, NULL, 1); + } + + ret = __osSiRawStartDma(0, &__osContPifRam); + __osContLastCmd = 1; + + __osSiRelAccess(); + + return ret; +} + +void osContGetReadData(OSContPad* data) { + u8* ptr; + __OSContReadFormat readformat; + int i; + + ptr = (u8*)__osContPifRam.ramarray; + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContReadFormat), data++) { + readformat = *(__OSContReadFormat*)ptr; + data->errno = (readformat.rxsize & 0xc0) >> 4; + if (data->errno == 0) { + data->button = readformat.button; + data->stick_x = readformat.stick_x; + data->stick_y = readformat.stick_y; + } + }; +} + +void __osPackReadData() { + u8* ptr; + __OSContReadFormat readformat; + int i; + + ptr = (u8*)__osContPifRam.ramarray; + for (i = 0; i < 0xF; i++) { + __osContPifRam.ramarray[i] = 0; + } + + __osContPifRam.pifstatus = 1; + readformat.dummy = 255; + readformat.txsize = 1; + readformat.rxsize = 4; + readformat.cmd = 1; + readformat.button = 65535; + readformat.stick_x = -1; + readformat.stick_y = -1; + for (i = 0; i < __osMaxControllers; i++) { + *(__OSContReadFormat*)ptr = readformat; + ptr+=sizeof(__OSContReadFormat); + } + *ptr = 254; +} \ No newline at end of file diff --git a/src/libultra/io/contsetch.c b/src/libultra/io/contsetch.c new file mode 100644 index 0000000000..15aec7f4cc --- /dev/null +++ b/src/libultra/io/contsetch.c @@ -0,0 +1,16 @@ +#include +#include + +s32 osContSetCh(u8 ch) { + __osSiGetAccess(); + + if (4 < ch) { + __osMaxControllers = 4; + } else { + __osMaxControllers = ch; + } + __osContLastCmd = -2; + + __osSiRelAccess(); + return 0; +} diff --git a/src/libultra/io/dpgetstat.c b/src/libultra/io/dpgetstat.c new file mode 100644 index 0000000000..66e7493fc2 --- /dev/null +++ b/src/libultra/io/dpgetstat.c @@ -0,0 +1,6 @@ +#include +#include + +u32 osDpGetStatus(void) { + return *(u32*)0xA410000C; +} diff --git a/src/libultra/io/dpsetstat.c b/src/libultra/io/dpsetstat.c new file mode 100644 index 0000000000..7dcb8ed780 --- /dev/null +++ b/src/libultra/io/dpsetstat.c @@ -0,0 +1,6 @@ +#include +#include + +void osDpSetStatus(u32 data) { + *(u32*)0xA410000C = data; +} diff --git a/src/libultra/io/epidma.c b/src/libultra/io/epidma.c new file mode 100644 index 0000000000..98fa6667e6 --- /dev/null +++ b/src/libultra/io/epidma.c @@ -0,0 +1,25 @@ +#include +#include + +s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { + register s32 result; + + if (!__osPiDevMgr.active) { + return -1; + } + + mb->piHandle = pihandle; + + if (direction == 0) { + mb->hdr.type = 15; + } else { + mb->hdr.type = 16; + } + + if (mb->hdr.pri == 1) { + result = osJamMesg(osPiGetCmdQueue(), mb, 0); + } else { + result = osSendMesg(osPiGetCmdQueue(), mb, 0); + } + return result; +} diff --git a/src/libultra/io/piacs.c b/src/libultra/io/piacs.c new file mode 100644 index 0000000000..c3d995205b --- /dev/null +++ b/src/libultra/io/piacs.c @@ -0,0 +1,20 @@ +#include +#include + +void __osPiCreateAccessQueue(void) { + __osPiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osPiAccessQueue, D_8009E3F0, 1); + osSendMesg(&__osPiAccessQueue, NULL, 0); +} + +void __osPiGetAccess(void) { + OSMesg dummyMesg; + if (!__osPiAccessQueueEnabled) { + __osPiCreateAccessQueue(); + } + osRecvMesg(&__osPiAccessQueue, &dummyMesg, 1); +} + +void __osPiRelAccess(void) { + osSendMesg(&__osPiAccessQueue, NULL, 0); +} diff --git a/src/libultra/io/pigetcmdq.c b/src/libultra/io/pigetcmdq.c new file mode 100644 index 0000000000..2e6048467e --- /dev/null +++ b/src/libultra/io/pigetcmdq.c @@ -0,0 +1,10 @@ +#include +#include + +OSMesgQueue* osPiGetCmdQueue(void) { + if (!__osPiDevMgr.active) { + return NULL; + } + + return __osPiDevMgr.cmdQueue; +} diff --git a/src/libultra/io/pimgr.c b/src/libultra/io/pimgr.c new file mode 100644 index 0000000000..e350923ab1 --- /dev/null +++ b/src/libultra/io/pimgr.c @@ -0,0 +1,37 @@ +#include +#include + +void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) { + u32 savedMask; + OSPri oldPri; + OSPri myPri; + + if (!__osPiDevMgr.active) { + osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt); + osCreateMesgQueue(&D_8009E3D0, D_8009E3E8, 1); + if (!__osPiAccessQueueEnabled) { + __osPiCreateAccessQueue(); + } + osSetEventMesg(8, &D_8009E3D0, (OSMesg) 0x22222222); + oldPri = -1; + myPri = osGetThreadPri(NULL); + if (myPri < pri) { + oldPri = myPri; + osSetThreadPri(NULL, pri); + } + savedMask = __osDisableInt(); + __osPiDevMgr.active = 1; + __osPiDevMgr.thread = &D_8009D220; + __osPiDevMgr.cmdQueue = cmdQ; + __osPiDevMgr.evtQueue = &D_8009E3D0; + __osPiDevMgr.acsQueue = &__osPiAccessQueue; + __osPiDevMgr.dma = (s32(*)(void))osPiRawStartDma; + __osPiDevMgr.unk18 = (s32(*)(void))func_800900C0; + osCreateThread(&D_8009D220, 0, __osDevMgrMain, (void *) &__osPiDevMgr, &piManagerStack[4096], pri); + osStartThread(&D_8009D220); + __osRestoreInt(savedMask); + if (oldPri != -1) { + osSetThreadPri(NULL, oldPri); + } + } +} diff --git a/src/libultra/io/pirawdma.c b/src/libultra/io/pirawdma.c new file mode 100644 index 0000000000..0cacac84b7 --- /dev/null +++ b/src/libultra/io/pirawdma.c @@ -0,0 +1,27 @@ +#include +#include + +s32 osPiRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { + register int stat; + + stat = *(vu32*)0xA4600010; + while (stat & (2 | 1)) { + stat = *(vu32*)0xA4600010; + } + + *(u32*)0xA4600000 = osVirtualToPhysical(dramAddr); + + *(u32*)0xA4600004 = ((osRomBase | devAddr) & 0x1fffffff); + + switch (direction) { + case 0: + *(u32*)0xA460000C = size - 1; + break; + case 1: + *(u32*)0xA4600008 = size - 1; + break; + default: + return -1; + } + return 0; +} diff --git a/src/libultra/io/si.c b/src/libultra/io/si.c new file mode 100644 index 0000000000..ca736a520f --- /dev/null +++ b/src/libultra/io/si.c @@ -0,0 +1,12 @@ +#include +#include + +int __osSiDeviceBusy() { + register u32 status; + status = *(u32*)0xA4800018; + if (status & 3) { + return 1; + } else { + return 0; + } +} diff --git a/src/libultra/io/siacs.c b/src/libultra/io/siacs.c new file mode 100644 index 0000000000..b484a829e7 --- /dev/null +++ b/src/libultra/io/siacs.c @@ -0,0 +1,20 @@ +#include +#include + +void __osSiCreateAccessQueue() { + __osSiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, 1); + osSendMesg(&__osSiAccessQueue, NULL, 0); +} + +void __osSiGetAccess(void) { + OSMesg dummyMesg; + if (!__osSiAccessQueueEnabled) { + __osSiCreateAccessQueue(); + } + osRecvMesg(&__osSiAccessQueue, &dummyMesg, 1); +} + +void __osSiRelAccess(void) { + osSendMesg(&__osSiAccessQueue, NULL, 0); +} diff --git a/src/libultra/io/sirawdma.c b/src/libultra/io/sirawdma.c new file mode 100644 index 0000000000..f4b3bc16e6 --- /dev/null +++ b/src/libultra/io/sirawdma.c @@ -0,0 +1,25 @@ +#include +#include + +s32 __osSiRawStartDma(s32 direction, void* dramAddr) { + if ((*(u32*)0xA4800018 & 0x3) != 0) { + return -1; + } + + if (direction == 1) { + osWritebackDCache(dramAddr, 64); + } + + *(u32*)0xA4800000 = osVirtualToPhysical(dramAddr); + + if (direction == 0) { + *(u32*)0xA4800004 = 0x1FC007C0; + } else { + *(u32*)0xA4800010 = 0x1FC007C0; + } + + if (direction == 0) { + osInvalDCache(dramAddr, 64); + } + return 0; +} diff --git a/src/libultra/io/sirawread.c b/src/libultra/io/sirawread.c new file mode 100644 index 0000000000..3a2968680b --- /dev/null +++ b/src/libultra/io/sirawread.c @@ -0,0 +1,10 @@ +#include +#include + +s32 __osSiRawReadIo(u32 devAddr, u32* data) { + if (__osSiDeviceBusy()) { + return -1; + } + *data = *(u32*)(devAddr | 0xA0000000); + return 0; +} diff --git a/src/libultra/io/sptaskyield.c b/src/libultra/io/sptaskyield.c new file mode 100644 index 0000000000..52b78da554 --- /dev/null +++ b/src/libultra/io/sptaskyield.c @@ -0,0 +1,6 @@ +#include +#include + +void osSpTaskYield(void) { + __osSpSetStatus(0x400); +} diff --git a/src/libultra/io/sptaskyielded.c b/src/libultra/io/sptaskyielded.c new file mode 100644 index 0000000000..cfc297dba5 --- /dev/null +++ b/src/libultra/io/sptaskyielded.c @@ -0,0 +1,18 @@ +#include +#include + +OSYieldResult osSpTaskYielded(OSTask* task) { + s32 status; + OSYieldResult result; + status = __osSpGetStatus(); + if (status & 0x100) { + result = 1; + } else { + result = 0; + } + if (status & 0x80) { + task->t.flags |= result; + task->t.flags &= ~(2); + } + return result; +} diff --git a/src/libultra/io/vi.c b/src/libultra/io/vi.c new file mode 100644 index 0000000000..f7d6871f06 --- /dev/null +++ b/src/libultra/io/vi.c @@ -0,0 +1,28 @@ +#include +#include + +void __osViInit(void) { + bzero(D_80098060, sizeof(D_80098060)); + __osViCurr = &D_80098060[0]; + __osViNext = &D_80098060[1]; + __osViNext->retraceCount = 1; + __osViCurr->retraceCount = 1; + __osViNext->framep = (void*)0x80000000; + __osViCurr->framep = (void*)0x80000000; + + if (osTvType == 0) { + __osViNext->modep = &osViModePalLan1; + } else if (osTvType == 2) { + __osViNext->modep = &osViModeMpalLan1; + } else { + __osViNext->modep = &osViModeNtscLan1; + } + + __osViNext->state = 0x20; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + + while (*(vu32*)0xA4400010 > 10); + *(vu32*)0xA4400000 = 0; + + __osViSwapContext(); +} diff --git a/src/libultra/io/vigetnextframebuf.c b/src/libultra/io/vigetnextframebuf.c new file mode 100644 index 0000000000..ecc69a4498 --- /dev/null +++ b/src/libultra/io/vigetnextframebuf.c @@ -0,0 +1,15 @@ +#include +#include + +void* osViGetNextFramebuffer(void) { + register u32 saveMask; + void* framep; + + saveMask = __osDisableInt(); + + framep = __osViNext->framep; + + __osRestoreInt(saveMask); + + return framep; +} diff --git a/src/libultra/io/virepeatline.c b/src/libultra/io/virepeatline.c new file mode 100644 index 0000000000..3bdc408eb1 --- /dev/null +++ b/src/libultra/io/virepeatline.c @@ -0,0 +1,16 @@ +#include +#include + +void osViRepeatLine(u8 active) { + register u32 saveMask; + + saveMask = __osDisableInt(); + + if (active) { + __osViNext->state |= 0x20; + } else { + __osViNext->state &= 0xffdf; + } + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetmode.c b/src/libultra/io/visetmode.c new file mode 100644 index 0000000000..2ba96ad1c7 --- /dev/null +++ b/src/libultra/io/visetmode.c @@ -0,0 +1,14 @@ +#include +#include + +void osViSetMode(OSViMode* modep) { + register u32 saveMask; + + saveMask = __osDisableInt(); + + __osViNext->modep = modep; + __osViNext->state = 1; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetspecial.c b/src/libultra/io/visetspecial.c new file mode 100644 index 0000000000..9a893c2512 --- /dev/null +++ b/src/libultra/io/visetspecial.c @@ -0,0 +1,39 @@ +#include +#include + +void osViSetSpecialFeatures(u32 func) { + register u32 saveMask = __osDisableInt(); + + if (func & 1) { + __osViNext->control |= 8; + } + if (func & 2) { + __osViNext->control &= ~8; + } + if (func & 4) { + __osViNext->control |= 4; + } + if (func & 8) { + + __osViNext->control &= ~4; + } + if (func & 0x10) { + + __osViNext->control |= 0x10; + } + if (func & 0x20) { + + __osViNext->control &= ~0x10; + } + if (func & 0x40) { + __osViNext->control |= 0x10000; + __osViNext->control &= ~0x300; + } + if (func & 0x80) { + __osViNext->control &= ~0x10000; + __osViNext->control |= __osViNext->modep->comRegs.ctrl & 0x300; + } + __osViNext->state |= 8; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetxscale.c b/src/libultra/io/visetxscale.c new file mode 100644 index 0000000000..c7720c6624 --- /dev/null +++ b/src/libultra/io/visetxscale.c @@ -0,0 +1,18 @@ +#include +#include + +void osViSetXScale(f32 value) { + register u32 nomValue; + register u32 saveMask; + + saveMask = __osDisableInt(); + + __osViNext->x.factor = value; + + __osViNext->state |= 0x2; + + nomValue = __osViNext->modep->comRegs.xScale & 0xfff; + __osViNext->x.scale = (u32)(__osViNext->x.factor * nomValue) & 0xFFF; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetyscale.c b/src/libultra/io/visetyscale.c index facaa411bd..eee837769c 100644 --- a/src/libultra/io/visetyscale.c +++ b/src/libultra/io/visetyscale.c @@ -3,12 +3,12 @@ #include #include -void osViSetYScale(f32 f12) { +void osViSetYScale(f32 value) { register u32 saveMask; saveMask = __osDisableInt(); - __osViNext->y.factor = f12; + __osViNext->y.factor = value; __osViNext->state |= 0x4; diff --git a/src/libultra/io/viswapbuf.c b/src/libultra/io/viswapbuf.c new file mode 100644 index 0000000000..68524f71d2 --- /dev/null +++ b/src/libultra/io/viswapbuf.c @@ -0,0 +1,12 @@ +#include +#include + +void osViSwapBuffer(void* frameBufPtr) { + + u32 saveMask = __osDisableInt(); + + __osViNext->framep = frameBufPtr; + __osViNext->state |= 0x10; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/libc/ldiv.c b/src/libultra/libc/ldiv.c new file mode 100644 index 0000000000..affe5da003 --- /dev/null +++ b/src/libultra/libc/ldiv.c @@ -0,0 +1,28 @@ +#include +#include + +ldiv_t ldiv(long numer, long denom) { + ldiv_t val; + + val.quot = numer / denom; + val.rem = numer - denom * val.quot; + if (val.quot < 0 && val.rem > 0) { + val.quot++; + val.rem -= denom; + } + + return val; +} + +lldiv_t lldiv(long long numer, long long denom) { + lldiv_t val; + + val.quot = numer / denom; + val.rem = numer - denom * val.quot; + if (val.quot < 0 && val.rem > 0) { + val.quot++; + val.rem -= denom; + } + + return val; +} diff --git a/src/libultra/libc/ll.c b/src/libultra/libc/ll.c new file mode 100644 index 0000000000..359633ee21 --- /dev/null +++ b/src/libultra/libc/ll.c @@ -0,0 +1,47 @@ +#include +#include + +long long __ull_rshift(unsigned long long left, unsigned long long right) { + return left >> right; +} + +unsigned long long __ull_rem(unsigned long long left, unsigned long long right) { + return left % right; +} + +unsigned long long __ull_div(unsigned long long left, unsigned long long right) { + return left / right; +} + +long long __ll_lshift(long long left, long long right) { + return left << right; +} + +long long __ll_rem(long long left, unsigned long long right) { + return left % right; +} + +long long __ll_div(long long left, long long right) { + return left / right; +} + +long long __ll_mul(long long left, long long right) { + return left * right; +} + +void __ull_divremi(unsigned long long *quotient, unsigned long long *remainder, unsigned long long dividend, unsigned short divisor) { + *quotient = dividend / divisor; + *remainder = dividend % divisor; +} + +long long __ll_mod(long long left, long long right) { + long long rem = left % right; + if ((rem < 0 && right > 0) || (rem > 0 && right < 0)) { + rem += right; + } + return rem; +} + +long long __ll_rshift(long long left, long long right) { + return left >> right; +} diff --git a/src/libultra/libc/llcvt.c b/src/libultra/libc/llcvt.c new file mode 100644 index 0000000000..eeb472781a --- /dev/null +++ b/src/libultra/libc/llcvt.c @@ -0,0 +1,34 @@ +#include +#include + +long long __d_to_ll(double d) { + return d; +} + +long long __f_to_ll(float f) { + return f; +} + +unsigned long long __d_to_ull(double d) { + return d; +} + +unsigned long long __f_to_ull(float f) { + return f; +} + +double __ll_to_d(long long s) { + return s; +} + +float __ll_to_f(long long s) { + return s; +} + +double __ull_to_d(unsigned long long u) { + return u; +} + +float __ull_to_f(unsigned long long u) { + return u; +} diff --git a/src/libultra/os/createmesgqueue.c b/src/libultra/os/createmesgqueue.c new file mode 100644 index 0000000000..960a44ecaa --- /dev/null +++ b/src/libultra/os/createmesgqueue.c @@ -0,0 +1,11 @@ +#include +#include + +void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msq, s32 count) { + mq->mtqueue = (OSThread *)&__osThreadTail; + mq->fullqueue = (OSThread *)&__osThreadTail; + mq->validCount = 0; + mq->first = 0; + mq->msgCount = count; + mq->msg = msq; +} diff --git a/src/libultra/os/getactivequeue.c b/src/libultra/os/getactivequeue.c new file mode 100644 index 0000000000..d5a08be5d0 --- /dev/null +++ b/src/libultra/os/getactivequeue.c @@ -0,0 +1,6 @@ +#include +#include + +OSThread* __osGetActiveQueue(void){ + return __osActiveQueue; +} diff --git a/src/boot_O1/boot_0x8008D350.c b/src/libultra/os/getmemsize.c similarity index 96% rename from src/boot_O1/boot_0x8008D350.c rename to src/libultra/os/getmemsize.c index 2866736541..7514927b56 100644 --- a/src/boot_O1/boot_0x8008D350.c +++ b/src/libultra/os/getmemsize.c @@ -1,7 +1,7 @@ #include #include -u32 func_8008D350(void) { +u32 osGetMemSize(void) { u32* spC; u32 sp8; u32 sp4; diff --git a/src/libultra/os/gettime.c b/src/libultra/os/gettime.c new file mode 100644 index 0000000000..a9193d6362 --- /dev/null +++ b/src/libultra/os/gettime.c @@ -0,0 +1,19 @@ +#include +#include + +OSTime osGetTime(void) { + u32 CurrentCount; + u32 elapseCount; + OSTime sp28; + register u32 savedMask; + + savedMask = __osDisableInt(); + + CurrentCount = osGetCount(); + elapseCount = CurrentCount - __osBaseCounter; + sp28 = __osCurrentTime; + + __osRestoreInt(savedMask); + + return elapseCount + sp28; +} diff --git a/src/libultra/os/initialize.c b/src/libultra/os/initialize.c index e063e351ff..86e484a7e8 100644 --- a/src/libultra/os/initialize.c +++ b/src/libultra/os/initialize.c @@ -2,16 +2,16 @@ #include void func_8008A660(void) { - D_8009D134 = 7; - D_8009D135 = *(u32*)0xA4600014; - D_8009D138 = *(u32*)0xA4600018; - D_8009D136 = *(u32*)0xA460001C; - D_8009D137 = *(u32*)0xA4600020; - D_8009D1AC = 7; - D_8009D1AD = *(u32*)0xA4600024; - D_8009D1B0 = *(u32*)0xA4600028; - D_8009D1AE = *(u32*)0xA460002C; - D_8009D1AF = *(u32*)0xA4600030; + D_8009D130.type = 7; + D_8009D130.latency = *(u32*)0xA4600014; + D_8009D130.pageSize = *(u32*)0xA4600018; + D_8009D130.relDuration = *(u32*)0xA460001C; + D_8009D130.pulse = *(u32*)0xA4600020; + D_8009D1A8.type = 7; + D_8009D1A8.latency = *(u32*)0xA4600024; + D_8009D1A8.pageSize = *(u32*)0xA4600028; + D_8009D1A8.relDuration = *(u32*)0xA460002C; + D_8009D1A8.pulse = *(u32*)0xA4600030; } u64 D_80097E50; // this has to be defined in this file for func_8008A6FC to match diff --git a/src/libultra/os/settime.c b/src/libultra/os/settime.c new file mode 100644 index 0000000000..a7c789ab59 --- /dev/null +++ b/src/libultra/os/settime.c @@ -0,0 +1,6 @@ +#include +#include + +void osSetTime(OSTime ticks) { + __osCurrentTime = ticks; +} diff --git a/src/libultra/os/settimer.c b/src/libultra/os/settimer.c new file mode 100644 index 0000000000..bf0a0f94c4 --- /dev/null +++ b/src/libultra/os/settimer.c @@ -0,0 +1,42 @@ +#include +#include + +int osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg) { + OSTime tim; + OSTimer* spC; + u32 sp14; + u32 sp10; + u32 saveMask; + + t->next = NULL; + t->prev = NULL; + t->interval = interval; + if (value != 0) { + t->value = value; + } else { + t->value = interval; + } + t->mq = mq; + t->msg = msg; + + saveMask = __osDisableInt(); + + if (__osTimerList->next != __osTimerList) { + if (0); + spC = __osTimerList->next; + sp14 = osGetCount(); + sp10 = sp14 - __osTimerCounter; + if (sp10 < spC->value) { + spC->value -= sp10; + } else { + spC->value = 1; + } + } + + tim = __osInsertTimer(t); + __osSetTimerIntr(__osTimerList->next->value); + + __osRestoreInt(saveMask); + + return 0; +} diff --git a/src/libultra/os/timerintr.c b/src/libultra/os/timerintr.c new file mode 100644 index 0000000000..c9f84dac58 --- /dev/null +++ b/src/libultra/os/timerintr.c @@ -0,0 +1,98 @@ +#include +#include + +OSTime __osCurrentTime; +u32 __osBaseCounter; +u32 __osViIntrCount; +u32 __osTimerCounter; + +void __osTimerServicesInit(void) { + __osCurrentTime = 0; + __osBaseCounter = 0; + __osViIntrCount = 0; + __osTimerList->prev = __osTimerList; + __osTimerList->next = __osTimerList->prev; + __osTimerList->value = 0; + __osTimerList->interval = __osTimerList->value; + __osTimerList->mq = NULL; + __osTimerList->msg = NULL; +} + +void __osTimerInterrupt(void) { + OSTimer* t; + u32 count; + u32 elapsed_cycles; + if (__osTimerList->next == __osTimerList) { + return; + } + while (1) { + t = __osTimerList->next; + if (t == __osTimerList) { + __osSetCompare(0); + __osTimerCounter = 0; + break; + } + count = osGetCount(); + elapsed_cycles = count - __osTimerCounter; + __osTimerCounter = count; + if (elapsed_cycles < t->value) { + t->value -= elapsed_cycles; + __osSetTimerIntr(t->value); + return; + } else { + t->prev->next = t->next; + t->next->prev = t->prev; + t->next = NULL; + t->prev = NULL; + if (t->mq != NULL) { + osSendMesg(t->mq, t->msg, 0); + } + if (t->interval != 0) { + t->value = t->interval; + __osInsertTimer(t); + } + } + } +} + +void __osSetTimerIntr(OSTime tim) { + OSTime NewTime; + u32 savedMask; + + if (tim < 468) { + tim = 468; + } + + savedMask = __osDisableInt(); + + __osTimerCounter = osGetCount(); + NewTime = tim + __osTimerCounter; + __osSetCompare(NewTime); + + __osRestoreInt(savedMask); +} + +OSTime __osInsertTimer(OSTimer* t) { + OSTimer* timep; + OSTime tim; + u32 savedMask; + + savedMask = __osDisableInt(); + + for (timep = __osTimerList->next, tim = t->value; timep != __osTimerList && tim > timep->value; + tim -= timep->value, timep = timep->next) { + ; + } + t->value = tim; + if (timep != __osTimerList) { + timep->value -= tim; + } + t->next = timep; + t->prev = timep->prev; + timep->prev->next = t; + timep->prev = t; + + __osRestoreInt(savedMask); + + return tim; +} diff --git a/src/libultra/os/yieldthread.c b/src/libultra/os/yieldthread.c new file mode 100644 index 0000000000..1db1ca2068 --- /dev/null +++ b/src/libultra/os/yieldthread.c @@ -0,0 +1,11 @@ +#include +#include + +void osYieldThread(void) { + register u32 saveMask = __osDisableInt(); + + __osRunningThread->state = 2; + __osEnqueueAndYield(&__osRunQueue); + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/rmon/sprintf.c b/src/libultra/rmon/sprintf.c new file mode 100644 index 0000000000..68aa4ac415 --- /dev/null +++ b/src/libultra/rmon/sprintf.c @@ -0,0 +1,26 @@ +#include +#include + +void* proutSprintf(void* dst, char* fmt, size_t size) { + return (char*)memcpy(dst, fmt, size) + size; +} + +int vsprintf(char* dst, char* fmt, va_list args) { + int ans = _Printf(&proutSprintf, dst, fmt, args); + if (ans > -1) { + dst[ans] = 0; + } + return ans; +} + +int sprintf(char* dst, char* fmt, ...) { + int ans; + va_list ap; + va_start(ap, fmt); + + ans = _Printf(&proutSprintf, dst, fmt, ap); + if (ans > -1) { + dst[ans] = 0; + } + return ans; +} diff --git a/src/libultra/rmon/xprintf.c b/src/libultra/rmon/xprintf.c new file mode 100644 index 0000000000..9efbddaae4 --- /dev/null +++ b/src/libultra/rmon/xprintf.c @@ -0,0 +1,233 @@ +#include +#include + +#define ATOI(i, a) \ + for (i = 0; *a >= '0' && *a <= '9'; a++) \ + if (i < 999) \ + i = *a + i * 10 - '0'; +#define _PROUT(fmt, _size) \ + if (_size > 0) { \ + arg = (void*)pfn(arg, fmt, _size); \ + if (arg != 0) \ + x.nchar += _size; \ + else \ + return x.nchar; \ + } +#define _PAD(m, src, extracond) \ + if (extracond && m > 0) { \ + int i; \ + int j; \ + for (j = m; j > 0; j -= i) { \ + if ((u32) j > 32) \ + i = 32; \ + else \ + i = j; \ + _PROUT(src, i); \ + } \ + } + +#define FLAGS_SPACE 1 +#define FLAGS_PLUS 2 +#define FLAGS_MINUS 4 +#define FLAGS_HASH 8 +#define FLAGS_ZERO 16 + +// TODO .data section should be included after boot .data is split +//char spaces[] = " "; +//char zeroes[] = "00000000000000000000000000000000"; + +int _Printf(printf_func pfn, void* arg, char* fmt, va_list ap) { + _Pft x; + x.nchar = 0; + while (1) { + unsigned char* s; + unsigned char c; + unsigned char* t; + + static const char fchar[] = " +-#0"; + static const u32 fbit[] = { FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0 }; + + unsigned char ac[0x20]; + + s = fmt; + while ((c = *s) != 0 && c != '%') { + s++; + } + _PROUT(fmt, s - fmt); + if (c == 0) { + return x.nchar; + } + fmt = (char *) ++s; + x.flags = 0; + // TODO the cast isn't necessary because strchr should take it in as const, but it currently doesn't + for (; (t = strchr((char*)fchar, *s)) != NULL; s++) { + x.flags |= fbit[t - fchar]; + } + if (*s == '*') { + x.width = va_arg(ap, s32); + if (x.width < 0) { + x.width = -x.width; + x.flags |= FLAGS_MINUS; + } + s++; + } else { + ATOI(x.width, s); + } + if (*s != '.') { + x.prec = -1; + } else { + s++; + if (*s == '*') { + x.prec = va_arg(ap, s32); + s++; + } else { + ATOI(x.prec, s); + } + } + if (strchr("hlL", *s) != NULL) { + x.qual = *s++; + } else { + x.qual = 0; + } + + if (x.qual == 'l' && *s == 'l') { + x.qual = 'L'; + s++; + } + _Putfld(&x, &ap, *s, ac); + x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + + x.n2 + x.nz2; + _PAD(x.width, spaces, !(x.flags & FLAGS_MINUS)); + _PROUT((char *) ac, x.n0); + _PAD(x.nz0, zeroes, 1); + _PROUT(x.s, x.n1); + _PAD(x.nz1, zeroes, 1); + _PROUT((char *) (&x.s[x.n1]), x.n2) + _PAD(x.nz2, zeroes, 1); + _PAD(x.width, spaces, x.flags & FLAGS_MINUS); + fmt = (char *) s + 1; + } +} + +void _Putfld(_Pft* px, va_list* pap, unsigned char code, unsigned char* ac) { + px->n0 = px->nz0 = px->n1 = px->nz1 = px->n2 = + px->nz2 = 0; + + switch (code) { + + case 'c': + ac[px->n0++] = va_arg(*pap, u32); + break; + + case 'd': + case 'i': + if (px->qual == 'l') { + px->v.ll = va_arg(*pap, s32); + } else if (px->qual == 'L') { + px->v.ll = va_arg(*pap, s64); + } else { + px->v.ll = va_arg(*pap, s32); + } + + if (px->qual == 'h') { + px->v.ll = (s16) px->v.ll; + } + + if (px->v.ll < 0) { + ac[px->n0++] = '-'; + } else if (px->flags & FLAGS_PLUS) { + ac[px->n0++] = '+'; + } else if (px->flags & FLAGS_SPACE) { + ac[px->n0++] = ' '; + } + + px->s = (char *) &ac[px->n0]; + + _Litob(px, code); + break; + + case 'x': + case 'X': + case 'u': + case 'o': + if (px->qual == 'l') { + px->v.ll = va_arg(*pap, s32); + } else if (px->qual == 'L') { + px->v.ll = va_arg(*pap, s64); + } else { + px->v.ll = va_arg(*pap, s32); + } + + if (px->qual == 'h') { + px->v.ll = (u16) px->v.ll; + } else if (px->qual == 0) { + px->v.ll = (u32) px->v.ll; + } + + if (px->flags & FLAGS_HASH) { + ac[px->n0++] = '0'; + if (code == 'x' || code == 'X') { + + ac[px->n0++] = code; + } + } + px->s = (char *) &ac[px->n0]; + _Litob(px, code); + break; + + case 'e': + case 'f': + case 'g': + case 'E': + case 'G': + px->v.ld = px->qual == 'L' ? va_arg(*pap, f64) : va_arg(*pap, f64); + + if (*(u16*)&px->v.ll & 0x8000) { + ac[px->n0++] = '-'; + } else { + if (px->flags & FLAGS_PLUS) { + ac[px->n0++] = '+'; + } else if (px->flags & FLAGS_SPACE) { + ac[px->n0++] = ' '; + } + } + + px->s = (char *) &ac[px->n0]; + _Ldtob(px, code); + break; + + case 'n': + if (px->qual == 'h') { + *(va_arg(*pap, u16 *)) = px->nchar; + } else if (px->qual == 'l') { + *va_arg(*pap, u32 *) = px->nchar; + } else if (px->qual == 'L') { + *va_arg(*pap, u64 *) = px->nchar; + } else { + *va_arg(*pap, u32 *) = px->nchar; + } + break; + + case 'p': + px->v.ll = (long) va_arg(*pap, void *); + px->s = (char *) &ac[px->n0]; + _Litob(px, 'x'); + break; + + case 's': + px->s = va_arg(*pap, char *); + px->n1 = strlen(px->s); + if (px->prec >= 0 && px->n1 > px->prec) { + px->n1 = px->prec; + } + break; + + case '%': + ac[px->n0++] = '%'; + break; + + default: + ac[px->n0++] = code; + break; + } +} diff --git a/tables/functions.py b/tables/functions.py index 28c03a1553..d7189c215a 100644 --- a/tables/functions.py +++ b/tables/functions.py @@ -231,7 +231,7 @@ 0x80087714:("__osAnalyzeArena","void","Heap* heap, u32* maxFreeBlock, u32* bytesFree, u32* bytesAllocated"), 0x800877C4:("__osCheckArena","s32","Heap* heap"), 0x80087830:("proutSprintf","void*","void* s, char* buf, size_t n"), - 0x80087854:("func_80087854","void","void"), + 0x80087854:("vsprintf","int","char* dst, char* fmt, va_list args"), 0x800878A4:("sprintf","int","char* s, char* fmt, ..."), 0x80087900:("func_80087900","void","void"), 0x80087934:("func_80087934","void","void"), @@ -251,20 +251,20 @@ 0x80088110:("func_80088110","void","void"), 0x800882A0:("func_800882A0","void","void"), 0x80088350:("__sinf","f32","f32 __x"), - 0x80088510:("sins","s32","u16 angle"), + 0x80088510:("sins","short","unsigned short x"), 0x80088580:("_VirtualToPhysicalTask","OSTask*","OSTask* intp"), 0x8008868C:("osSpTaskLoad","void","OSTask* intp"), 0x800887F4:("osSpTaskStartGo","void","OSTask* tp"), - 0x80088840:("__ull_rshift","void","void"), - 0x8008886C:("__ull_rem","void","void"), - 0x800888A8:("__ull_div","u64","u64 param_1, u64 param_2"), - 0x800888E4:("__ll_lshift","void","void"), - 0x80088910:("__ll_rem","void","void"), - 0x8008894C:("__ll_div","void","void"), - 0x800889A8:("__ll_mul","u64","u64 param_1, u64 param_2"), - 0x800889D8:("__ull_divremi","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE2 param_5"), - 0x80088A38:("__ll_mod","void","void"), - 0x80088AD4:("__ll_rshift","void","void"), + 0x80088840:("__ull_rshift","long long","unsigned long long left, unsigned long long right"), + 0x8008886C:("__ull_rem","unsigned long long","unsigned long long left, unsigned long long right"), + 0x800888A8:("__ull_div","unsigned long long","unsigned long long left, unsigned long long right"), + 0x800888E4:("__ll_lshift","long long","long long left, long long right"), + 0x80088910:("__ll_rem","long long","long long left, unsigned long long right"), + 0x8008894C:("__ll_div","long long","long long left, long long right"), + 0x800889A8:("__ll_mul","long long","long long left, long long right"), + 0x800889D8:("__ull_divremi","void","unsigned long long* quotient, unsigned long long* remainder, unsigned long long dividend, unsigned short divisor"), + 0x80088A38:("__ll_mod","long long","long long left, long long right"), + 0x80088AD4:("__ll_rshift","long long","long long left, long long right"), 0x80088B00:("__osExceptionPreamble","void","void"), 0x80088B10:("__osException","void","void"), 0x80088D48:("func_80088D48","void","void"), @@ -298,8 +298,8 @@ 0x80089CBC:("__osContGetInitData","void","u8* pattern, OSContStatus* data"), 0x80089D68:("__osPackRequestData","void","u8 cmd"), 0x80089E40:("osCreateThread","void","OSThread* t, OSId id, osCreateThread_func entry, void* arg, void* sp, OSPri p"), - 0x80089F90:("osContStartReadData","void","void"), - 0x8008A014:("osContGetReadData","void","void"), + 0x80089F90:("osContStartReadData","s32","OSMesgQueue* mq"), + 0x8008A014:("osContGetReadData","void","OSContPad* data"), 0x8008A0A0:("__osPackReadData","void","void"), 0x8008A170:("func_8008A170","void","void"), 0x8008A540:("osVirtualToPhysical","u32","void* vaddr"), @@ -319,8 +319,8 @@ 0x8008AEE0:("__osSiRawReadIo","s32","u32 devAddr, u32* data"), 0x8008AF30:("osGetThreadId","OSId","OSThread* t"), 0x8008AF50:("osSpTaskYield","void","void"), - 0x8008AF70:("func_8008AF70","void","void"), - 0x8008B044:("func_8008B044","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6"), + 0x8008AF70:("__osPfsRWInode","s32","OSPfs* param_1, __OSInode* param_2, u8 param_3, u8 param_4"), + 0x8008B044:("osPfsReadWriteFile","s32","OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in_bytes, u8* data_buffer"), 0x8008B3C0:("func_8008B3C0","void","void"), 0x8008B490:("func_8008B490","void","void"), 0x8008B554:("func_8008B554","void","void"), @@ -338,8 +338,9 @@ 0x8008C190:("__osPiCreateAccessQueue","void","void"), 0x8008C1E0:("__osPiGetAccess","void","void"), 0x8008C224:("__osPiRelAccess","void","void"), - 0x8008C260:("func_8008C260","void","s32 param_1"), - 0x8008C670:("func_8008C670","void","void"), + 0x8008C260:("__osDevMgrMain","void","void* arg"), + 0x8008C640:("func_8008C640","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE1 param_5, UNK_TYPE1 param_6, UNK_TYPE1 param_7, UNK_TYPE1 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11, UNK_TYPE4 param_12, UNK_TYPE4 param_13, UNK_TYPE4 param_14, UNK_TYPE4 param_15, UNK_TYPE4 param_16, UNK_TYPE4 param_17, UNK_TYPE4 param_18"), + 0x8008C670:("osPiRawStartDma","s32","s32 direction, u32 devAddr, void* dramAddr, u32 size"), 0x8008C740:("func_8008C740","void","void"), 0x8008C7B4:("func_8008C7B4","void","void"), 0x8008C8B0:("func_8008C8B0","void","void"), @@ -347,7 +348,7 @@ 0x8008CD64:("func_8008CD64","void","void"), 0x8008CF10:("func_8008CF10","void","void"), 0x8008CFE4:("func_8008CFE4","void","void"), - 0x8008D2C0:("osGetCount","void","void"), + 0x8008D2C0:("osGetCount","u32","void"), 0x8008D2E0:("func_8008D2E0","void","void"), 0x8008D350:("calculate_mem_size","u32","void"), 0x8008D470:("func_8008D470","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6"), @@ -358,8 +359,8 @@ 0x8008D7AC:("osContGetQuery","void","OSContStatus* data"), 0x8008D7D0:("guLookAtHiliteF","void","float mf[4][4], UNK_PTR l, int* h, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp, float xl1, float yl1, float zl1, float xl2, float yl2, float zl2, int twidth, int theight"), 0x8008DF90:("guLookAtHilite","void","Mtx* m, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 twidth, s32 theight"), - 0x8008E050:("_Printf","int","printf_func pfn, void* arg, char* fmt, char* ap"), - 0x8008E698:("func_8008E698","void","void"), + 0x8008E050:("_Printf","int","printf_func pfn, void* arg, char* fmt, va_list ap"), + 0x8008E698:("_Putfld","void","_Pft* px, va_list* pap, unsigned char code, unsigned char* ac"), 0x8008ED30:("func_8008ED30","void","void"), 0x8008EDE0:("osUnmapTLBAll","void","void"), 0x8008EE30:("osEPiStartDma","s32","OSPiHandle* pihandle, OSIoMesg* mb, s32 direction"), @@ -374,7 +375,7 @@ 0x8008F3A0:("__osTimerServicesInit","void","void"), 0x8008F42C:("__osTimerInterrupt","void","void"), 0x8008F5A4:("__osSetTimerIntr","void","OSTime tim"), - 0x8008F644:("__osInsertTimer","void","OSTimer* t"), + 0x8008F644:("__osInsertTimer","OSTime","OSTimer* t"), 0x8008F7D0:("func_8008F7D0","void","void"), 0x8008FA00:("__osSpDeviceBusy","int","void"), 0x8008FA30:("__osSiDeviceBusy","int","void"), @@ -384,10 +385,10 @@ 0x8008FCE0:("osGetThreadPri","OSPri","OSThread* t"), 0x8008FD00:("func_8008FD00","void","void"), 0x8008FE60:("osViSwapBuffer","void","void* frameBufPtr"), - 0x8008FEB0:("func_8008FEB0","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8"), - 0x80090058:("func_80090058","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8"), + 0x8008FEB0:("guPositionF","void","float mf[4][4], float r, float p, float h, float s, float x, float y, float z"), + 0x80090058:("guPosition","void","Mtx* m, float r, float p, float h, float s, float x, float y, float z"), 0x800900C0:("func_800900C0","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5"), - 0x800902A0:("osSpTaskYielded","void","void"), + 0x800902A0:("osSpTaskYielded","OSYieldResult","OSTask* task"), 0x80090300:("memcmp","s32","void* __s1, void* __s2, size_t __n"), 0x80090420:("osGetTime","OSTime","void"), 0x800904B0:("guRotateF","void","float mf[4][4], float a, float x, float y, float z"), @@ -397,42 +398,42 @@ 0x80090810:("func_80090810","void","void"), 0x80090900:("func_80090900","void","void"), 0x80090AF0:("osAiSetFrequency","s32","u32 frequency"), - 0x80090C40:("func_80090C40","void","void"), + 0x80090C40:("__osContRamRead","s32","OSMesgQueue* mq, int channel, u16 address, u8* buffer"), 0x80090E70:("func_80090E70","void","void"), - 0x800910A0:("func_800910A0","void","void"), - 0x80091170:("func_80091170","void","void"), + 0x800910A0:("__osContAddressCrc","u8","u16 addr"), + 0x80091170:("__osContDataCrc","u8","u8* data"), 0x80091210:("__osGetActiveQueue","OSThread*","void"), 0x80091220:("guNormalize","void","float* x, float* y, float* z"), 0x80091280:("__osSetCompare","void","u32 value"), 0x80091290:("__osGetCompare","u32","void"), 0x800912A0:("osDpGetStatus","u32","void"), - 0x800912B0:("osDpSetStatus","void","u32 status"), + 0x800912B0:("osDpSetStatus","void","u32 data"), 0x800912C0:("_bcopy","void","void* __src, void* __dest, size_t __n"), 0x800915D0:("__osResetGlobalIntMask","void","void"), 0x80091630:("func_80091630","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5"), 0x80091808:("func_80091808","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5"), - 0x800918A0:("guOrthoF","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8"), - 0x800919F4:("guOrtho","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8"), + 0x800918A0:("guOrthoF","void","float mf[4][4], float l, float r, float b, float t, float n, float f, float scale"), + 0x800919F4:("guOrtho","void","Mtx* m, float l, float r, float b, float t, float n, float f, float scale"), 0x80091A60:("__osDisableInt","OSIntMask","void"), 0x80091AD0:("__osRestoreInt","void","OSIntMask im"), 0x80091AF0:("__osViInit","void","void"), 0x80091C10:("__osViSwapContext","void","void"), - 0x80091F10:("osPiGetCmdQueue","void","void"), + 0x80091F10:("osPiGetCmdQueue","OSMesgQueue*","void"), 0x80091F40:("__cosf","f32","f32 __x"), 0x800920B0:("func_800920B0","void","void"), 0x80092100:("osViSetSpecialFeatures","void","u32 func"), - 0x80092260:("coss","s32","u16 angle"), - 0x80092290:("osSetTime","void","void"), + 0x80092260:("coss","short","unsigned short x"), + 0x80092290:("osSetTime","void","OSTime ticks"), 0x800922C0:("func_800922C0","void","void"), - 0x800923E0:("osViSetEvent","void","OSMesgQueue* param_1, OSMesg param_2, u32 retraceCount"), + 0x800923E0:("osViSetEvent","void","OSMesgQueue* mq, OSMesg m, u32 retraceCount"), 0x80092440:("func_80092440","void","void"), 0x800925CC:("func_800925CC","void","void"), 0x80092680:("func_80092680","void","void"), 0x80092730:("func_80092730","void","void"), - 0x80092920:("func_80092920","OSPiHandle*","void"), + 0x80092920:("osCartRomInit","OSPiHandle*","void"), 0x80092A80:("func_80092A80","void","void"), - 0x80092C00:("func_80092C00","void","void"), - 0x80092C80:("osContSetCh","void","void"), + 0x80092C00:("__osPfsSelectBank","s32","OSPfs* pfs, UNK_TYPE4 param_2"), + 0x80092C80:("osContSetCh","s32","u8 ch"), 0x80092CE0:("__osSetFpcCsr","u32","u32 value"), 0x80092CF0:("__osGetFpcCsr","u32","void"), 0x80092D00:("func_80092D00","void","void"), @@ -441,21 +442,21 @@ 0x800931F0:("func_800931F0","void","void"), 0x80093728:("func_80093728","void","void"), 0x80093A00:("func_80093A00","void","void"), - 0x80093BA0:("osAiGetLength","void","void"), + 0x80093BA0:("osAiGetLength","u32","void"), 0x80093BB0:("func_80093BB0","void","void"), 0x80093C00:("osMapTLBRdb","void","void"), 0x80093C60:("osYieldThread","void","void"), 0x80093CC0:("func_80093CC0","void","void"), 0x80093D90:("__osGetCause","u32","void"), - 0x80093DA0:("func_80093DA0","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5"), + 0x80093DA0:("__osContRamWrite","s32","OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force"), 0x80093FF0:("func_80093FF0","void","void"), - 0x80094150:("osSetTimer","s32","OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg"), - 0x800942E0:("_Ldtob","void","void"), - 0x80094770:("func_80094770","void","void"), - 0x80094828:("func_80094828","void","UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE2 param_5"), - 0x80094DF0:("ldiv","ldiv_t","s32 __numer, s32 __denom"), - 0x80094E74:("lldiv","lldiv_t*","s64 __numer, s64 __denom"), - 0x80094F80:("_Litob","void","void"), + 0x80094150:("osSetTimer","int","OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg"), + 0x800942E0:("_Ldtob","void","_Pft* px, unsigned char code"), + 0x80094770:("_Ldunscale","void","void"), + 0x80094828:("_Genld","void","_Pft* px, unsigned char code, unsigned char* p, short nsig, short xexp"), + 0x80094DF0:("ldiv","ldiv_t","long numer, long denom"), + 0x80094E74:("lldiv","lldiv_t","long long numer, long long denom"), + 0x80094F80:("_Litob","void","_Pft* px, unsigned char code"), 0x80095220:("__osSiRawWriteIo","s32","u32 devAddr, u32 data"), 0x80095270:("__osSpGetStatus","u32","void"), 0x80095280:("__osSpSetStatus","void","u32 value"), @@ -467,16 +468,16 @@ 0x80095600:("func_80095600","void","void"), 0x80095740:("guMtxF2L","void","float mf[4][4], Mtx* m"), 0x800957B0:("osStartThread","void","OSThread* param_1"), - 0x80095900:("osViSetYScale","void","f32 param_1"), - 0x80095950:("osViSetXScale","void","f32 xscale"), - 0x80095A60:("__d_to_ll","void","void"), - 0x80095A7C:("__f_to_ll","void","void"), - 0x80095A98:("__d_to_ull","void","void"), - 0x80095B38:("__f_to_ull","void","void"), - 0x80095BD4:("__ll_to_d","void","void"), - 0x80095BEC:("__ll_to_f","void","void"), - 0x80095C04:("__ull_to_d","void","void"), - 0x80095C38:("__ull_to_f","void","void"), + 0x80095900:("osViSetYScale","void","f32 value"), + 0x80095950:("osViSetXScale","void","f32 value"), + 0x80095A60:("__d_to_ll","long long","double d"), + 0x80095A7C:("__f_to_ll","long long","float f"), + 0x80095A98:("__d_to_ull","unsigned long long","double d"), + 0x80095B38:("__f_to_ull","unsigned long long","float f"), + 0x80095BD4:("__ll_to_d","double","long long l"), + 0x80095BEC:("__ll_to_f","float","long long l"), + 0x80095C04:("__ull_to_d","double","unsigned long long l"), + 0x80095C38:("__ull_to_f","float","unsigned long long l"), 0x80095C70:("func_80095C70","void","void"), 0x80096360:("func_80096360","void","void"), 0x80096410:("func_80096410","void","void"), diff --git a/tables/objects.py b/tables/objects.py index 31d737fca8..e4177008eb 100644 --- a/tables/objects.py +++ b/tables/objects.py @@ -60,7 +60,7 @@ 0x8008AEE0:"sirawread", 0x8008AF30:"getthreadid", 0x8008AF50:"sptaskyield", - 0x8008AF70:"", + 0x8008AF70:"pfsreadwritefile", 0x8008B3C0:"", 0x8008B600:"", 0x8008B650:"visetmode", @@ -72,11 +72,13 @@ 0x8008BF60:"probetlb", 0x8008C020:"pimgr", 0x8008C190:"piacs", - 0x8008C260:"", + 0x8008C260:"devmgr", + 0x8008C640:"", + 0x8008C670:"pirawdma", 0x8008C740:"", 0x8008D2C0:"getcount", 0x8008D2E0:"", - 0x8008D350:"", + 0x8008D350:"getmemsize", 0x8008D470:"", 0x8008D640:"seteventmesg", 0x8008D700:"sqrtf", @@ -86,7 +88,7 @@ 0x8008E050:"xprintf", 0x8008ED30:"", 0x8008EDE0:"unmaptlball", - 0x8008EE30:"pidma", + 0x8008EE30:"epidma", 0x8008EED0:"", 0x8008F100:"", 0x8008F1A0:"string", @@ -103,7 +105,7 @@ 0x8008FCE0:"getthreadpri", 0x8008FD00:"", 0x8008FE60:"viswapbuf", - 0x8008FEB0:"", + 0x8008FEB0:"position", 0x800900C0:"", 0x800902A0:"sptaskyielded", 0x80090300:"memcmp", @@ -114,9 +116,9 @@ 0x80090810:"", 0x80090900:"", 0x80090AF0:"aisetfreq", - 0x80090C40:"", + 0x80090C40:"contramread", 0x80090E70:"", - 0x800910A0:"", + 0x800910A0:"crc", 0x80091210:"getactivequeue", 0x80091220:"normalize", 0x80091280:"setcompare", @@ -140,7 +142,7 @@ 0x800923e0:"visetevent", 0x80092440:"", 0x80092730:"", - 0x80092920:"", + 0x80092920:"cartrominit", 0x80092A80:"", 0x80092C00:"", 0x80092C80:"contsetch", @@ -155,7 +157,7 @@ 0x80093C60:"yieldthread", 0x80093CC0:"", 0x80093D90:"getcause", - 0x80093DA0:"", + 0x80093DA0:"contramwrite", 0x80093FF0:"", 0x80094150:"settimer", 0x800942E0:"xldtob", diff --git a/tables/variables.py b/tables/variables.py index d90590aaca..78c9c81058 100644 --- a/tables/variables.py +++ b/tables/variables.py @@ -28,8 +28,8 @@ 0x80097500:("D_80097500","UNK_TYPE4","",0x4), 0x80097524:("D_80097524","UNK_TYPE4","",0x4), 0x80097530:("randSeed","u32","",0x4), - 0x80097540:("osViModeNtscHpf1","UNK_TYPE1","",0x1), - 0x80097590:("D_80097590","UNK_TYPE1","",0x1), + 0x80097540:("osViModeNtscHpf1","OSViMode","",0x50), + 0x80097590:("osViModePalLan1","OSViMode","",0x50), 0x800975E0:("sintable","s16","[1024]",0x800), 0x80097DE0:("D_80097DE0","UNK_TYPE1","",0x1), 0x80097DE4:("D_80097DE4","UNK_TYPE1","",0x1), @@ -39,33 +39,32 @@ 0x80097E1C:("__osActiveQueue","OSThread*","",0x4), 0x80097E20:("__osRunningThread","OSThread*","",0x4), 0x80097E24:("__osFaultedThread","OSThread*","",0x4), - 0x80097E30:("__osSiAccessQueueEnabled","UNK_TYPE4","",0x4), + 0x80097E30:("__osSiAccessQueueEnabled","u32","",0x4), 0x80097E40:("D_80097E40","UNK_TYPE4","",0x4), 0x80097E50:("osClockRate","u64","",0x8), 0x80097E58:("osViClock","s32","",0x4), 0x80097E5C:("__osShutdown","UNK_TYPE4","",0x4), 0x80097E60:("__OSGlobalIntMask","UNK_TYPE4","",0x4), - 0x80097E70:("__osPiDevMgr","UNK_TYPE4","",0x4), - 0x80097E8C:("osPiHandleListHead","OSPiHandle*","",0x4), + 0x80097E70:("__osPiDevMgr","OSDevMgr","",0x1c), + 0x80097E8C:("__osPiTable","OSPiHandle*","",0x4), 0x80097E90:("D_80097E90","UNK_PTR","",0x4), 0x80097EA0:("__osPiAccessQueueEnabled","UNK_TYPE4","",0x4), - 0x80097EB0:("osViModeNtscHpn1","UNK_TYPE1","",0x1), + 0x80097EB0:("osViModeNtscHpn1","OSViMode","",0x50), 0x80097F00:("D_80097F00","UNK_TYPE4","",0x4), 0x80097F04:("D_80097F04","UNK_TYPE1","",0x1), 0x80097F10:("D_80097F10","UNK_TYPE4","",0x4), 0x80097F20:("spaces","char","[]",0x21), - 0x80097F44:("zeros","char","[]",0x24), + 0x80097F44:("zeroes","char","[]",0x24), 0x80097F70:("__osTimerList","OSTimer*","",0x4), 0x80097F80:("D_80097F80","UNK_TYPE4","",0x4), - 0x80097F90:("D_80097F90","UNK_TYPE4","",0x4), + 0x80097F90:("D_80097F90","float","",0x4), 0x80097FA0:("D_80097FA0","UNK_TYPE1","",0x1), 0x80097FA4:("D_80097FA4","UNK_TYPE1","",0x1), 0x80097FA5:("D_80097FA5","UNK_TYPE1","",0x1), 0x80097FB0:("D_80097FB0","UNK_TYPE4","",0x4), 0x80097FC0:("osViModeNtscLan1","OSViMode","",0x50), 0x80098010:("osViModeMpalLan1","OSViMode","",0x50), - 0x80098060:("D_80098060","__OSViContext","",0x30), - 0x80098090:("D_80098090","UNK_TYPE2","",0x2), + 0x80098060:("D_80098060","__OSViContext","[2]",0x60), 0x800980C0:("__osViCurr","__OSViContext*","",0x4), 0x800980C4:("__osViNext","__OSViContext*","",0x4), 0x800980D0:("D_800980D0","UNK_TYPE4","",0x4), @@ -252,7 +251,7 @@ 0x800992F8:("D_800992F8","f64","",0x8), 0x80099300:("D_80099300","char","[]",0x4), 0x80099304:("D_80099304","char","[]",0x6), - 0x8009930C:("D_8009930C","UNK_TYPE1","",0x1), + 0x8009930C:("D_8009930C","unsigned int","[6]",0x18), 0x80099324:("__switch_D_80099324","UNK_PTR","",0x4), 0x80099400:("D_80099400","f32","",0x4), 0x80099428:("D_80099428","f64","",0x8), @@ -311,8 +310,8 @@ 0x8009CD60:("heapLockMessageBuffer","UNK_TYPE4","",0x4), 0x8009CD70:("tmp_task","OSTask","",0x40), 0x8009CDB0:("D_8009CDB0","UNK_TYPE1","",0x1), - 0x8009CEB0:("D_8009CEB0","UNK_TYPE1","",0x1), - 0x8009CEB8:("__osSiAccessQueue","UNK_TYPE1","",0x1), + 0x8009CEB0:("siAccessBuf","OSMesg","[1]",0x4), + 0x8009CEB8:("__osSiAccessQueue","OSMesgQueue","",0x18), 0x8009CED0:("__osContPifRam","OSPifRam","",0x40), 0x8009CF0C:("D_8009CF0C","UNK_TYPE1","",0x1), 0x8009CF10:("__osContLastCmd","u8","",0x1), @@ -322,33 +321,23 @@ 0x8009CF60:("D_8009CF60","UNK_TYPE1","",0x1), 0x8009CF70:("D_8009CF70","UNK_TYPE4","",0x4), 0x8009CF80:("__osThreadSave","UNK_TYPE1","",0x1), - 0x8009D130:("D_8009D130","UNK_TYPE1","",0x1), - 0x8009D134:("D_8009D134","u8","",0x1), - 0x8009D135:("D_8009D135","u8","",0x1), - 0x8009D136:("D_8009D136","u8","",0x1), - 0x8009D137:("D_8009D137","u8","",0x1), - 0x8009D138:("D_8009D138","u8","",0x1), - 0x8009D1A8:("D_8009D1A8","UNK_TYPE1","",0x1), - 0x8009D1AC:("D_8009D1AC","u8","",0x1), - 0x8009D1AD:("D_8009D1AD","u8","",0x1), - 0x8009D1AE:("D_8009D1AE","u8","",0x1), - 0x8009D1AF:("D_8009D1AF","u8","",0x1), - 0x8009D1B0:("D_8009D1B0","u8","",0x1), + 0x8009D130:("D_8009D130","OSPiHandle","",0x74), + 0x8009D1A8:("D_8009D1A8","OSPiHandle","",0x74), 0x8009D220:("D_8009D220","OSThread","",0x1b0), 0x8009D3D0:("piManagerStack","u8","[4096]",0x1000), 0x8009E3D0:("D_8009E3D0","OSMesgQueue","",0x18), - 0x8009E3E8:("D_8009E3E8","UNK_TYPE1","",0x1), - 0x8009E3F0:("D_8009E3F0","UNK_TYPE1","",0x1), + 0x8009E3E8:("D_8009E3E8","OSMesg","[1]",0x4), + 0x8009E3F0:("D_8009E3F0","OSMesg","[1]",0x4), 0x8009E3F8:("__osPiAccessQueue","OSMesgQueue","",0x18), 0x8009E410:("D_8009E410","UNK_TYPE1","",0x1), 0x8009E510:("__osEventStateTab","__OSEventState","[16]",0x80), 0x8009E590:("D_8009E590","OSTimer","",0x20), 0x8009E5B0:("__osCurrentTime","OSTime","",0x8), 0x8009E5B8:("__osBaseCounter","u32","",0x4), - 0x8009E5BC:("__osViIntrCount","UNK_TYPE4","",0x4), - 0x8009E5C0:("__osTimerCounter","UNK_TYPE4","",0x4), - 0x8009E5D0:("D_8009E5D0","UNK_TYPE1","",0x1), - 0x8009E610:("D_8009E610","OSPiHandle","",0x74), + 0x8009E5BC:("__osViIntrCount","u32","",0x4), + 0x8009E5C0:("__osTimerCounter","u32","",0x4), + 0x8009E5D0:("__osPfsPifRam","OSPifRam","",0x40), + 0x8009E610:("CartRomHandle","OSPiHandle","",0x74), 0x8009E690:("viThread","OSThread","",0x1b0), 0x8009E840:("viThreadStack","u8","[4096]",0x1000), 0x8009F840:("viEventQueue","OSMesgQueue","",0x18), @@ -3760,7 +3749,7 @@ 0x801DFD88:("graphThreadName","char","[]",0x6), 0x801DFD90:("D_801DFD90","char","[]",0xc), 0x801DFD9C:("D_801DFD9C","char","[]",0xc), - 0x801DFDA8:("D_801DFDA8","UNK_TYPE1","",0x1), + 0x801DFDA8:("D_801DFDA8","char","[]",0x2f), 0x801DFDE0:("D_801DFDE0","char","[]",0x1b), 0x801DFDFC:("D_801DFDFC","char","[]",0x1a), 0x801DFE18:("D_801DFE18","char","[]",0x2e), diff --git a/tools/set_o32abi_bit.py b/tools/set_o32abi_bit.py new file mode 100644 index 0000000000..bf81641608 --- /dev/null +++ b/tools/set_o32abi_bit.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import argparse, struct, sys + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + + parser.add_argument('file', help='input file') + args = parser.parse_args() + + with open(args.file, 'r+b') as f: + magic = struct.unpack('>I', f.read(4))[0] + if magic != 0x7F454C46: + print('Error: Not an ELF file') + sys.exit(1) + + f.seek(36) + flags = struct.unpack('>I', f.read(4))[0] + if flags & 0xF0000000 != 0x20000000: # test for mips3 + print('Error: Architecture not mips3') + sys.exit(1) + + flags |= 0x00001000 # set EF_MIPS_ABI_O32 + f.seek(36) + f.write(struct.pack('>I', flags)) + + diff --git a/undef.txt b/undef.txt index e9e1a7b956..f22e0ee2c9 100644 --- a/undef.txt +++ b/undef.txt @@ -49,7 +49,7 @@ randLast = boot_bss_start + 0x00003850; heapLockMessageBuffer = boot_bss_start + 0x00003860; tmp_task = boot_bss_start + 0x00003870; D_8009CDB0 = boot_bss_start + 0x000038B0; -D_8009CEB0 = boot_bss_start + 0x000039B0; +siAccessBuf = boot_bss_start + 0x000039B0; __osSiAccessQueue = boot_bss_start + 0x000039B8; __osContPifRam = boot_bss_start + 0x000039D0; D_8009CF0C = boot_bss_start + 0x00003A0C; @@ -61,17 +61,7 @@ D_8009CF60 = boot_bss_start + 0x00003A60; D_8009CF70 = boot_bss_start + 0x00003A70; __osThreadSave = boot_bss_start + 0x00003A80; D_8009D130 = boot_bss_start + 0x00003C30; -D_8009D134 = boot_bss_start + 0x00003C34; -D_8009D135 = boot_bss_start + 0x00003C35; -D_8009D136 = boot_bss_start + 0x00003C36; -D_8009D137 = boot_bss_start + 0x00003C37; -D_8009D138 = boot_bss_start + 0x00003C38; D_8009D1A8 = boot_bss_start + 0x00003CA8; -D_8009D1AC = boot_bss_start + 0x00003CAC; -D_8009D1AD = boot_bss_start + 0x00003CAD; -D_8009D1AE = boot_bss_start + 0x00003CAE; -D_8009D1AF = boot_bss_start + 0x00003CAF; -D_8009D1B0 = boot_bss_start + 0x00003CB0; D_8009D220 = boot_bss_start + 0x00003D20; piManagerStack = boot_bss_start + 0x00003ED0; D_8009E3D0 = boot_bss_start + 0x00004ED0; @@ -85,8 +75,8 @@ __osCurrentTime = boot_bss_start + 0x000050B0; __osBaseCounter = boot_bss_start + 0x000050B8; __osViIntrCount = boot_bss_start + 0x000050BC; __osTimerCounter = boot_bss_start + 0x000050C0; -D_8009E5D0 = boot_bss_start + 0x000050D0; -D_8009E610 = boot_bss_start + 0x00005110; +__osPfsPifRam = boot_bss_start + 0x000050D0; +CartRomHandle = boot_bss_start + 0x00005110; viThread = boot_bss_start + 0x00005190; viThreadStack = boot_bss_start + 0x00005340; viEventQueue = boot_bss_start + 0x00006340;