summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-09-02 15:34:29 -0400
committerGitHub <noreply@github.com>2023-09-02 15:34:29 -0400
commit4fa13e4132cf8adb2f07bb34927e62e525c8cc79 (patch)
tree5f00c923350f9386a7f46b0c50b888c878d7eacf /include
parent9cceea48f31bdeea1c2933a1f64a74b60b80f17a (diff)
Move libultra function declarations to libultra headers (#1196)
* Delete unused headers * Move PR and io to ultra64 * move headers to ultra64 * more cleanups * more reorganizing * i think that should be all * format * ifdef guards cleanup * Add IO_READ and IO_WRITE macros for future use * warnings * review Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> * warnings again * warn * ifdef guards * fix merge * fix merge * fix merge * bss * padutils.h * bss * bss * bss * fix merge * bss * bss * bss * fix merge * fixes * fixes * bss * bss * fix merge * fix * fix * fix includepaths * fix paths * bss * fix * ultra64/ -> PR/ * header guards * fix ehader guards * fix * fix++ * format * bss is borken * prevent 2 * :despair: * bss * rename assert to dbg_hungup * fix * a * fix * bss * fix * bss * bss --------- Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>
Diffstat (limited to 'include')
-rw-r--r--include/PR/abi.h4
-rw-r--r--include/PR/controller.h (renamed from include/io/controller.h)69
-rw-r--r--include/PR/controller_voice.h (renamed from include/ultra64/controller_voice.h)10
-rw-r--r--include/PR/gbi.h16
-rw-r--r--include/PR/gs2dex.h (renamed from include/ultra64/gs2dex.h)6
-rw-r--r--include/PR/gu.h85
-rw-r--r--include/PR/hardware.h (renamed from include/ultra64/hardware.h)2
-rw-r--r--include/PR/mbi.h4
-rw-r--r--include/PR/os.h27
-rw-r--r--include/PR/os_ai.h12
-rw-r--r--include/PR/os_cache.h12
-rw-r--r--include/PR/os_cont.h79
-rw-r--r--include/PR/os_convert.h (renamed from include/ultra64/convert.h)5
-rw-r--r--include/PR/os_exception.h21
-rw-r--r--include/PR/os_flash.h23
-rw-r--r--include/PR/os_host.h9
-rw-r--r--include/PR/os_internal.h (renamed from include/os_internal.h)9
-rw-r--r--include/PR/os_internal_error.h9
-rw-r--r--include/PR/os_internal_reg.h24
-rw-r--r--include/PR/os_internal_si.h13
-rw-r--r--include/PR/os_libc.h15
-rw-r--r--include/PR/os_message.h (renamed from include/ultra64/message.h)42
-rw-r--r--include/PR/os_motor.h (renamed from include/ultra64/motor.h)10
-rw-r--r--include/PR/os_pfs.h (renamed from include/PR/pfs.h)16
-rw-r--r--include/PR/os_pi.h (renamed from include/os.h)99
-rw-r--r--include/PR/os_reg.h9
-rw-r--r--include/PR/os_system.h10
-rw-r--r--include/PR/os_thread.h (renamed from include/ultra64/thread.h)68
-rw-r--r--include/PR/os_time.h25
-rw-r--r--include/PR/os_tlb.h9
-rw-r--r--include/PR/os_vi.h (renamed from include/ultra64/vi.h)37
-rw-r--r--include/PR/os_voice.h (renamed from include/ultra64/os_voice.h)13
-rw-r--r--include/PR/osint.h38
-rw-r--r--include/PR/piint.h20
-rw-r--r--include/PR/r4300.h (renamed from include/ultra64/r4300.h)6
-rw-r--r--include/PR/rcp.h (renamed from include/ultra64/rcp.h)8
-rw-r--r--include/PR/rdp.h (renamed from include/ultra64/rdp.h)9
-rw-r--r--include/PR/rsp.h (renamed from include/ultra64/rsp.h)15
-rw-r--r--include/PR/sched.h15
-rw-r--r--include/PR/siint.h12
-rw-r--r--include/PR/sptask.h (renamed from include/ultra64/sptask.h)10
-rw-r--r--include/PR/ucode.h (renamed from include/ultra64/ucode.h)4
-rw-r--r--include/PR/ultratypes.h26
-rw-r--r--include/PR/viint.h73
-rw-r--r--include/PR/xstdio.h (renamed from include/xstdio.h)9
-rw-r--r--include/audio/load.h4
-rw-r--r--include/bstring.h4
-rw-r--r--include/debug.h7
-rw-r--r--include/fault.h2
-rw-r--r--include/functions.h242
-rw-r--r--include/gfx.h1
-rw-r--r--include/gfxprint.h3
-rw-r--r--include/irqmgr.h8
-rw-r--r--include/libc/alloca.h4
-rw-r--r--include/libc/assert.h4
-rw-r--r--include/libc/math.h10
-rw-r--r--include/libc/stdarg.h6
-rw-r--r--include/libc/stdbool.h4
-rw-r--r--include/libc/stddef.h4
-rw-r--r--include/libc/stdint.h4
-rw-r--r--include/libc/stdlib.h7
-rw-r--r--include/libc/string.h12
-rw-r--r--include/macros.h2
-rw-r--r--include/os_malloc.h6
-rw-r--r--include/osint.h26
-rw-r--r--include/padmgr.h10
-rw-r--r--include/padutils.h14
-rw-r--r--include/ramrom.h13
-rw-r--r--include/rdb.h10
-rw-r--r--include/regs.h2
-rw-r--r--include/rmon.h4
-rw-r--r--include/scheduler.h4
-rw-r--r--include/ultra64.h32
-rw-r--r--include/ultra64/viint.h37
-rw-r--r--include/ultraerror.h6
-rw-r--r--include/ultralog.h28
-rw-r--r--include/variables.h6
-rw-r--r--include/viint.h28
-rw-r--r--include/z64.h7
-rw-r--r--include/z64actor.h1
-rw-r--r--include/z64audio.h3
-rw-r--r--include/z64bombers_notebook.h3
-rw-r--r--include/z64frameadvance.h8
-rw-r--r--include/z64game.h3
-rw-r--r--include/z64jpeg.h2
-rw-r--r--include/z64math.h11
-rw-r--r--include/z64player.h2
-rw-r--r--include/z64rumble.h2
-rw-r--r--include/z64save.h2
89 files changed, 881 insertions, 754 deletions
diff --git a/include/PR/abi.h b/include/PR/abi.h
index 15ae5d911..7d3113022 100644
--- a/include/PR/abi.h
+++ b/include/PR/abi.h
@@ -1,5 +1,5 @@
-#ifndef ULTRA64_ABI_H
-#define ULTRA64_ABI_H
+#ifndef PR_ABI_H
+#define PR_ABI_H
/* Audio commands: */
/*
diff --git a/include/io/controller.h b/include/PR/controller.h
index d29c11f1f..40dc48b8d 100644
--- a/include/io/controller.h
+++ b/include/PR/controller.h
@@ -1,14 +1,14 @@
-#ifndef _CONTROLLER_H_
-#define _CONTROLLER_H_
+#ifndef PR_CONTROLLER_H
+#define PR_CONTROLLER_H
-#include "PR/ultratypes.h"
-#include "PR/pfs.h"
+#include "ultratypes.h"
+#include "os_cont.h"
+#include "os_pfs.h"
#define CHNL_ERR(format) (((format).rxsize & CHNL_ERR_MASK) >> 4)
#define SIAccessQueueSize 2
#define BLOCKSIZE 32
-#define MAXCONTROLLERS 4
#define PFS_ONE_PAGE 8
#define PFS_PAGE_SIZE (BLOCKSIZE*PFS_ONE_PAGE)
@@ -104,27 +104,6 @@
#define PFS_ERR_NOPACK 1
-/* controller errors */
-#define CONT_NO_RESPONSE_ERROR 0x8
-#define CONT_OVERRUN_ERROR 0x4
-
-/* Controller type */
-#define CONT_ABSOLUTE 0x0001
-#define CONT_RELATIVE 0x0002
-#define CONT_JOYPORT 0x0004
-#define CONT_EEPROM 0x8000
-#define CONT_EEP16K 0x4000
-#define CONT_TYPE_MASK 0x1F07
-#define CONT_TYPE_NORMAL 0x0005
-#define CONT_TYPE_MOUSE 0x0002
-#define CONT_TYPE_VOICE 0x0100
-
-/* Controller status */
-#define CONT_CARD_ON 0x01
-#define CONT_CARD_PULL 0x02
-#define CONT_ADDR_CRC_ER 0x04
-#define CONT_EEPROM_BUSY 0x80
-
// Accessory detection
#define CONT_ADDR_DETECT 0x8000
// Rumble
@@ -145,22 +124,6 @@
#define CONT_BLOCK_GB_BANK CONT_BLOCKS(CONT_ADDR_GB_BANK)
#define CONT_BLOCK_GB_STATUS CONT_BLOCKS(CONT_ADDR_GB_STATUS)
-/* Buttons */
-#define BTN_CRIGHT 0x0001
-#define BTN_CLEFT 0x0002
-#define BTN_CDOWN 0x0004
-#define BTN_CUP 0x0008
-#define BTN_R 0x0010
-#define BTN_L 0x0020
-#define BTN_RESET 0x0080
-#define BTN_DRIGHT 0x0100
-#define BTN_DLEFT 0x0200
-#define BTN_DDOWN 0x0400
-#define BTN_DUP 0x0800
-#define BTN_START 0x1000
-#define BTN_Z 0x2000
-#define BTN_B 0x4000
-#define BTN_A 0x8000
typedef struct {
/* 0x00 */ u32 ramarray[15];
@@ -213,6 +176,28 @@ typedef struct {
#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr))
+s32 __osCheckPackId(OSPfs* pfs, __OSPackId* check);
+s32 __osGetId(OSPfs* pfs);
+u16 __osSumcalc(u8* ptr, s32 length);
+s32 __osIdCheckSum(u16* ptr, u16* checkSum, u16* idSum);
+s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid);
+s32 __osCheckPackId(OSPfs *pfs, __OSPackId *check);
+s32 __osCheckId(OSPfs* pfs);
+s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank);
+s32 __osPfsSelectBank(OSPfs* pfs, u8 bank);
+s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, s32 fileSizeInPages, s32* startPage, u8 bank, s32* decleared, s32* finalPage);
+s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 initialPage, u8 bank, __OSInodeUnit *finalPage);
+s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* buffer);
+s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32 force);
+void __osContGetInitData(u8* pattern, OSContStatus* data);
+void __osPackRequestData(u8 poll);
+void __osPfsRequestData(u8 poll);
+void __osPfsGetInitData(u8* pattern, OSContStatus* contData);
+u8 __osContAddressCrc(u16 addr);
+u8 __osContDataCrc(u8* data);
+s32 __osPfsGetStatus(OSMesgQueue* queue, s32 channel);
+s32 __osContChannelReset(OSMesgQueue* mq, s32 channel);
+
extern OSPifRam __osContPifRam;
// extern UNK_TYPE1 D_8009CF0C;
extern u8 __osContLastPoll;
diff --git a/include/ultra64/controller_voice.h b/include/PR/controller_voice.h
index a5480d877..022e69c03 100644
--- a/include/ultra64/controller_voice.h
+++ b/include/PR/controller_voice.h
@@ -1,9 +1,9 @@
-#ifndef CONTROLLER_VOICE_H
-#define CONTROLLER_VOICE_H
+#ifndef PR_CONTROLLER_VOICE_H
+#define PR_CONTROLLER_VOICE_H
-#include "PR/ultratypes.h"
-#include "ultra64/os_voice.h"
-#include "ultra64/message.h"
+#include "ultratypes.h"
+#include "os_voice.h"
+#include "os_message.h"
#include "libc/stddef.h"
typedef struct {
diff --git a/include/PR/gbi.h b/include/PR/gbi.h
index 1b57c6a34..c6fcdc1e2 100644
--- a/include/PR/gbi.h
+++ b/include/PR/gbi.h
@@ -1,7 +1,9 @@
#include "mbi.h"
-#ifndef _ULTRA64_GBI_H_
-#define _ULTRA64_GBI_H_
+#ifndef PR_GBI_H
+#define PR_GBI_H
+
+#include "ultratypes.h"
/* To enable Fast3DEX grucode support, define F3DEX_GBI. */
@@ -1054,6 +1056,16 @@ typedef struct {
unsigned char v[3];
} Tri;
+typedef long int Mtx_t[4][4];
+typedef union {
+ Mtx_t m;
+ struct {
+ u16 intPart[4][4];
+ u16 fracPart[4][4];
+ };
+ long long int force_structure_alignment;
+} Mtx; // size = 0x40
+
/*
* Viewport
*/
diff --git a/include/ultra64/gs2dex.h b/include/PR/gs2dex.h
index 1e77f1cd3..55ef95238 100644
--- a/include/ultra64/gs2dex.h
+++ b/include/PR/gs2dex.h
@@ -1,5 +1,7 @@
-#ifndef GS2DEX_H
-#define GS2DEX_H
+#ifndef PR_GS2DEX_H
+#define PR_GS2DEX_H
+
+#include "ultratypes.h"
#ifdef _LANGUAGE_C_PLUS_PLUS
extern "C" {
diff --git a/include/PR/gu.h b/include/PR/gu.h
index 8bafcf7d3..51beaf97b 100644
--- a/include/PR/gu.h
+++ b/include/PR/gu.h
@@ -1,26 +1,63 @@
-#ifndef _GU_H_
-#define _GU_H_
-
-typedef struct {
- /* 0x0 */ unsigned char* base;
- /* 0x4 */ int fmt;
- /* 0x8 */ int siz;
- /* 0xC */ int xsize;
- /* 0x10 */ int ysize;
- /* 0x14 */ int lsize;
- /* 0x18 */ int addr;
- /* 0x1C */ int w;
- /* 0x20 */ int h;
- /* 0x24 */ int s;
- /* 0x28 */ int t;
-} Image;
-
-
-typedef struct {
- /* 0x0 */ float col[3];
- /* 0xC */ float pos[3];
- /* 0x18 */ float a1;
- /* 0x1C */ float a2;
-} PositionalLight;
+#ifndef PR_GU_H
+#define PR_GU_H
+
+#include "ultratypes.h"
+#include "gbi.h"
+
+
+#ifndef MAX
+#define MAX(a,b) (((a)>(b))?(a):(b))
+#endif
+#ifndef MIN
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#endif
+
+#define M_DTOR (3.14159265358979323846/180.0)
+
+#define FTOFIX32(x) (long)((x) * (float)0x00010000)
+#define FIX32TOF(x) ((float)(x) * (1.0f / (float)0x00010000))
+#define FTOFRAC8(x) ((int) MIN(((x) * (128.0f)), 127.0f) & 0xff)
+
+
+void guMtxIdent(Mtx* mtx);
+void guMtxIdentF(float mf[4][4]);
+
+void guOrtho(Mtx* m, f32 l, f32 r, f32 b, f32 t, f32 n, f32 f, f32 scale);
+void guOrthoF(float m[4][4], f32 l, f32 r, f32 b, f32 t, f32 n, f32 f, f32 scale);
+
+void guPerspective(Mtx* m, u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale);
+void guPerspectiveF(float mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale);
+
+void guLookAt(Mtx* m, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp);
+void guLookAtF(float mf[4][4], f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp);
+
+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 hiliteWidth, s32 hiliteHeight);
+void guLookAtHiliteF(float mf[4][4], 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 hiliteWidth, s32 hiliteHeight);
+
+void guRotate(Mtx* m, f32 a, f32 x, f32 y, f32 z);
+void guRotateF(float m[4][4], f32 a, f32 x, f32 y, f32 z);
+
+void guScale(Mtx* mtx, f32 x, f32 y, f32 z);
+void guTranslate(Mtx* mtx, f32 x, f32 y, f32 z);
+
+void guPosition(Mtx* m, f32 rot, f32 pitch, f32 yaw, f32 scale, f32 x, f32 y, f32 z);
+void guPositionF(float mf[4][4], f32 rot, f32 pitch, f32 yaw, f32 scale, f32 x, f32 y, f32 z);
+
+void guMtxF2L(float mf[4][4], Mtx* m);
+void guMtxL2F(float m1[4][4], Mtx* m2);
+
+void guNormalize(float* x, float* y, float* z);
+
+
+f32 sinf(f32 __x);
+f32 cosf(f32 __x);
+
+s16 sins(u16 x);
+s16 coss(u16 x);
+
+f32 sqrtf(f32 f);
+#ifdef __sgi
+#pragma intrinsic(sqrtf);
+#endif
#endif
diff --git a/include/ultra64/hardware.h b/include/PR/hardware.h
index 57d560ab0..3bcf1b7fc 100644
--- a/include/ultra64/hardware.h
+++ b/include/PR/hardware.h
@@ -1,6 +1,8 @@
#ifndef _ULTRA64_HARDWARE_H_
#define _ULTRA64_HARDWARE_H_
+// TODO: not real libultra header. Refactor to R4300.h
+
// Segment Wrapper
// Uncached RDRAM
#define KSEG1 0xA0000000 // 0xA0000000 - 0xBFFFFFFF Physical memory, uncached, unmapped
diff --git a/include/PR/mbi.h b/include/PR/mbi.h
index 0577165e7..f72ad9acd 100644
--- a/include/PR/mbi.h
+++ b/include/PR/mbi.h
@@ -1,5 +1,5 @@
-#ifndef _MBI_H_
-#define _MBI_H_
+#ifndef PR_MBI_H
+#define PR_MBI_H
/**************************************************************************
* *
diff --git a/include/PR/os.h b/include/PR/os.h
new file mode 100644
index 000000000..1b39d79a1
--- /dev/null
+++ b/include/PR/os.h
@@ -0,0 +1,27 @@
+#ifndef PR_OS_H
+#define PR_OS_H
+
+#include "os_ai.h"
+#include "os_cache.h"
+#include "os_cont.h"
+#include "os_convert.h"
+#include "os_exception.h"
+#include "os_flash.h"
+#include "os_host.h"
+#include "os_internal_error.h"
+#include "os_internal_reg.h"
+#include "os_internal_si.h"
+#include "os_internal.h"
+#include "os_libc.h"
+#include "os_message.h"
+#include "os_pfs.h"
+#include "os_pi.h"
+#include "os_reg.h"
+#include "os_system.h"
+#include "os_thread.h"
+#include "os_time.h"
+#include "os_tlb.h"
+#include "os_vi.h"
+#include "os_voice.h"
+
+#endif
diff --git a/include/PR/os_ai.h b/include/PR/os_ai.h
new file mode 100644
index 000000000..22f50d41e
--- /dev/null
+++ b/include/PR/os_ai.h
@@ -0,0 +1,12 @@
+#ifndef PR_OS_AI_H
+#define PR_OS_AI_H
+
+#include "ultratypes.h"
+
+
+u32 osAiGetLength(void);
+s32 osAiSetFrequency(u32 frequency);
+s32 osAiSetNextBuffer(void* buf, u32 size);
+
+
+#endif
diff --git a/include/PR/os_cache.h b/include/PR/os_cache.h
new file mode 100644
index 000000000..8a920c728
--- /dev/null
+++ b/include/PR/os_cache.h
@@ -0,0 +1,12 @@
+#ifndef PR_OS_CACHE_H
+#define PR_OS_CACHE_H
+
+#include "ultratypes.h"
+#include "libc/stddef.h"
+
+void osInvalDCache(void* vaddr, size_t nbytes);
+void osInvalICache(void* vaddr, size_t nbytes);
+void osWritebackDCache(void* vaddr, s32 nbytes);
+void osWritebackDCacheAll(void);
+
+#endif
diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h
new file mode 100644
index 000000000..6a63b8901
--- /dev/null
+++ b/include/PR/os_cont.h
@@ -0,0 +1,79 @@
+#ifndef PR_OS_CONT_H
+#define PR_OS_CONT_H
+
+#include "ultratypes.h"
+#include "os_message.h"
+
+
+typedef struct {
+ /* 0x0 */ u16 type;
+ /* 0x2 */ u8 status;
+ /* 0x3 */ u8 errno;
+} OSContStatus; // size = 0x4
+
+typedef struct {
+ /* 0x0 */ u16 button;
+ /* 0x2 */ s8 stick_x;
+ /* 0x3 */ s8 stick_y;
+ /* 0x4 */ u8 errno;
+} OSContPad; // size = 0x6
+
+#define MAXCONTROLLERS 4
+
+/* controller errors */
+#define CONT_NO_RESPONSE_ERROR 0x8
+#define CONT_OVERRUN_ERROR 0x4
+
+/* Controller type */
+#define CONT_ABSOLUTE 0x0001
+#define CONT_RELATIVE 0x0002
+#define CONT_JOYPORT 0x0004
+#define CONT_EEPROM 0x8000
+#define CONT_EEP16K 0x4000
+#define CONT_TYPE_MASK 0x1F07
+#define CONT_TYPE_NORMAL 0x0005
+#define CONT_TYPE_MOUSE 0x0002
+#define CONT_TYPE_VOICE 0x0100
+
+/* Controller status */
+#define CONT_CARD_ON 0x01
+#define CONT_CARD_PULL 0x02
+#define CONT_ADDR_CRC_ER 0x04
+#define CONT_EEPROM_BUSY 0x80
+
+// TODO: use real libultra button defines instead of this
+/* Buttons */
+#define BTN_CRIGHT 0x0001
+#define BTN_CLEFT 0x0002
+#define BTN_CDOWN 0x0004
+#define BTN_CUP 0x0008
+#define BTN_R 0x0010
+#define BTN_L 0x0020
+#define BTN_RESET 0x0080
+#define BTN_DRIGHT 0x0100
+#define BTN_DLEFT 0x0200
+#define BTN_DDOWN 0x0400
+#define BTN_DUP 0x0800
+#define BTN_START 0x1000
+#define BTN_Z 0x2000
+#define BTN_B 0x4000
+#define BTN_A 0x8000
+
+#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */
+#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */
+#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */
+#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */
+#define CONT_ERR_NOT_READY 12
+#define CONT_ERR_VOICE_MEMORY 13
+#define CONT_ERR_VOICE_WORD 14
+#define CONT_ERR_VOICE_NO_RESPONSE 15
+
+
+s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data);
+s32 osContStartQuery(OSMesgQueue* mq);
+s32 osContStartReadData(OSMesgQueue* mq);
+s32 osContSetCh(u8 ch);
+void osContGetQuery(OSContStatus* data);
+void osContGetReadData(OSContPad* data);
+
+#endif
diff --git a/include/ultra64/convert.h b/include/PR/os_convert.h
index 68e91a85a..468d77f9a 100644
--- a/include/ultra64/convert.h
+++ b/include/PR/os_convert.h
@@ -1,5 +1,5 @@
-#ifndef ULTRA64_CONVERT_H
-#define ULTRA64_CONVERT_H
+#ifndef PR_CONVERT_H
+#define PR_CONVERT_H
#include "libc/stdint.h"
@@ -24,6 +24,5 @@
/* Functions */
extern uintptr_t osVirtualToPhysical(void*);
-extern void* osPhysicalToVirtual(uintptr_t);
#endif
diff --git a/include/PR/os_exception.h b/include/PR/os_exception.h
new file mode 100644
index 000000000..b5c2e7ba8
--- /dev/null
+++ b/include/PR/os_exception.h
@@ -0,0 +1,21 @@
+#ifndef PR_OS_EXCEPTION_H
+#define PR_OS_EXCEPTION_H
+
+#include "ultratypes.h"
+
+
+typedef u32 OSIntMask;
+typedef u32 OSHWIntr;
+
+OSIntMask osGetIntMask(void);
+OSIntMask osSetIntMask(OSIntMask im);
+
+
+// Internal
+void __osSetHWIntrRoutine(OSHWIntr idx, OSMesgQueue* queue, OSMesg msg);
+void __osGetHWIntrRoutine(OSHWIntr idx, OSMesgQueue** outQueue, OSMesg* outMsg);
+void __osSetGlobalIntMask(OSHWIntr mask);
+void __osResetGlobalIntMask(OSHWIntr mask);
+
+
+#endif
diff --git a/include/PR/os_flash.h b/include/PR/os_flash.h
new file mode 100644
index 000000000..36e728c5a
--- /dev/null
+++ b/include/PR/os_flash.h
@@ -0,0 +1,23 @@
+#ifndef PR_OS_FLASH_H
+#define PR_OS_FLASH_H
+
+#include "ultratypes.h"
+#include "os_pi.h"
+
+
+OSPiHandle* osFlashReInit(u8 latency, u8 pulse, u8 pageSize, u8 relDuration, u32 start);
+OSPiHandle* osFlashInit(void);
+void osFlashReadStatus(u8* flashStatus);
+void osFlashReadId(u32* flashType, u32* flashVendor);
+void osFlashClearStatus(void);
+s32 osFlashAllErase(void);
+s32 osFlashSectorErase(u32 pageNum);
+s32 osFlashWriteBuffer(OSIoMesg* mb, s32 priority, void* dramAddr, OSMesgQueue* mq);
+s32 osFlashWriteArray(u32 pageNum);
+s32 osFlashReadArray(OSIoMesg* mb, s32 priority, u32 pageNum, void* dramAddr, u32 pageCount, OSMesgQueue* mq);
+void osFlashChange(u32 flashNum);
+void osFlashAllEraseThrough(void);
+void osFlashSectorEraseThrough(u32 pageNum);
+s32 osFlashCheckEraseEnd(void);
+
+#endif
diff --git a/include/PR/os_host.h b/include/PR/os_host.h
new file mode 100644
index 000000000..5d0ad482f
--- /dev/null
+++ b/include/PR/os_host.h
@@ -0,0 +1,9 @@
+#ifndef PR_OS_HOST_H
+#define PR_OS_HOST_H
+
+void __osInitialize_common(void);
+void __osInitialize_autodetect(void);
+
+#define osInitialize() __osInitialize_common()
+
+#endif
diff --git a/include/os_internal.h b/include/PR/os_internal.h
index 2d82b41a9..eadd0182b 100644
--- a/include/os_internal.h
+++ b/include/PR/os_internal.h
@@ -1,5 +1,10 @@
-#ifndef _OS_INTERNAL_H_
-#define _OS_INTERNAL_H_
+#ifndef PR_OS_INTERNAL_H
+#define PR_OS_INTERNAL_H
+
+#include "ultratypes.h"
+#include "os_message.h"
+#include "os_pi.h"
+
typedef struct {
/* 0x00 */ OSMesgQueue* queue;
diff --git a/include/PR/os_internal_error.h b/include/PR/os_internal_error.h
new file mode 100644
index 000000000..db2c8b981
--- /dev/null
+++ b/include/PR/os_internal_error.h
@@ -0,0 +1,9 @@
+#ifndef PR_OS_INTERNAL_ERROR_H
+#define PR_OS_INTERNAL_ERROR_H
+
+#include "os_thread.h"
+
+
+OSThread* __osGetCurrFaultedThread(void);
+
+#endif
diff --git a/include/PR/os_internal_reg.h b/include/PR/os_internal_reg.h
new file mode 100644
index 000000000..753692017
--- /dev/null
+++ b/include/PR/os_internal_reg.h
@@ -0,0 +1,24 @@
+#ifndef PR_OS_INTERNAL_REG
+#define PR_OS_INTERNAL_REG
+
+#include "ultratypes.h"
+#include "os_exception.h"
+
+
+u32 __osGetCause(void);
+void __osSetCause(u32);
+u32 __osGetCompare(void);
+void __osSetCompare(u32 value);
+u32 __osGetConfig(void);
+void __osSetConfig(u32);
+u32 __osGetSR(void);
+void __osSetSR(u32 value);
+OSIntMask __osDisableInt(void);
+void __osRestoreInt(OSIntMask im);
+u32 __osGetWatchLo(void);
+void __osSetWatchLo(u32 value);
+
+u32 __osSetFpcCsr(u32 value);
+u32 __osGetFpcCsr(void);
+
+#endif
diff --git a/include/PR/os_internal_si.h b/include/PR/os_internal_si.h
new file mode 100644
index 000000000..e1d88acca
--- /dev/null
+++ b/include/PR/os_internal_si.h
@@ -0,0 +1,13 @@
+#ifndef PR_OS_INTERNAL_SI_H
+#define PR_OS_INTERNAL_SI_H
+
+#include "ultratypes.h"
+#include "libc/stdint.h"
+
+
+s32 __osSiRawWriteIo(uintptr_t devAddr, u32 data);
+s32 __osSiRawReadIo(uintptr_t devAddr, u32* data);
+s32 __osSiRawStartDma(s32 direction, void* dramAddr);
+
+
+#endif
diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h
new file mode 100644
index 000000000..755f24692
--- /dev/null
+++ b/include/PR/os_libc.h
@@ -0,0 +1,15 @@
+#ifndef PR_OS_LIBC_H
+#define PR_OS_LIBC_H
+
+#include "libc/stdarg.h"
+
+
+void bcopy(void* __src, void* __dest, int __n);
+int bcmp(void* __s1, void* __s2, int __n);
+void bzero(void* begin, int length);
+
+s32 vsprintf(char* dst, char* fmt, va_list args);
+int sprintf(char* dst, const char* fmt, ...);
+void osSyncPrintf(const char* fmt, ...);
+
+#endif
diff --git a/include/ultra64/message.h b/include/PR/os_message.h
index de0c39b83..bb577f57b 100644
--- a/include/ultra64/message.h
+++ b/include/PR/os_message.h
@@ -1,7 +1,19 @@
-#ifndef ULTRA64_MESSAGE_H
-#define ULTRA64_MESSAGE_H
+#ifndef PR_OS_MESSAGE_H
+#define PR_OS_MESSAGE_H
-#include "ultra64/thread.h"
+#include "os_thread.h"
+
+typedef void* OSMesg;
+typedef u32 OSEvent;
+
+typedef struct OSMesgQueue {
+ /* 0x00 */ OSThread* mtQueue;
+ /* 0x04 */ OSThread* fullQueue;
+ /* 0x08 */ s32 validCount;
+ /* 0x0C */ s32 first;
+ /* 0x10 */ s32 msgCount;
+ /* 0x14 */ OSMesg* msg;
+} OSMesgQueue; // size = 0x18
#define OS_NUM_EVENTS 15
@@ -30,24 +42,20 @@
#define OS_EVENT_RDB_FLUSH_PROF 21
#define OS_EVENT_RDB_ACK_PROF 22
-typedef void* OSMesg;
-typedef u32 OSEvent;
-
#define OS_MESG_NOBLOCK 0
#define OS_MESG_BLOCK 1
-typedef struct OSMesgQueue {
- /* 0x00 */ OSThread* mtQueue;
- /* 0x04 */ OSThread* fullQueue;
- /* 0x08 */ s32 validCount;
- /* 0x0C */ s32 first;
- /* 0x10 */ s32 msgCount;
- /* 0x14 */ OSMesg* msg;
-} OSMesgQueue; // size = 0x18
+#define MQ_GET_COUNT(mq) ((mq)->validCount)
+
+#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0)
+#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount)
+
+void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msq, s32 count);
+s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags);
+s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag);
+s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags);
-#define MQ_COUNT(mq) ((mq)->validCount)
+void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg m);
-#define MQ_IS_EMPTY(mq) (MQ_COUNT(mq) == 0)
-#define MQ_IS_FULL(mq) (MQ_COUNT(mq) >= (mq)->msgCount)
#endif
diff --git a/include/ultra64/motor.h b/include/PR/os_motor.h
index ed969b3de..378768588 100644
--- a/include/ultra64/motor.h
+++ b/include/PR/os_motor.h
@@ -1,9 +1,9 @@
-#ifndef ULTRA64_MOTOR_H
-#define ULTRA64_MOTOR_H
+#ifndef PR_OS_MOTOR_H
+#define PR_OS_MOTOR_H
-#include "PR/ultratypes.h"
-#include "PR/pfs.h"
-#include "ultra64/message.h"
+#include "ultratypes.h"
+#include "os_pfs.h"
+#include "os_message.h"
#define MOTOR_START 1
#define MOTOR_STOP 0
diff --git a/include/PR/pfs.h b/include/PR/os_pfs.h
index 596fafbfe..4ce1acd52 100644
--- a/include/PR/pfs.h
+++ b/include/PR/os_pfs.h
@@ -1,5 +1,5 @@
-#ifndef _ULTRA64_PFS_H_
-#define _ULTRA64_PFS_H_
+#ifndef PR_OS_PFS_H
+#define PR_OS_PFS_H
#include "os.h"
@@ -134,8 +134,16 @@ typedef struct {
/* 0x101 */ u8 map[PFS_INODE_DIST_MAP];
} __OSInodeCache; // size = 0x202
-s32 __osCheckPackId(OSPfs* pfs, __OSPackId* check);
-s32 __osGetId(OSPfs* pfs);
+
+s32 osPfsInitPak(OSMesgQueue* queue, OSPfs* pfs, s32 channel);
s32 osPfsChecker(OSPfs* pfs);
+s32 osPfsAllocateFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32 fileSize, s32* fileNo);
+s32 osPfsFindFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32* fileNo);
+s32 osPfsDeleteFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName);
+s32 osPfsReadWriteFile(OSPfs* pfs, s32 fileNo, u8 flag, s32 offset, s32 size, u8* data);
+s32 osPfsFileState(OSPfs* pfs, s32 fileNo, OSPfsState* state);
+s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern);
+s32 osPfsFreeBlocks(OSPfs* pfs, s32* leftoverBytes);
+
#endif
diff --git a/include/os.h b/include/PR/os_pi.h
index 47fed80a0..2e67ca840 100644
--- a/include/os.h
+++ b/include/PR/os_pi.h
@@ -1,36 +1,11 @@
-#ifndef _OS_H_
-#define _OS_H_
+#ifndef PR_OS_PI_H
+#define PR_OS_PI_H
+#include "ultratypes.h"
+#include "os_message.h"
+#include "libc/stddef.h"
#include "libc/stdint.h"
-#include "libc/stdlib.h"
-#include "ultra64/thread.h"
-#include "ultra64/message.h"
-#define OS_READ 0
-#define OS_WRITE 1
-
-/*
- * I/O message types
- */
-#define OS_MESG_TYPE_BASE 10
-#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE+0)
-#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE+1)
-#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE+2)
-#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE+3)
-#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE+4)
-#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE+5)
-#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE+6)
-
-/*
- * I/O message priority
- */
-#define OS_MESG_PRI_NORMAL 0
-#define OS_MESG_PRI_HIGH 1
-
-
-typedef u32 OSIntMask;
-
-typedef u32 OSPageMask;
typedef struct {
/* 0x00 */ u32 errStatus;
@@ -41,7 +16,6 @@ typedef struct {
/* 0x14 */ u32 C1ErrSector[4];
} __OSBlockInfo; // size = 0x24
-
typedef struct {
/* 0x00 */ u32 cmdType;
/* 0x04 */ u16 transferMode;
@@ -53,7 +27,6 @@ typedef struct {
/* 0x18 */ __OSBlockInfo block[2];
} __OSTranxInfo; // size = 0x60
-
typedef struct OSPiHandle {
/* 0x00 */ struct OSPiHandle* next;
/* 0x04 */ u8 type;
@@ -67,13 +40,11 @@ typedef struct OSPiHandle {
/* 0x14 */ __OSTranxInfo transferInfo;
} OSPiHandle; // size = 0x74
-
typedef struct {
/* 0x0 */ u8 type;
/* 0x4 */ uintptr_t address;
} OSPiInfo; // size = 0x8
-
typedef struct {
/* 0x0 */ u16 type;
/* 0x2 */ u8 pri;
@@ -81,7 +52,6 @@ typedef struct {
/* 0x4 */ OSMesgQueue* retQueue;
} OSIoMesgHdr; // size = 0x8
-
typedef struct {
/* 0x00 */ OSIoMesgHdr hdr;
/* 0x08 */ void* dramAddr;
@@ -90,7 +60,6 @@ typedef struct {
/* 0x14 */ OSPiHandle* piHandle;
} OSIoMesg; // size = 0x88
-
typedef struct {
/* 0x00 */ s32 active; // u32 maybe? need to check
/* 0x04 */ OSThread* thread;
@@ -101,45 +70,37 @@ typedef struct {
/* 0x18 */ s32 (*epiDmaCallback)(OSPiHandle*, s32, uintptr_t, void*, size_t);
} OSDevMgr; // size = 0x1C
-typedef u64 OSTime;
-typedef struct OSTimer_s {
- /* 0x00 */ struct OSTimer_s* next;
- /* 0x04 */ struct OSTimer_s* prev;
- /* 0x08 */ OSTime interval;
- /* 0x10 */ OSTime value;
- /* 0x18 */ OSMesgQueue* mq;
- /* 0x1C */ OSMesg msg;
-} OSTimer; // size = 0x20
-typedef struct {
- /* 0x0 */ u16 type;
- /* 0x2 */ u8 status;
- /* 0x3 */ u8 errno;
-} OSContStatus; // size = 0x4
+#define OS_READ 0
+#define OS_WRITE 1
+
+/*
+ * I/O message types
+ */
+#define OS_MESG_TYPE_BASE 10
+#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE+0)
+#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE+1)
+#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE+2)
+#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE+3)
+#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE+4)
+#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE+5)
+#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE+6)
+/*
+ * I/O message priority
+ */
+#define OS_MESG_PRI_NORMAL 0
+#define OS_MESG_PRI_HIGH 1
-typedef struct {
- /* 0x0 */ u16 button;
- /* 0x2 */ s8 stick_x;
- /* 0x3 */ s8 stick_y;
- /* 0x4 */ u8 errno;
-} OSContPad; // size = 0x6
+void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt);
-typedef struct {
- /* 0x00 */ void* address;
- /* 0x04 */ u8 databuffer[32];
- /* 0x24 */ u8 addressCrc;
- /* 0x25 */ u8 dataCrc;
- /* 0x26 */ u8 errno;
-} OSContRamIo; // size = 0x28
+OSPiHandle* osCartRomInit(void);
-typedef struct {
- /* 0x0 */ u16* histo_base;
- /* 0x4 */ u32 histo_size;
- /* 0x8 */ u32* text_start;
- /* 0xC */ u32* text_end;
-} OSProf; // size = 0x10
+s32 osEPiWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data);
+s32 osEPiReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data);
+s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction);
+s32 osEPiLinkHandle(OSPiHandle* handle);
#endif
diff --git a/include/PR/os_reg.h b/include/PR/os_reg.h
new file mode 100644
index 000000000..043c7ce9f
--- /dev/null
+++ b/include/PR/os_reg.h
@@ -0,0 +1,9 @@
+#ifndef PR_OS_REG_H
+#define PR_OS_REG_H
+
+#include "ultratypes.h"
+
+
+u32 osGetCount(void);
+
+#endif
diff --git a/include/PR/os_system.h b/include/PR/os_system.h
new file mode 100644
index 000000000..21f06f164
--- /dev/null
+++ b/include/PR/os_system.h
@@ -0,0 +1,10 @@
+#ifndef PR_OS_SYSTEM_H
+#define PR_OS_SYSTEM_H
+
+#include "ultratypes.h"
+
+
+u32 osGetMemSize(void);
+s32 osAfterPreNMI(void);
+
+#endif
diff --git a/include/ultra64/thread.h b/include/PR/os_thread.h
index 4adf025e1..b88520087 100644
--- a/include/ultra64/thread.h
+++ b/include/PR/os_thread.h
@@ -1,31 +1,7 @@
-#ifndef _ULTRA64_THREAD_H_
-#define _ULTRA64_THREAD_H_
+#ifndef PR_OS_THREAD_H
+#define PR_OS_THREAD_H
-#include "PR/ultratypes.h"
-
-#define OS_PRIORITY_IDLE 0
-#define OS_PRIORITY_MAIN 10
-#define OS_PRIORITY_GRAPH 11
-#define OS_PRIORITY_AUDIOMGR 12
-#define OS_PRIORITY_PADMGR 14
-#define OS_PRIORITY_SCHED 15
-#define OS_PRIORITY_DMAMGR 16
-#define OS_PRIORITY_IRQMGR 17
-#define OS_PRIORITY_PIMGR 150
-#define OS_PRIORITY_FAULTCLIENT 126
-#define OS_PRIORITY_FAULT 127
-#define OS_PRIORITY_APPMAX 127
-#define OS_PRIORITY_RMONSPIN 200
-#define OS_PRIORITY_RMON 250
-#define OS_PRIORITY_VIMGR 254
-#define OS_PRIORITY_MAX 255
-
-#define OS_PRIORITY_THREADTAIL -1
-
-#define OS_STATE_STOPPED (1 << 0)
-#define OS_STATE_RUNNABLE (1 << 1)
-#define OS_STATE_RUNNING (1 << 2)
-#define OS_STATE_WAITING (1 << 3)
+#include "ultratypes.h"
#define OS_FLAG_CPU_BREAK 1
#define OS_FLAG_FAULT 2
@@ -71,4 +47,42 @@ typedef struct OSThread {
/* 0x20 */ __OSThreadContext context;
} OSThread; // size = 0x1B0
+#define OS_STATE_STOPPED (1 << 0)
+#define OS_STATE_RUNNABLE (1 << 1)
+#define OS_STATE_RUNNING (1 << 2)
+#define OS_STATE_WAITING (1 << 3)
+
+
+#define OS_PRIORITY_IDLE 0
+#define OS_PRIORITY_MAIN 10
+#define OS_PRIORITY_GRAPH 11
+#define OS_PRIORITY_AUDIOMGR 12
+#define OS_PRIORITY_PADMGR 14
+#define OS_PRIORITY_SCHED 15
+#define OS_PRIORITY_DMAMGR 16
+#define OS_PRIORITY_IRQMGR 17
+#define OS_PRIORITY_PIMGR 150
+#define OS_PRIORITY_FAULTCLIENT 126
+#define OS_PRIORITY_FAULT 127
+#define OS_PRIORITY_APPMAX 127
+#define OS_PRIORITY_RMONSPIN 200
+#define OS_PRIORITY_RMON 250
+#define OS_PRIORITY_VIMGR 254
+#define OS_PRIORITY_MAX 255
+
+#define OS_PRIORITY_THREADTAIL -1
+
+
+void osCreateThread(OSThread* thread, OSId id, void* entry, void* arg, void* sp, OSPri p);
+void osDestroyThread(OSThread* t);
+void osYieldThread(void);
+void osStartThread(OSThread* t);
+void osStopThread(OSThread* t);
+OSId osGetThreadId(OSThread* t);
+void osSetThreadPri(OSThread* thread, OSPri p);
+OSPri osGetThreadPri(OSThread* t);
+
+// internal
+OSThread* __osGetActiveQueue(void);
+
#endif
diff --git a/include/PR/os_time.h b/include/PR/os_time.h
new file mode 100644
index 000000000..31702c0bb
--- /dev/null
+++ b/include/PR/os_time.h
@@ -0,0 +1,25 @@
+#ifndef PR_OS_TIME_H
+#define PR_OS_TIME_H
+
+#include "ultratypes.h"
+#include "os_message.h"
+
+
+typedef u64 OSTime;
+
+typedef struct OSTimer_s {
+ /* 0x00 */ struct OSTimer_s* next;
+ /* 0x04 */ struct OSTimer_s* prev;
+ /* 0x08 */ OSTime interval;
+ /* 0x10 */ OSTime value;
+ /* 0x18 */ OSMesgQueue* mq;
+ /* 0x1C */ OSMesg msg;
+} OSTimer; // size = 0x20
+
+OSTime osGetTime(void);
+void osSetTime(OSTime ticks);
+s32 osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg);
+s32 osStopTimer(OSTimer* t);
+
+
+#endif
diff --git a/include/PR/os_tlb.h b/include/PR/os_tlb.h
new file mode 100644
index 000000000..7d0b5a341
--- /dev/null
+++ b/include/PR/os_tlb.h
@@ -0,0 +1,9 @@
+#ifndef PR_OS_TLB_H
+#define PR_OS_TLB_H
+
+#include "ultratypes.h"
+
+void osMapTLBRdb(void);
+void osUnmapTLBAll(void);
+
+#endif
diff --git a/include/ultra64/vi.h b/include/PR/os_vi.h
index 7737b58b4..e4098e97e 100644
--- a/include/ultra64/vi.h
+++ b/include/PR/os_vi.h
@@ -1,8 +1,8 @@
-#ifndef _ULTRA64_VI_H_
-#define _ULTRA64_VI_H_
+#ifndef PR_OS_VI_H
+#define PR_OS_VI_H
#include "PR/ultratypes.h"
-#include "ultra64/message.h"
+#include "PR/os_message.h"
/* Special Features */
#define OS_VI_GAMMA_ON (1 << 0)
@@ -52,23 +52,6 @@ typedef struct {
/* 0x24 */ OSViFieldRegs fldRegs[2];
} OSViMode; // size = 0x4C
-typedef struct {
- /* 0x0 */ f32 factor;
- /* 0x4 */ u16 offset;
- /* 0x8 */ u32 scale;
-} __OSViScale; // size = 0x0C
-
-typedef struct {
- /* 0x00 */ u16 state;
- /* 0x02 */ u16 retraceCount;
- /* 0x04 */ void* buffer;
- /* 0x08 */ OSViMode* modep;
- /* 0x0C */ u32 features;
- /* 0x10 */ OSMesgQueue* mq;
- /* 0x14 */ OSMesg* msg;
- /* 0x18 */ __OSViScale x;
- /* 0x24 */ __OSViScale y;
-} __OSViContext; // size = 0x30
#define OS_VI_NTSC_LPN1 0 /* NTSC */
#define OS_VI_NTSC_LPF1 1
@@ -135,4 +118,18 @@ typedef struct {
#define OS_TV_MPAL 2
#define OS_VI_UNK28 28
+
+void* osViGetCurrentFramebuffer(void);
+void* osViGetNextFramebuffer(void);
+void osViSetXScale(f32 value);
+void osViSetYScale(f32 value);
+void osViExtendVStart(u32 a0);
+void osViSetSpecialFeatures(u32 func);
+void osViSetMode(OSViMode* modep);
+void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount);
+void osViSwapBuffer(void* frameBufPtr);
+void osViBlack(u8 active);
+void osCreateViManager(OSPri pri);
+
+
#endif
diff --git a/include/ultra64/os_voice.h b/include/PR/os_voice.h
index 8452ed45c..c6317a28c 100644
--- a/include/ultra64/os_voice.h
+++ b/include/PR/os_voice.h
@@ -1,8 +1,8 @@
-#ifndef OS_VOICE_H
-#define OS_VOICE_H
+#ifndef PR_OS_VOICE_H
+#define PR_OS_VOICE_H
-#include "PR/ultratypes.h"
-#include "ultra64/message.h"
+#include "ultratypes.h"
+#include "os_message.h"
typedef enum OsVoiceHandleMode {
/* 0 */ VOICE_HANDLE_MODE_0,
@@ -29,14 +29,15 @@ typedef struct {
/* 0x14 */ u16 distance[5]; // Distance value
} OSVoiceData; // size = 0x20
-s32 osVoiceInit(OSMesgQueue* mq, OSVoiceHandle* hd, s32 channel);
+
+s32 osVoiceInit(OSMesgQueue* mq, OSVoiceHandle* hd, int channel);
s32 osVoiceSetWord(OSVoiceHandle* hd, u8* word);
s32 osVoiceCheckWord(u8* word);
s32 osVoiceStartReadData(OSVoiceHandle* hd);
s32 osVoiceStopReadData(OSVoiceHandle* hd);
s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* result);
s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 numWords);
-s32 osVoiceMaskDictionary(OSVoiceHandle* hd, u8* maskPattern, s32 size);
+s32 osVoiceMaskDictionary(OSVoiceHandle* hd, u8* maskPattern, int size);
s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital);
#endif
diff --git a/include/PR/osint.h b/include/PR/osint.h
new file mode 100644
index 000000000..c2e1a2b90
--- /dev/null
+++ b/include/PR/osint.h
@@ -0,0 +1,38 @@
+#ifndef PR_OSINT_H
+#define PR_OSINT_H
+
+#include "ultratypes.h"
+#include "os_message.h"
+#include "os.h"
+#include "os_internal.h"
+
+typedef struct __OSEventState {
+ /* 0x0 */ OSMesgQueue* messageQueue;
+ /* 0x4 */ OSMesg message;
+} __OSEventState; // size = 0x8
+
+typedef struct __OSThreadTail {
+ /* 0x0 */ OSThread* next;
+ /* 0x4 */ OSPri priority;
+} __OSThreadTail; // size = 0x8
+
+void __osEnqueueAndYield(OSThread** param_1);
+void __osDequeueThread(OSThread** queue, OSThread* t);
+void __osEnqueueThread(OSThread** param_1, OSThread* param_2);
+OSThread* __osPopThread(OSThread** param_1);
+void __osDispatchThread(void);
+void __osCleanupThread(void);
+
+void __osSetTimerIntr(OSTime tim);
+OSTime __osInsertTimer(OSTimer* t);
+void __osTimerInterrupt(void);
+u32 __osProbeTLB(void* param_1);
+s32 __osSpDeviceBusy(void);
+
+void __osTimerServicesInit(void);
+
+extern __osHwInt __osHwIntTable[];
+extern __OSEventState __osEventStateTab[OS_NUM_EVENTS];
+
+
+#endif
diff --git a/include/PR/piint.h b/include/PR/piint.h
new file mode 100644
index 000000000..0ca1f0d2e
--- /dev/null
+++ b/include/PR/piint.h
@@ -0,0 +1,20 @@
+#ifndef PR_PIINT_H
+#define PR_PIINT_H
+
+#include "ultratypes.h"
+#include "os_pi.h"
+#include "libc/stdint.h"
+
+
+void __osDevMgrMain(void* arg);
+void __osPiCreateAccessQueue(void);
+void __osPiRelAccess(void);
+void __osPiGetAccess(void);
+s32 __osPiRawStartDma(s32 direction, uintptr_t devAddr, void* dramAddr, size_t size);
+s32 __osEPiRawWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data);
+s32 __osEPiRawReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data);
+s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, uintptr_t cartAddr, void* dramAddr, size_t size);
+OSMesgQueue* osPiGetCmdQueue(void);
+
+
+#endif
diff --git a/include/ultra64/r4300.h b/include/PR/r4300.h
index 30e8a9ea8..37d7e8946 100644
--- a/include/ultra64/r4300.h
+++ b/include/PR/r4300.h
@@ -1,8 +1,8 @@
-#ifndef ULTRA64_R4300_H
-#define ULTRA64_R4300_H
+#ifndef PR_R4300_H
+#define PR_R4300_H
#ifdef _LANGUAGE_C
-#include "PR/ultratypes.h"
+#include "ultratypes.h"
#define U32(x) ((u32)x)
#define C_REG(x) (x)
#else
diff --git a/include/ultra64/rcp.h b/include/PR/rcp.h
index 7a336be28..1c97c64e3 100644
--- a/include/ultra64/rcp.h
+++ b/include/PR/rcp.h
@@ -1,5 +1,5 @@
-#ifndef _ULTRA64_RCP_H_
-#define _ULTRA64_RCP_H_
+#ifndef PR_RCP_H
+#define PR_RCP_H
#define VI_NTSC_CLOCK 48681812 /* Hz = 48.681812 MHz */
#define VI_PAL_CLOCK 49656530 /* Hz = 49.656530 MHz */
@@ -11,7 +11,6 @@
#define DEVICE_TYPE_SRAM 3 /* SRAM */
#define DEVICE_TYPE_INIT 7 /* initial value */
-
#define CHNL_ERR_NORESP 0x80 /* Bit 7 (Rx): No response error */
#define CHNL_ERR_OVERRUN 0x40 /* Bit 6 (Rx): Overrun error */
#define CHNL_ERR_FRAME 0x80 /* Bit 7 (Tx): Frame error */
@@ -19,4 +18,7 @@
#define CHNL_ERR_MASK 0xC0 /* Bit 6-7: channel errors */
+#define IO_READ(addr) (*(vu32*)PHYS_TO_K1(addr))
+#define IO_WRITE(addr,data) (*(vu32*)PHYS_TO_K1(addr)=(u32)(data))
+
#endif
diff --git a/include/ultra64/rdp.h b/include/PR/rdp.h
index b4b3bb532..4bd6bc99d 100644
--- a/include/ultra64/rdp.h
+++ b/include/PR/rdp.h
@@ -1,5 +1,5 @@
-#ifndef ULTRA64_RDP_H
-#define ULTRA64_RDP_H
+#ifndef PR_RDP_H
+#define PR_RDP_H
/* DP Command Registers */
#define DPC_START_REG 0x04100000
@@ -42,4 +42,9 @@
#define DPC_CLR_CMD_CTR (1 << 8)
#define DPC_CLR_CLOCK_CTR (1 << 9)
+
+u32 osDpGetStatus(void);
+void osDpSetStatus(u32 data);
+
+
#endif
diff --git a/include/ultra64/rsp.h b/include/PR/rsp.h
index f8ec4ef51..467db831c 100644
--- a/include/ultra64/rsp.h
+++ b/include/PR/rsp.h
@@ -1,5 +1,9 @@
-#ifndef _ULTRA64_RSP_H_
-#define _ULTRA64_RSP_H_
+#ifndef PR_RSP_H
+#define PR_RSP_H
+
+#include "ultratypes.h"
+#include "libc/stddef.h"
+
/* SP Status Flags */
#define SP_STATUS_HALT (1 << 0)
@@ -44,4 +48,11 @@
#define SP_CLR_SIG7 (1 << 23)
#define SP_SET_SIG7 (1 << 24)
+
+u32 __osSpGetStatus(void);
+void __osSpSetStatus(u32 data);
+s32 __osSpSetPc(void* pc);
+s32 __osSpRawStartDma(s32 direction, void* devAddr, void* dramAddr, size_t size);
+
+
#endif
diff --git a/include/PR/sched.h b/include/PR/sched.h
index d0aac1d0e..7db228a5d 100644
--- a/include/PR/sched.h
+++ b/include/PR/sched.h
@@ -1,9 +1,16 @@
-#ifndef SCHED_H
-#define SCHED_H
+#ifndef PR_SCHED_H
+#define PR_SCHED_H
#include "PR/ultratypes.h"
-#include "ultra64/vi.h"
-#include "ultra64/sptask.h"
+#include "PR/os_vi.h"
+#include "PR/sptask.h"
+
+#define OS_SC_STACKSIZE 0x2000
+
+#define OS_SC_RETRACE_MSG 1
+#define OS_SC_DONE_MSG 2
+#define OS_SC_NMI_MSG 3 // name is made up, 3 is OS_SC_RDP_DONE_MSG in the original sched.c
+#define OS_SC_PRE_NMI_MSG 4
#define OS_SC_NEEDS_RDP 0x0001
#define OS_SC_NEEDS_RSP 0x0002
diff --git a/include/PR/siint.h b/include/PR/siint.h
new file mode 100644
index 000000000..a6d16323e
--- /dev/null
+++ b/include/PR/siint.h
@@ -0,0 +1,12 @@
+#ifndef PR_SIINT_H
+#define PR_SIINT_H
+
+#include "ultratypes.h"
+
+
+void __osSiGetAccess(void);
+void __osSiRelAccess(void);
+s32 __osSiDeviceBusy(void);
+void __osSiCreateAccessQueue(void);
+
+#endif
diff --git a/include/ultra64/sptask.h b/include/PR/sptask.h
index ef4aa4d04..3ec4bf1bf 100644
--- a/include/ultra64/sptask.h
+++ b/include/PR/sptask.h
@@ -1,5 +1,5 @@
-#ifndef _SPTASK_H_
-#define _SPTASK_H_
+#ifndef PR_SPTASK_H
+#define PR_SPTASK_H
#include "PR/ultratypes.h"
#include "libc/stddef.h"
@@ -109,4 +109,10 @@ typedef union {
typedef u32 OSYieldResult;
+void osSpTaskLoad(OSTask* intp);
+void osSpTaskStartGo(OSTask* tp);
+
+void osSpTaskYield(void);
+OSYieldResult osSpTaskYielded(OSTask* task);
+
#endif
diff --git a/include/ultra64/ucode.h b/include/PR/ucode.h
index 8a1d89037..2314222ba 100644
--- a/include/ultra64/ucode.h
+++ b/include/PR/ucode.h
@@ -1,5 +1,5 @@
-#ifndef ULTRA64_UCODE_H
-#define ULTRA64_UCODE_H
+#ifndef PR_UCODE_H
+#define PR_UCODE_H
#include "PR/ultratypes.h"
diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h
index 8b4e1a82c..530f30755 100644
--- a/include/PR/ultratypes.h
+++ b/include/PR/ultratypes.h
@@ -1,5 +1,5 @@
-#ifndef _ULTRATYPES_H_
-#define _ULTRATYPES_H_
+#ifndef PR_ULTRATYPES_H
+#define PR_ULTRATYPES_H
typedef signed char s8;
typedef unsigned char u8;
@@ -22,27 +22,7 @@ typedef volatile s64 vs64;
typedef float f32;
typedef double f64;
+// TODO: move this somewhere else
typedef void* TexturePtr;
-typedef long int Mtx_t[4][4];
-typedef union {
- Mtx_t m;
- struct {
- u16 intPart[4][4];
- u16 fracPart[4][4];
- };
- long long int forc_structure_alignment;
-} Mtx; // size = 0x40
-
-typedef float MtxF_t[4][4];
-typedef union {
- MtxF_t mf;
- struct {
- float xx, yx, zx, wx,
- xy, yy, zy, wy,
- xz, yz, zz, wz,
- xw, yw, zw, ww;
- };
-} MtxF; // size = 0x40
-
#endif
diff --git a/include/PR/viint.h b/include/PR/viint.h
new file mode 100644
index 000000000..29d4fffc6
--- /dev/null
+++ b/include/PR/viint.h
@@ -0,0 +1,73 @@
+#ifndef PR_VIINT_H
+#define PR_VIINT_H
+
+#include "ultratypes.h"
+
+#define OS_TV_TYPE_PAL 0
+#define OS_TV_TYPE_NTSC 1
+#define OS_TV_TYPE_MPAL 2
+
+#define VI_STATE_MODE_UPDATED (1 << 0)
+#define VI_STATE_XSCALE_UPDATED (1 << 1)
+#define VI_STATE_YSCALE_UPDATED (1 << 2)
+#define VI_STATE_CTRL_UPDATED (1 << 3) // related to control regs changing
+#define VI_STATE_BUFFER_UPDATED (1 << 4) // swap buffer
+#define VI_STATE_BLACK (1 << 5) // probably related to a black screen
+#define VI_STATE_REPEATLINE (1 << 6) // repeat line?
+#define VI_STATE_FADE (1 << 7) // fade
+
+#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */
+#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */
+#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */
+
+#define VI_SCALE_MASK 0xFFF
+#define VI_2_10_FPART_MASK 0x3FF
+#define VI_SUBPIXEL_SH 0x10
+
+// For use in initializing OSViMode structures
+
+#define BURST(hsync_width, color_width, vsync_width, color_start) \
+ (((u32)(hsync_width) & 0xFF) | (((u32)(color_width) & 0xFF) << 8) | (((u32)(vsync_width) & 0xF) << 16) | (((u32)(color_start) & 0xFFFF) << 20))
+#define WIDTH(v) (v)
+#define VSYNC(v) (v)
+#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration) & 0xFFFF))
+#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower) & 0xFFFF))
+#define START(start, end) (((u32)(start) << 16) | ((u32)(end) & 0xFFFF))
+
+#define FTOFIX(val, i, f) ((u32)((val) * (f32)(1 << (f))) & ((1 << ((i) + (f))) - 1))
+
+#define F210(val) FTOFIX(val, 2, 10)
+#define SCALE(scaleup, off) (F210((1.0f / (f32)(scaleup))) | (F210((f32)(off)) << 16))
+
+#define VCURRENT(v) v
+#define ORIGIN(v) v
+#define VINTR(v) v
+#define HSTART START
+
+
+typedef struct {
+ /* 0x0 */ f32 factor;
+ /* 0x4 */ u16 offset;
+ /* 0x8 */ u32 scale;
+} __OSViScale; // size = 0x0C
+
+typedef struct {
+ /* 0x00 */ u16 state;
+ /* 0x02 */ u16 retraceCount;
+ /* 0x04 */ void* buffer;
+ /* 0x08 */ OSViMode* modep;
+ /* 0x0C */ u32 features;
+ /* 0x10 */ OSMesgQueue* mq;
+ /* 0x14 */ OSMesg* msg;
+ /* 0x18 */ __OSViScale x;
+ /* 0x24 */ __OSViScale y;
+} __OSViContext; // size = 0x30
+
+void __osViSwapContext(void);
+extern __OSViContext* __osViCurr;
+extern __OSViContext* __osViNext;
+extern u32 __additional_scanline;
+__OSViContext* __osViGetCurrentContext(void);
+void __osViInit(void);
+
+#endif
diff --git a/include/xstdio.h b/include/PR/xstdio.h
index 102a25ee4..9850d88f8 100644
--- a/include/xstdio.h
+++ b/include/PR/xstdio.h
@@ -1,6 +1,7 @@
-#ifndef _XSTDIO_H_
-#define _XSTDIO_H_
+#ifndef PR_XSTDIO_H
+#define PR_XSTDIO_H
+#include "ultratypes.h"
#include "libc/stdarg.h"
typedef struct {
@@ -30,4 +31,8 @@ typedef void* (*PrintCallback)(void*, const char*, size_t);
#define FLAGS_HASH 8
#define FLAGS_ZERO 16
+s32 _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap);
+void _Litob(_Pft* args, u8 type);
+void _Ldtob(_Pft* args, u8 type);
+
#endif
diff --git a/include/audio/load.h b/include/audio/load.h
index b5bc01594..1e896d744 100644
--- a/include/audio/load.h
+++ b/include/audio/load.h
@@ -5,9 +5,9 @@
#include "PR/ultratypes.h"
#include "libc/stddef.h"
#include "libc/stdint.h"
-#include "ultra64/message.h"
+#include "PR/os_message.h"
#include "unk.h"
-#include "os.h"
+#include "PR/os.h"
struct Sample;
diff --git a/include/bstring.h b/include/bstring.h
deleted file mode 100644
index e8d6a66cf..000000000
--- a/include/bstring.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef _BSTRING_H_
-#define _BSTRING_H_
-
-#endif
diff --git a/include/debug.h b/include/debug.h
new file mode 100644
index 000000000..96d3d11c7
--- /dev/null
+++ b/include/debug.h
@@ -0,0 +1,7 @@
+#ifndef DEBUG_H
+#define DEBUG_H
+
+void _dbg_hungup(const char* file, int lineNum);
+void Reset(void);
+
+#endif
diff --git a/include/fault.h b/include/fault.h
index c93feee25..8affde4ae 100644
--- a/include/fault.h
+++ b/include/fault.h
@@ -5,7 +5,7 @@
#include "unk.h"
#include "libc/stdarg.h"
#include "libc/stdint.h"
-#include "io/controller.h"
+#include "PR/controller.h"
#include "padmgr.h"
#include "stack.h"
diff --git a/include/functions.h b/include/functions.h
index 6c7bc067a..7eb67e3ba 100644
--- a/include/functions.h
+++ b/include/functions.h
@@ -41,7 +41,6 @@ void CIC6105_AddRomInfoFaultPage(void);
void CIC6105_RemoveRomInfoFaultPage(void);
void func_800818F4(void);
void __osSyncVPrintf(const char* fmt, ...);
-void osSyncPrintf(const char* fmt, ...);
void rmonPrintf(const char* fmt, ...);
void func_80084940(void);
@@ -68,8 +67,6 @@ void PadUtils_UpdateRelXY(Input* input);
void MtxConv_F2L(Mtx* mtx, MtxF* mf);
void MtxConv_L2F(MtxF* mtx, Mtx* mf);
-void __assert(const char* file, u32 lineNum);
-// void func_800862B4(void);
s32 func_80086620(OSMesgQueue* param_1, PadMgr* param_2, OSContStatus* param_3);
u32 Rand_Next(void);
@@ -81,9 +78,6 @@ u32 Rand_Next_Variable(u32* rndNum);
f32 Rand_ZeroOne_Variable(u32* rndNum);
f32 Rand_Centered_Variable(u32* rndNum);
-void* proutSprintf(void* dst, const char* fmt, size_t size);
-s32 vsprintf(char* dst, char* fmt, va_list args);
-s32 sprintf(char* dst, char* fmt, ...);
s32 PrintUtils_VPrintf(PrintCallback* pfn, const char* fmt, va_list args);
s32 PrintUtils_Printf(PrintCallback* pfn, const char* fmt, ...);
void Sleep_Cycles(OSTime time);
@@ -91,223 +85,7 @@ void Sleep_Nsec(u32 nsec);
void Sleep_Usec(u32 usec);
void Sleep_Msec(u32 ms);
void Sleep_Sec(u32 sec);
-// void __osSetCause(void);
-s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags);
-s32 osPfsFreeBlocks(OSPfs* pfs, s32* leftoverBytes);
-void osViExtendVStart(u32 a0);
-void osStopThread(OSThread* t);
-s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags);
-OSIntMask osSetIntMask(OSIntMask im);
-// OSIntMask osGetIntMask(void);
-void guScale(Mtx* mtx, f32 x, f32 y, f32 z);
-f32 sinf(f32 __x);
-s16 sins(u16 x);
-OSTask* _VirtualToPhysicalTask(OSTask* intp);
-void osSpTaskLoad(OSTask* intp);
-void osSpTaskStartGo(OSTask* tp);
-long long __ull_rshift(unsigned long long left, unsigned long long right);
-unsigned long long __ull_rem(unsigned long long left, unsigned long long right);
-unsigned long long __ull_div(unsigned long long left, unsigned long long right);
-long long __ll_lshift(long long left, long long right);
-long long __ll_rem(long long left, unsigned long long right);
-long long __ll_div(long long left, long long right);
-long long __ll_mul(long long left, long long right);
-void __ull_divremi(unsigned long long* quotient, unsigned long long* remainder, unsigned long long dividend, unsigned short divisor);
-long long __ll_mod(long long left, long long right);
-long long __ll_rshift(long long left, long long right);
-void __osExceptionPreamble(void);
-void __osException(void);
-// void send_mesg(void);
-// void handle_CpU(void);
-void __osEnqueueAndYield(OSThread** param_1);
-void __osEnqueueThread(OSThread** param_1, OSThread* param_2);
-OSThread* __osPopThread(OSThread** param_1);
-// void __osNop(void);
-void __osDispatchThread(void);
-void __osCleanupThread(void);
-void __osDequeueThread(OSThread** queue, OSThread* t);
-void osDestroyThread(OSThread* t);
-void bzero(void* begin, s32 length);
-
-void __osSiCreateAccessQueue(void);
-void __osSiGetAccess(void);
-void __osSiRelAccess(void);
-s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data);
-void __osContGetInitData(u8* pattern, OSContStatus* data);
-void __osPackRequestData(u8 poll);
-void osCreateThread(OSThread* thread, OSId id, void* entry, void* arg, void* sp, OSPri p);
-s32 osContStartReadData(OSMesgQueue* mq);
-void osContGetReadData(OSContPad* data);
-void __osPackReadData(void);
-uintptr_t osVirtualToPhysical(void* virtualAddress);
-u32 __osGetSR(void);
-void __osSetSR(u32 value);
-void osWritebackDCache(void* vaddr, s32 nbytes);
-void __createSpeedParam(void);
-void osInitialize(void);
-void __osInitialize_autodetect(void);
-void* osViGetNextFramebuffer(void);
-void guPerspectiveF(float mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale);
-void guPerspective(Mtx* m, u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale);
-s32 __osSpRawStartDma(s32 direction, void* devAddr, void* dramAddr, size_t size);
-s32 __osSiRawStartDma(s32 direction, void* dramAddr);
-s32 osEPiLinkHandle(OSPiHandle* handle);
-void osViBlack(u8 active);
-s32 __osSiRawReadIo(uintptr_t devAddr, u32* data);
-OSId osGetThreadId(OSThread* t);
-void osSpTaskYield(void);
-s32 __osPfsGetNextPage(OSPfs* pfs, u8* bank, __OSInode* inode, __OSInodeUnit* page);
-s32 osPfsReadWriteFile(OSPfs* pfs, s32 fileNo, u8 flag, s32 offset, s32 size, u8* data);
-s32 __osPfsGetStatus(OSMesgQueue* queue, s32 channel);
-// void __osPfsRequestOneChannel(void);
-// void __osPfsGetOneChannelData(void);
-void guMtxIdentF(float mf[4][4]);
-void osViSetMode(OSViMode* modep);
-// void __osGetConfig(void);
-// void __osSetConfig(void);
-void guLookAtF(float mf[4][4], f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp);
-void guLookAt(Mtx* m, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp);
-s32 osPfsAllocateFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32 fileSize, s32* fileNo);
-s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, s32 fileSizeInPages, s32* startPage, u8 bank, s32* decleared, s32* finalPage);
-s32 osStopTimer(OSTimer* t);
-u32 __osProbeTLB(void* param_1);
-void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt);
-void __osPiCreateAccessQueue(void);
-void __osPiGetAccess(void);
-void __osPiRelAccess(void);
-void __osDevMgrMain(void* arg);
-// 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);
-s32 __osPiRawStartDma(s32 direction, uintptr_t devAddr, void* dramAddr, size_t size);
-u16 __osSumcalc(u8* ptr, s32 length);
-s32 __osIdCheckSum(u16* ptr, u16* checkSum, u16* idSum);
-s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid);
-// void __osCheckPackId(void);
-s32 __osCheckId(OSPfs* pfs);
-s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank);
-u32 osGetCount(void);
-void guMtxL2F(MtxF* m1, Mtx* m2);
-u32 osGetMemSize(void);
-s32 osPfsFindFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32* fileNo);
-void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg m);
-f32 sqrtf(f32 f);
-s32 osAfterPreNMI(void);
-s32 osContStartQuery(OSMesgQueue* mq);
-void osContGetQuery(OSContStatus* data);
-void guLookAtHiliteF(float mf[4][4], 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 hiliteWidth, s32 hiliteHeight);
-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 hiliteWidth, s32 hiliteHeight);
-s32 _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap);
-void _Putfld(_Pft* px, va_list* pap, u8 code, u8* ac);
-void osUnmapTLBAll(void);
-s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction);
-const char* strchr(const char* s, s32 c);
-size_t strlen(const char* s);
-void* memcpy(void* s1, const void* s2, size_t n);
-void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msq, s32 count);
-void osInvalICache(void* vaddr, size_t nbytes);
-void osInvalDCache(void* vaddr, size_t nbytes);
-void __osTimerServicesInit(void);
-void __osTimerInterrupt(void);
-void __osSetTimerIntr(OSTime tim);
-OSTime __osInsertTimer(OSTimer* t);
-s32 __osSpDeviceBusy(void);
-s32 __osSiDeviceBusy(void);
-void guMtxIdent(Mtx* mtx);
-s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag);
-void osSetThreadPri(OSThread* thread, OSPri p);
-OSPri osGetThreadPri(OSThread* t);
-s32 __osEPiRawReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data);
-void osViSwapBuffer(void* frameBufPtr);
-void guPositionF(float mf[4][4], f32 rot, f32 pitch, f32 yaw, f32 scale, f32 x, f32 y, f32 z);
-void guPosition(Mtx* m, f32 rot, f32 pitch, f32 yaw, f32 scale, f32 x, f32 y, f32 z);
-s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, uintptr_t cartAddr, void* dramAddr, size_t size);
-OSYieldResult osSpTaskYielded(OSTask* task);
-s32 bcmp(void* __s1, void* __s2, size_t __n);
-OSTime osGetTime(void);
-void guRotateF(float m[4][4], f32 a, f32 x, f32 y, f32 z);
-void guRotate(Mtx* m, f32 a, f32 x, f32 y, f32 z);
-void __osSetGlobalIntMask(u32 mask);
-s32 __osContChannelReset(OSMesgQueue* mq, s32 channel);
-s32 osAiSetFrequency(u32 frequency);
-s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* buffer);
-u8 __osContAddressCrc(u16 addr);
-u8 __osContDataCrc(u8* data);
-OSThread* __osGetActiveQueue(void);
-void guNormalize(float* x, float* y, float* z);
-void __osSetCompare(u32 value);
-// u32 __osGetCompare(void);
-u32 osDpGetStatus(void);
-void osDpSetStatus(u32 data);
-void bcopy(void* __src, void* __dest, size_t __n);
-void __osResetGlobalIntMask(u32 mask);
-// void osPfsDeleteFile(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5);
-// void __osPfsReleasePages(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5);
-void guOrthoF(float m[4][4], f32 l, f32 r, f32 b, f32 t, f32 n, f32 f, f32 scale);
-void guOrtho(Mtx* m, f32 l, f32 r, f32 b, f32 t, f32 n, f32 f, f32 scale);
-OSIntMask __osDisableInt(void);
-void __osRestoreInt(OSIntMask im);
-void __osViInit(void);
-void __osViSwapContext(void);
-OSMesgQueue* osPiGetCmdQueue(void);
-f32 cosf(f32 __x);
-s32 osEPiReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data);
-void osViSetSpecialFeatures(u32 func);
-s16 coss(u16 x);
-void osSetTime(OSTime ticks);
-void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount);
-s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern);
-// void __osPfsRequestData(void);
-// void __osPfsGetInitData(void);
-OSPiHandle* osCartRomInit(void);
-// void guS2DInitBg(void);
-s32 __osPfsSelectBank(OSPfs* pfs, u8 bank);
-s32 osContSetCh(u8 ch);
-u32 __osSetFpcCsr(u32 value);
-u32 __osGetFpcCsr(void);
-// void osPfsFileState(void);
-// void osPfsInitPak(void);
-// void __osPfsCheckRamArea(void);
-// void osPfsChecker(void);
-u32 osAiGetLength(void);
-s32 osEPiWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data);
-void osMapTLBRdb(void);
-void osYieldThread(void);
-void guTranslate(Mtx* mtx, f32 x, f32 y, f32 z);
-u32 __osGetCause(void);
-s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32 force);
-s32 __osEPiRawWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data);
-s32 osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg);
-void _Ldtob(_Pft* args, u8 type);
-// void _Ldunscale(void);
-void _Genld(_Pft* px, u8 code, u8* p, s16 nsig, s16 xexp);
-ldiv_t ldiv(long numer, long denom);
-lldiv_t lldiv(long long numer, long long denom);
-void _Litob(_Pft* args, u8 type);
-s32 __osSiRawWriteIo(uintptr_t devAddr, u32 data);
-u32 __osSpGetStatus(void);
-void __osSpSetStatus(u32 data);
-void osCreateViManager(OSPri pri);
-// void viMgrMain(OSDevMgr* iParm1);
-__OSViContext* __osViGetCurrentContext(void);
-void osWritebackDCacheAll(void);
-OSThread* __osGetCurrFaultedThread(void);
-void guMtxF2L(float mf[4][4], Mtx* m);
-void osStartThread(OSThread* t);
-void osViSetYScale(f32 value);
-void osViSetXScale(f32 value);
-long long __d_to_ll(double d);
-long long __f_to_ll(float f);
-unsigned long long __d_to_ull(double d);
-unsigned long long __f_to_ull(float f);
-double __ll_to_d(long long s);
-float __ll_to_f(long long s);
-double __ull_to_d(unsigned long long u);
-float __ull_to_f(unsigned long long u);
-u32* osViGetCurrentFramebuffer(void);
-s32 __osSpSetPc(void* pc);
-void __osGetHWIntrRoutine(s32 idx, OSMesgQueue** outQueue, OSMesg* outMsg);
-void __osSetHWIntrRoutine(s32 idx, OSMesgQueue* queue, OSMesg msg);
-u32 __osGetWatchLo(void);
-void __osSetWatchLo(u32 value);
+
f32 fmodf(f32 dividend, f32 divisor);
void* __osMemset(void* ptr, s32 val, size_t size);
s32 __osStrcmp(const char* str1, const char* str2);
@@ -1625,22 +1403,6 @@ void SysFlashrom_WriteDataSync(void* addr, u32 pageNum, u32 pageCount);
s32 func_80185F90(u32 arg0);
-u32 osFlashGetAddr(u32 pageNum);
-OSPiHandle* osFlashReInit(u8 latency, u8 pulse, u8 pageSize, u8 relDuration, u32 start);
-void osFlashChange(u32 flashNum);
-OSPiHandle* osFlashInit(void);
-void osFlashReadStatus(u8* flashStatus);
-void osFlashReadId(u32* flashType, u32* flashVendor);
-void osFlashClearStatus(void);
-s32 osFlashAllErase(void);
-void osFlashAllEraseThrough(void);
-s32 osFlashCheckEraseEnd(void);
-s32 osFlashSectorErase(u32 pageNum);
-void osFlashSectorEraseThrough(u32 pageNum);
-s32 osFlashWriteBuffer(OSIoMesg* mb, s32 priority, void* dramAddr, OSMesgQueue* mq);
-s32 osFlashWriteArray(u32 pageNum);
-s32 osFlashReadArray(OSIoMesg* mb, s32 priority, u32 pageNum, void* dramAddr, u32 pageCount, OSMesgQueue* mq);
-
Acmd* AudioSynth_Update(Acmd* abiCmdStart, s32* numAbiCmds, s16* aiBufStart, s32 numSamplesPerFrame);
AudioTask* AudioThread_Update(void);
@@ -1661,8 +1423,6 @@ void AudioThread_InitMesgQueues(void);
void Audio_InvalDCache(void* buf, size_t size);
void Audio_WritebackDCache(void* buf, size_t size);
-s32 osAiSetNextBuffer(void* buf, u32 size);
-
void AudioPlayback_NoteDisable(Note* note);
void AudioPlayback_ProcessNotes(void);
TunedSample* AudioPlayback_GetInstrumentTunedSample(Instrument* instrument, s32 semitone);
diff --git a/include/gfx.h b/include/gfx.h
index b9bbb744d..790279368 100644
--- a/include/gfx.h
+++ b/include/gfx.h
@@ -5,6 +5,7 @@
#include "PR/sched.h"
#include "thga.h"
#include "alignment.h"
+#include "unk.h"
struct GameState;
diff --git a/include/gfxprint.h b/include/gfxprint.h
index b652cc132..6149a5c4a 100644
--- a/include/gfxprint.h
+++ b/include/gfxprint.h
@@ -4,7 +4,8 @@
#include "color.h"
#include "PR/gbi.h"
#include "PR/ultratypes.h"
-#include "xstdio.h"
+#include "PR/xstdio.h"
+#include "unk.h"
#define GFXP_UNUSED "\x8E"
#define GFXP_UNUSED_CHAR 0x8E
diff --git a/include/irqmgr.h b/include/irqmgr.h
index ac2c74960..a19169dc7 100644
--- a/include/irqmgr.h
+++ b/include/irqmgr.h
@@ -1,14 +1,8 @@
#ifndef IRQMGR_H
#define IRQMGR_H
-#include "PR/sched.h"
-#include "os.h"
#include "ultra64.h"
-
-#define OS_SC_RETRACE_MSG 1
-#define OS_SC_DONE_MSG 2
-#define OS_SC_NMI_MSG 3 // name is made up, 3 is OS_SC_RDP_DONE_MSG in the original sched.c
-#define OS_SC_PRE_NMI_MSG 4
+#include "PR/sched.h"
typedef struct IrqMgrClient {
/* 0x0 */ struct IrqMgrClient* next;
diff --git a/include/libc/alloca.h b/include/libc/alloca.h
index 4e8720f7e..fa49dd133 100644
--- a/include/libc/alloca.h
+++ b/include/libc/alloca.h
@@ -1,5 +1,5 @@
-#ifndef ALLOCA_H
-#define ALLOCA_H
+#ifndef LIBC_ALLOCA_H
+#define LIBC_ALLOCA_H
void* alloca(u32);
#define alloca __builtin_alloca
diff --git a/include/libc/assert.h b/include/libc/assert.h
deleted file mode 100644
index 1bc72e314..000000000
--- a/include/libc/assert.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef ASSERT_H
-#define ASSERT_H
-
-#endif
diff --git a/include/libc/math.h b/include/libc/math.h
index 1cdac0fb3..618ab52b5 100644
--- a/include/libc/math.h
+++ b/include/libc/math.h
@@ -1,5 +1,5 @@
-#ifndef MATH_H
-#define MATH_H
+#ifndef LIBC_MATH_H
+#define LIBC_MATH_H
#include "PR/ultratypes.h"
@@ -27,8 +27,10 @@ extern f32 __libm_qnan_f;
float fabsf(float f);
#pragma intrinsic(fabsf)
-float sqrtf(float f);
-#pragma intrinsic(sqrtf)
+#ifdef __GNUC__
+#define fabsf(f) __builtin_fabsf((float)(f))
+#endif
+
double sqrt(double d);
#pragma intrinsic(sqrt)
diff --git a/include/libc/stdarg.h b/include/libc/stdarg.h
index 77b8b8866..55f694385 100644
--- a/include/libc/stdarg.h
+++ b/include/libc/stdarg.h
@@ -1,7 +1,5 @@
-#ifndef STDARG_H
-#define STDARG_H
-
-#include "ultra64.h"
+#ifndef LIBC_STDARG_H
+#define LIBC_STDARG_H
// When building with GCC, use the official vaarg macros to avoid warnings
// and possibly bad codegen.
diff --git a/include/libc/stdbool.h b/include/libc/stdbool.h
index d441054c1..52546edb3 100644
--- a/include/libc/stdbool.h
+++ b/include/libc/stdbool.h
@@ -1,5 +1,5 @@
-#ifndef STDBOOL
-#define STDBOOL
+#ifndef LIBC_STDBOOL_H
+#define LIBC_STDBOOL_H
#define __bool_true_false_are_defined 1
diff --git a/include/libc/stddef.h b/include/libc/stddef.h
index 4f55e5725..e867d8e2a 100644
--- a/include/libc/stddef.h
+++ b/include/libc/stddef.h
@@ -1,5 +1,5 @@
-#ifndef STDDEF_H
-#define STDDEF_H
+#ifndef LIBC_STDDEF_H
+#define LIBC_STDDEF_H
#include "PR/ultratypes.h"
diff --git a/include/libc/stdint.h b/include/libc/stdint.h
index 20288d40d..854fd2546 100644
--- a/include/libc/stdint.h
+++ b/include/libc/stdint.h
@@ -1,5 +1,5 @@
-#ifndef STDINT_H
-#define STDINT_H
+#ifndef LIBC_STDINT_H
+#define LIBC_STDINT_H
#include "PR/ultratypes.h"
diff --git a/include/libc/stdlib.h b/include/libc/stdlib.h
index 57d352a13..ec15b4f6c 100644
--- a/include/libc/stdlib.h
+++ b/include/libc/stdlib.h
@@ -1,5 +1,5 @@
-#ifndef STDLIB_H
-#define STDLIB_H
+#ifndef LIBC_STDLIB_H
+#define LIBC_STDLIB_H
#include "libc/stddef.h"
@@ -22,4 +22,7 @@ typedef int ssize_t;
typedef long wchar_t;
+ldiv_t ldiv(long numer, long denom);
+lldiv_t lldiv(long long numer, long long denom);
+
#endif /* STDLIB_H */
diff --git a/include/libc/string.h b/include/libc/string.h
new file mode 100644
index 000000000..9c6a1cb08
--- /dev/null
+++ b/include/libc/string.h
@@ -0,0 +1,12 @@
+#ifndef LIBC_STRING_H
+#define LIBC_STRING_H
+
+#include "libc/stddef.h"
+
+
+const char* strchr(const char* s, int c);
+size_t strlen(const char* s);
+void* memcpy(void* s1, const void* s2, size_t n);
+
+
+#endif
diff --git a/include/macros.h b/include/macros.h
index b03d01b3e..ff764f644 100644
--- a/include/macros.h
+++ b/include/macros.h
@@ -2,7 +2,7 @@
#define MACROS_H
#include "libc/stdint.h"
-#include "ultra64/convert.h"
+#include "PR/os_convert.h"
#include "main.h"
#define SCREEN_WIDTH 320
diff --git a/include/os_malloc.h b/include/os_malloc.h
index 6f6bbf900..4106d42e8 100644
--- a/include/os_malloc.h
+++ b/include/os_malloc.h
@@ -1,8 +1,8 @@
-#ifndef OS_MALLOC
-#define OS_MALLOC
+#ifndef OS_MALLOC_H
+#define OS_MALLOC_H
#include "PR/ultratypes.h"
-#include "ultra64/message.h"
+#include "PR/os_message.h"
#include "libc/stddef.h"
typedef struct ArenaNode {
diff --git a/include/osint.h b/include/osint.h
deleted file mode 100644
index fa74a82eb..000000000
--- a/include/osint.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef _OSINT_H_
-#define _OSINT_H_
-
-// TODO should be in libultra/os
-
-#include "libc/stdarg.h"
-#include "os.h"
-#include "os_internal.h"
-#include "ultraerror.h"
-#include "ultralog.h"
-
-typedef struct {
- /* 0x0 */ OSMesgQueue* messageQueue;
- /* 0x4 */ OSMesg message;
-} __OSEventState;
-
-
-typedef struct {
- /* 0x0 */ OSThread* next;
- /* 0x4 */ OSPri priority;
-} __OSThreadTail;
-
-extern __osHwInt __osHwIntTable[];
-extern __OSEventState __osEventStateTab[];
-
-#endif
diff --git a/include/padmgr.h b/include/padmgr.h
index 7cb3cc800..59157dd81 100644
--- a/include/padmgr.h
+++ b/include/padmgr.h
@@ -2,15 +2,9 @@
#define PADMGR_H
#include "libc/stdbool.h"
-#include "io/controller.h"
+#include "ultra64.h"
#include "irqmgr.h"
-
-typedef struct Input {
- /* 0x00 */ OSContPad cur;
- /* 0x06 */ OSContPad prev;
- /* 0x0C */ OSContPad press; // X/Y store delta from last frame
- /* 0x12 */ OSContPad rel; // X/Y store adjusted
-} Input; // size = 0x18
+#include "padutils.h"
typedef enum {
/* 0 */ PADMGR_CONT_NONE,
diff --git a/include/padutils.h b/include/padutils.h
new file mode 100644
index 000000000..4531bc010
--- /dev/null
+++ b/include/padutils.h
@@ -0,0 +1,14 @@
+#ifndef PADUTILS_H
+#define PADUTILS_H
+
+#include "PR/controller.h"
+
+
+typedef struct Input {
+ /* 0x00 */ OSContPad cur;
+ /* 0x06 */ OSContPad prev;
+ /* 0x0C */ OSContPad press; // X/Y store delta from last frame
+ /* 0x12 */ OSContPad rel; // X/Y store adjusted
+} Input; // size = 0x18
+
+#endif
diff --git a/include/ramrom.h b/include/ramrom.h
deleted file mode 100644
index 6671b9931..000000000
--- a/include/ramrom.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _RAMROM_H_
-#define _RAMROM_H_
-
-#include "PR/ultratypes.h"
-
-typedef struct {
- /* 0x0 */ long type;
- /* 0x4 */ long length;
- /* 0x8 */ long magic;
- /* 0xC */ unsigned char userdata[24564];
-} RamRomBuffer;
-
-#endif
diff --git a/include/rdb.h b/include/rdb.h
deleted file mode 100644
index 04b3ed5bc..000000000
--- a/include/rdb.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef _RDB_H_
-#define _RDB_H_
-
-typedef struct {
- /* 0x0 */ unsigned int type : 2;
- /* 0x0 */ unsigned int length : 2;
- /* 0x1 */ unsigned char buf[3];
-} rdbPacket;
-
-#endif
diff --git a/include/regs.h b/include/regs.h
index bc8bacb1b..2d113ea48 100644
--- a/include/regs.h
+++ b/include/regs.h
@@ -5,6 +5,8 @@
#define REGS_H
#include "ultra64.h"
+#include "unk.h"
+
#define REG_GROUPS 29 // number of REG groups, i.e. REG, SREG, OREG, etc.
#define REG_PAGES 6
diff --git a/include/rmon.h b/include/rmon.h
deleted file mode 100644
index efdd555c6..000000000
--- a/include/rmon.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef _RMON_H_
-#define _RMON_H_
-
-#endif
diff --git a/include/scheduler.h b/include/scheduler.h
index 3cf588b1f..1aeae07ec 100644
--- a/include/scheduler.h
+++ b/include/scheduler.h
@@ -3,8 +3,8 @@
#include "PR/ultratypes.h"
#include "PR/sched.h"
-#include "ultra64/vi.h"
-#include "ultra64/sptask.h"
+#include "PR/os_vi.h"
+#include "PR/sptask.h"
#include "irqmgr.h"
#define TASK_FRAMEBUFFER(task) ((CfbInfo*)(task)->framebuffer)
diff --git a/include/ultra64.h b/include/ultra64.h
index f7baade42..54bb66d69 100644
--- a/include/ultra64.h
+++ b/include/ultra64.h
@@ -1,21 +1,23 @@
-#ifndef _ULTRA64_H_
-#define _ULTRA64_H_
+#ifndef ULTRA64_H
+#define ULTRA64_H
#include "PR/ultratypes.h"
#include "PR/gbi.h"
-#include "unk.h"
-
-#include "ultra64/controller_voice.h"
-#include "ultra64/hardware.h"
-#include "ultra64/message.h"
-#include "ultra64/sptask.h"
-#include "ultra64/thread.h"
-#include "ultra64/rcp.h"
-#include "ultra64/rdp.h"
-#include "ultra64/rsp.h"
-#include "ultra64/r4300.h"
-#include "ultra64/ucode.h"
-#include "ultra64/vi.h"
+#include "PR/gu.h"
+#include "PR/controller_voice.h"
+#include "PR/hardware.h"
+#include "PR/os.h"
+#include "PR/osint.h"
+#include "PR/piint.h"
+#include "PR/siint.h"
+#include "PR/sptask.h"
+#include "PR/rcp.h"
+#include "PR/rdp.h"
+#include "PR/rsp.h"
+#include "PR/r4300.h"
+#include "PR/ucode.h"
+#include "PR/viint.h"
+#include "PR/xstdio.h"
#endif
diff --git a/include/ultra64/viint.h b/include/ultra64/viint.h
deleted file mode 100644
index 6f61307eb..000000000
--- a/include/ultra64/viint.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef ULTRA64_VIINT_H
-#define ULTRA64_VIINT_H
-
-#define VI_STATE_MODE_SET (1 << 0)
-#define VI_STATE_XSCALE_SET (1 << 1)
-#define VI_STATE_YSCALE_FACTOR_SET (1 << 2)
-#define VI_STATE_CTRL_SET (1 << 3)
-#define VI_STATE_BUFFER_SET (1 << 4)
-#define VI_STATE_BLACK (1 << 5)
-#define VI_STATE_REPEATLINE (1 << 6)
-#define VI_STATE_FADE (1 << 7)
-
-#define VI_SCALE_MASK 0xFFF
-#define VI_2_10_FPART_MASK 0x3FF
-#define VI_SUBPIXEL_SH 0x10
-
-// For use in initializing OSViMode structures
-
-#define BURST(hsync_width, color_width, vsync_width, color_start) \
- (((u32)(hsync_width) & 0xFF) | (((u32)(color_width) & 0xFF) << 8) | (((u32)(vsync_width) & 0xF) << 16) | (((u32)(color_start) & 0xFFFF) << 20))
-#define WIDTH(v) (v)
-#define VSYNC(v) (v)
-#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration) & 0xFFFF))
-#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower) & 0xFFFF))
-#define START(start, end) (((u32)(start) << 16) | ((u32)(end) & 0xFFFF))
-
-#define FTOFIX(val, i, f) ((u32)((val) * (f32)(1 << (f))) & ((1 << ((i) + (f))) - 1))
-
-#define F210(val) FTOFIX(val, 2, 10)
-#define SCALE(scaleup, off) (F210((1.0f / (f32)(scaleup))) | (F210((f32)(off)) << 16))
-
-#define VCURRENT(v) v
-#define ORIGIN(v) v
-#define VINTR(v) v
-#define HSTART START
-
-#endif
diff --git a/include/ultraerror.h b/include/ultraerror.h
deleted file mode 100644
index 030b05af6..000000000
--- a/include/ultraerror.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _ULTRAERROR_H_
-#define _ULTRAERROR_H_
-
-typedef void (*OSErrorHandler)(/* ECOFF does not store param types */);
-
-#endif
diff --git a/include/ultralog.h b/include/ultralog.h
deleted file mode 100644
index ae052d91d..000000000
--- a/include/ultralog.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef _ULTRALOG_H_
-#define _ULTRALOG_H_
-
-#include "PR/ultratypes.h"
-
-typedef struct {
- /* 0x0 */ u32 magic;
- /* 0x4 */ u32 len;
- /* 0x8 */ u32* base;
- /* 0xC */ s32 startCount;
- /* 0x10 */ s32 writeOffset;
-} OSLog;
-
-
-typedef struct {
- /* 0x0 */ u32 magic;
- /* 0x4 */ u32 timeStamp;
- /* 0x8 */ u16 argCount;
- /* 0xA */ u16 eventID;
-} OSLogItem;
-
-
-typedef struct {
- /* 0x0 */ u32 magic;
- /* 0x4 */ u32 version;
-} OSLogFileHdr;
-
-#endif
diff --git a/include/variables.h b/include/variables.h
index 1614d922b..0f499fde4 100644
--- a/include/variables.h
+++ b/include/variables.h
@@ -34,7 +34,6 @@ extern s32 sIrqMgrRetraceCount;
extern OSViMode osViModeNtscHpf1;
extern OSViMode osViModePalLan1;
extern s16 sintable[0x400];
-extern __osHwInt __osHwIntTable[];
// extern UNK_TYPE1 D_80097DE4;
// extern UNK_TYPE4 D_80097E08;
extern OSThread* __osThreadTail;
@@ -63,14 +62,12 @@ extern s32 __osPfsLastChannel;
extern OSViMode osViModeNtscLan1;
extern OSViMode osViModeMpalLan1;
// extern __OSViContext D_80098060[2];
-extern __OSViContext* __osViCurr;
-extern __OSViContext* __osViNext;
+
// extern UNK_TYPE4 sCartRomNeedsInit;
extern OSViMode osViModeFpalLan1;
// extern u8 ldigs[];
// extern u8 udigs[];
// extern OSDevMgr __osViDevMgr;
-extern u32 __additional_scanline;
extern char bootThreadName[];
extern char idleThreadName[];
@@ -160,7 +157,6 @@ extern OSPiHandle D_8009D1A8;
extern OSMesg D_8009E3F0[1];
extern OSMesgQueue __osPiAccessQueue;
extern __OSInode __osPfsInodeCache;
-extern __OSEventState __osEventStateTab[16];
extern OSTimer D_8009E590;
extern OSTime __osCurrentTime;
extern u32 __osBaseCounter;
diff --git a/include/viint.h b/include/viint.h
deleted file mode 100644
index fadd5d781..000000000
--- a/include/viint.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef _VIINT_H_
-#define _VIINT_H_
-
-// TODO should be in libultra/io
-
-#include "PR/ultratypes.h"
-#include "os.h"
-
-// typedef struct {
-// /* 0x0 */ f32 factor;
-// /* 0x4 */ u16 offset;
-// /* 0x8 */ u32 scale;
-// } __OSViScale;
-
-
-typedef struct {
- /* 0x0 */ u16 state;
- /* 0x2 */ u16 retraceCount;
- /* 0x4 */ void* buffer;
- /* 0x8 */ OSViMode* modep;
- /* 0xC */ u32 control;
- /* 0x10 */ OSMesgQueue* msgq;
- /* 0x14 */ OSMesg msg;
- /* 0x18 */ __OSViScale x;
- /* 0x24 */ __OSViScale y;
-} __OSViContext; // size = 0x30
-
-#endif
diff --git a/include/z64.h b/include/z64.h
index c94bec081..69e7e01f2 100644
--- a/include/z64.h
+++ b/include/z64.h
@@ -9,14 +9,10 @@
#include "libc/stdlib.h"
#include "ultra64.h"
-#include "ultra64/gs2dex.h"
-#include "io/controller.h"
-#include "osint.h"
-#include "os.h"
+
#include "irqmgr.h"
#include "padmgr.h"
#include "scheduler.h"
-#include "xstdio.h"
#include "color.h"
#include "ichain.h"
@@ -27,6 +23,7 @@
#include "gfx.h"
#include "gfxprint.h"
+#include "padutils.h"
#include "sys_matrix.h"
#include "tha.h"
#include "thga.h"
diff --git a/include/z64actor.h b/include/z64actor.h
index d794b8dd1..5f0ea59ad 100644
--- a/include/z64actor.h
+++ b/include/z64actor.h
@@ -2,6 +2,7 @@
#define Z64ACTOR_H
#include "PR/ultratypes.h"
+#include "padutils.h"
#include "z64math.h"
#include "z64animation.h"
#include "z64collision_check.h"
diff --git a/include/z64audio.h b/include/z64audio.h
index e09848e7a..d2a9afd08 100644
--- a/include/z64audio.h
+++ b/include/z64audio.h
@@ -2,7 +2,8 @@
#define Z64AUDIO_H
#include "PR/ultratypes.h"
-#include "ultra64/os_voice.h"
+#include "PR/os_voice.h"
+#include "audiothread_cmd.h"
#include "libc/stddef.h"
#include "unk.h"
#include "audiothread_cmd.h"
diff --git a/include/z64bombers_notebook.h b/include/z64bombers_notebook.h
index 403f4a88a..5b89aaf70 100644
--- a/include/z64bombers_notebook.h
+++ b/include/z64bombers_notebook.h
@@ -2,9 +2,10 @@
#define Z64BOMBERS_NOTEBOOK_H
#include "ultra64.h"
-#include "io/controller.h"
#include "z64dma.h"
+struct PlayState;
+
#define DEFINE_PERSON(enum, _photo, _description, _metEnum, _metMessage, _metFlag) enum,
typedef enum BombersNotebookPerson {
#include "tables/bombers_notebook/person_table.h"
diff --git a/include/z64frameadvance.h b/include/z64frameadvance.h
index 179a1adba..a05ee8d58 100644
--- a/include/z64frameadvance.h
+++ b/include/z64frameadvance.h
@@ -1,15 +1,17 @@
#ifndef Z64FRAMEADVANCE_H
#define Z64FRAMEADVANCE_H
-#include "padmgr.h"
+#include "ultra64.h"
+
+struct Input;
+
typedef struct FrameAdvanceContext {
/* 0x0 */ s32 enabled;
/* 0x4 */ s32 timer;
} FrameAdvanceContext; // size = 0x8
-
void FrameAdvance_Init(FrameAdvanceContext* frameAdvCtx);
-s32 FrameAdvance_Update(FrameAdvanceContext* frameAdvCtx, Input* input);
+s32 FrameAdvance_Update(FrameAdvanceContext* frameAdvCtx, struct Input* input);
#endif
diff --git a/include/z64game.h b/include/z64game.h
index a0c57853a..8b63b701f 100644
--- a/include/z64game.h
+++ b/include/z64game.h
@@ -4,9 +4,10 @@
#include "ultra64.h"
#include "libc/stdbool.h"
#include "libc/stdint.h"
-#include "io/controller.h"
+#include "padutils.h"
#include "tha.h"
#include "padmgr.h"
+#include "unk.h"
struct GraphicsContext;
struct GameState;
diff --git a/include/z64jpeg.h b/include/z64jpeg.h
index 60797af98..181140386 100644
--- a/include/z64jpeg.h
+++ b/include/z64jpeg.h
@@ -2,7 +2,7 @@
#define Z64JPEG_H
#include "PR/ultratypes.h"
-#include "ultra64/message.h"
+#include "PR/os_message.h"
#include "PR/sched.h"
typedef struct {
diff --git a/include/z64math.h b/include/z64math.h
index a86cf9a20..6fa64f4f4 100644
--- a/include/z64math.h
+++ b/include/z64math.h
@@ -114,6 +114,17 @@ typedef enum {
/* 2 */ OLIB_DIFF // Sub `a` and `b` to dest
} OlibVec3fDiff;
+typedef float MtxF_t[4][4];
+typedef union {
+ MtxF_t mf;
+ struct {
+ float xx, yx, zx, wx,
+ xy, yy, zy, wy,
+ xz, yz, zz, wz,
+ xw, yw, zw, ww;
+ };
+} MtxF; // size = 0x40
+
#define LERPIMP(v0, v1, t) ((v0) + (((v1) - (v0)) * (t)))
#define F32_LERP(v0, v1, t) ((1.0f - (t)) * (f32)(v0) + (t) * (f32)(v1))
#define F32_LERPIMP(v0, v1, t) ((f32)(v0) + (((f32)(v1) - (f32)(v0)) * (t)))
diff --git a/include/z64player.h b/include/z64player.h
index 03bb71d94..f628cd0bc 100644
--- a/include/z64player.h
+++ b/include/z64player.h
@@ -2,7 +2,7 @@
#define Z64PLAYER_H
#include "alignment.h"
-#include "os.h"
+#include "PR/os.h"
#include "z64actor.h"
struct Player;
diff --git a/include/z64rumble.h b/include/z64rumble.h
index cb422d2de..844d712db 100644
--- a/include/z64rumble.h
+++ b/include/z64rumble.h
@@ -2,7 +2,7 @@
#define Z64RUMBLE_H
#include "PR/ultratypes.h"
-#include "io/controller.h"
+#include "PR/controller.h"
typedef enum RumbleManagerState {
/* 0 */ RUMBLEMANAGER_STATE_WIPE, // Disables the request processing and wipes every request. It can be either set manually or automatically by the system as fail-safe in case the Rumble Pak has been vibrating for 2 minutes
diff --git a/include/z64save.h b/include/z64save.h
index 5abf105e9..cdc46f023 100644
--- a/include/z64save.h
+++ b/include/z64save.h
@@ -2,9 +2,9 @@
#define Z64SAVE_H
#include "ultra64.h"
+#include "PR/os.h"
#include "z64item.h"
#include "z64math.h"
-#include "os.h"
struct GameState;
struct PlayState;