From 6475196f0fd24b1697241e3662bc732cdd81d212 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Thu, 26 Oct 2023 10:44:27 -0300 Subject: [PATCH] Yet another libultra cleanup (#1384) * os symbols * various variables * more variables * more cleanup * yeet HW_REG * OS_PHYSICAL_TO_K0 and other cleanups * Rename r4300.h * migrate pimgr data and cleanup on initialize.c * rename osFlash symbols * cleanup gu * vimodes * yeet rmon, do libc files * some os files * hardwareinterrupt * cleanup a lot of os files * cleanup osVirtualToPhysical * various io files * another io chunk * final io chunk * yeet hardware.h * yeet PHYSICAL_TO_VIRTUAL and VIRTUAL_TO_PHYSICAL * fix typo * fix merge * remove global.h from libultra files * fixes and format * brief explanation * review * review * review * review * SEGMENTED_TO_K0 * Revert "SEGMENTED_TO_K0" This reverts commit f8d62d670f91af401feb56489e1cbc45a1260049. * take two * bss * bss --- include/PR/{r4300.h => R4300.h} | 0 include/PR/controller.h | 4 +- include/PR/hardware.h | 36 --------- include/PR/os.h | 11 +++ include/PR/os_exception.h | 32 +++++++- include/PR/os_internal.h | 14 +--- include/PR/os_internal_rsp.h | 4 +- include/PR/os_time.h | 2 +- include/PR/os_vi.h | 8 +- include/PR/piint.h | 75 +++++++++++++++++++ .../PR/{voice_internal.h => voiceinternal.h} | 0 include/alignment.h | 8 +- include/attributes.h | 15 ++++ include/gfx.h | 2 + include/macros.h | 5 +- include/ultra64.h | 3 +- spec | 28 +++---- src/audio/lib/aisetnextbuf.c | 6 +- src/boot/fault.c | 5 +- src/code/sched.c | 12 +-- src/code/z_actor.c | 2 +- src/code/z_bgcheck.c | 2 +- src/code/z_effect_soft_sprite_old_init.c | 2 +- src/code/z_en_hy_code.c | 6 +- src/code/z_lib.c | 8 +- src/code/z_play.c | 14 ++-- src/code/z_player_lib.c | 8 +- src/code/z_room.c | 4 +- src/code/z_scene.c | 4 +- src/libultra/flash/osFlash.c | 22 ++++-- src/libultra/gu/coss.c | 2 +- src/libultra/gu/lookat.c | 3 +- src/libultra/gu/lookathil.c | 3 +- src/libultra/gu/ortho.c | 4 +- src/libultra/gu/perspective.c | 3 +- src/libultra/gu/position.c | 3 +- src/libultra/gu/rotate.c | 7 +- src/libultra/gu/sqrtf.c | 2 +- src/libultra/gu/{guS2DInitBg.c => us2dex.c} | 2 +- src/libultra/io/aigetlen.c | 4 +- src/libultra/io/aisetfreq.c | 12 +-- src/libultra/io/cartrominit.c | 38 +++++----- src/libultra/io/contchannelreset.c | 9 ++- src/libultra/io/contpfs.c | 38 +--------- src/libultra/io/contquery.c | 9 ++- src/libultra/io/contramread.c | 5 +- src/libultra/io/contramwrite.c | 4 +- src/libultra/io/contreaddata.c | 4 +- src/libultra/io/controller.c | 42 ++++++----- src/libultra/io/contsetch.c | 9 ++- src/libultra/io/crc.c | 2 +- src/libultra/io/devmgr.c | 26 ++++--- src/libultra/io/dpgetstat.c | 4 +- src/libultra/io/dpsetstat.c | 4 +- src/libultra/io/epidma.c | 10 +-- src/libultra/io/epilinkhandle.c | 2 +- src/libultra/io/epirawdma.c | 28 +++---- src/libultra/io/epirawread.c | 22 +++--- src/libultra/io/epirawwrite.c | 22 +++--- src/libultra/io/epiread.c | 2 +- src/libultra/io/epiwrite.c | 2 +- src/libultra/io/motor.c | 3 +- src/libultra/io/pfsallocatefile.c | 2 +- src/libultra/io/pfschecker.c | 4 +- src/libultra/io/pfsdeletefile.c | 4 +- src/libultra/io/pfsfilestate.c | 5 +- src/libultra/io/pfsfreeblocks.c | 4 +- src/libultra/io/pfsgetstatus.c | 2 +- src/libultra/io/pfsinitpak.c | 4 +- src/libultra/io/pfsisplug.c | 35 +++++---- src/libultra/io/pfsreadwritefile.c | 2 +- src/libultra/io/pfssearchfile.c | 3 +- src/libultra/io/pfsselectbank.c | 4 +- src/libultra/io/piacs.c | 4 +- src/libultra/io/pigetcmdq.c | 2 +- src/libultra/io/pimgr.c | 14 +++- src/libultra/io/pirawdma.c | 14 ++-- src/libultra/io/si.c | 5 +- src/libultra/io/siacs.c | 9 ++- src/libultra/io/sirawdma.c | 11 +-- src/libultra/io/sirawread.c | 4 +- src/libultra/io/sirawwrite.c | 6 +- src/libultra/io/sp.c | 5 +- src/libultra/io/spgetstat.c | 4 +- src/libultra/io/sprawdma.c | 12 +-- src/libultra/io/spsetpc.c | 9 +-- src/libultra/io/spsetstat.c | 4 +- src/libultra/io/sptask.c | 11 +-- src/libultra/io/sptaskyield.c | 4 +- src/libultra/io/sptaskyielded.c | 14 ++-- src/libultra/io/vi.c | 13 ++-- src/libultra/io/viblack.c | 10 +-- src/libultra/io/viextendvstart.c | 5 ++ src/libultra/io/vigetcurrcontext.c | 2 +- src/libultra/io/vigetcurrframebuf.c | 2 +- src/libultra/io/vigetnextframebuf.c | 6 +- src/libultra/io/vimgr.c | 23 +++--- src/libultra/{gu => io}/visetevent.c | 2 +- src/libultra/io/visetmode.c | 8 +- src/libultra/io/visetspecial.c | 2 +- src/libultra/io/visetxscale.c | 12 ++- src/libultra/io/visetyscale.c | 8 +- src/libultra/io/viswapbuf.c | 4 +- src/libultra/io/viswapcontext.c | 36 +++++---- src/libultra/libc/ldiv.c | 3 +- src/libultra/libc/ll.c | 2 +- src/libultra/libc/llcvt.c | 2 +- src/libultra/{rmon => libc}/sprintf.c | 3 +- src/libultra/libc/string.c | 4 +- src/libultra/{rmon => libc}/xldtob.c | 3 +- src/libultra/{rmon => libc}/xlitob.c | 9 ++- src/libultra/{rmon => libc}/xprintf.c | 2 +- src/libultra/os/afterprenmi.c | 1 - src/libultra/os/createmesgqueue.c | 6 +- src/libultra/os/createthread.c | 12 +-- src/libultra/os/destroythread.c | 8 +- src/libultra/os/getactivequeue.c | 2 +- src/libultra/os/getcurrfaultthread.c | 2 +- src/libultra/os/gethwinterrupt.c | 7 +- src/libultra/os/getmemsize.c | 43 ++++++----- src/libultra/os/getthreadid.c | 2 +- src/libultra/os/getthreadpri.c | 2 +- src/libultra/os/gettime.c | 8 +- src/libultra/os/initialize.c | 55 +++++++------- src/libultra/os/jammesg.c | 10 +-- src/libultra/os/recvmesg.c | 10 +-- src/libultra/os/resetglobalintmask.c | 4 +- src/libultra/os/sendmesg.c | 12 ++- src/libultra/os/seteventmesg.c | 11 ++- src/libultra/os/setglobalintmask.c | 2 +- src/libultra/os/sethwinterrupt.c | 8 +- src/libultra/os/setthreadpri.c | 10 +-- src/libultra/os/settime.c | 2 +- src/libultra/os/settimer.c | 36 +++++---- src/libultra/os/startthread.c | 19 +++-- src/libultra/os/stopthread.c | 19 +++-- src/libultra/os/stoptimer.c | 2 +- src/libultra/os/thread.c | 2 +- src/libultra/os/threadsave.c | 2 +- src/libultra/os/timerintr.c | 5 +- src/libultra/os/viextend.c | 5 -- src/libultra/os/virtualtophysical.c | 16 ++-- src/libultra/os/yieldthread.c | 4 +- src/libultra/vimodes/vimodefpallan1.c | 37 +++++++++ .../vimodempallan1.c} | 22 +++--- .../vimodentschpf1.c} | 22 +++--- src/libultra/vimodes/vimodentschpn1.c | 37 +++++++++ .../vimodentsclan1.c} | 22 +++--- .../vimodepallan1.c} | 22 +++--- src/libultra/voice/voicecontread2.c | 6 +- src/libultra/voice/voicecontread36.c | 6 +- src/libultra/voice/voicecontwrite20.c | 6 +- src/libultra/voice/voicecontwrite4.c | 6 +- src/libultra/voice/voicegetstatus.c | 2 +- src/libultra/voice/voiceinit.c | 2 +- src/libultra/voice/voicemaskdictionary.c | 2 +- src/libultra/voice/voicesetadconverter.c | 5 +- src/libultra/voice/voicesetword.c | 2 +- src/overlays/actors/ovl_Boss_03/z_boss_03.c | 2 +- src/overlays/actors/ovl_Boss_06/z_boss_06.c | 4 +- src/overlays/actors/ovl_Dm_An/z_dm_an.c | 8 +- src/overlays/actors/ovl_Dm_Bal/z_dm_bal.c | 2 +- src/overlays/actors/ovl_Dm_Gm/z_dm_gm.c | 8 +- src/overlays/actors/ovl_Dm_Stk/z_dm_stk.c | 8 +- src/overlays/actors/ovl_En_Bal/z_en_bal.c | 2 +- .../actors/ovl_En_Bba_01/z_en_bba_01.c | 6 +- .../actors/ovl_En_Cne_01/z_en_cne_01.c | 6 +- src/overlays/actors/ovl_En_Dnk/z_en_dnk.c | 2 +- src/overlays/actors/ovl_En_Fish2/z_en_fish2.c | 2 +- src/overlays/actors/ovl_En_Ge2/z_en_ge2.c | 2 +- src/overlays/actors/ovl_En_Geg/z_en_geg.c | 4 +- src/overlays/actors/ovl_En_Go/z_en_go.c | 8 +- .../actors/ovl_En_Guruguru/z_en_guruguru.c | 4 +- .../actors/ovl_En_Kaizoku/z_en_kaizoku.c | 2 +- src/overlays/actors/ovl_En_Ma4/z_en_ma4.c | 4 +- .../actors/ovl_En_Ma_Yts/z_en_ma_yts.c | 4 +- src/overlays/actors/ovl_En_Nwc/z_en_nwc.c | 4 +- .../actors/ovl_En_Pamera/z_en_pamera.c | 6 +- .../actors/ovl_En_S_Goro/z_en_s_goro.c | 6 +- src/overlays/actors/ovl_En_Sob1/z_en_sob1.c | 6 +- src/overlays/actors/ovl_En_Ssh/z_en_ssh.c | 2 +- src/overlays/actors/ovl_En_St/z_en_st.c | 2 +- .../ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c | 2 +- .../ovl_Effect_Ss_D_Fire/z_eff_ss_d_fire.c | 2 +- .../z_eff_ss_dt_bubble.c | 2 +- .../ovl_Effect_Ss_Extra/z_eff_ss_extra.c | 4 +- .../ovl_Effect_Ss_Sibuki/z_eff_ss_sibuki.c | 2 +- .../ovl_kaleido_scope/z_kaleido_scope_NES.c | 2 +- tools/disasm/files.txt | 18 +++-- tools/namefixer.py | 3 + tools/sizes/boot_functions.csv | 4 +- 191 files changed, 938 insertions(+), 765 deletions(-) rename include/PR/{r4300.h => R4300.h} (100%) delete mode 100644 include/PR/hardware.h rename include/PR/{voice_internal.h => voiceinternal.h} (100%) create mode 100644 include/attributes.h rename src/libultra/gu/{guS2DInitBg.c => us2dex.c} (97%) create mode 100644 src/libultra/io/viextendvstart.c rename src/libultra/{gu => io}/visetevent.c (91%) rename src/libultra/{rmon => libc}/sprintf.c (92%) rename src/libultra/{rmon => libc}/xldtob.c (99%) rename src/libultra/{rmon => libc}/xlitob.c (89%) rename src/libultra/{rmon => libc}/xprintf.c (99%) delete mode 100644 src/libultra/os/viextend.c create mode 100644 src/libultra/vimodes/vimodefpallan1.c rename src/libultra/{io/osViModeMpalLan1.c => vimodes/vimodempallan1.c} (52%) rename src/libultra/{io/osViModeNtscHpf1.c => vimodes/vimodentschpf1.c} (52%) create mode 100644 src/libultra/vimodes/vimodentschpn1.c rename src/libultra/{io/osViModeNtscLan1.c => vimodes/vimodentsclan1.c} (52%) rename src/libultra/{io/osViModePalLan1.c => vimodes/vimodepallan1.c} (53%) diff --git a/include/PR/r4300.h b/include/PR/R4300.h similarity index 100% rename from include/PR/r4300.h rename to include/PR/R4300.h diff --git a/include/PR/controller.h b/include/PR/controller.h index 8f5f35fe6c..367912452c 100644 --- a/include/PR/controller.h +++ b/include/PR/controller.h @@ -142,8 +142,6 @@ typedef struct { /* 0x7 */ s8 stick_y; } __OSContReadFormat; - -// Original name: __OSContRequesFormat typedef struct { /* 0x00 */ u8 align; /* 0x01 */ u8 txsize; @@ -153,7 +151,7 @@ typedef struct { /* 0x05 */ u8 typel; /* 0x06 */ u8 status; /* 0x07 */ u8 align1; -} __OSContRequestHeader; // size = 0x8 +} __OSContRequesFormat; // size = 0x8 typedef struct { /* 0x00 */ u8 txsize; diff --git a/include/PR/hardware.h b/include/PR/hardware.h deleted file mode 100644 index c6f27bdffc..0000000000 --- a/include/PR/hardware.h +++ /dev/null @@ -1,36 +0,0 @@ -#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 -#define RDRAM_UNCACHED KSEG1 - -// Cached RDRAM -#define KSEG0 0x80000000 // 0x80000000 - 0x9FFFFFFF Physical memory, cached, unmapped -#define RDRAM_CACHED KSEG0 - -// Volatile access wrapper, enforcing uncached memory -#define HW_REG(reg, type) *(volatile type*)((reg) | KSEG1) - -#define TMEM_SIZE 0x1000 - -#define MI_INIT_MODE_REG 0x04300000 -#define MI_MODE_REG MI_INIT_MODE_REG -#define MI_VERSION_REG 0x04300004 -#define MI_INTR_REG 0x04300008 -#define MI_INTR_MASK_REG 0x0430000C - -/* Interrupt pending bits */ -#define CAUSE_IP8 0x00008000 /* External level 8 pending - COMPARE */ -#define CAUSE_IP7 0x00004000 /* External level 7 pending - INT4 */ -#define CAUSE_IP6 0x00002000 /* External level 6 pending - INT3 */ -#define CAUSE_IP5 0x00001000 /* External level 5 pending - INT2 */ -#define CAUSE_IP4 0x00000800 /* External level 4 pending - INT1 */ -#define CAUSE_IP3 0x00000400 /* External level 3 pending - INT0 */ -#define CAUSE_SW2 0x00000200 /* Software level 2 pending */ -#define CAUSE_SW1 0x00000100 /* Software level 1 pending */ - -#endif diff --git a/include/PR/os.h b/include/PR/os.h index 1b39d79a17..8b55f5bcb7 100644 --- a/include/PR/os.h +++ b/include/PR/os.h @@ -24,4 +24,15 @@ #include "os_vi.h" #include "os_voice.h" +/* + * Stack size for I/O device managers: PIM (PI Manager), VIM (VI Manager), + * SIM (SI Manager) + * + */ +#define OS_PIM_STACKSIZE 4096 +#define OS_VIM_STACKSIZE 4096 +#define OS_SIM_STACKSIZE 4096 + +#define OS_MIN_STACKSIZE 72 + #endif diff --git a/include/PR/os_exception.h b/include/PR/os_exception.h index b5c2e7ba8a..7140c96636 100644 --- a/include/PR/os_exception.h +++ b/include/PR/os_exception.h @@ -7,13 +7,41 @@ typedef u32 OSIntMask; typedef u32 OSHWIntr; +/* Flags for debugging purpose */ + +#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ +#define OS_FLAG_FAULT 2 /* CPU fault has occurred */ + +/* Interrupt masks */ + +#define OS_IM_NONE 0x00000001 +#define OS_IM_RCP 0x00000401 +#define OS_IM_SW1 0x00000501 +#define OS_IM_SW2 0x00000601 +#define OS_IM_CART 0x00000c01 +#define OS_IM_PRENMI 0x00001401 +#define OS_IM_RDBWRITE 0x00002401 +#define OS_IM_RDBREAD 0x00004401 +#define OS_IM_COUNTER 0x00008401 +#define OS_IM_CPU 0x0000FF01 +#define OS_IM_SP 0x00010401 +#define OS_IM_SI 0x00020401 +#define OS_IM_AI 0x00040401 +#define OS_IM_VI 0x00080401 +#define OS_IM_PI 0x00100401 +#define OS_IM_DP 0x00200401 +#define OS_IM_ALL 0x003FFF01 +#define RCP_IMASK 0x003F0000 +#define RCP_IMASKSHIFT 16 + + 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 __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void* stackEnd); +void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handler)(void), void** stackEnd); void __osSetGlobalIntMask(OSHWIntr mask); void __osResetGlobalIntMask(OSHWIntr mask); diff --git a/include/PR/os_internal.h b/include/PR/os_internal.h index 58e6608013..f2c5bfa177 100644 --- a/include/PR/os_internal.h +++ b/include/PR/os_internal.h @@ -7,18 +7,8 @@ #include "os_internal_rsp.h" typedef struct __osHwInt { - /* 0x00 */ OSMesgQueue* queue; - /* 0x04 */ OSMesg msg; + /* 0x00 */ s32 (*handler)(void); + /* 0x04 */ void* stackEnd; } __osHwInt; // size = 0x08 -typedef struct { - /* 0x00 */ u32 initialized; - /* 0x04 */ OSThread* mgrThread; - /* 0x08 */ OSMesgQueue* cmdQueue; - /* 0x0C */ OSMesgQueue* eventQueue; - /* 0x10 */ OSMesgQueue* accessQueue; - /* 0x14 */ s32 (*piDmaCallback)(s32, uintptr_t, void*, size_t); - /* 0x18 */ s32 (*epiDmaCallback)(OSPiHandle*, s32, uintptr_t, void*, size_t); -} OSMgrArgs; // size = 0x1C - #endif diff --git a/include/PR/os_internal_rsp.h b/include/PR/os_internal_rsp.h index ce72a146b8..a79426bc79 100644 --- a/include/PR/os_internal_rsp.h +++ b/include/PR/os_internal_rsp.h @@ -5,7 +5,7 @@ u32 __osSpGetStatus(void); void __osSpSetStatus(u32 data); -s32 __osSpSetPc(void* pc); -s32 __osSpRawStartDma(s32 direction, void* devAddr, void* dramAddr, size_t size); +s32 __osSpSetPc(u32 pc); +s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, size_t size); #endif diff --git a/include/PR/os_time.h b/include/PR/os_time.h index 31702c0bb2..d0da9b8a9b 100644 --- a/include/PR/os_time.h +++ b/include/PR/os_time.h @@ -18,7 +18,7 @@ typedef struct OSTimer_s { OSTime osGetTime(void); void osSetTime(OSTime ticks); -s32 osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg); +s32 osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg); s32 osStopTimer(OSTimer* t); diff --git a/include/PR/os_vi.h b/include/PR/os_vi.h index d2872962bb..041622916c 100644 --- a/include/PR/os_vi.h +++ b/include/PR/os_vi.h @@ -115,6 +115,12 @@ typedef struct { #define OS_VI_UNK28 28 +extern OSViMode osViModeNtscHpf1; +extern OSViMode osViModePalLan1; +extern OSViMode osViModeNtscHpn1; +extern OSViMode osViModeNtscLan1; +extern OSViMode osViModeMpalLan1; +extern OSViMode osViModeFpalLan1; extern OSViMode osViModeNtscHpf1; extern OSViMode osViModePalLan1; @@ -127,7 +133,7 @@ void* osViGetCurrentFramebuffer(void); void* osViGetNextFramebuffer(void); void osViSetXScale(f32 value); void osViSetYScale(f32 value); -void osViExtendVStart(u32 a0); +void osViExtendVStart(u32 value); void osViSetSpecialFeatures(u32 func); void osViSetMode(OSViMode* modep); void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount); diff --git a/include/PR/piint.h b/include/PR/piint.h index 91d9667068..8517f9d63b 100644 --- a/include/PR/piint.h +++ b/include/PR/piint.h @@ -5,6 +5,81 @@ #include "os_pi.h" #include "libc/stdint.h" +#define LEO_BASE_REG 0x05000000 + +#define LEO_CMD (LEO_BASE_REG + 0x508) +#define LEO_STATUS (LEO_BASE_REG + 0x508) + +#define LEO_BM_CTL (LEO_BASE_REG + 0x510) +#define LEO_BM_STATUS (LEO_BASE_REG + 0x510) + +#define LEO_SEQ_CTL (LEO_BASE_REG + 0x518) +#define LEO_SEQ_STATUS (LEO_BASE_REG + 0x518) + +#define LEO_C2_BUFF (LEO_BASE_REG + 0x000) // C2 Sector Buffer +#define LEO_SECTOR_BUFF (LEO_BASE_REG + 0x400) // Data Sector Buffer +#define LEO_DATA (LEO_BASE_REG + 0x500) // Data +#define LEO_MISC_REG (LEO_BASE_REG + 0x504) // Misc Register +#define LEO_CUR_TK (LEO_BASE_REG + 0x50C) // Current Track +#define LEO_ERR_SECTOR (LEO_BASE_REG + 0x514) // Sector Error Status +#define LEO_CUR_SECTOR (LEO_BASE_REG + 0x51C) // Current Sector +#define LEO_HARD_RESET (LEO_BASE_REG + 0x520) // Hard Reset +#define LEO_C1_S0 (LEO_BASE_REG + 0x524) // C1 +#define LEO_HOST_SECBYTE (LEO_BASE_REG + 0x528) // Sector Size (in bytes) +#define LEO_C1_S2 (LEO_BASE_REG + 0x52C) // C1 +#define LEO_SEC_BYTE (LEO_BASE_REG + 0x530) // Sectors per Block, Full Size +#define LEO_C1_S4 (LEO_BASE_REG + 0x534) // C1 +#define LEO_C1_S6 (LEO_BASE_REG + 0x538) // C1 +#define LEO_CUR_ADDR (LEO_BASE_REG + 0x53C) // Current Address? +#define LEO_ID_REG (LEO_BASE_REG + 0x540) // ID +#define LEO_TEST_REG (LEO_BASE_REG + 0x544) // Test Read +#define LEO_TEST_PIN_SEL (LEO_BASE_REG + 0x548) // Test Write +#define LEO_RAM_ADDR (LEO_BASE_REG + 0x580) // Microsequencer RAM + +#define LEO_STATUS_PRESENCE_MASK 0xFFFF + +#define LEO_STATUS_DATA_REQUEST 0x40000000 +#define LEO_STATUS_C2_TRANSFER 0x10000000 +#define LEO_STATUS_BUFFER_MANAGER_ERROR 0x08000000 +#define LEO_STATUS_BUFFER_MANAGER_INTERRUPT 0x04000000 +#define LEO_STATUS_MECHANIC_INTERRUPT 0x02000000 +#define LEO_STATUS_DISK_PRESENT 0x01000000 +#define LEO_STATUS_BUSY_STATE 0x00800000 +#define LEO_STATUS_RESET_STATE 0x00400000 +#define LEO_STATUS_MOTOR_NOT_SPINNING 0x00100000 +#define LEO_STATUS_HEAD_RETRACTED 0x00080000 +#define LEO_STATUS_WRITE_PROTECT_ERROR 0x00040000 +#define LEO_STATUS_MECHANIC_ERROR 0x00020000 +#define LEO_STATUS_DISK_CHANGE 0x00010000 + +#define LEO_STATUS_MODE_MASK (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_SLEEP (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_STANDBY (LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_ACTIVE 0 + +#define LEO_CUR_TK_INDEX_LOCK 0x60000000 + +#define LEO_BM_STATUS_RUNNING 0x80000000 // Running +#define LEO_BM_STATUS_ERROR 0x04000000 // Error +#define LEO_BM_STATUS_MICRO 0x02000000 // Micro Status? +#define LEO_BM_STATUS_BLOCK 0x01000000 // Block Transfer +#define LEO_BM_STATUS_C1CORRECTION 0x00800000 // C1 Correction +#define LEO_BM_STATUS_C1DOUBLE 0x00400000 // C1 Double +#define LEO_BM_STATUS_C1SINGLE 0x00200000 // C1 Single +#define LEO_BM_STATUS_C1ERROR 0x00010000 // C1 Error + +#define LEO_BM_CTL_START 0x80000000 // Start Buffer Manager +#define LEO_BM_CTL_MODE 0x40000000 // Buffer Manager Mode +#define LEO_BM_CTL_IMASK 0x20000000 // BM Interrupt Mask +#define LEO_BM_CTL_RESET 0x10000000 // Buffer Manager Reset +#define LEO_BM_CTL_DISABLE_OR 0x08000000 // Disable OR Check? +#define LEO_BM_CTL_DISABLE_C1 0x04000000 // Disable C1 Correction +#define LEO_BM_CTL_BLOCK 0x02000000 // Block Transfer +#define LEO_BM_CTL_CLR_MECHANIC_INTR 0x01000000 // Mechanic Interrupt Reset + +#define LEO_BM_CTL_CONTROL_MASK 0xFF000000 +#define LEO_BM_CTL_SECTOR_MASK 0x00FF0000 +#define LEO_BM_CTL_SECTOR_SHIFT 16 extern OSDevMgr __osPiDevMgr; extern OSPiHandle* __osCurrentHandle[]; diff --git a/include/PR/voice_internal.h b/include/PR/voiceinternal.h similarity index 100% rename from include/PR/voice_internal.h rename to include/PR/voiceinternal.h diff --git a/include/alignment.h b/include/alignment.h index e26a1d3f33..f2fd657504 100644 --- a/include/alignment.h +++ b/include/alignment.h @@ -1,16 +1,16 @@ #ifndef ALIGNMENT_H #define ALIGNMENT_H +#include "attributes.h" + #define ALIGN8(val) (((val) + 7) & ~7) #define ALIGN16(val) (((val) + 0xF) & ~0xF) #define ALIGN32(val) (((val) + 0x1F) & ~0x1F) #define ALIGN64(val) (((val) + 0x3F) & ~0x3F) #define ALIGN256(val) (((val) + 0xFF) & ~0xFF) -#ifdef __GNUC__ -#define ALIGNED8 __attribute__ ((aligned (8))) -#else -#define ALIGNED8 +#ifndef ALIGNED +#define ALIGNED(x) __attribute__ ((aligned (x))) #endif #ifdef __sgi /* IDO compiler */ diff --git a/include/attributes.h b/include/attributes.h new file mode 100644 index 0000000000..ea54a323eb --- /dev/null +++ b/include/attributes.h @@ -0,0 +1,15 @@ +#ifndef ATTRIBUTES_H +#define ATTRIBUTES_H + +// If not building with a modern GCC-like compiler then make any use of __attribute__ a no-op +#if (!defined(__GNUC__) && !defined(__clang__)) || defined(M2CTX) || defined(__sgi) + #ifndef __attribute__ + #define __attribute__(x) + #endif +#endif + +#define UNUSED __attribute__((unused)) +#define FALLTHROUGH __attribute__((fallthrough)) +#define NORETURN __attribute__((noreturn)) + +#endif diff --git a/include/gfx.h b/include/gfx.h index bc309001e9..87f949d8be 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -9,6 +9,8 @@ struct GameState; +#define TMEM_SIZE 0x1000 + typedef enum SetupDL { /* 0x00 */ SETUPDL_0, /* 0x01 */ SETUPDL_1, diff --git a/include/macros.h b/include/macros.h index c81d504494..223a12e8e5 100644 --- a/include/macros.h +++ b/include/macros.h @@ -21,10 +21,7 @@ #define ARRAY_COUNT_2D(arr) (ARRAY_COUNT(arr) * ARRAY_COUNT(arr[0])) -// TODO: After uintptr_t cast change should have an AVOID_UB target that just toggles the KSEG0 bit in the address rather than add/sub 0x80000000 -#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) + RDRAM_CACHED) -#define VIRTUAL_TO_PHYSICAL(addr) (uintptr_t)((u8*)(addr) - RDRAM_CACHED) -#define SEGMENTED_TO_VIRTUAL(addr) (void*)(PHYSICAL_TO_VIRTUAL(gSegments[SEGMENT_NUMBER(addr)]) + SEGMENT_OFFSET(addr)) +#define SEGMENTED_TO_K0(addr) (void*)((gSegments[SEGMENT_NUMBER(addr)] + K0BASE) + SEGMENT_OFFSET(addr)) #define GET_ACTIVE_CAM(play) ((play)->cameraPtrs[(play)->activeCamId]) diff --git a/include/ultra64.h b/include/ultra64.h index 9f810a733f..2a834aaa69 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -7,7 +7,6 @@ #include "PR/gu.h" #include "PR/guint.h" #include "PR/controller_voice.h" -#include "PR/hardware.h" #include "PR/os.h" #include "PR/osint.h" #include "PR/piint.h" @@ -15,7 +14,7 @@ #include "PR/sptask.h" #include "PR/rcp.h" #include "PR/rdp.h" -#include "PR/r4300.h" +#include "PR/R4300.h" #include "PR/ucode.h" #include "PR/viint.h" #include "PR/xstdio.h" diff --git a/spec b/spec index f0f1f865fa..a8be960fba 100644 --- a/spec +++ b/spec @@ -42,21 +42,21 @@ beginseg include "build/src/boot/O2/system_malloc.o" include "build/src/boot/O2/rand.o" include "build/src/boot/O2/__osMalloc.o" - include "build/src/libultra/rmon/sprintf.o" + include "build/src/libultra/libc/sprintf.o" include "build/src/boot/O2/printutils.o" include "build/src/boot/O2/sleep.o" include "build/asm/boot/setcause.text.o" include "build/src/libultra/os/sendmesg.o" include "build/src/libultra/io/pfsfreeblocks.o" - include "build/src/libultra/os/viextend.o" + include "build/src/libultra/io/viextendvstart.o" include "build/src/libultra/os/stopthread.o" include "build/src/libultra/os/recvmesg.o" include "build/asm/boot/setintmask.text.o" include "build/data/boot/setintmask.rodata.o" include "build/asm/boot/getintmask.text.o" include "build/src/libultra/voice/voicesetword.o" - include "build/src/libultra/io/osViModeNtscHpf1.o" - include "build/src/libultra/io/osViModePalLan1.o" + include "build/src/libultra/vimodes/vimodentschpf1.o" + include "build/src/libultra/vimodes/vimodepallan1.o" include "build/asm/boot/guScale.text.o" include "build/src/libultra/gu/sinf.o" include "build/src/libultra/gu/sins.o" @@ -108,11 +108,11 @@ beginseg include "build/src/libultra/os/stoptimer.o" include "build/asm/boot/probetlb.text.o" include "build/src/libultra/io/pimgr.o" - include "build/data/boot/pimgr.data.o" include "build/src/libultra/io/piacs.o" pad_text include "build/src/libultra/io/devmgr.o" include "build/src/libultra/io/pirawdma.o" + include "build/src/libultra/vimodes/vimodentschpn1.o" include "build/src/libultra/io/contpfs.o" include "build/asm/boot/getcount.text.o" pad_text @@ -124,7 +124,7 @@ beginseg include "build/src/libultra/os/afterprenmi.o" include "build/src/libultra/io/contquery.o" include "build/src/libultra/gu/lookathil.o" - include "build/src/libultra/rmon/xprintf.o" + include "build/src/libultra/libc/xprintf.o" include "build/src/libultra/voice/voicecleardictionary.o" include "build/asm/boot/unmaptlball.text.o" include "build/src/libultra/io/epidma.o" @@ -169,8 +169,8 @@ beginseg include "build/src/libultra/io/pfsdeletefile.o" include "build/src/libultra/gu/ortho.o" include "build/asm/boot/interrupt.text.o" - include "build/src/libultra/io/osViModeNtscLan1.o" - include "build/src/libultra/io/osViModeMpalLan1.o" + include "build/src/libultra/vimodes/vimodentsclan1.o" + include "build/src/libultra/vimodes/vimodempallan1.o" include "build/src/libultra/io/vi.o" include "build/src/libultra/io/viswapcontext.o" include "build/src/libultra/io/pigetcmdq.o" @@ -180,12 +180,12 @@ beginseg include "build/src/libultra/gu/coss.o" include "build/src/libultra/os/settime.o" include "build/src/libultra/voice/voicestopread.o" - include "build/src/libultra/gu/visetevent.o" + include "build/src/libultra/io/visetevent.o" include "build/src/libultra/io/pfsisplug.o" include "build/src/libultra/voice/voicegetstatus.o" include "build/src/libultra/io/cartrominit.o" - include "build/src/libultra/gu/guS2DInitBg.o" - include "build/data/boot/guS2DInitBg.data.o" + include "build/src/libultra/gu/us2dex.o" + include "build/src/libultra/vimodes/vimodefpallan1.o" include "build/src/libultra/io/pfsselectbank.o" include "build/src/libultra/io/contsetch.o" include "build/asm/boot/setfpccsr.text.o" @@ -203,10 +203,10 @@ beginseg include "build/src/libultra/io/contramwrite.o" include "build/src/libultra/io/epirawwrite.o" include "build/src/libultra/os/settimer.o" - include "build/data/boot/__libm_qnan_f.rodata.o" - include "build/src/libultra/rmon/xldtob.o" + include "build/data/boot/libm_vals.rodata.o" + include "build/src/libultra/libc/xldtob.o" include "build/src/libultra/libc/ldiv.o" - include "build/src/libultra/rmon/xlitob.o" + include "build/src/libultra/libc/xlitob.o" include "build/src/libultra/io/sirawwrite.o" include "build/src/libultra/io/spgetstat.o" include "build/src/libultra/io/spsetstat.o" diff --git a/src/audio/lib/aisetnextbuf.c b/src/audio/lib/aisetnextbuf.c index c3434b19a4..57f8ade57a 100644 --- a/src/audio/lib/aisetnextbuf.c +++ b/src/audio/lib/aisetnextbuf.c @@ -18,15 +18,15 @@ s32 osAiSetNextBuffer(void* buf, u32 size) { } // Originally a call to __osAiDeviceBusy - status = HW_REG(AI_STATUS_REG, s32); + status = IO_READ(AI_STATUS_REG); if (status & AI_STATUS_FIFO_FULL) { return -1; } // OS_K0_TO_PHYSICAL replaces osVirtualToPhysical, this replacement // assumes that only KSEG0 addresses are given - HW_REG(AI_DRAM_ADDR_REG, u32) = OS_K0_TO_PHYSICAL(bufAdjusted); - HW_REG(AI_LEN_REG, u32) = size; + IO_WRITE(AI_DRAM_ADDR_REG, OS_K0_TO_PHYSICAL(bufAdjusted)); + IO_WRITE(AI_LEN_REG, size); return 0; } diff --git a/src/boot/fault.c b/src/boot/fault.c index 26b579850c..0ee4faed75 100644 --- a/src/boot/fault.c +++ b/src/boot/fault.c @@ -42,12 +42,15 @@ #include "fault_internal.h" #include "fault.h" +#include "prevent_bss_reordering.h" #include "prevent_bss_reordering2.h" -#include "global.h" #include "vt.h" #include "PR/osint.h" #include "stackcheck.h" #include "z64thread.h" +#include "main.h" +#include "macros.h" +#include "global.h" FaultMgr* sFaultInstance; f32 sFaultTimeTotal; // read but not set anywhere diff --git a/src/code/sched.c b/src/code/sched.c index 289b4a6964..f16880b613 100644 --- a/src/code/sched.c +++ b/src/code/sched.c @@ -74,14 +74,14 @@ void Sched_HandleAudioCancel(SchedContext* sched) { osSyncPrintf("AUDIO SP キャンセルします\n"); if ((sched->curRSPTask != NULL) && (sched->curRSPTask->list.t.type == M_AUDTASK)) { - if (!(HW_REG(SP_STATUS_REG, u32) & SP_STATUS_HALT)) { + if (!(IO_READ(SP_STATUS_REG) & SP_STATUS_HALT)) { // Attempts to stop AUDIO SP osSyncPrintf("AUDIO SP止めようとします\n"); - HW_REG(SP_STATUS_REG, u32) = SP_SET_HALT; + IO_WRITE(SP_STATUS_REG, SP_SET_HALT); i = 0; - while (!(HW_REG(SP_STATUS_REG, u32) & SP_STATUS_HALT)) { + while (!(IO_READ(SP_STATUS_REG) & SP_STATUS_HALT)) { if (i++ > 100) { // AUDIO SP did not stop (10ms timeout) osSyncPrintf("AUDIO SP止まりませんでした(10msタイムアウト)\n"); @@ -136,14 +136,14 @@ void Sched_HandleGfxCancel(SchedContext* sched) { osSyncPrintf("GRAPH SP キャンセルします\n"); if ((sched->curRSPTask != NULL) && (sched->curRSPTask->list.t.type == M_GFXTASK)) { - if (!(HW_REG(SP_STATUS_REG, u32) & SP_STATUS_HALT)) { + if (!(IO_READ(SP_STATUS_REG) & SP_STATUS_HALT)) { // GRAPH SP tries to stop osSyncPrintf("GRAPH SP止めようとします\n"); - HW_REG(SP_STATUS_REG, u32) = SP_SET_HALT; + IO_WRITE(SP_STATUS_REG, SP_SET_HALT); i = 0; - while (!(HW_REG(SP_STATUS_REG, u32) & SP_STATUS_HALT)) { + while (!(IO_READ(SP_STATUS_REG) & SP_STATUS_HALT)) { if (i++ > 100) { // GRAPH SP did not stop (10ms timeout) osSyncPrintf("GRAPH SP止まりませんでした(10msタイムアウト)\n"); diff --git a/src/code/z_actor.c b/src/code/z_actor.c index f2b39de4e5..d7d28dd91a 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1098,7 +1098,7 @@ void Actor_SetScale(Actor* actor, f32 scale) { } void Actor_SetObjectDependency(PlayState* play, Actor* actor) { - gSegments[0x06] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[actor->objectSlot].segment); + gSegments[0x06] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[actor->objectSlot].segment); } void Actor_Init(Actor* actor, PlayState* play) { diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index f0807172cd..d16102567a 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -3957,7 +3957,7 @@ s32 BgCheck_SphVsFirstDynaPoly(CollisionContext* colCtx, u16 xpFlags, CollisionP } /** - * SEGMENTED_TO_VIRTUAL CollisionHeader members + * SEGMENTED_TO_K0 CollisionHeader members */ void CollisionHeader_SegmentedToVirtual(CollisionHeader* colHeader) { colHeader->vtxList = Lib_SegmentedToVirtual(colHeader->vtxList); diff --git a/src/code/z_effect_soft_sprite_old_init.c b/src/code/z_effect_soft_sprite_old_init.c index 245f90a82e..4ee7418015 100644 --- a/src/code/z_effect_soft_sprite_old_init.c +++ b/src/code/z_effect_soft_sprite_old_init.c @@ -50,7 +50,7 @@ void EffectSs_DrawGEffect(PlayState* play, EffectSs* this, TexturePtr texture) { SkinMatrix_SetScale(&mfScale, scale, scale, scale); SkinMatrix_MtxFMtxFMult(&mfTrans, &play->billboardMtxF, &mfTrans11DA0); SkinMatrix_MtxFMtxFMult(&mfTrans11DA0, &mfScale, &mfResult); - gSegments[0x06] = VIRTUAL_TO_PHYSICAL(objectPtr); + gSegments[0x06] = OS_K0_TO_PHYSICAL(objectPtr); gSPSegment(POLY_XLU_DISP++, 0x06, objectPtr); mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &mfResult); diff --git a/src/code/z_en_hy_code.c b/src/code/z_en_hy_code.c index c7d89137bb..3ca6b175d5 100644 --- a/src/code/z_en_hy_code.c +++ b/src/code/z_en_hy_code.c @@ -133,7 +133,7 @@ EnDoor* EnHy_FindNearestDoor(Actor* actor, PlayState* play) { } void EnHy_ChangeObjectAndAnim(EnHy* enHy, PlayState* play, s16 animIndex) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[enHy->animObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[enHy->animObjectSlot].segment); EnHy_ChangeAnim(&enHy->skelAnime, animIndex); } @@ -141,7 +141,7 @@ s32 EnHy_UpdateSkelAnime(EnHy* enHy, PlayState* play) { s32 isUpdated = false; if (enHy->actor.draw != NULL) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[enHy->animObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[enHy->animObjectSlot].segment); SkelAnime_Update(&enHy->skelAnime); isUpdated = true; } @@ -168,7 +168,7 @@ s32 EnHy_Init(EnHy* enHy, PlayState* play, FlexSkeletonHeader* skeletonHeaderSeg enHy->actor.objectSlot = enHy->skelLowerObjectSlot; isInitialized = true; ActorShape_Init(&enHy->actor.shape, 0.0f, NULL, 0.0f); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[enHy->actor.objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[enHy->actor.objectSlot].segment); SkelAnime_InitFlex(play, &enHy->skelAnime, skeletonHeaderSeg, NULL, enHy->jointTable, enHy->morphTable, ENHY_LIMB_MAX); EnHy_ChangeObjectAndAnim(enHy, play, animIndex); diff --git a/src/code/z_lib.c b/src/code/z_lib.c index a68d7c8825..c520b00d56 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -699,14 +699,14 @@ void Lib_Nop801004FC(void) { } void* Lib_SegmentedToVirtual(void* ptr) { - return SEGMENTED_TO_VIRTUAL(ptr); + return SEGMENTED_TO_K0(ptr); } void* Lib_SegmentedToVirtualNull(void* ptr) { if (((uintptr_t)ptr >> 28) == 0) { return ptr; } else { - return SEGMENTED_TO_VIRTUAL(ptr); + return SEGMENTED_TO_K0(ptr); } } @@ -719,7 +719,7 @@ void* Lib_VirtualToPhysical(void* ptr) { if (ptr == NULL) { return NULL; } else { - return (void*)VIRTUAL_TO_PHYSICAL(ptr); + return (void*)OS_K0_TO_PHYSICAL(ptr); } } @@ -732,6 +732,6 @@ void* Lib_PhysicalToVirtual(void* ptr) { if (ptr == NULL) { return NULL; } else { - return (void*)PHYSICAL_TO_VIRTUAL(ptr); + return OS_PHYSICAL_TO_K0(ptr); } } diff --git a/src/code/z_play.c b/src/code/z_play.c index 6d3dac1fe6..783b73de29 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -923,9 +923,9 @@ void Play_UpdateMain(PlayState* this) { u8 freezeFlashTimer; s32 sp5C = false; - gSegments[4] = VIRTUAL_TO_PHYSICAL(this->objectCtx.slots[this->objectCtx.mainKeepSlot].segment); - gSegments[5] = VIRTUAL_TO_PHYSICAL(this->objectCtx.slots[this->objectCtx.subKeepSlot].segment); - gSegments[2] = VIRTUAL_TO_PHYSICAL(this->sceneSegment); + gSegments[4] = OS_K0_TO_PHYSICAL(this->objectCtx.slots[this->objectCtx.mainKeepSlot].segment); + gSegments[5] = OS_K0_TO_PHYSICAL(this->objectCtx.slots[this->objectCtx.subKeepSlot].segment); + gSegments[2] = OS_K0_TO_PHYSICAL(this->sceneSegment); if (R_PICTO_PHOTO_STATE == PICTO_PHOTO_STATE_PROCESS) { R_PICTO_PHOTO_STATE = PICTO_PHOTO_STATE_READY; @@ -1155,9 +1155,9 @@ void Play_DrawMain(PlayState* this) { OPEN_DISPS(gfxCtx); - gSegments[4] = VIRTUAL_TO_PHYSICAL(this->objectCtx.slots[this->objectCtx.mainKeepSlot].segment); - gSegments[5] = VIRTUAL_TO_PHYSICAL(this->objectCtx.slots[this->objectCtx.subKeepSlot].segment); - gSegments[2] = VIRTUAL_TO_PHYSICAL(this->sceneSegment); + gSegments[4] = OS_K0_TO_PHYSICAL(this->objectCtx.slots[this->objectCtx.mainKeepSlot].segment); + gSegments[5] = OS_K0_TO_PHYSICAL(this->objectCtx.slots[this->objectCtx.subKeepSlot].segment); + gSegments[2] = OS_K0_TO_PHYSICAL(this->sceneSegment); gSPSegment(POLY_OPA_DISP++, 0x04, this->objectCtx.slots[this->objectCtx.mainKeepSlot].segment); gSPSegment(POLY_XLU_DISP++, 0x04, this->objectCtx.slots[this->objectCtx.mainKeepSlot].segment); @@ -1605,7 +1605,7 @@ void Play_SpawnScene(PlayState* this, s32 sceneId, s32 spawn) { this->sceneConfig = scene->drawConfig; this->sceneSegment = Play_LoadFile(this, &scene->segment); scene->unk_D = 0; - gSegments[2] = VIRTUAL_TO_PHYSICAL(this->sceneSegment); + gSegments[2] = OS_K0_TO_PHYSICAL(this->sceneSegment); Play_InitScene(this, spawn); Room_AllocateAndLoad(this, &this->roomCtx); } diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 486abcbda9..43b1cd05dc 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -2590,7 +2590,7 @@ void Player_DrawGetItemImpl(PlayState* play, Player* player, Vec3f* refPos, s32 OPEN_DISPS(play->state.gfxCtx); - gSegments[6] = VIRTUAL_TO_PHYSICAL(player->giObjectSegment); + gSegments[6] = OS_K0_TO_PHYSICAL(player->giObjectSegment); gSPSegment(POLY_OPA_DISP++, 0x06, player->giObjectSegment); gSPSegment(POLY_XLU_DISP++, 0x06, player->giObjectSegment); @@ -2852,7 +2852,7 @@ void func_80127488(PlayState* play, Player* player, u8 alpha) { } void Player_DrawCouplesMask(PlayState* play, Player* player) { - gSegments[0xA] = VIRTUAL_TO_PHYSICAL(player->maskObjectSegment); + gSegments[0xA] = OS_K0_TO_PHYSICAL(player->maskObjectSegment); AnimatedMat_DrawOpa(play, Lib_SegmentedToVirtual(&object_mask_meoto_Matanimheader_001CD8)); } @@ -2884,7 +2884,7 @@ void Player_DrawCircusLeadersMask(PlayState* play, Player* player) { Matrix_Scale(scaleXZ, scaleY, scaleXZ, MTXMODE_APPLY); gSPMatrix(&gfx[0], Matrix_NewMtx(play->state.gfxCtx), G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPSegment(&gfx[1], 0x08, VIRTUAL_TO_PHYSICAL(SEGMENTED_TO_VIRTUAL(gEffBubble1Tex))); + gSPSegment(&gfx[1], 0x08, OS_K0_TO_PHYSICAL(SEGMENTED_TO_K0(gEffBubble1Tex))); gDPSetPrimColor(&gfx[2], 0, 0, 255, 255, 255, 255); gDPSetEnvColor(&gfx[3], 150, 150, 150, 0); gSPDisplayList(&gfx[4], gEffBubbleDL); @@ -2940,7 +2940,7 @@ void Player_DrawBlastMask(PlayState* play, Player* player) { if (player->blastMaskTimer != 0) { s32 alpha; - gSegments[0xA] = VIRTUAL_TO_PHYSICAL(player->maskObjectSegment); + gSegments[0xA] = OS_K0_TO_PHYSICAL(player->maskObjectSegment); AnimatedMat_DrawOpa(play, Lib_SegmentedToVirtual(&object_mask_bakuretu_Matanimheader_0011F8)); diff --git a/src/code/z_room.c b/src/code/z_room.c index ff94768255..758bfaa385 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -574,7 +574,7 @@ s32 Room_HandleLoadCallbacks(PlayState* play, RoomContext* roomCtx) { if (osRecvMesg(&roomCtx->loadQueue, NULL, OS_MESG_NOBLOCK) == 0) { roomCtx->status = 0; roomCtx->curRoom.segment = roomCtx->activeRoomVram; - gSegments[3] = VIRTUAL_TO_PHYSICAL(roomCtx->activeRoomVram); + gSegments[3] = OS_K0_TO_PHYSICAL(roomCtx->activeRoomVram); Scene_ExecuteCommands(play, roomCtx->curRoom.segment); func_80123140(play, GET_PLAYER(play)); @@ -605,7 +605,7 @@ RoomDrawHandler sRoomDrawHandlers[] = { void Room_Draw(PlayState* play, Room* room, u32 flags) { if (room->segment != NULL) { - gSegments[3] = VIRTUAL_TO_PHYSICAL(room->segment); + gSegments[3] = OS_K0_TO_PHYSICAL(room->segment); sRoomDrawHandlers[room->roomShape->base.type](play, room, flags); } return; diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 923ba5a0e8..326e010ea6 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -65,7 +65,7 @@ void Object_InitContext(GameState* gameState, ObjectContext* objectCtx) { objectCtx->spaceEnd = (void*)((u32)objectCtx->spaceStart + spaceSize); objectCtx->mainKeepSlot = Object_SpawnPersistent(objectCtx, GAMEPLAY_KEEP); - gSegments[4] = VIRTUAL_TO_PHYSICAL(objectCtx->slots[objectCtx->mainKeepSlot].segment); + gSegments[4] = OS_K0_TO_PHYSICAL(objectCtx->slots[objectCtx->mainKeepSlot].segment); } void Object_UpdateEntries(ObjectContext* objectCtx) { @@ -240,7 +240,7 @@ void Scene_CommandSpecialFiles(PlayState* play, SceneCmd* cmd) { if (cmd->specialFiles.subKeepId != 0) { play->objectCtx.subKeepSlot = Object_SpawnPersistent(&play->objectCtx, cmd->specialFiles.subKeepId); // TODO: Segment number enum? - gSegments[0x05] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[play->objectCtx.subKeepSlot].segment); + gSegments[0x05] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[play->objectCtx.subKeepSlot].segment); } if (cmd->specialFiles.naviQuestHintFileId != NAVI_QUEST_HINTS_NONE) { diff --git a/src/libultra/flash/osFlash.c b/src/libultra/flash/osFlash.c index 6a744a95ee..17162c53c6 100644 --- a/src/libultra/flash/osFlash.c +++ b/src/libultra/flash/osFlash.c @@ -1,19 +1,25 @@ -#include "prevent_bss_reordering.h" #include "ultra64.h" -#include "global.h" #include "PR/os_internal_flash.h" +#include "alignment.h" +#include "macros.h" -u32 __osFlashID[4]; -OSIoMesg __osFlashMsg; -OSMesgQueue __osFlashMessageQ; -OSPiHandle __osFlashHandler; +u32 __osFlashID[4] ALIGNED(8); +OSIoMesg __osFlashMsg ALIGNED(8); +OSMesgQueue __osFlashMessageQ ALIGNED(8); +OSPiHandle __osFlashHandler ALIGNED(8); OSMesg __osFlashMsgBuf[1]; s32 __osFlashVersion; static s32 sBssPad[5]; uintptr_t osFlashGetAddr(u32 pageNum) { - // Account for hadware bug in old flash where the address bits are shifted 1-off where they should be - uintptr_t addr = (__osFlashVersion == OLD_FLASH) ? pageNum * (FLASH_BLOCK_SIZE >> 1) : pageNum * FLASH_BLOCK_SIZE; + uintptr_t addr; + + if (__osFlashVersion == OLD_FLASH) { + // Account for hardware bug in old flash where the address bits are shifted 1-off where they should be + addr = pageNum * (FLASH_BLOCK_SIZE >> 1); + } else { + addr = pageNum * FLASH_BLOCK_SIZE; + } return addr; } diff --git a/src/libultra/gu/coss.c b/src/libultra/gu/coss.c index ebed284053..cd134d07bc 100644 --- a/src/libultra/gu/coss.c +++ b/src/libultra/gu/coss.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" /** * Compute the sine of a hex angle and return a short, using the formula cos(x) = sin(x+pi). diff --git a/src/libultra/gu/lookat.c b/src/libultra/gu/lookat.c index e1c7500cf1..692bb089a5 100644 --- a/src/libultra/gu/lookat.c +++ b/src/libultra/gu/lookat.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "macros.h" void guLookAtF(f32 mf[4][4], f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp) { f32 length; diff --git a/src/libultra/gu/lookathil.c b/src/libultra/gu/lookathil.c index 22540337cd..ef8b443db3 100644 --- a/src/libultra/gu/lookathil.c +++ b/src/libultra/gu/lookathil.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "macros.h" void guLookAtHiliteF(f32 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, /* light 1 direction */ diff --git a/src/libultra/gu/ortho.c b/src/libultra/gu/ortho.c index 592f2995de..2a1d785186 100644 --- a/src/libultra/gu/ortho.c +++ b/src/libultra/gu/ortho.c @@ -1,8 +1,9 @@ -#include "global.h" +#include "ultra64.h" 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); @@ -20,6 +21,7 @@ void guOrthoF(float m[4][4], float l, float r, float b, float t, float n, float 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/perspective.c b/src/libultra/gu/perspective.c index d3dab2ef40..a869e7723d 100644 --- a/src/libultra/gu/perspective.c +++ b/src/libultra/gu/perspective.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" void guPerspectiveF(float mf[4][4], u16* perspNorm, float fovy, float aspect, float near, float far, float scale) { float cot; @@ -36,6 +36,7 @@ void guPerspectiveF(float mf[4][4], u16* perspNorm, float fovy, float aspect, fl void guPerspective(Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale) { float mf[4][4]; + guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); guMtxF2L(mf, m); } diff --git a/src/libultra/gu/position.c b/src/libultra/gu/position.c index 9ba9d35702..17852abc02 100644 --- a/src/libultra/gu/position.c +++ b/src/libultra/gu/position.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/math.h" /** * guPositionF diff --git a/src/libultra/gu/rotate.c b/src/libultra/gu/rotate.c index 46dd605d49..b51c35fef6 100644 --- a/src/libultra/gu/rotate.c +++ b/src/libultra/gu/rotate.c @@ -1,7 +1,8 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/math.h" void guRotateF(float m[4][4], float a, float x, float y, float z) { - static float D_80097F90 = M_PI / 180.0f; + static float dtor = M_PI / 180.0f; float sine; float cosine; float ab; @@ -14,7 +15,7 @@ void guRotateF(float m[4][4], float a, float x, float y, float z) { guNormalize(&x, &y, &z); - a = a * D_80097F90; + a *= dtor; sine = sinf(a); cosine = cosf(a); diff --git a/src/libultra/gu/sqrtf.c b/src/libultra/gu/sqrtf.c index 5e5fa233cc..70e59989e8 100644 --- a/src/libultra/gu/sqrtf.c +++ b/src/libultra/gu/sqrtf.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" #ifndef __GNUC__ #define __builtin_sqrtf sqrtf diff --git a/src/libultra/gu/guS2DInitBg.c b/src/libultra/gu/us2dex.c similarity index 97% rename from src/libultra/gu/guS2DInitBg.c rename to src/libultra/gu/us2dex.c index c87176f490..810a7d3d13 100644 --- a/src/libultra/gu/guS2DInitBg.c +++ b/src/libultra/gu/us2dex.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" #include "PR/gs2dex.h" void guS2DInitBg(uObjBg* bg) { diff --git a/src/libultra/io/aigetlen.c b/src/libultra/io/aigetlen.c index 58d8db4875..0e7171928b 100644 --- a/src/libultra/io/aigetlen.c +++ b/src/libultra/io/aigetlen.c @@ -1,5 +1,5 @@ -#include "global.h" +#include "ultra64.h" u32 osAiGetLength(void) { - return HW_REG(AI_LEN_REG, u32); + return IO_READ(AI_LEN_REG); } diff --git a/src/libultra/io/aisetfreq.c b/src/libultra/io/aisetfreq.c index 8702941b9a..8771b4c95b 100644 --- a/src/libultra/io/aisetfreq.c +++ b/src/libultra/io/aisetfreq.c @@ -1,20 +1,20 @@ -#include "global.h" +#include "ultra64.h" s32 osAiSetFrequency(u32 frequency) { u8 bitrate; f32 dacRateF = ((f32)osViClock / frequency) + 0.5f; u32 dacRate = dacRateF; - if (dacRate < 132) { + if (dacRate < AI_MIN_DAC_RATE) { return -1; } bitrate = (dacRate / 66); - if (bitrate > 16) { - bitrate = 16; + if (bitrate > AI_MAX_BIT_RATE) { + bitrate = AI_MAX_BIT_RATE; } - HW_REG(AI_DACRATE_REG, u32) = dacRate - 1; - HW_REG(AI_BITRATE_REG, u32) = bitrate - 1; + IO_WRITE(AI_DACRATE_REG, dacRate - 1); + IO_WRITE(AI_BITRATE_REG, bitrate - 1); return osViClock / (s32)dacRate; } diff --git a/src/libultra/io/cartrominit.c b/src/libultra/io/cartrominit.c index 39de77260c..eeca4b339e 100644 --- a/src/libultra/io/cartrominit.c +++ b/src/libultra/io/cartrominit.c @@ -1,6 +1,8 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdbool.h" +#include "alignment.h" -OSPiHandle __CartRomHandle; +OSPiHandle __CartRomHandle ALIGNED(8); OSPiHandle* osCartRomInit(void) { register u32 initialConfig; @@ -22,36 +24,36 @@ OSPiHandle* osCartRomInit(void) { sCartRomNeedsInit = false; __CartRomHandle.type = DEVICE_TYPE_CART; - __CartRomHandle.baseAddress = 0xB0000000; - __CartRomHandle.domain = 0; + __CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); + __CartRomHandle.domain = PI_DOMAIN1; __CartRomHandle.speed = 0; bzero(&__CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); /* Uses `status & PI_STATUS_ERROR` in OoT */ - while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + while (status = IO_READ(PI_STATUS_REG), status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { ; } - lastLatency = HW_REG(PI_BSD_DOM1_LAT_REG, u32); - lastPageSize = HW_REG(PI_BSD_DOM1_PGS_REG, u32); - lastRelDuration = HW_REG(PI_BSD_DOM1_RLS_REG, u32); - lastPulse = HW_REG(PI_BSD_DOM1_PWD_REG, u32); + lastLatency = IO_READ(PI_BSD_DOM1_LAT_REG); + lastPageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + lastRelDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + lastPulse = IO_READ(PI_BSD_DOM1_PWD_REG); - HW_REG(PI_BSD_DOM1_LAT_REG, u32) = 0xFF; - HW_REG(PI_BSD_DOM1_PGS_REG, u32) = 0; - HW_REG(PI_BSD_DOM1_RLS_REG, u32) = 3; - HW_REG(PI_BSD_DOM1_PWD_REG, u32) = 0xFF; + IO_WRITE(PI_BSD_DOM1_LAT_REG, 0xFF); + IO_WRITE(PI_BSD_DOM1_PGS_REG, 0); + IO_WRITE(PI_BSD_DOM1_RLS_REG, 3); + IO_WRITE(PI_BSD_DOM1_PWD_REG, 0xFF); - initialConfig = HW_REG(__CartRomHandle.baseAddress, u32); + initialConfig = IO_READ(__CartRomHandle.baseAddress); __CartRomHandle.latency = initialConfig & 0xFF; __CartRomHandle.pageSize = (initialConfig >> 0x10) & 0xF; __CartRomHandle.relDuration = (initialConfig >> 0x14) & 0xF; __CartRomHandle.pulse = (initialConfig >> 8) & 0xFF; - HW_REG(PI_BSD_DOM1_LAT_REG, u32) = lastLatency; - HW_REG(PI_BSD_DOM1_PGS_REG, u32) = lastPageSize; - HW_REG(PI_BSD_DOM1_RLS_REG, u32) = lastRelDuration; - HW_REG(PI_BSD_DOM1_PWD_REG, u32) = lastPulse; + IO_WRITE(PI_BSD_DOM1_LAT_REG, lastLatency); + IO_WRITE(PI_BSD_DOM1_PGS_REG, lastPageSize); + IO_WRITE(PI_BSD_DOM1_RLS_REG, lastRelDuration); + IO_WRITE(PI_BSD_DOM1_PWD_REG, lastPulse); prevInt = __osDisableInt(); __CartRomHandle.next = __osPiTable; diff --git a/src/libultra/io/contchannelreset.c b/src/libultra/io/contchannelreset.c index d0f1fbd9bc..d0dc33eef4 100644 --- a/src/libultra/io/contchannelreset.c +++ b/src/libultra/io/contchannelreset.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" s32 __osContChannelReset(OSMesgQueue* mq, s32 channel) { s32 i; @@ -7,13 +8,13 @@ s32 __osContChannelReset(OSMesgQueue* mq, s32 channel) { __osSiGetAccess(); - __osPfsPifRam.status = 1; + __osPfsPifRam.status = CONT_CMD_EXE; for (i = 0; i < channel; i++) { - *bufptr++ = 0; + *bufptr++ = CONT_CMD_REQUEST_STATUS; } - *bufptr++ = 0xFD; + *bufptr++ = CONT_CMD_CHANNEL_RESET; *bufptr = CONT_CMD_END; __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); diff --git a/src/libultra/io/contpfs.c b/src/libultra/io/contpfs.c index e6817c3d07..b86f35c0d4 100644 --- a/src/libultra/io/contpfs.c +++ b/src/libultra/io/contpfs.c @@ -1,39 +1,9 @@ #include "ultra64.h" -#include "global.h" +#include "PR/controller.h" +#include "alignment.h" + +__OSInode __osPfsInodeCache ALIGNED(8); -__OSInode __osPfsInodeCache; -OSViMode osViModeNtscHpn1 = { - 8, // type - { - // comRegs - 0x324E, // ctrl - 0x500, // width - 0x3E52239, // burst - 0x20C, // vSync - 0xC15, // hSync - 0xC150C15, // leap - 0x6C02EC, // hStart - 0x400, // xScale - 0, // vCurrent - }, - { // fldRegs - { - // [0] - 0x500, // origin - 0x400, // yScale - 0x2301FD, // vStart - 0xE0204, // vBurst - 2, // vIntr - }, - { - // [1] - 0xA00, // origin - 0x400, // yScale - 0x2501FF, // vStart - 0xE0204, // vBurst - 2, // vIntr - } }, -}; s32 __osPfsInodeCacheChannel = -1; u8 __osPfsInodeCacheBank = 250; diff --git a/src/libultra/io/contquery.c b/src/libultra/io/contquery.c index a9a944f54b..cacf956160 100644 --- a/src/libultra/io/contquery.c +++ b/src/libultra/io/contquery.c @@ -1,19 +1,20 @@ -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" s32 osContStartQuery(OSMesgQueue* mq) { s32 ret; __osSiGetAccess(); - if (__osContLastPoll != 0) { - __osPackRequestData(0); + if (__osContLastPoll != CONT_CMD_REQUEST_STATUS) { + __osPackRequestData(CONT_CMD_REQUEST_STATUS); __osSiRawStartDma(OS_WRITE, &__osContPifRam); osRecvMesg(mq, NULL, OS_MESG_BLOCK); } ret = __osSiRawStartDma(OS_READ, &__osContPifRam); - __osContLastPoll = 0; + __osContLastPoll = CONT_CMD_REQUEST_STATUS; __osSiRelAccess(); diff --git a/src/libultra/io/contramread.c b/src/libultra/io/contramread.c index 06def61bae..56b928d378 100644 --- a/src/libultra/io/contramread.c +++ b/src/libultra/io/contramread.c @@ -1,5 +1,6 @@ -#include "global.h" -#include "PR/voice_internal.h" +#include "ultra64.h" +#include "PR/controller.h" +#include "PR/voiceinternal.h" #define BLOCKSIZE 32 diff --git a/src/libultra/io/contramwrite.c b/src/libultra/io/contramwrite.c index 507fbb1e8c..0c84434098 100644 --- a/src/libultra/io/contramwrite.c +++ b/src/libultra/io/contramwrite.c @@ -1,6 +1,6 @@ #include "ultra64.h" -#include "PR/voice_internal.h" -#include "global.h" +#include "PR/controller.h" +#include "PR/voiceinternal.h" s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32 force) { s32 ret = 0; diff --git a/src/libultra/io/contreaddata.c b/src/libultra/io/contreaddata.c index 21a8b90ce3..eded3a3384 100644 --- a/src/libultra/io/contreaddata.c +++ b/src/libultra/io/contreaddata.c @@ -1,4 +1,6 @@ -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" +#include "macros.h" void __osPackReadData(void); diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c index 30cb4c1d97..762dcbb098 100644 --- a/src/libultra/io/controller.c +++ b/src/libultra/io/controller.c @@ -1,13 +1,16 @@ -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" +#include "alignment.h" +#include "macros.h" s32 __osContinitialized = false; -OSPifRam __osContPifRam; +OSPifRam __osContPifRam ALIGNED(16); u8 __osContLastPoll; u8 __osMaxControllers; OSTimer __osEepromTimer; -OSMesgQueue __osEepromTimerQ; +OSMesgQueue __osEepromTimerQ ALIGNED(8); OSMesg __osEepromTimerMsg[1]; s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { @@ -24,15 +27,15 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { __osContinitialized = true; t = osGetTime(); - if (t < 0x165A0BC) { + if (t < OS_USEC_TO_CYCLES(500000)) { osCreateMesgQueue(&timerMesgQueue, &dummy, 1); - osSetTimer(&mytimer, 0x165A0BC - t, 0, &timerMesgQueue, &dummy); + osSetTimer(&mytimer, OS_USEC_TO_CYCLES(500000) - t, 0, &timerMesgQueue, &dummy); osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); } __osMaxControllers = 4; - __osPackRequestData(0); + __osPackRequestData(CONT_CMD_REQUEST_STATUS); ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam); osRecvMesg(mq, &dummy, OS_MESG_BLOCK); @@ -50,15 +53,16 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { void __osContGetInitData(u8* pattern, OSContStatus* data) { u8* ptr; - __OSContRequestHeader requestHeader; + __OSContRequesFormat requestHeader; s32 i; u8 bits; bits = 0; ptr = (u8*)__osContPifRam.ramarray; for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestHeader), data++) { - requestHeader = *(__OSContRequestHeader*)ptr; - data->errno = (requestHeader.rxsize & 0xC0) >> 4; + requestHeader = *(__OSContRequesFormat*)ptr; + data->errno = CHNL_ERR(requestHeader); + if (data->errno == 0) { data->type = requestHeader.typel << 8 | requestHeader.typeh; data->status = requestHeader.status; @@ -71,7 +75,7 @@ void __osContGetInitData(u8* pattern, OSContStatus* data) { void __osPackRequestData(u8 poll) { u8* ptr; - __OSContRequestHeader requestHeader; + __OSContRequesFormat requestHeader; s32 i; for (i = 0; i < ARRAY_COUNT(__osContPifRam.ramarray); i++) { @@ -80,18 +84,18 @@ void __osPackRequestData(u8 poll) { __osContPifRam.status = CONT_CMD_READ_BUTTON; ptr = (u8*)__osContPifRam.ramarray; - requestHeader.align = 255; - requestHeader.txsize = 1; - requestHeader.rxsize = 3; + requestHeader.align = CONT_CMD_NOP; + requestHeader.txsize = CONT_CMD_RESET_TX; + requestHeader.rxsize = CONT_CMD_RESET_RX; requestHeader.poll = poll; - requestHeader.typeh = 255; - requestHeader.typel = 255; - requestHeader.status = 255; - requestHeader.align1 = 255; + requestHeader.typeh = CONT_CMD_NOP; + requestHeader.typel = CONT_CMD_NOP; + requestHeader.status = CONT_CMD_NOP; + requestHeader.align1 = CONT_CMD_NOP; for (i = 0; i < __osMaxControllers; i++) { - *(__OSContRequestHeader*)ptr = requestHeader; + *(__OSContRequesFormat*)ptr = requestHeader; ptr += sizeof(requestHeader); } - *ptr = 254; + *ptr = CONT_CMD_END; } diff --git a/src/libultra/io/contsetch.c b/src/libultra/io/contsetch.c index e2740489c5..8868d762b2 100644 --- a/src/libultra/io/contsetch.c +++ b/src/libultra/io/contsetch.c @@ -1,14 +1,15 @@ -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" s32 osContSetCh(u8 ch) { __osSiGetAccess(); - if (4 < ch) { - __osMaxControllers = 4; + if (ch > MAXCONTROLLERS) { + __osMaxControllers = MAXCONTROLLERS; } else { __osMaxControllers = ch; } - __osContLastPoll = -2; + __osContLastPoll = CONT_CMD_END; __osSiRelAccess(); return 0; diff --git a/src/libultra/io/crc.c b/src/libultra/io/crc.c index acae7b4081..235b1c077e 100644 --- a/src/libultra/io/crc.c +++ b/src/libultra/io/crc.c @@ -69,7 +69,7 @@ * implementing CRC (Cyclic Redundancy Check) calculation * ](http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html) */ -#include "global.h" +#include "ultra64.h" #define ADDRESS_CRC_MESSAGE_LENGTH 10 #define ADDRESS_CRC_LENGTH 5 diff --git a/src/libultra/io/devmgr.c b/src/libultra/io/devmgr.c index b27822afae..168ca9b8df 100644 --- a/src/libultra/io/devmgr.c +++ b/src/libultra/io/devmgr.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdbool.h" void __osDevMgrMain(void* arg) { OSIoMesg* ioMesg; @@ -34,31 +35,32 @@ void __osDevMgrMain(void* arg) { } osRecvMesg(devMgr->acsQueue, &sp6C, OS_MESG_BLOCK); - __osResetGlobalIntMask(0x00100401); - __osEPiRawWriteIo(ioMesg->piHandle, 0x05000510, transfer->bmCtlShadow | 0x80000000); + __osResetGlobalIntMask(OS_IM_PI); + __osEPiRawWriteIo(ioMesg->piHandle, LEO_BM_CTL, transfer->bmCtlShadow | LEO_BM_CTL_START); - label: + readblock1: osRecvMesg(devMgr->evtQueue, &sp70, OS_MESG_BLOCK); transfer = &ioMesg->piHandle->transferInfo; block = &transfer->block[transfer->blockNum]; if (block->errStatus == 0x1D) { u32 status; - __osEPiRawWriteIo(ioMesg->piHandle, 0x05000510, transfer->bmCtlShadow | 0x10000000); - __osEPiRawWriteIo(ioMesg->piHandle, 0x05000510, transfer->bmCtlShadow); - __osEPiRawReadIo(ioMesg->piHandle, 0x05000508, &status); - if (status & 0x02000000) { - __osEPiRawWriteIo(ioMesg->piHandle, 0x05000510, transfer->bmCtlShadow | 0x1000000); + __osEPiRawWriteIo(ioMesg->piHandle, LEO_BM_CTL, transfer->bmCtlShadow | LEO_BM_CTL_RESET); + __osEPiRawWriteIo(ioMesg->piHandle, LEO_BM_CTL, transfer->bmCtlShadow); + __osEPiRawReadIo(ioMesg->piHandle, LEO_STATUS, &status); + if (status & LEO_STATUS_MECHANIC_INTERRUPT) { + __osEPiRawWriteIo(ioMesg->piHandle, LEO_BM_CTL, + transfer->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); } block->errStatus = 4; - HW_REG(PI_STATUS_REG, u32) = PI_CLR_INTR; - __osSetGlobalIntMask(0x00100C01); + IO_WRITE(PI_STATUS_REG, PI_CLR_INTR); + __osSetGlobalIntMask(OS_IM_PI | SR_IBIT4); } osSendMesg(ioMesg->hdr.retQueue, (OSMesg)ioMesg, OS_MESG_NOBLOCK); if ((msgVar == 1) && (ioMesg->piHandle->transferInfo.block[0].errStatus == 0)) { msgVar = 0; - goto label; + goto readblock1; } osSendMesg(devMgr->acsQueue, NULL, OS_MESG_NOBLOCK); diff --git a/src/libultra/io/dpgetstat.c b/src/libultra/io/dpgetstat.c index 0c4b3073ba..1dbf5e09b8 100644 --- a/src/libultra/io/dpgetstat.c +++ b/src/libultra/io/dpgetstat.c @@ -1,5 +1,5 @@ -#include "global.h" +#include "ultra64.h" u32 osDpGetStatus(void) { - return HW_REG(DPC_STATUS_REG, u32); + return IO_READ(DPC_STATUS_REG); } diff --git a/src/libultra/io/dpsetstat.c b/src/libultra/io/dpsetstat.c index d2655626c6..5eaa88534d 100644 --- a/src/libultra/io/dpsetstat.c +++ b/src/libultra/io/dpsetstat.c @@ -1,5 +1,5 @@ -#include "global.h" +#include "ultra64.h" void osDpSetStatus(u32 data) { - HW_REG(DPC_STATUS_REG, u32) = data; + IO_WRITE(DPC_STATUS_REG, data); } diff --git a/src/libultra/io/epidma.c b/src/libultra/io/epidma.c index 0b8c847d6a..ba2e55bced 100644 --- a/src/libultra/io/epidma.c +++ b/src/libultra/io/epidma.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { register s32 result; @@ -9,13 +9,13 @@ s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { mb->piHandle = pihandle; - if (direction == 0) { - mb->hdr.type = 15; + if (direction == OS_READ) { + mb->hdr.type = OS_MESG_TYPE_EDMAREAD; } else { - mb->hdr.type = 16; + mb->hdr.type = OS_MESG_TYPE_EDMAWRITE; } - if (mb->hdr.pri == 1) { + if (mb->hdr.pri == OS_MESG_PRI_HIGH) { result = osJamMesg(osPiGetCmdQueue(), mb, OS_MESG_NOBLOCK); } else { result = osSendMesg(osPiGetCmdQueue(), mb, OS_MESG_NOBLOCK); diff --git a/src/libultra/io/epilinkhandle.c b/src/libultra/io/epilinkhandle.c index bedd6d71c0..76832e9e3c 100644 --- a/src/libultra/io/epilinkhandle.c +++ b/src/libultra/io/epilinkhandle.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" s32 osEPiLinkHandle(OSPiHandle* handle) { u32 saveMask = __osDisableInt(); diff --git a/src/libultra/io/epirawdma.c b/src/libultra/io/epirawdma.c index d0707dce95..737bdce6ea 100644 --- a/src/libultra/io/epirawdma.c +++ b/src/libultra/io/epirawdma.c @@ -1,10 +1,10 @@ -#include "global.h" +#include "ultra64.h" s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, uintptr_t cartAddr, void* dramAddr, size_t size) { s32 status; OSPiHandle* curHandle; - while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + while (status = IO_READ(PI_STATUS_REG), status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { ; } @@ -13,35 +13,35 @@ s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, uintptr_t cartAddr, vo if (handle->domain == 0) { if (curHandle->latency != handle->latency) { - HW_REG(PI_BSD_DOM1_LAT_REG, u32) = handle->latency; + IO_WRITE(PI_BSD_DOM1_LAT_REG, handle->latency); } if (curHandle->pageSize != handle->pageSize) { - HW_REG(PI_BSD_DOM1_PGS_REG, u32) = handle->pageSize; + IO_WRITE(PI_BSD_DOM1_PGS_REG, handle->pageSize); } if (curHandle->relDuration != handle->relDuration) { - HW_REG(PI_BSD_DOM1_RLS_REG, u32) = handle->relDuration; + IO_WRITE(PI_BSD_DOM1_RLS_REG, handle->relDuration); } if (curHandle->pulse != handle->pulse) { - HW_REG(PI_BSD_DOM1_PWD_REG, u32) = handle->pulse; + IO_WRITE(PI_BSD_DOM1_PWD_REG, handle->pulse); } } else { if (curHandle->latency != handle->latency) { - HW_REG(PI_BSD_DOM2_LAT_REG, u32) = handle->latency; + IO_WRITE(PI_BSD_DOM2_LAT_REG, handle->latency); } if (curHandle->pageSize != handle->pageSize) { - HW_REG(PI_BSD_DOM2_PGS_REG, u32) = handle->pageSize; + IO_WRITE(PI_BSD_DOM2_PGS_REG, handle->pageSize); } if (curHandle->relDuration != handle->relDuration) { - HW_REG(PI_BSD_DOM2_RLS_REG, u32) = handle->relDuration; + IO_WRITE(PI_BSD_DOM2_RLS_REG, handle->relDuration); } if (curHandle->pulse != handle->pulse) { - HW_REG(PI_BSD_DOM2_PWD_REG, u32) = handle->pulse; + IO_WRITE(PI_BSD_DOM2_PWD_REG, handle->pulse); } } @@ -52,15 +52,15 @@ s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, uintptr_t cartAddr, vo curHandle->pulse = handle->pulse; } - HW_REG(PI_DRAM_ADDR_REG, void*) = (void*)osVirtualToPhysical(dramAddr); - HW_REG(PI_CART_ADDR_REG, void*) = (void*)((handle->baseAddress | cartAddr) & 0x1FFFFFFF); + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(handle->baseAddress | cartAddr)); switch (direction) { case OS_READ: - HW_REG(PI_WR_LEN_REG, u32) = size - 1; + IO_WRITE(PI_WR_LEN_REG, size - 1); break; case OS_WRITE: - HW_REG(PI_RD_LEN_REG, u32) = size - 1; + IO_WRITE(PI_RD_LEN_REG, size - 1); break; default: return -1; diff --git a/src/libultra/io/epirawread.c b/src/libultra/io/epirawread.c index 1dd2d1381d..a9379c492c 100644 --- a/src/libultra/io/epirawread.c +++ b/src/libultra/io/epirawread.c @@ -1,10 +1,10 @@ -#include "global.h" +#include "ultra64.h" s32 __osEPiRawReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data) { s32 status; OSPiHandle* curHandle; - while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + while (status = IO_READ(PI_STATUS_REG), status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { ; } @@ -13,35 +13,35 @@ s32 __osEPiRawReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data) { if (handle->domain == 0) { if (curHandle->latency != handle->latency) { - HW_REG(PI_BSD_DOM1_LAT_REG, u32) = handle->latency; + IO_WRITE(PI_BSD_DOM1_LAT_REG, handle->latency); } if (curHandle->pageSize != handle->pageSize) { - HW_REG(PI_BSD_DOM1_PGS_REG, u32) = handle->pageSize; + IO_WRITE(PI_BSD_DOM1_PGS_REG, handle->pageSize); } if (curHandle->relDuration != handle->relDuration) { - HW_REG(PI_BSD_DOM1_RLS_REG, u32) = handle->relDuration; + IO_WRITE(PI_BSD_DOM1_RLS_REG, handle->relDuration); } if (curHandle->pulse != handle->pulse) { - HW_REG(PI_BSD_DOM1_PWD_REG, u32) = handle->pulse; + IO_WRITE(PI_BSD_DOM1_PWD_REG, handle->pulse); } } else { if (curHandle->latency != handle->latency) { - HW_REG(PI_BSD_DOM2_LAT_REG, u32) = handle->latency; + IO_WRITE(PI_BSD_DOM2_LAT_REG, handle->latency); } if (curHandle->pageSize != handle->pageSize) { - HW_REG(PI_BSD_DOM2_PGS_REG, u32) = handle->pageSize; + IO_WRITE(PI_BSD_DOM2_PGS_REG, handle->pageSize); } if (curHandle->relDuration != handle->relDuration) { - HW_REG(PI_BSD_DOM2_RLS_REG, u32) = handle->relDuration; + IO_WRITE(PI_BSD_DOM2_RLS_REG, handle->relDuration); } if (curHandle->pulse != handle->pulse) { - HW_REG(PI_BSD_DOM2_PWD_REG, u32) = handle->pulse; + IO_WRITE(PI_BSD_DOM2_PWD_REG, handle->pulse); } } @@ -52,6 +52,6 @@ s32 __osEPiRawReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data) { curHandle->pulse = handle->pulse; } - *data = HW_REG(handle->baseAddress | devAddr, u32); + *data = IO_READ(handle->baseAddress | devAddr); return 0; } diff --git a/src/libultra/io/epirawwrite.c b/src/libultra/io/epirawwrite.c index fe8ce81c52..946400ca71 100644 --- a/src/libultra/io/epirawwrite.c +++ b/src/libultra/io/epirawwrite.c @@ -1,45 +1,45 @@ -#include "global.h" +#include "ultra64.h" s32 __osEPiRawWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data) { s32 status; OSPiHandle* curHandle; - while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) {} + while (status = IO_READ(PI_STATUS_REG), status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) {} if (__osCurrentHandle[handle->domain]->type != handle->type) { curHandle = __osCurrentHandle[handle->domain]; if (handle->domain == 0) { if (curHandle->latency != handle->latency) { - HW_REG(PI_BSD_DOM1_LAT_REG, u32) = handle->latency; + IO_WRITE(PI_BSD_DOM1_LAT_REG, handle->latency); } if (curHandle->pageSize != handle->pageSize) { - HW_REG(PI_BSD_DOM1_PGS_REG, u32) = handle->pageSize; + IO_WRITE(PI_BSD_DOM1_PGS_REG, handle->pageSize); } if (curHandle->relDuration != handle->relDuration) { - HW_REG(PI_BSD_DOM1_RLS_REG, u32) = handle->relDuration; + IO_WRITE(PI_BSD_DOM1_RLS_REG, handle->relDuration); } if (curHandle->pulse != handle->pulse) { - HW_REG(PI_BSD_DOM1_PWD_REG, u32) = handle->pulse; + IO_WRITE(PI_BSD_DOM1_PWD_REG, handle->pulse); } } else { if (curHandle->latency != handle->latency) { - HW_REG(PI_BSD_DOM2_LAT_REG, u32) = handle->latency; + IO_WRITE(PI_BSD_DOM2_LAT_REG, handle->latency); } if (curHandle->pageSize != handle->pageSize) { - HW_REG(PI_BSD_DOM2_PGS_REG, u32) = handle->pageSize; + IO_WRITE(PI_BSD_DOM2_PGS_REG, handle->pageSize); } if (curHandle->relDuration != handle->relDuration) { - HW_REG(PI_BSD_DOM2_RLS_REG, u32) = handle->relDuration; + IO_WRITE(PI_BSD_DOM2_RLS_REG, handle->relDuration); } if (curHandle->pulse != handle->pulse) { - HW_REG(PI_BSD_DOM2_PWD_REG, u32) = handle->pulse; + IO_WRITE(PI_BSD_DOM2_PWD_REG, handle->pulse); } } @@ -50,6 +50,6 @@ s32 __osEPiRawWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data) { curHandle->pulse = handle->pulse; } - HW_REG(handle->baseAddress | devAddr, u32) = data; + IO_WRITE(handle->baseAddress | devAddr, data); return 0; } diff --git a/src/libultra/io/epiread.c b/src/libultra/io/epiread.c index 5a2205bdc5..f7f6ac1f95 100644 --- a/src/libultra/io/epiread.c +++ b/src/libultra/io/epiread.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" s32 osEPiReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data) { register s32 ret; diff --git a/src/libultra/io/epiwrite.c b/src/libultra/io/epiwrite.c index 2132507413..00b97e85ad 100644 --- a/src/libultra/io/epiwrite.c +++ b/src/libultra/io/epiwrite.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" s32 osEPiWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data) { register s32 ret; diff --git a/src/libultra/io/motor.c b/src/libultra/io/motor.c index ba934d8004..343047e7b2 100644 --- a/src/libultra/io/motor.c +++ b/src/libultra/io/motor.c @@ -1,7 +1,6 @@ +#include "ultra64.h" #include "PR/os_motor.h" - #include "PR/controller.h" -#include "functions.h" #define BANK_ADDR 0x400 #define MOTOR_ID 0x80 diff --git a/src/libultra/io/pfsallocatefile.c b/src/libultra/io/pfsallocatefile.c index 821568b87d..aeced23ee4 100644 --- a/src/libultra/io/pfsallocatefile.c +++ b/src/libultra/io/pfsallocatefile.c @@ -1,5 +1,5 @@ #include "ultra64.h" -#include "global.h" +#include "PR/controller.h" s32 osPfsAllocateFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32 fileSize, s32* fileNo) { s32 startPage; diff --git a/src/libultra/io/pfschecker.c b/src/libultra/io/pfschecker.c index 79045ce1b2..f9ffb7ebfe 100644 --- a/src/libultra/io/pfschecker.c +++ b/src/libultra/io/pfschecker.c @@ -1,5 +1,5 @@ -#include "PR/os_pfs.h" -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" #define CHECK_IPAGE(p) \ (((p).ipage >= pfs->inodeStartPage) && ((p).inode_t.bank < pfs->banks) && ((p).inode_t.page >= 0x01) && \ diff --git a/src/libultra/io/pfsdeletefile.c b/src/libultra/io/pfsdeletefile.c index 3d6558a0db..7dd9abca0f 100644 --- a/src/libultra/io/pfsdeletefile.c +++ b/src/libultra/io/pfsdeletefile.c @@ -1,5 +1,5 @@ -#include "PR/os_pfs.h" -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" s32 __osPfsReleasePages(OSPfs* pfs, __OSInode* inode, u8 initialPage, u8 bank, __OSInodeUnit* finalPage); diff --git a/src/libultra/io/pfsfilestate.c b/src/libultra/io/pfsfilestate.c index 887eac1f6c..a39d55c02c 100644 --- a/src/libultra/io/pfsfilestate.c +++ b/src/libultra/io/pfsfilestate.c @@ -1,5 +1,6 @@ -#include "PR/os_pfs.h" -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" +#include "libc/stdbool.h" s32 osPfsFileState(OSPfs* pfs, s32 fileNo, OSPfsState* state) { s32 ret; diff --git a/src/libultra/io/pfsfreeblocks.c b/src/libultra/io/pfsfreeblocks.c index 2f8c6493f7..9bf79cfe8a 100644 --- a/src/libultra/io/pfsfreeblocks.c +++ b/src/libultra/io/pfsfreeblocks.c @@ -1,5 +1,5 @@ -#include "global.h" -#include "PR/os_pfs.h" +#include "ultra64.h" +#include "PR/controller.h" s32 osPfsFreeBlocks(OSPfs* pfs, s32* leftoverBytes) { s32 j; diff --git a/src/libultra/io/pfsgetstatus.c b/src/libultra/io/pfsgetstatus.c index 1d8e6dcf5f..116b340f7f 100644 --- a/src/libultra/io/pfsgetstatus.c +++ b/src/libultra/io/pfsgetstatus.c @@ -1,5 +1,5 @@ #include "ultra64.h" -#include "global.h" +#include "PR/controller.h" void __osPfsRequestOneChannel(s32 channel, u8 poll); void __osPfsGetOneChannelData(s32 channel, OSContStatus* contData); diff --git a/src/libultra/io/pfsinitpak.c b/src/libultra/io/pfsinitpak.c index f4d917b62d..2688bd5d86 100644 --- a/src/libultra/io/pfsinitpak.c +++ b/src/libultra/io/pfsinitpak.c @@ -1,5 +1,5 @@ -#include "PR/os_pfs.h" -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" s32 __osPfsCheckRamArea(OSPfs* pfs); diff --git a/src/libultra/io/pfsisplug.c b/src/libultra/io/pfsisplug.c index 99a2cbc422..e93c812d37 100644 --- a/src/libultra/io/pfsisplug.c +++ b/src/libultra/io/pfsisplug.c @@ -1,6 +1,9 @@ #include "PR/os_pfs.h" #include "PR/controller.h" -#include "global.h" +#include "PR/siint.h" +#include "alignment.h" + +OSPifRam __osPfsPifRam ALIGNED(16); void __osPfsRequestData(u8 poll); void __osPfsGetInitData(u8* pattern, OSContStatus* contData); @@ -50,40 +53,40 @@ s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern) { void __osPfsRequestData(u8 poll) { u8* bufPtr = (u8*)&__osPfsPifRam; - __OSContRequestHeader req; + __OSContRequesFormat req; s32 i; __osContLastPoll = poll; - __osPfsPifRam.status = 1; + __osPfsPifRam.status = CONT_CMD_EXE; - req.align = 0xFF; - req.txsize = 1; - req.rxsize = 3; + req.align = CONT_CMD_NOP; + req.txsize = CONT_CMD_REQUEST_STATUS_TX; + req.rxsize = CONT_CMD_REQUEST_STATUS_RX; req.poll = poll; - req.typeh = 0xFF; - req.typel = 0xFF; - req.status = 0xFF; - req.align1 = 0xFF; + req.typeh = CONT_CMD_NOP; + req.typel = CONT_CMD_NOP; + req.status = CONT_CMD_NOP; + req.align1 = CONT_CMD_NOP; for (i = 0; i < __osMaxControllers; i++) { - *((__OSContRequestHeader*)bufPtr) = req; - bufPtr += sizeof(req); + *(__OSContRequesFormat*)bufPtr = req; + bufPtr += sizeof(__OSContRequesFormat); } - *((u8*)bufPtr) = CONT_CMD_END; + *bufPtr = CONT_CMD_END; } void __osPfsGetInitData(u8* pattern, OSContStatus* contData) { u8* bufptr; - __OSContRequestHeader req; + __OSContRequesFormat req; s32 i; u8 bits = 0; bufptr = (u8*)&__osPfsPifRam; for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(req), contData++) { - req = *((__OSContRequestHeader*)bufptr); - contData->errno = ((req.rxsize & 0xC0) >> 4); + req = *(__OSContRequesFormat*)bufptr; + contData->errno = CHNL_ERR(req); if (contData->errno) { continue; diff --git a/src/libultra/io/pfsreadwritefile.c b/src/libultra/io/pfsreadwritefile.c index b5ab6e4b4c..2d26e00133 100644 --- a/src/libultra/io/pfsreadwritefile.c +++ b/src/libultra/io/pfsreadwritefile.c @@ -1,5 +1,5 @@ #include "ultra64.h" -#include "global.h" +#include "PR/controller.h" #define CHECK_IPAGE(p, pfs) \ (((p).ipage >= (pfs).inodeStartPage) && ((p).inode_t.bank < (pfs).banks) && ((p).inode_t.page >= 0x01) && \ diff --git a/src/libultra/io/pfssearchfile.c b/src/libultra/io/pfssearchfile.c index c5f8bcce46..1a034b7f02 100644 --- a/src/libultra/io/pfssearchfile.c +++ b/src/libultra/io/pfssearchfile.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" s32 osPfsFindFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32* fileNo) { s32 j; diff --git a/src/libultra/io/pfsselectbank.c b/src/libultra/io/pfsselectbank.c index 59a69fccb5..380cbf10ad 100644 --- a/src/libultra/io/pfsselectbank.c +++ b/src/libultra/io/pfsselectbank.c @@ -1,5 +1,5 @@ -#include "PR/os_pfs.h" -#include "global.h" +#include "ultra64.h" +#include "PR/controller.h" s32 __osPfsSelectBank(OSPfs* pfs, u8 bank) { u8 buf[BLOCKSIZE]; diff --git a/src/libultra/io/piacs.c b/src/libultra/io/piacs.c index f1107b7580..08346578ed 100644 --- a/src/libultra/io/piacs.c +++ b/src/libultra/io/piacs.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "macros.h" u32 __osPiAccessQueueEnabled = 0; @@ -13,6 +14,7 @@ void __osPiCreateAccessQueue(void) { void __osPiGetAccess(void) { OSMesg dummyMesg; + if (!__osPiAccessQueueEnabled) { __osPiCreateAccessQueue(); } diff --git a/src/libultra/io/pigetcmdq.c b/src/libultra/io/pigetcmdq.c index 6d367200b0..917881f708 100644 --- a/src/libultra/io/pigetcmdq.c +++ b/src/libultra/io/pigetcmdq.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" OSMesgQueue* osPiGetCmdQueue(void) { if (!__osPiDevMgr.active) { diff --git a/src/libultra/io/pimgr.c b/src/libultra/io/pimgr.c index b6e1fea13a..dfde5007c9 100644 --- a/src/libultra/io/pimgr.c +++ b/src/libultra/io/pimgr.c @@ -1,13 +1,19 @@ -#include "global.h" +#include "ultra64.h" +#include "alignment.h" #include "stack.h" +#include "macros.h" -OSPiHandle __Dom1SpeedParam; -OSPiHandle __Dom2SpeedParam; +OSPiHandle __Dom1SpeedParam ALIGNED(8); +OSPiHandle __Dom2SpeedParam ALIGNED(8); OSThread sPiMgrThread; STACK(sPiMgrStack, 0x1000); -OSMesgQueue piEventQueue; +OSMesgQueue piEventQueue ALIGNED(8); OSMesg piEventBuf[1]; +OSDevMgr __osPiDevMgr = { 0 }; +OSPiHandle* __osPiTable = NULL; +OSPiHandle* __osCurrentHandle[2] ALIGNED(8) = { &__Dom1SpeedParam, &__Dom2SpeedParam }; + void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) { u32 savedMask; OSPri oldPri; diff --git a/src/libultra/io/pirawdma.c b/src/libultra/io/pirawdma.c index b33afddfc4..905ab1348c 100644 --- a/src/libultra/io/pirawdma.c +++ b/src/libultra/io/pirawdma.c @@ -1,22 +1,22 @@ -#include "global.h" +#include "ultra64.h" s32 __osPiRawStartDma(s32 direction, uintptr_t devAddr, void* dramAddr, size_t size) { - register int status = HW_REG(PI_STATUS_REG, u32); + register int status = IO_READ(PI_STATUS_REG); while (status & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) { - status = HW_REG(PI_STATUS_REG, u32); + status = IO_READ(PI_STATUS_REG); } - HW_REG(PI_DRAM_ADDR_REG, u32) = osVirtualToPhysical(dramAddr); + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); - HW_REG(PI_CART_ADDR_REG, u32) = (((uintptr_t)osRomBase | devAddr) & 0x1FFFFFFF); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS((uintptr_t)osRomBase | devAddr)); switch (direction) { case OS_READ: - HW_REG(PI_WR_LEN_REG, u32) = size - 1; + IO_WRITE(PI_WR_LEN_REG, size - 1); break; case OS_WRITE: - HW_REG(PI_RD_LEN_REG, u32) = size - 1; + IO_WRITE(PI_RD_LEN_REG, size - 1); break; default: return -1; diff --git a/src/libultra/io/si.c b/src/libultra/io/si.c index 563c682765..f1511c0d6f 100644 --- a/src/libultra/io/si.c +++ b/src/libultra/io/si.c @@ -1,7 +1,8 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdbool.h" s32 __osSiDeviceBusy() { - register u32 status = HW_REG(SI_STATUS_REG, u32); + register u32 status = IO_READ(SI_STATUS_REG); if (status & (SI_STATUS_DMA_BUSY | SI_STATUS_IO_READ_BUSY)) { return true; diff --git a/src/libultra/io/siacs.c b/src/libultra/io/siacs.c index 7a221408e5..6a99d8dd1e 100644 --- a/src/libultra/io/siacs.c +++ b/src/libultra/io/siacs.c @@ -1,9 +1,11 @@ -#include "global.h" +#include "ultra64.h" +#include "alignment.h" +#include "macros.h" u32 __osSiAccessQueueEnabled = 0; -OSMesg siAccessBuf[1]; -OSMesgQueue __osSiAccessQueue; +OSMesg siAccessBuf[1] ALIGNED(8); +OSMesgQueue __osSiAccessQueue ALIGNED(8); void __osSiCreateAccessQueue() { __osSiAccessQueueEnabled = 1; @@ -13,6 +15,7 @@ void __osSiCreateAccessQueue() { void __osSiGetAccess(void) { OSMesg dummyMesg; + if (!__osSiAccessQueueEnabled) { __osSiCreateAccessQueue(); } diff --git a/src/libultra/io/sirawdma.c b/src/libultra/io/sirawdma.c index 08a347cc91..4c5dc8cc93 100644 --- a/src/libultra/io/sirawdma.c +++ b/src/libultra/io/sirawdma.c @@ -1,7 +1,8 @@ -#include "global.h" +#include "ultra64.h" +#include "alignment.h" s32 __osSiRawStartDma(s32 direction, void* dramAddr) { - if (HW_REG(SI_STATUS_REG, u32) & (SI_STATUS_DMA_BUSY | SI_STATUS_IO_READ_BUSY)) { + if (IO_READ(SI_STATUS_REG) & (SI_STATUS_DMA_BUSY | SI_STATUS_IO_READ_BUSY)) { return -1; } @@ -9,12 +10,12 @@ s32 __osSiRawStartDma(s32 direction, void* dramAddr) { osWritebackDCache(dramAddr, ALIGN16(PIF_RAM_END - PIF_RAM_START)); } - HW_REG(SI_DRAM_ADDR_REG, u32) = osVirtualToPhysical(dramAddr); + IO_WRITE(SI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); if (direction == OS_READ) { - HW_REG(SI_PIF_ADDR_RD64B_REG, void*) = (void*)PIF_RAM_START; + IO_WRITE(SI_PIF_ADDR_RD64B_REG, PIF_RAM_START); } else { - HW_REG(SI_PIF_ADDR_WR64B_REG, void*) = (void*)PIF_RAM_START; + IO_WRITE(SI_PIF_ADDR_WR64B_REG, PIF_RAM_START); } if (direction == OS_READ) { diff --git a/src/libultra/io/sirawread.c b/src/libultra/io/sirawread.c index 7e3537603c..aca70e11b0 100644 --- a/src/libultra/io/sirawread.c +++ b/src/libultra/io/sirawread.c @@ -1,9 +1,9 @@ -#include "global.h" +#include "ultra64.h" s32 __osSiRawReadIo(uintptr_t devAddr, u32* data) { if (__osSiDeviceBusy()) { return -1; } - *data = *(u32*)(devAddr | 0xA0000000); + *data = IO_READ(devAddr); return 0; } diff --git a/src/libultra/io/sirawwrite.c b/src/libultra/io/sirawwrite.c index 0f98b08c52..3175c59990 100644 --- a/src/libultra/io/sirawwrite.c +++ b/src/libultra/io/sirawwrite.c @@ -1,11 +1,11 @@ -#include "global.h" +#include "ultra64.h" s32 __osSiRawWriteIo(uintptr_t devAddr, u32 data) { - if (__osSiDeviceBusy() != 0) { + if (__osSiDeviceBusy()) { return -1; } - *(u32*)(devAddr | 0xA0000000) = data; + IO_WRITE(devAddr, data); return 0; } diff --git a/src/libultra/io/sp.c b/src/libultra/io/sp.c index c028c76927..e1d95eeb88 100644 --- a/src/libultra/io/sp.c +++ b/src/libultra/io/sp.c @@ -1,7 +1,8 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdbool.h" s32 __osSpDeviceBusy(void) { - register u32 status = HW_REG(SP_STATUS_REG, u32); + register u32 status = IO_READ(SP_STATUS_REG); if (status & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL)) { return true; diff --git a/src/libultra/io/spgetstat.c b/src/libultra/io/spgetstat.c index 8987b2414a..641261cf70 100644 --- a/src/libultra/io/spgetstat.c +++ b/src/libultra/io/spgetstat.c @@ -1,5 +1,5 @@ -#include "global.h" +#include "ultra64.h" u32 __osSpGetStatus() { - return HW_REG(SP_STATUS_REG, u32); + return IO_READ(SP_STATUS_REG); } diff --git a/src/libultra/io/sprawdma.c b/src/libultra/io/sprawdma.c index 494f3db50d..b09eff34dd 100644 --- a/src/libultra/io/sprawdma.c +++ b/src/libultra/io/sprawdma.c @@ -1,17 +1,17 @@ -#include "global.h" +#include "ultra64.h" -s32 __osSpRawStartDma(s32 direction, void* devAddr, void* dramAddr, size_t size) { +s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, size_t size) { if (__osSpDeviceBusy()) { return -1; } - HW_REG(SP_MEM_ADDR_REG, u32) = devAddr; - HW_REG(SP_DRAM_ADDR_REG, u32) = osVirtualToPhysical(dramAddr); + IO_WRITE(SP_MEM_ADDR_REG, devAddr); + IO_WRITE(SP_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); if (direction == OS_READ) { - HW_REG(SP_WR_LEN_REG, u32) = size - 1; + IO_WRITE(SP_WR_LEN_REG, size - 1); } else { - HW_REG(SP_RD_LEN_REG, u32) = size - 1; + IO_WRITE(SP_RD_LEN_REG, size - 1); } return 0; diff --git a/src/libultra/io/spsetpc.c b/src/libultra/io/spsetpc.c index 2c3cc32ba0..2789428db8 100644 --- a/src/libultra/io/spsetpc.c +++ b/src/libultra/io/spsetpc.c @@ -1,13 +1,12 @@ -#include "global.h" +#include "ultra64.h" -s32 __osSpSetPc(void* pc) { - register u32 spStatus = HW_REG(SP_STATUS_REG, u32); +s32 __osSpSetPc(u32 pc) { + register u32 spStatus = IO_READ(SP_STATUS_REG); if (!(spStatus & SP_STATUS_HALT)) { return -1; - } else { - HW_REG(SP_PC_REG, void*) = pc; } + IO_WRITE(SP_PC_REG, pc); return 0; } diff --git a/src/libultra/io/spsetstat.c b/src/libultra/io/spsetstat.c index eb183eab47..558b88fcf9 100644 --- a/src/libultra/io/spsetstat.c +++ b/src/libultra/io/spsetstat.c @@ -1,5 +1,5 @@ -#include "global.h" +#include "ultra64.h" void __osSpSetStatus(u32 data) { - HW_REG(SP_STATUS_REG, u32) = data; + IO_WRITE(SP_STATUS_REG, data); } diff --git a/src/libultra/io/sptask.c b/src/libultra/io/sptask.c index 8445f53b05..b261664f00 100644 --- a/src/libultra/io/sptask.c +++ b/src/libultra/io/sptask.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" #define _osVirtualToPhysical(ptr) \ if (ptr != NULL) { \ @@ -33,19 +33,20 @@ void osSpTaskLoad(OSTask* intp) { intp->t.flags &= ~OS_TASK_YIELDED; if (tp->t.flags & OS_TASK_LOADABLE) { - tp->t.ucode = HW_REG((uintptr_t)intp->t.yieldDataPtr + OS_YIELD_DATA_SIZE - 4, u32); + tp->t.ucode = IO_READ((uintptr_t)intp->t.yieldDataPtr + OS_YIELD_DATA_SIZE - 4); } } + osWritebackDCache(tp, sizeof(OSTask)); __osSpSetStatus(SP_CLR_SIG0 | SP_CLR_SIG1 | SP_CLR_SIG2 | SP_SET_INTR_BREAK); - while (__osSpSetPc((void*)SP_IMEM_START) == -1) {} + while (__osSpSetPc(SP_IMEM_START) == -1) {} - while (__osSpRawStartDma(1, (void*)(SP_IMEM_START - sizeof(*tp)), tp, sizeof(OSTask)) == -1) {} + while (__osSpRawStartDma(1, (SP_IMEM_START - sizeof(*tp)), tp, sizeof(OSTask)) == -1) {} while (__osSpDeviceBusy()) {} - while (__osSpRawStartDma(1, (void*)SP_IMEM_START, tp->t.ucodeBoot, tp->t.ucodeBootSize) == -1) {} + while (__osSpRawStartDma(1, SP_IMEM_START, tp->t.ucodeBoot, tp->t.ucodeBootSize) == -1) {} } void osSpTaskStartGo(OSTask* tp) { diff --git a/src/libultra/io/sptaskyield.c b/src/libultra/io/sptaskyield.c index ce0819b349..0d3285d819 100644 --- a/src/libultra/io/sptaskyield.c +++ b/src/libultra/io/sptaskyield.c @@ -1,5 +1,5 @@ -#include "global.h" +#include "ultra64.h" void osSpTaskYield(void) { - __osSpSetStatus(0x400); + __osSpSetStatus(SP_SET_YIELD); } diff --git a/src/libultra/io/sptaskyielded.c b/src/libultra/io/sptaskyielded.c index 66b541921a..88c112305c 100644 --- a/src/libultra/io/sptaskyielded.c +++ b/src/libultra/io/sptaskyielded.c @@ -1,17 +1,17 @@ -#include "global.h" +#include "ultra64.h" OSYieldResult osSpTaskYielded(OSTask* task) { - s32 status; + s32 status = __osSpGetStatus(); OSYieldResult result; - status = __osSpGetStatus(); - if (status & 0x100) { - result = 1; + + if (status & SP_STATUS_YIELDED) { + result = OS_TASK_YIELDED; } else { result = 0; } - if (status & 0x80) { + if (status & SP_STATUS_YIELD) { task->t.flags |= result; - task->t.flags &= ~(2); + task->t.flags &= ~OS_TASK_DP_WAIT; } return result; } diff --git a/src/libultra/io/vi.c b/src/libultra/io/vi.c index a1e3e77c49..e4bdfe5597 100644 --- a/src/libultra/io/vi.c +++ b/src/libultra/io/vi.c @@ -1,6 +1,7 @@ -#include "global.h" +#include "ultra64.h" +#include "alignment.h" -static __OSViContext vi[2] = { 0 }; +static __OSViContext vi[2] ALIGNED(8) = { 0 }; __OSViContext* __osViCurr = &vi[0]; __OSViContext* __osViNext = &vi[1]; @@ -10,8 +11,8 @@ void __osViInit(void) { __osViNext = &vi[1]; __osViNext->retraceCount = 1; __osViCurr->retraceCount = 1; - __osViNext->buffer = (void*)0x80000000; - __osViCurr->buffer = (void*)0x80000000; + __osViNext->buffer = (void*)K0BASE; + __osViCurr->buffer = (void*)K0BASE; if (osTvType == OS_TV_PAL) { __osViNext->modep = &osViModePalLan1; @@ -24,9 +25,9 @@ void __osViInit(void) { __osViNext->state = 0x20; __osViNext->features = __osViNext->modep->comRegs.ctrl; - while (HW_REG(VI_CURRENT_REG, u32) > 10) {} + while (IO_READ(VI_CURRENT_REG) > 10) {} - HW_REG(VI_STATUS_REG, u32) = 0; + IO_WRITE(VI_STATUS_REG, 0); __osViSwapContext(); } diff --git a/src/libultra/io/viblack.c b/src/libultra/io/viblack.c index 6b8fec9536..60f62aec1c 100644 --- a/src/libultra/io/viblack.c +++ b/src/libultra/io/viblack.c @@ -1,14 +1,12 @@ -#include "global.h" +#include "ultra64.h" void osViBlack(u8 active) { - register u32 saveMask; - - saveMask = __osDisableInt(); + register u32 saveMask = __osDisableInt(); if (active) { - __osViNext->state |= 0x20; + __osViNext->state |= VI_STATE_BLACK; } else { - __osViNext->state &= ~0x20; + __osViNext->state &= ~VI_STATE_BLACK; } __osRestoreInt(saveMask); diff --git a/src/libultra/io/viextendvstart.c b/src/libultra/io/viextendvstart.c new file mode 100644 index 0000000000..a28a8386d5 --- /dev/null +++ b/src/libultra/io/viextendvstart.c @@ -0,0 +1,5 @@ +#include "ultra64.h" + +void osViExtendVStart(u32 value) { + __additional_scanline = value; +} diff --git a/src/libultra/io/vigetcurrcontext.c b/src/libultra/io/vigetcurrcontext.c index 2b7de83417..3bb95fb4f7 100644 --- a/src/libultra/io/vigetcurrcontext.c +++ b/src/libultra/io/vigetcurrcontext.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" __OSViContext* __osViGetCurrentContext(void) { return __osViCurr; diff --git a/src/libultra/io/vigetcurrframebuf.c b/src/libultra/io/vigetcurrframebuf.c index 8127a3f63a..f0caeb7b15 100644 --- a/src/libultra/io/vigetcurrframebuf.c +++ b/src/libultra/io/vigetcurrframebuf.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" void* osViGetCurrentFramebuffer(void) { register u32 prevInt = __osDisableInt(); diff --git a/src/libultra/io/vigetnextframebuf.c b/src/libultra/io/vigetnextframebuf.c index 21fd8ece7a..af6fb3179b 100644 --- a/src/libultra/io/vigetnextframebuf.c +++ b/src/libultra/io/vigetnextframebuf.c @@ -1,11 +1,9 @@ -#include "global.h" +#include "ultra64.h" void* osViGetNextFramebuffer(void) { - register u32 saveMask; + register u32 saveMask = __osDisableInt(); void* buffer; - saveMask = __osDisableInt(); - buffer = __osViNext->buffer; __osRestoreInt(saveMask); diff --git a/src/libultra/io/vimgr.c b/src/libultra/io/vimgr.c index 7bdb3ac51f..485bdf5973 100644 --- a/src/libultra/io/vimgr.c +++ b/src/libultra/io/vimgr.c @@ -1,14 +1,17 @@ -#include "global.h" +#include "ultra64.h" #include "PR/osint.h" #include "stack.h" #include "PR/osint.h" +#include "libc/stdbool.h" +#include "macros.h" +#include "alignment.h" OSThread viThread; -STACK(sViStack, 0x1000); -OSMesgQueue viEventQueue; -OSMesg viEventBuf[6]; -OSIoMesg viRetraceMsg; -OSIoMesg viCounterMsg; +STACK(sViStack, OS_VIM_STACKSIZE) ALIGNED(16); +OSMesgQueue viEventQueue ALIGNED(8); +OSMesg viEventBuf[6] ALIGNED(8); +OSIoMesg viRetraceMsg ALIGNED(8); +OSIoMesg viCounterMsg ALIGNED(8); OSDevMgr __osViDevMgr = { 0 }; u32 __additional_scanline = 0; @@ -57,8 +60,8 @@ void osCreateViManager(OSPri pri) { } } -void viMgrMain(void* vargs) { - OSMgrArgs* args; +void viMgrMain(void* arg) { + OSDevMgr* dmArgs; static u16 viRetrace; u32 addTime; OSIoMesg* mesg; @@ -70,10 +73,10 @@ void viMgrMain(void* vargs) { viRetrace = 1; } - args = (OSMgrArgs*)vargs; + dmArgs = (OSDevMgr*)arg; while (true) { - osRecvMesg(args->eventQueue, (OSMesg*)&mesg, OS_MESG_BLOCK); + osRecvMesg(dmArgs->evtQueue, (OSMesg*)&mesg, OS_MESG_BLOCK); switch (mesg->hdr.type) { case OS_MESG_TYPE_VRETRACE: __osViSwapContext(); diff --git a/src/libultra/gu/visetevent.c b/src/libultra/io/visetevent.c similarity index 91% rename from src/libultra/gu/visetevent.c rename to src/libultra/io/visetevent.c index 3a14ccbc1b..701f41863d 100644 --- a/src/libultra/gu/visetevent.c +++ b/src/libultra/io/visetevent.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount) { register u32 saveMask = __osDisableInt(); diff --git a/src/libultra/io/visetmode.c b/src/libultra/io/visetmode.c index 6953bf63b8..6117b06a2b 100644 --- a/src/libultra/io/visetmode.c +++ b/src/libultra/io/visetmode.c @@ -1,12 +1,10 @@ -#include "global.h" +#include "ultra64.h" void osViSetMode(OSViMode* modep) { - register u32 saveMask; - - saveMask = __osDisableInt(); + register u32 saveMask = __osDisableInt(); __osViNext->modep = modep; - __osViNext->state = 1; + __osViNext->state = VI_STATE_MODE_UPDATED; __osViNext->features = __osViNext->modep->comRegs.ctrl; __osRestoreInt(saveMask); diff --git a/src/libultra/io/visetspecial.c b/src/libultra/io/visetspecial.c index a5ef1220a4..758807b1bf 100644 --- a/src/libultra/io/visetspecial.c +++ b/src/libultra/io/visetspecial.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" void osViSetSpecialFeatures(u32 func) { register u32 saveMask = __osDisableInt(); diff --git a/src/libultra/io/visetxscale.c b/src/libultra/io/visetxscale.c index 0e2cf762d9..94f192b879 100644 --- a/src/libultra/io/visetxscale.c +++ b/src/libultra/io/visetxscale.c @@ -1,17 +1,15 @@ -#include "global.h" +#include "ultra64.h" void osViSetXScale(f32 value) { register u32 nomValue; - register u32 saveMask; - - saveMask = __osDisableInt(); + register u32 saveMask = __osDisableInt(); __osViNext->x.factor = value; - __osViNext->state |= 0x2; + __osViNext->state |= VI_STATE_XSCALE_UPDATED; - nomValue = __osViNext->modep->comRegs.xScale & 0xFFF; - __osViNext->x.scale = (u32)(__osViNext->x.factor * nomValue) & 0xFFF; + nomValue = __osViNext->modep->comRegs.xScale & VI_SCALE_MASK; + __osViNext->x.scale = (u32)(__osViNext->x.factor * nomValue) & VI_SCALE_MASK; __osRestoreInt(saveMask); } diff --git a/src/libultra/io/visetyscale.c b/src/libultra/io/visetyscale.c index 6ef85963df..093a61fa92 100644 --- a/src/libultra/io/visetyscale.c +++ b/src/libultra/io/visetyscale.c @@ -1,13 +1,11 @@ -#include "global.h" +#include "ultra64.h" void osViSetYScale(f32 value) { - register u32 saveMask; - - saveMask = __osDisableInt(); + register u32 saveMask = __osDisableInt(); __osViNext->y.factor = value; - __osViNext->state |= 0x4; + __osViNext->state |= VI_STATE_YSCALE_UPDATED; __osRestoreInt(saveMask); } diff --git a/src/libultra/io/viswapbuf.c b/src/libultra/io/viswapbuf.c index c60918092a..dafce36f37 100644 --- a/src/libultra/io/viswapbuf.c +++ b/src/libultra/io/viswapbuf.c @@ -1,11 +1,11 @@ -#include "global.h" +#include "ultra64.h" void osViSwapBuffer(void* frameBufPtr) { u32 saveMask = __osDisableInt(); __osViNext->buffer = frameBufPtr; - __osViNext->state |= 0x10; + __osViNext->state |= VI_STATE_BUFFER_UPDATED; __osRestoreInt(saveMask); } diff --git a/src/libultra/io/viswapcontext.c b/src/libultra/io/viswapcontext.c index 514e3aa1df..b6e9a8c5f1 100644 --- a/src/libultra/io/viswapcontext.c +++ b/src/libultra/io/viswapcontext.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" void __osViSwapContext(void) { register OSViMode* viMode; @@ -8,15 +8,13 @@ void __osViSwapContext(void) { u32 vstart; u32 sp34; u32 field; - register u32 s2; field = 0; viNext = __osViNext; viMode = viNext->modep; - field = HW_REG(VI_V_CURRENT_LINE_REG, u32) & 1; - s2 = osVirtualToPhysical(viNext->buffer); - origin = (viMode->fldRegs[field].origin) + s2; - if (viNext->state & 2) { + field = IO_READ(VI_V_CURRENT_LINE_REG) & 1; + origin = osVirtualToPhysical(viNext->buffer) + viMode->fldRegs[field].origin; + if (viNext->state & VI_STATE_XSCALE_UPDATED) { viNext->x.scale |= viMode->comRegs.xScale & ~0xFFF; } else { viNext->x.scale = viMode->comRegs.xScale; @@ -46,19 +44,19 @@ void __osViSwapContext(void) { origin = osVirtualToPhysical(viNext->buffer); } - HW_REG(VI_ORIGIN_REG, u32) = origin; - HW_REG(VI_WIDTH_REG, u32) = viMode->comRegs.width; - HW_REG(VI_BURST_REG, u32) = viMode->comRegs.burst; - HW_REG(VI_V_SYNC_REG, u32) = viMode->comRegs.vSync; - HW_REG(VI_H_SYNC_REG, u32) = viMode->comRegs.hSync; - HW_REG(VI_LEAP_REG, u32) = viMode->comRegs.leap; - HW_REG(VI_H_START_REG, u32) = hStart; - HW_REG(VI_V_START_REG, u32) = vstart; - HW_REG(VI_V_BURST_REG, u32) = viMode->fldRegs[field].vBurst; - HW_REG(VI_INTR_REG, u32) = viMode->fldRegs[field].vIntr; - HW_REG(VI_X_SCALE_REG, u32) = viNext->x.scale; - HW_REG(VI_Y_SCALE_REG, u32) = viNext->y.scale; - HW_REG(VI_CONTROL_REG, u32) = viNext->features; + IO_WRITE(VI_ORIGIN_REG, origin); + IO_WRITE(VI_WIDTH_REG, viMode->comRegs.width); + IO_WRITE(VI_BURST_REG, viMode->comRegs.burst); + IO_WRITE(VI_V_SYNC_REG, viMode->comRegs.vSync); + IO_WRITE(VI_H_SYNC_REG, viMode->comRegs.hSync); + IO_WRITE(VI_LEAP_REG, viMode->comRegs.leap); + IO_WRITE(VI_H_START_REG, hStart); + IO_WRITE(VI_V_START_REG, vstart); + IO_WRITE(VI_V_BURST_REG, viMode->fldRegs[field].vBurst); + IO_WRITE(VI_INTR_REG, viMode->fldRegs[field].vIntr); + IO_WRITE(VI_X_SCALE_REG, viNext->x.scale); + IO_WRITE(VI_Y_SCALE_REG, viNext->y.scale); + IO_WRITE(VI_CONTROL_REG, viNext->features); __osViNext = __osViCurr; __osViCurr = viNext; diff --git a/src/libultra/libc/ldiv.c b/src/libultra/libc/ldiv.c index 9f9d750312..66b144da48 100644 --- a/src/libultra/libc/ldiv.c +++ b/src/libultra/libc/ldiv.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdlib.h" ldiv_t ldiv(long numer, long denom) { ldiv_t val; diff --git a/src/libultra/libc/ll.c b/src/libultra/libc/ll.c index 0fd42d1ed7..a05917090d 100644 --- a/src/libultra/libc/ll.c +++ b/src/libultra/libc/ll.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" long long __ull_rshift(unsigned long long left, unsigned long long right) { return left >> right; diff --git a/src/libultra/libc/llcvt.c b/src/libultra/libc/llcvt.c index 2ef487938d..f78d882725 100644 --- a/src/libultra/libc/llcvt.c +++ b/src/libultra/libc/llcvt.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" long long __d_to_ll(double d) { return d; diff --git a/src/libultra/rmon/sprintf.c b/src/libultra/libc/sprintf.c similarity index 92% rename from src/libultra/rmon/sprintf.c rename to src/libultra/libc/sprintf.c index 9f3610fe08..773b982fff 100644 --- a/src/libultra/rmon/sprintf.c +++ b/src/libultra/libc/sprintf.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdlib.h" #include "libc/string.h" void* proutSprintf(void* dst, const char* fmt, size_t size) { diff --git a/src/libultra/libc/string.c b/src/libultra/libc/string.c index b23bf564da..b4bdf84aee 100644 --- a/src/libultra/libc/string.c +++ b/src/libultra/libc/string.c @@ -1,4 +1,6 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdlib.h" +#include "libc/string.h" const char* strchr(const char* s, int c) { const unsigned char ch = c; diff --git a/src/libultra/rmon/xldtob.c b/src/libultra/libc/xldtob.c similarity index 99% rename from src/libultra/rmon/xldtob.c rename to src/libultra/libc/xldtob.c index e30bf4b81b..df9c30a28e 100644 --- a/src/libultra/rmon/xldtob.c +++ b/src/libultra/libc/xldtob.c @@ -1,4 +1,5 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdlib.h" #include "libc/string.h" #define BUFF_LEN 0x20 diff --git a/src/libultra/rmon/xlitob.c b/src/libultra/libc/xlitob.c similarity index 89% rename from src/libultra/rmon/xlitob.c rename to src/libultra/libc/xlitob.c index 70b9c32a45..9eb0e98d1b 100644 --- a/src/libultra/rmon/xlitob.c +++ b/src/libultra/libc/xlitob.c @@ -1,14 +1,15 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdlib.h" #include "libc/string.h" #define BUFF_LEN 0x18 -u8 ldigs[] = "0123456789abcdef"; -u8 udigs[] = "0123456789ABCDEF"; +char ldigs[] = "0123456789abcdef"; +char udigs[] = "0123456789ABCDEF"; void _Litob(_Pft* args, u8 type) { u8 buff[BUFF_LEN]; - const u8* numMap; + const char* numMap; s32 base; s32 idx; u64 num; diff --git a/src/libultra/rmon/xprintf.c b/src/libultra/libc/xprintf.c similarity index 99% rename from src/libultra/rmon/xprintf.c rename to src/libultra/libc/xprintf.c index 3fc6b5e2af..a4094833fa 100644 --- a/src/libultra/rmon/xprintf.c +++ b/src/libultra/libc/xprintf.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" #include "libc/string.h" #define ATOI(i, a) \ diff --git a/src/libultra/os/afterprenmi.c b/src/libultra/os/afterprenmi.c index b59814763f..6a9a83de33 100644 --- a/src/libultra/os/afterprenmi.c +++ b/src/libultra/os/afterprenmi.c @@ -1,5 +1,4 @@ #include "ultra64.h" -#include "global.h" s32 osAfterPreNMI(void) { return __osSpSetPc(0); diff --git a/src/libultra/os/createmesgqueue.c b/src/libultra/os/createmesgqueue.c index bcbaf1c547..34f85f867b 100644 --- a/src/libultra/os/createmesgqueue.c +++ b/src/libultra/os/createmesgqueue.c @@ -1,8 +1,8 @@ -#include "global.h" +#include "ultra64.h" void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msq, s32 count) { - mq->mtQueue = (OSThread*)&__osThreadTail; - mq->fullQueue = (OSThread*)&__osThreadTail; + mq->mtQueue = (OSThread*)&__osThreadTail.next; + mq->fullQueue = (OSThread*)&__osThreadTail.next; mq->validCount = 0; mq->first = 0; mq->msgCount = count; diff --git a/src/libultra/os/createthread.c b/src/libultra/os/createthread.c index e67743eb31..d0f3a74197 100644 --- a/src/libultra/os/createthread.c +++ b/src/libultra/os/createthread.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" void osCreateThread(OSThread* thread, OSId id, void* entry, void* arg, void* sp, OSPri p) { register u32 saveMask; @@ -13,12 +13,12 @@ void osCreateThread(OSThread* thread, OSId id, void* entry, void* arg, void* sp, thread->context.sp = (u64)(s32)sp - 16; thread->context.ra = __osCleanupThread; - mask = 0x3FFF01; - thread->context.sr = 0xFF03; - thread->context.rcp = (mask & 0x3F0000) >> 16; - thread->context.fpcsr = 0x01000800; + mask = OS_IM_ALL; + thread->context.sr = (mask & (SR_IMASK | SR_IE)) | SR_EXL; + thread->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT; + thread->context.fpcsr = (u32)(FPCSR_FS | FPCSR_EV); thread->fp = 0; - thread->state = 1; + thread->state = OS_STATE_STOPPED; thread->flags = 0; saveMask = __osDisableInt(); diff --git a/src/libultra/os/destroythread.c b/src/libultra/os/destroythread.c index 0e92d2fcfe..4bb7c9f34d 100644 --- a/src/libultra/os/destroythread.c +++ b/src/libultra/os/destroythread.c @@ -1,15 +1,13 @@ -#include "global.h" +#include "ultra64.h" void osDestroyThread(OSThread* t) { - register u32 saveMask; + register u32 saveMask = __osDisableInt(); register OSThread* pred; register OSThread* succ; - saveMask = __osDisableInt(); - if (t == NULL) { t = __osRunningThread; - } else if (t->state != 1) { + } else if (t->state != OS_STATE_STOPPED) { __osDequeueThread(t->queue, t); } diff --git a/src/libultra/os/getactivequeue.c b/src/libultra/os/getactivequeue.c index de55d7f041..633e01814a 100644 --- a/src/libultra/os/getactivequeue.c +++ b/src/libultra/os/getactivequeue.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" OSThread* __osGetActiveQueue(void) { return __osActiveQueue; diff --git a/src/libultra/os/getcurrfaultthread.c b/src/libultra/os/getcurrfaultthread.c index f36799b26f..bf2edb92d3 100644 --- a/src/libultra/os/getcurrfaultthread.c +++ b/src/libultra/os/getcurrfaultthread.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" OSThread* __osGetCurrFaultedThread(void) { return __osFaultedThread; diff --git a/src/libultra/os/gethwinterrupt.c b/src/libultra/os/gethwinterrupt.c index 711985df79..76366663c8 100644 --- a/src/libultra/os/gethwinterrupt.c +++ b/src/libultra/os/gethwinterrupt.c @@ -1,8 +1,7 @@ -#include "global.h" #include "PR/os_internal.h" #include "PR/osint.h" -void __osGetHWIntrRoutine(OSHWIntr idx, OSMesgQueue** outQueue, OSMesg* outMsg) { - *outQueue = __osHwIntTable[idx].queue; - *outMsg = __osHwIntTable[idx].msg; +void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handler)(void), void** stackEnd) { + *handler = __osHwIntTable[interrupt].handler; + *stackEnd = __osHwIntTable[interrupt].stackEnd; } diff --git a/src/libultra/os/getmemsize.c b/src/libultra/os/getmemsize.c index e9a995f30e..ea27022559 100644 --- a/src/libultra/os/getmemsize.c +++ b/src/libultra/os/getmemsize.c @@ -1,28 +1,33 @@ -#include "global.h" +#include "ultra64.h" + +#define STEP 0x100000 +#define SIZE_4MB 0x400000 +#define SIZE_8MB 0x800000 u32 osGetMemSize(void) { - u32* spC; - u32 sp8; - u32 sp4; - u32 sp0; + vu32* ptr; + u32 size = SIZE_4MB; + u32 data0; + u32 data1; - sp8 = 0x400000; + while (size < SIZE_8MB) { + ptr = (vu32*)(K1BASE + size); - do { - spC = (u32*)(sp8 + 0xA0000000); - sp4 = *(u32*)(0xA0000000 + sp8); - sp0 = *(u32*)(0xA00FFFFC + sp8); - *(u32*)(0xA0000000 + sp8) = *(u32*)(0xA0000000 + sp8) ^ 0xFFFFFFFF; - spC[0x000FFFFC / 4] = spC[0x000FFFFC / 4] ^ 0xFFFFFFFF; + data0 = *ptr; + data1 = ptr[STEP / 4 - 1]; - if ((spC[0] != (sp4 ^ 0xFFFFFFFF)) || (spC[0x000FFFFC / 4] != (sp0 ^ 0xFFFFFFFF))) { - return sp8; + *ptr ^= ~0; + ptr[STEP / 4 - 1] ^= ~0; + + if ((*ptr != (data0 ^ ~0)) || (ptr[STEP / 4 - 1] != (data1 ^ ~0))) { + return size; } - *spC = sp4; - spC[0x000FFFFC / 4] = sp0; - sp8 = sp8 + 0x100000; - } while (sp8 < 0x800000); + *ptr = data0; + ptr[STEP / 4 - 1] = data1; - return sp8; + size += STEP; + } + + return size; } diff --git a/src/libultra/os/getthreadid.c b/src/libultra/os/getthreadid.c index 57c8e275f9..d773898803 100644 --- a/src/libultra/os/getthreadid.c +++ b/src/libultra/os/getthreadid.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" OSId osGetThreadId(OSThread* t) { if (t == NULL) { diff --git a/src/libultra/os/getthreadpri.c b/src/libultra/os/getthreadpri.c index ada853ffbf..7ea51bb648 100644 --- a/src/libultra/os/getthreadpri.c +++ b/src/libultra/os/getthreadpri.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" OSPri osGetThreadPri(OSThread* t) { if (t == NULL) { diff --git a/src/libultra/os/gettime.c b/src/libultra/os/gettime.c index a29688a0af..4d5b044b11 100644 --- a/src/libultra/os/gettime.c +++ b/src/libultra/os/gettime.c @@ -1,18 +1,18 @@ -#include "global.h" +#include "ultra64.h" OSTime osGetTime(void) { u32 CurrentCount; u32 elapseCount; - OSTime sp28; + OSTime currentCount; register u32 savedMask; savedMask = __osDisableInt(); CurrentCount = osGetCount(); elapseCount = CurrentCount - __osBaseCounter; - sp28 = __osCurrentTime; + currentCount = __osCurrentTime; __osRestoreInt(savedMask); - return elapseCount + sp28; + return elapseCount + currentCount; } diff --git a/src/libultra/os/initialize.c b/src/libultra/os/initialize.c index 458aa55b94..a39aa91c02 100644 --- a/src/libultra/os/initialize.c +++ b/src/libultra/os/initialize.c @@ -1,8 +1,9 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdbool.h" #define COLD_RESET 0 -typedef struct { +typedef struct __osExceptionVector { /* 0x0 */ u32 ins_00; // lui k0, 0x8000 /* 0x4 */ u32 ins_04; // addiu k0, k0, 0x39E0 /* 0x8 */ u32 ins_08; // jr k0 ; __osException @@ -14,22 +15,22 @@ extern __osExceptionVector __osExceptionPreamble; u64 osClockRate = OS_CLOCK_RATE; s32 osViClock = VI_NTSC_CLOCK; u32 __osShutdown = 0; -u32 __OSGlobalIntMask = 0x003FFF01; +u32 __OSGlobalIntMask = OS_IM_ALL; u32 __osFinalrom; void __createSpeedParam(void) { __Dom1SpeedParam.type = DEVICE_TYPE_INIT; - __Dom1SpeedParam.latency = HW_REG(PI_BSD_DOM1_LAT_REG, u32); - __Dom1SpeedParam.pulse = HW_REG(PI_BSD_DOM1_PWD_REG, u32); - __Dom1SpeedParam.pageSize = HW_REG(PI_BSD_DOM1_PGS_REG, u32); - __Dom1SpeedParam.relDuration = HW_REG(PI_BSD_DOM1_RLS_REG, u32); + __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); + __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); __Dom2SpeedParam.type = DEVICE_TYPE_INIT; - __Dom2SpeedParam.latency = HW_REG(PI_BSD_DOM2_LAT_REG, u32); - __Dom2SpeedParam.pulse = HW_REG(PI_BSD_DOM2_PWD_REG, u32); - __Dom2SpeedParam.pageSize = HW_REG(PI_BSD_DOM2_PGS_REG, u32); - __Dom2SpeedParam.relDuration = HW_REG(PI_BSD_DOM2_RLS_REG, u32); + __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); + __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); + __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); + __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); } void __osInitialize_common(void) { @@ -37,29 +38,29 @@ void __osInitialize_common(void) { __osFinalrom = 1; - __osSetSR(__osGetSR() | 0x20000000); - __osSetFpcCsr(0x01000800); + __osSetSR(__osGetSR() | SR_CU1); + __osSetFpcCsr(FPCSR_FS | FPCSR_EV); __osSetWatchLo(0x04900000); - while (__osSiRawReadIo(0x1FC007FC, &pifdata)) {} + while (__osSiRawReadIo(PIF_RAM_END - 3, &pifdata)) {} - while (__osSiRawWriteIo(0x1FC007FC, pifdata | 8)) {} + while (__osSiRawWriteIo(PIF_RAM_END - 3, pifdata | 8)) {} - *(__osExceptionVector*)0x80000000 = __osExceptionPreamble; - *(__osExceptionVector*)0x80000080 = __osExceptionPreamble; - *(__osExceptionVector*)0x80000100 = __osExceptionPreamble; - *(__osExceptionVector*)0x80000180 = __osExceptionPreamble; + *(__osExceptionVector*)UT_VEC = __osExceptionPreamble; + *(__osExceptionVector*)XUT_VEC = __osExceptionPreamble; + *(__osExceptionVector*)ECC_VEC = __osExceptionPreamble; + *(__osExceptionVector*)E_VEC = __osExceptionPreamble; - osWritebackDCache(0x80000000, 400); - osInvalICache(0x80000000, 400); + osWritebackDCache((void*)UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); + osInvalICache((void*)UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); __createSpeedParam(); osUnmapTLBAll(); osMapTLBRdb(); - osClockRate = (u64)((osClockRate * 3LL) / 4ULL); + osClockRate = osClockRate * 3 / 4; if (osResetType == COLD_RESET) { - bzero(osAppNMIBuffer, 64); + bzero(osAppNMIBuffer, OS_APP_NMI_BUFSIZE); } if (osTvType == OS_TV_PAL) { @@ -70,13 +71,13 @@ void __osInitialize_common(void) { osViClock = VI_NTSC_CLOCK; } - if (__osGetCause() & 0x1000) { + if (__osGetCause() & CAUSE_IP5) { while (true) {} } - HW_REG(AI_CONTROL_REG, u32) = 1; - HW_REG(AI_DACRATE_REG, u32) = 0x3FFF; - HW_REG(AI_BITRATE_REG, u32) = 0xF; + IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); + IO_WRITE(AI_DACRATE_REG, AI_MAX_DAC_RATE - 1); + IO_WRITE(AI_BITRATE_REG, AI_MAX_BIT_RATE - 1); } void __osInitialize_autodetect(void) { diff --git a/src/libultra/os/jammesg.c b/src/libultra/os/jammesg.c index e91753e2c7..0baddad1c9 100644 --- a/src/libultra/os/jammesg.c +++ b/src/libultra/os/jammesg.c @@ -1,13 +1,11 @@ -#include "global.h" +#include "ultra64.h" s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) { - register u32 saveMask; - - saveMask = __osDisableInt(); + register u32 saveMask = __osDisableInt(); while (mq->validCount >= mq->msgCount) { - if (flag == 1) { - __osRunningThread->state = 8; + if (flag == OS_MESG_BLOCK) { + __osRunningThread->state = OS_STATE_WAITING; __osEnqueueAndYield(&mq->fullQueue); } else { __osRestoreInt(saveMask); diff --git a/src/libultra/os/recvmesg.c b/src/libultra/os/recvmesg.c index ec0b3f93b9..03a399b9ab 100644 --- a/src/libultra/os/recvmesg.c +++ b/src/libultra/os/recvmesg.c @@ -1,12 +1,10 @@ -#include "global.h" +#include "ultra64.h" s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags) { - register u32 saveMask; + register u32 saveMask = __osDisableInt(); - saveMask = __osDisableInt(); - - while (mq->validCount == 0) { - if (flags == 0) { + while (MQ_IS_EMPTY(mq)) { + if (flags == OS_MESG_NOBLOCK) { __osRestoreInt(saveMask); return -1; } diff --git a/src/libultra/os/resetglobalintmask.c b/src/libultra/os/resetglobalintmask.c index 6289a1d4cf..0cf5113a5b 100644 --- a/src/libultra/os/resetglobalintmask.c +++ b/src/libultra/os/resetglobalintmask.c @@ -1,8 +1,8 @@ -#include "global.h" +#include "ultra64.h" void __osResetGlobalIntMask(OSHWIntr mask) { register s32 prevInt = __osDisableInt(); - __OSGlobalIntMask &= ~(mask & ~0x401); + __OSGlobalIntMask &= ~(mask & ~OS_IM_RCP); __osRestoreInt(prevInt); } diff --git a/src/libultra/os/sendmesg.c b/src/libultra/os/sendmesg.c index 6859c107b7..b2ab181095 100644 --- a/src/libultra/os/sendmesg.c +++ b/src/libultra/os/sendmesg.c @@ -1,14 +1,12 @@ -#include "global.h" +#include "ultra64.h" s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags) { - register u32 saveMask; + register u32 saveMask = __osDisableInt(); register s32 last; - saveMask = __osDisableInt(); - - while (mq->validCount >= mq->msgCount) { - if (flags == 1) { - __osRunningThread->state = 8; + while (MQ_IS_FULL(mq)) { + if (flags == OS_MESG_BLOCK) { + __osRunningThread->state = OS_STATE_WAITING; __osEnqueueAndYield(&mq->fullQueue); } else { __osRestoreInt(saveMask); diff --git a/src/libultra/os/seteventmesg.c b/src/libultra/os/seteventmesg.c index 74258517f7..6f4fb0f97f 100644 --- a/src/libultra/os/seteventmesg.c +++ b/src/libultra/os/seteventmesg.c @@ -1,23 +1,22 @@ -#include "global.h" +#include "ultra64.h" #include "PR/osint.h" #include "libc/stdbool.h" +#include "alignment.h" u32 __osPreNMI = false; -__OSEventState __osEventStateTab[OS_NUM_EVENTS]; +__OSEventState __osEventStateTab[OS_NUM_EVENTS] ALIGNED(8); void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg m) { - register u32 saveMask; + register u32 saveMask = __osDisableInt(); __OSEventState* es; - saveMask = __osDisableInt(); - es = &__osEventStateTab[e]; es->messageQueue = mq; es->message = m; - if (e == 14) { + if (e == OS_EVENT_PRENMI) { if (__osShutdown && !__osPreNMI) { osSendMesg(mq, m, OS_MESG_NOBLOCK); } diff --git a/src/libultra/os/setglobalintmask.c b/src/libultra/os/setglobalintmask.c index 067343f6ee..42333ee2b5 100644 --- a/src/libultra/os/setglobalintmask.c +++ b/src/libultra/os/setglobalintmask.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" void __osSetGlobalIntMask(OSHWIntr mask) { register s32 prevInt = __osDisableInt(); diff --git a/src/libultra/os/sethwinterrupt.c b/src/libultra/os/sethwinterrupt.c index 4f536cade4..3a42123f76 100644 --- a/src/libultra/os/sethwinterrupt.c +++ b/src/libultra/os/sethwinterrupt.c @@ -1,11 +1,11 @@ -#include "global.h" +#include "PR/os_internal.h" #include "PR/osint.h" -void __osSetHWIntrRoutine(OSHWIntr idx, OSMesgQueue* queue, OSMesg msg) { +void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void* stackEnd) { register s32 prevInt = __osDisableInt(); - __osHwIntTable[idx].queue = queue; - __osHwIntTable[idx].msg = msg; + __osHwIntTable[interrupt].handler = handler; + __osHwIntTable[interrupt].stackEnd = stackEnd; __osRestoreInt(prevInt); } diff --git a/src/libultra/os/setthreadpri.c b/src/libultra/os/setthreadpri.c index 2da5bf2660..39ec0d159c 100644 --- a/src/libultra/os/setthreadpri.c +++ b/src/libultra/os/setthreadpri.c @@ -1,9 +1,7 @@ -#include "global.h" +#include "ultra64.h" void osSetThreadPri(OSThread* thread, OSPri p) { - register u32 saveMask; - - saveMask = __osDisableInt(); + register u32 saveMask = __osDisableInt(); if (thread == NULL) { thread = __osRunningThread; @@ -12,13 +10,13 @@ void osSetThreadPri(OSThread* thread, OSPri p) { if (thread->priority != p) { thread->priority = p; - if (thread != __osRunningThread && thread->state != 1) { + if (thread != __osRunningThread && thread->state != OS_STATE_STOPPED) { __osDequeueThread(thread->queue, thread); __osEnqueueThread(thread->queue, thread); } if (__osRunningThread->priority < __osRunQueue->priority) { - __osRunningThread->state = 2; + __osRunningThread->state = OS_STATE_RUNNABLE; __osEnqueueAndYield(&__osRunQueue); } } diff --git a/src/libultra/os/settime.c b/src/libultra/os/settime.c index e6fc07bb47..fc4b77987c 100644 --- a/src/libultra/os/settime.c +++ b/src/libultra/os/settime.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" void osSetTime(OSTime ticks) { __osCurrentTime = ticks; diff --git a/src/libultra/os/settimer.c b/src/libultra/os/settimer.c index 77f568a02e..5cf01c675c 100644 --- a/src/libultra/os/settimer.c +++ b/src/libultra/os/settimer.c @@ -1,17 +1,17 @@ -#include "global.h" +#include "ultra64.h" -int osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg) { - OSTime tim; - OSTimer* spC; - u32 sp14; - u32 sp10; +int osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg) { + OSTime time; + OSTimer* next; + u32 count; + u32 value; u32 saveMask; t->next = NULL; t->prev = NULL; t->interval = interval; - if (value != 0) { - t->value = value; + if (countdown != 0) { + t->value = countdown; } else { t->value = interval; } @@ -20,21 +20,19 @@ int osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMes saveMask = __osDisableInt(); - if (__osTimerList->next != __osTimerList) { - //! FAKE: - if (1) {} - - spC = __osTimerList->next; - sp14 = osGetCount(); - sp10 = sp14 - __osTimerCounter; - if (sp10 < spC->value) { - spC->value -= sp10; + if (__osTimerList->next == __osTimerList) { + } else { + next = __osTimerList->next; + count = osGetCount(); + value = count - __osTimerCounter; + if (value < next->value) { + next->value -= value; } else { - spC->value = 1; + next->value = 1; } } - tim = __osInsertTimer(t); + time = __osInsertTimer(t); __osSetTimerIntr(__osTimerList->next->value); __osRestoreInt(saveMask); diff --git a/src/libultra/os/startthread.c b/src/libultra/os/startthread.c index fb19b67e2e..259e5545cf 100644 --- a/src/libultra/os/startthread.c +++ b/src/libultra/os/startthread.c @@ -1,21 +1,20 @@ -#include "global.h" +#include "ultra64.h" void osStartThread(OSThread* t) { - register u32 saveMask; - - saveMask = __osDisableInt(); + register u32 saveMask = __osDisableInt(); switch (t->state) { - case 8: - t->state = 2; + case OS_STATE_WAITING: + t->state = OS_STATE_RUNNABLE; __osEnqueueThread(&__osRunQueue, t); break; - case 1: + + case OS_STATE_STOPPED: if ((t->queue == NULL) || (t->queue == &__osRunQueue)) { - t->state = 2; + t->state = OS_STATE_RUNNABLE; __osEnqueueThread(&__osRunQueue, t); } else { - t->state = 8; + t->state = OS_STATE_WAITING; __osEnqueueThread(t->queue, t); __osEnqueueThread(&__osRunQueue, __osPopThread(t->queue)); } @@ -26,7 +25,7 @@ void osStartThread(OSThread* t) { __osDispatchThread(); } else { if (__osRunningThread->priority < __osRunQueue->priority) { - __osRunningThread->state = 2; + __osRunningThread->state = OS_STATE_RUNNABLE; __osEnqueueAndYield(&__osRunQueue); } } diff --git a/src/libultra/os/stopthread.c b/src/libultra/os/stopthread.c index 0fb388074b..f4634326b1 100644 --- a/src/libultra/os/stopthread.c +++ b/src/libultra/os/stopthread.c @@ -1,25 +1,24 @@ -#include "global.h" +#include "ultra64.h" void osStopThread(OSThread* t) { - register u32 saveMask; + register u32 saveMask = __osDisableInt(); register u16 state; - saveMask = __osDisableInt(); - if (t == NULL) { - state = 4; + state = OS_STATE_RUNNING; } else { state = t->state; } switch (state) { - case 4: - __osRunningThread->state = 1; + case OS_STATE_RUNNING: + __osRunningThread->state = OS_STATE_STOPPED; __osEnqueueAndYield(NULL); break; - case 2: - case 8: - t->state = 1; + + case OS_STATE_RUNNABLE: + case OS_STATE_WAITING: + t->state = OS_STATE_STOPPED; __osDequeueThread(t->queue, t); break; } diff --git a/src/libultra/os/stoptimer.c b/src/libultra/os/stoptimer.c index 70a483461a..936a19af8b 100644 --- a/src/libultra/os/stoptimer.c +++ b/src/libultra/os/stoptimer.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" s32 osStopTimer(OSTimer* t) { register u32 savedMask; diff --git a/src/libultra/os/thread.c b/src/libultra/os/thread.c index 98d04ab54e..cd0484b443 100644 --- a/src/libultra/os/thread.c +++ b/src/libultra/os/thread.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "ultra64.h" __OSThreadTail __osThreadTail = { NULL, OS_PRIORITY_THREADTAIL }; OSThread* __osRunQueue = (OSThread*)&__osThreadTail; diff --git a/src/libultra/os/threadsave.c b/src/libultra/os/threadsave.c index bcf79be8d6..2f7abe20d2 100644 --- a/src/libultra/os/threadsave.c +++ b/src/libultra/os/threadsave.c @@ -1,3 +1,3 @@ -#include "global.h" +#include "ultra64.h" OSThread __osThreadSave; diff --git a/src/libultra/os/timerintr.c b/src/libultra/os/timerintr.c index 69ac931e1a..ae30b5cf7b 100644 --- a/src/libultra/os/timerintr.c +++ b/src/libultra/os/timerintr.c @@ -1,12 +1,11 @@ -#include "global.h" +#include "ultra64.h" +#include "libc/stdbool.h" OSTimer __osBaseTimer; OSTime __osCurrentTime; u32 __osBaseCounter; u32 __osViIntrCount; u32 __osTimerCounter; -s32 D_8009E5C8[2]; // dummy bss padding required -OSPifRam __osPfsPifRam; OSTimer* __osTimerList = &__osBaseTimer; diff --git a/src/libultra/os/viextend.c b/src/libultra/os/viextend.c deleted file mode 100644 index ce9f718d01..0000000000 --- a/src/libultra/os/viextend.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "global.h" - -void osViExtendVStart(u32 a0) { - __additional_scanline = a0; -} diff --git a/src/libultra/os/virtualtophysical.c b/src/libultra/os/virtualtophysical.c index 403ab5f4f3..864f54eb86 100644 --- a/src/libultra/os/virtualtophysical.c +++ b/src/libultra/os/virtualtophysical.c @@ -1,14 +1,12 @@ -#include "PR/ultratypes.h" -#include "PR/osint.h" +#include "ultra64.h" #include "libc/stdint.h" -#include "global.h" -uintptr_t osVirtualToPhysical(void* virtualAddress) { - if (((uintptr_t)virtualAddress >= 0x80000000) && ((uintptr_t)virtualAddress < 0xA0000000)) { - return (uintptr_t)virtualAddress & 0x1FFFFFFF; - } else if (((uintptr_t)virtualAddress >= 0xA0000000) && ((uintptr_t)virtualAddress < 0xC0000000)) { - return (uintptr_t)virtualAddress & 0x1FFFFFFF; +uintptr_t osVirtualToPhysical(void* addr) { + if (IS_KSEG0(addr)) { + return K0_TO_PHYS(addr); + } else if (IS_KSEG1(addr)) { + return K1_TO_PHYS(addr); } else { - return __osProbeTLB(virtualAddress); + return __osProbeTLB(addr); } } diff --git a/src/libultra/os/yieldthread.c b/src/libultra/os/yieldthread.c index c49fd0f121..7fd4e2491c 100644 --- a/src/libultra/os/yieldthread.c +++ b/src/libultra/os/yieldthread.c @@ -1,9 +1,9 @@ -#include "global.h" +#include "ultra64.h" void osYieldThread(void) { register u32 saveMask = __osDisableInt(); - __osRunningThread->state = 2; + __osRunningThread->state = OS_STATE_RUNNABLE; __osEnqueueAndYield(&__osRunQueue); __osRestoreInt(saveMask); diff --git a/src/libultra/vimodes/vimodefpallan1.c b/src/libultra/vimodes/vimodefpallan1.c new file mode 100644 index 0000000000..125f0b5fc8 --- /dev/null +++ b/src/libultra/vimodes/vimodefpallan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "PR/viint.h" + +OSViMode osViModeFpalLan1 = { + OS_VI_FPAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(47, 617), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/src/libultra/io/osViModeMpalLan1.c b/src/libultra/vimodes/vimodempallan1.c similarity index 52% rename from src/libultra/io/osViModeMpalLan1.c rename to src/libultra/vimodes/vimodempallan1.c index a7f5173a9d..7e611fe9b7 100644 --- a/src/libultra/io/osViModeMpalLan1.c +++ b/src/libultra/vimodes/vimodempallan1.c @@ -1,19 +1,21 @@ -#include "global.h" +#include "PR/os.h" +#include "PR/rcp.h" #include "PR/viint.h" OSViMode osViModeMpalLan1 = { OS_VI_MPAL_LAN1, // type { // comRegs - 0x311E, // ctrl - WIDTH(320), // width - BURST(57, 30, 5, 70), // burst - VSYNC(525), // vSync - HSYNC(3089, 4), // hSync - LEAP(3097, 3098), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent }, { // fldRegs { diff --git a/src/libultra/io/osViModeNtscHpf1.c b/src/libultra/vimodes/vimodentschpf1.c similarity index 52% rename from src/libultra/io/osViModeNtscHpf1.c rename to src/libultra/vimodes/vimodentschpf1.c index 672a2a17f1..ce7c7d8a71 100644 --- a/src/libultra/io/osViModeNtscHpf1.c +++ b/src/libultra/vimodes/vimodentschpf1.c @@ -1,19 +1,21 @@ -#include "global.h" +#include "PR/os.h" +#include "PR/rcp.h" #include "PR/viint.h" OSViMode osViModeNtscHpf1 = { OS_VI_NTSC_HPF1, // type { // comRegs - 0x324E, // ctrl - WIDTH(640), // width - BURST(57, 34, 5, 62), // 0x3E52239, // burst - VSYNC(524), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // 0x6C02EC, // hStart - SCALE(1, 0), // xScale - VCURRENT(0), // vCurrent + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(640), // width + BURST(57, 34, 5, 62), // 0x3E52239, // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // 0x6C02EC, // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent }, { // fldRegs { diff --git a/src/libultra/vimodes/vimodentschpn1.c b/src/libultra/vimodes/vimodentschpn1.c new file mode 100644 index 0000000000..877da10c33 --- /dev/null +++ b/src/libultra/vimodes/vimodentschpn1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "PR/viint.h" + +OSViMode osViModeNtscHpn1 = { + OS_VI_NTSC_HPN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_SERRATE_ON | VI_CTRL_ANTIALIAS_MODE_2 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(1280), // width + BURST(57, 34, 5, 62), // burst + VSYNC(524), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(1, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(1280), // origin + SCALE(1, 0), // yScale + HSTART(35, 509), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(2560), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/src/libultra/io/osViModeNtscLan1.c b/src/libultra/vimodes/vimodentsclan1.c similarity index 52% rename from src/libultra/io/osViModeNtscLan1.c rename to src/libultra/vimodes/vimodentsclan1.c index afbe46fab5..76dd9135f9 100644 --- a/src/libultra/io/osViModeNtscLan1.c +++ b/src/libultra/vimodes/vimodentsclan1.c @@ -1,19 +1,21 @@ -#include "global.h" +#include "PR/os.h" +#include "PR/rcp.h" #include "PR/viint.h" OSViMode osViModeNtscLan1 = { OS_VI_NTSC_LAN1, // type { // comRegs - 0x311E, // ctrl - WIDTH(320), // width - BURST(57, 34, 5, 62), // burst - VSYNC(525), // vSync - HSYNC(3093, 0), // hSync - LEAP(3093, 3093), // leap - HSTART(108, 748), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent }, { // fldRegs { diff --git a/src/libultra/io/osViModePalLan1.c b/src/libultra/vimodes/vimodepallan1.c similarity index 53% rename from src/libultra/io/osViModePalLan1.c rename to src/libultra/vimodes/vimodepallan1.c index 66ae4e6f1a..933f9c00c5 100644 --- a/src/libultra/io/osViModePalLan1.c +++ b/src/libultra/vimodes/vimodepallan1.c @@ -1,19 +1,21 @@ -#include "global.h" +#include "PR/os.h" +#include "PR/rcp.h" #include "PR/viint.h" OSViMode osViModePalLan1 = { OS_VI_PAL_LAN1, // type { // comRegs - 0x311E, // ctrl - WIDTH(320), // width - BURST(58, 30, 4, 69), // burst - VSYNC(625), // vSync - HSYNC(3177, 23), // hSync - LEAP(3183, 3181), // leap - HSTART(128, 768), // hStart - SCALE(2, 0), // xScale - VCURRENT(0), // vCurrent + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent }, { // fldRegs { diff --git a/src/libultra/voice/voicecontread2.c b/src/libultra/voice/voicecontread2.c index ba60a64c3f..a9e6660bbb 100644 --- a/src/libultra/voice/voicecontread2.c +++ b/src/libultra/voice/voicecontread2.c @@ -2,11 +2,11 @@ * File: voicecontread2.c */ +#include "ultra64.h" #include "PR/controller_voice.h" -#include "PR/voice_internal.h" +#include "PR/voiceinternal.h" #include "PR/controller.h" -#include "functions.h" -#include "variables.h" +#include "macros.h" #define READ2FORMAT(ptr) ((__OSVoiceRead2Format*)(ptr)) diff --git a/src/libultra/voice/voicecontread36.c b/src/libultra/voice/voicecontread36.c index 248360b00e..eb4ead42ef 100644 --- a/src/libultra/voice/voicecontread36.c +++ b/src/libultra/voice/voicecontread36.c @@ -2,11 +2,11 @@ * File: voicecontread36.c */ +#include "ultra64.h" #include "PR/controller_voice.h" -#include "PR/voice_internal.h" +#include "PR/voiceinternal.h" #include "PR/controller.h" -#include "functions.h" -#include "variables.h" +#include "macros.h" #define READ36FORMAT(ptr) ((__OSVoiceRead36Format*)(ptr)) diff --git a/src/libultra/voice/voicecontwrite20.c b/src/libultra/voice/voicecontwrite20.c index a346294bd5..89d5e933c8 100644 --- a/src/libultra/voice/voicecontwrite20.c +++ b/src/libultra/voice/voicecontwrite20.c @@ -2,11 +2,11 @@ * File: voicecontwrite20.c */ +#include "ultra64.h" #include "PR/controller_voice.h" -#include "PR/voice_internal.h" +#include "PR/voiceinternal.h" #include "PR/controller.h" -#include "functions.h" -#include "variables.h" +#include "macros.h" #define WRITE20FORMAT(ptr) ((__OSVoiceWrite20Format*)(ptr)) diff --git a/src/libultra/voice/voicecontwrite4.c b/src/libultra/voice/voicecontwrite4.c index e828fc4c61..b0c6a4e53f 100644 --- a/src/libultra/voice/voicecontwrite4.c +++ b/src/libultra/voice/voicecontwrite4.c @@ -2,11 +2,11 @@ * File: voicecontwrite4.c */ +#include "ultra64.h" #include "PR/controller_voice.h" -#include "PR/voice_internal.h" +#include "PR/voiceinternal.h" #include "PR/controller.h" -#include "functions.h" -#include "variables.h" +#include "macros.h" #define WRITE4FORMAT(ptr) ((__OSVoiceWrite4Format*)(ptr)) diff --git a/src/libultra/voice/voicegetstatus.c b/src/libultra/voice/voicegetstatus.c index b19348908a..2e5713f763 100644 --- a/src/libultra/voice/voicegetstatus.c +++ b/src/libultra/voice/voicegetstatus.c @@ -2,9 +2,9 @@ * File: voicegetstatus.c */ +#include "ultra64.h" #include "PR/controller_voice.h" #include "PR/controller.h" -#include "functions.h" s32 __osVoiceGetStatus(OSMesgQueue* mq, s32 channel, u8* status) { __OSContRequestHeaderAligned header; diff --git a/src/libultra/voice/voiceinit.c b/src/libultra/voice/voiceinit.c index f8c965f703..69fc2fd7c3 100644 --- a/src/libultra/voice/voiceinit.c +++ b/src/libultra/voice/voiceinit.c @@ -4,10 +4,10 @@ * Initializes Voice Recognition System control structure and hardware */ +#include "ultra64.h" #include "PR/controller_voice.h" #include "PR/os_voice.h" #include "PR/controller.h" -#include "functions.h" #include "macros.h" static u8 sCmds[] = { diff --git a/src/libultra/voice/voicemaskdictionary.c b/src/libultra/voice/voicemaskdictionary.c index 225c45dee3..6ff957d45e 100644 --- a/src/libultra/voice/voicemaskdictionary.c +++ b/src/libultra/voice/voicemaskdictionary.c @@ -4,10 +4,10 @@ * Mask words registered in the voice recognition system */ +#include "ultra64.h" #include "PR/controller_voice.h" #include "PR/os_voice.h" #include "PR/controller.h" -#include "functions.h" #include "macros.h" s32 osVoiceMaskDictionary(OSVoiceHandle* hd, u8* maskPattern, int size) { diff --git a/src/libultra/voice/voicesetadconverter.c b/src/libultra/voice/voicesetadconverter.c index 1b3d87cd5f..bb8e7e169d 100644 --- a/src/libultra/voice/voicesetadconverter.c +++ b/src/libultra/voice/voicesetadconverter.c @@ -2,11 +2,10 @@ * File: voicesetadconverter.c */ +#include "ultra64.h" #include "PR/controller_voice.h" -#include "PR/voice_internal.h" +#include "PR/voiceinternal.h" #include "PR/controller.h" -#include "functions.h" -#include "variables.h" #define SWRITEFORMAT(ptr) ((__OSVoiceSWriteFormat*)(ptr)) diff --git a/src/libultra/voice/voicesetword.c b/src/libultra/voice/voicesetword.c index 82b0f88aa2..f832b60106 100644 --- a/src/libultra/voice/voicesetword.c +++ b/src/libultra/voice/voicesetword.c @@ -4,10 +4,10 @@ * Registers words to the Voice Recognition System dictionary */ +#include "ultra64.h" #include "PR/controller_voice.h" #include "PR/os_voice.h" #include "PR/controller.h" -#include "functions.h" #include "macros.h" s32 osVoiceSetWord(OSVoiceHandle* hd, u8* word) { diff --git a/src/overlays/actors/ovl_Boss_03/z_boss_03.c b/src/overlays/actors/ovl_Boss_03/z_boss_03.c index 0ff34cad49..202e836a59 100644 --- a/src/overlays/actors/ovl_Boss_03/z_boss_03.c +++ b/src/overlays/actors/ovl_Boss_03/z_boss_03.c @@ -2156,7 +2156,7 @@ void Boss03_SetObject(PlayState* play, s16 objectId) { OPEN_DISPS(play->state.gfxCtx); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); gSPSegment(POLY_OPA_DISP++, 0x06, play->objectCtx.slots[objectSlot].segment); gSPSegment(POLY_XLU_DISP++, 0x06, play->objectCtx.slots[objectSlot].segment); diff --git a/src/overlays/actors/ovl_Boss_06/z_boss_06.c b/src/overlays/actors/ovl_Boss_06/z_boss_06.c index d8f1571ce5..afce1ef950 100644 --- a/src/overlays/actors/ovl_Boss_06/z_boss_06.c +++ b/src/overlays/actors/ovl_Boss_06/z_boss_06.c @@ -147,7 +147,7 @@ void Boss06_Init(Actor* thisx, PlayState* play) { this->actor.shape.rot.y = -0x8000; Collider_InitAndSetCylinder(play, &this->collider, &this->actor, &sCylinderInit); - temp_v0 = SEGMENTED_TO_VIRTUAL(&object_knight_Tex_019490); + temp_v0 = SEGMENTED_TO_K0(&object_knight_Tex_019490); for (i = 0; i < ARRAY_COUNT(this->unk_200); i++) { this->unk_200[i] = temp_v0[i]; } @@ -530,7 +530,7 @@ void Boss06_Draw(Actor* thisx, PlayState* play2) { if (this->unk_144 & 2) { temp_s0 = Math_SinS(D_809F4970->unk_144) * 1000.0f; temp_f10 = (Math_CosS(D_809F4970->unk_144) * -2000.0f) - 2000.0f; - temp_v0_2 = SEGMENTED_TO_VIRTUAL(&object_knight_Vtx_018BD0); + temp_v0_2 = SEGMENTED_TO_K0(&object_knight_Vtx_018BD0); temp_v0_2[0].v.ob[1] = (s16)this->unk_1A0 + 0xE92; temp_v0_2[3].v.ob[1] = (s16)this->unk_1A0 + 0xE92; diff --git a/src/overlays/actors/ovl_Dm_An/z_dm_an.c b/src/overlays/actors/ovl_Dm_An/z_dm_an.c index 090360dd7f..e67e9e6f5e 100644 --- a/src/overlays/actors/ovl_Dm_An/z_dm_an.c +++ b/src/overlays/actors/ovl_Dm_An/z_dm_an.c @@ -92,9 +92,9 @@ s32 DmAn_UpdateSkelAnime(DmAn* this, PlayState* play) { } if (objectSlot2 > OBJECT_SLOT_NONE) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot2].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot2].segment); isAnimFinished = SkelAnime_Update(&this->skelAnime); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); } return isAnimFinished; @@ -112,10 +112,10 @@ s32 DmAn_ChangeAnim(DmAn* this, PlayState* play, DmAnAnimation animIndex) { } if ((objectSlot2 > OBJECT_SLOT_NONE) && (this->animIndex != animIndex)) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot2].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot2].segment); this->animIndex = animIndex; didAnimChange = SubS_ChangeAnimationByInfoS(&this->skelAnime, sAnimationInfo, animIndex); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); } return didAnimChange; diff --git a/src/overlays/actors/ovl_Dm_Bal/z_dm_bal.c b/src/overlays/actors/ovl_Dm_Bal/z_dm_bal.c index a0fa8d6b35..254a4ca90e 100644 --- a/src/overlays/actors/ovl_Dm_Bal/z_dm_bal.c +++ b/src/overlays/actors/ovl_Dm_Bal/z_dm_bal.c @@ -222,7 +222,7 @@ void DmBal_Draw(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); Gfx_SetupDL25_Opa(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(sEyeTextures[this->eyeIndex])); + gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_K0(sEyeTextures[this->eyeIndex])); SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, DmBal_OverrideLimbDraw, DmBal_PostLimbDraw, &this->actor); diff --git a/src/overlays/actors/ovl_Dm_Gm/z_dm_gm.c b/src/overlays/actors/ovl_Dm_Gm/z_dm_gm.c index 458b51193d..4eb1399985 100644 --- a/src/overlays/actors/ovl_Dm_Gm/z_dm_gm.c +++ b/src/overlays/actors/ovl_Dm_Gm/z_dm_gm.c @@ -92,9 +92,9 @@ s32 DmGm_UpdateSkelAnime(DmGm* this, PlayState* play) { } if (objectIndex2 > OBJECT_SLOT_NONE) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectIndex2].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectIndex2].segment); isAnimFinished = SkelAnime_Update(&this->skelAnime); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); } return isAnimFinished; @@ -112,10 +112,10 @@ s32 DmGm_ChangeAnim(DmGm* this, PlayState* play, DmGmAnimation animIndex) { } if ((objectIndex2 > OBJECT_SLOT_NONE) && (this->animIndex != animIndex)) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectIndex2].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectIndex2].segment); this->animIndex = animIndex; didAnimChange = SubS_ChangeAnimationByInfoS(&this->skelAnime, sAnimationInfo, animIndex); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); } return didAnimChange; diff --git a/src/overlays/actors/ovl_Dm_Stk/z_dm_stk.c b/src/overlays/actors/ovl_Dm_Stk/z_dm_stk.c index e4f85e15c6..73bf18c1a7 100644 --- a/src/overlays/actors/ovl_Dm_Stk/z_dm_stk.c +++ b/src/overlays/actors/ovl_Dm_Stk/z_dm_stk.c @@ -320,7 +320,7 @@ void DmStk_LoadObjectForAnimation(DmStk* this, PlayState* play) { } if (objectSlot > OBJECT_SLOT_NONE) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); } } @@ -1968,13 +1968,13 @@ void DmStk_PostLimbDraw2(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot (this->objectStk2ObjectSlot > OBJECT_SLOT_NONE)) { Matrix_Push(); Matrix_Scale(2.0f, 2.0f, 2.0f, MTXMODE_APPLY); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectStk2ObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectStk2ObjectSlot].segment); gSPSegment(POLY_OPA_DISP++, 0x06, play->objectCtx.slots[this->objectStk2ObjectSlot].segment); AnimatedMat_Draw(play, Lib_SegmentedToVirtual(gSkullKidMajorasMaskCurseOverlayTexAnim)); Gfx_DrawDListOpa(play, gSkullKidMajorasMaskCurseOverlayDL); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectStkObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectStkObjectSlot].segment); gSPSegment(POLY_OPA_DISP++, 0x06, play->objectCtx.slots[this->objectStkObjectSlot].segment); @@ -2095,7 +2095,7 @@ void DmStk_Draw(Actor* thisx, PlayState* play) { return; } - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectStkObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectStkObjectSlot].segment); OPEN_DISPS(play->state.gfxCtx); diff --git a/src/overlays/actors/ovl_En_Bal/z_en_bal.c b/src/overlays/actors/ovl_En_Bal/z_en_bal.c index 95b4951246..3bd63b1a62 100644 --- a/src/overlays/actors/ovl_En_Bal/z_en_bal.c +++ b/src/overlays/actors/ovl_En_Bal/z_en_bal.c @@ -1166,7 +1166,7 @@ void EnBal_Draw(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); Gfx_SetupDL25_Opa(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 8, SEGMENTED_TO_VIRTUAL(sEyeTextures[this->eyeTexIndex])); + gSPSegment(POLY_OPA_DISP++, 8, SEGMENTED_TO_K0(sEyeTextures[this->eyeTexIndex])); SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, EnBal_OverrideLimbDraw, EnBal_PostLimbDraw, &this->picto.actor); diff --git a/src/overlays/actors/ovl_En_Bba_01/z_en_bba_01.c b/src/overlays/actors/ovl_En_Bba_01/z_en_bba_01.c index 850ffa1988..54595f3607 100644 --- a/src/overlays/actors/ovl_En_Bba_01/z_en_bba_01.c +++ b/src/overlays/actors/ovl_En_Bba_01/z_en_bba_01.c @@ -265,8 +265,8 @@ s32 EnBba01_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* OPEN_DISPS(play->state.gfxCtx); gSPSegment(POLY_OPA_DISP++, 0x06, play->objectCtx.slots[this->enHy.headObjectSlot].segment); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->enHy.headObjectSlot].segment); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->enHy.skelLowerObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->enHy.headObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->enHy.skelLowerObjectSlot].segment); CLOSE_DISPS(play->state.gfxCtx); } @@ -304,7 +304,7 @@ void EnBba01_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* ro OPEN_DISPS(play->state.gfxCtx); gSPSegment(POLY_OPA_DISP++, 0x06, play->objectCtx.slots[this->enHy.skelUpperObjectSlot].segment); - gSegments[0x06] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->enHy.skelUpperObjectSlot].segment); + gSegments[0x06] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->enHy.skelUpperObjectSlot].segment); CLOSE_DISPS(play->state.gfxCtx); } diff --git a/src/overlays/actors/ovl_En_Cne_01/z_en_cne_01.c b/src/overlays/actors/ovl_En_Cne_01/z_en_cne_01.c index c551692185..d2d2323c51 100644 --- a/src/overlays/actors/ovl_En_Cne_01/z_en_cne_01.c +++ b/src/overlays/actors/ovl_En_Cne_01/z_en_cne_01.c @@ -255,9 +255,9 @@ s32 EnCne01_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* OPEN_DISPS(play->state.gfxCtx); gSPSegment(POLY_OPA_DISP++, 0x06, play->objectCtx.slots[this->enHy.headObjectSlot].segment); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->enHy.headObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->enHy.headObjectSlot].segment); *dList = gCneHeadBrownHairDL; - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->enHy.skelLowerObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->enHy.skelLowerObjectSlot].segment); CLOSE_DISPS(play->state.gfxCtx); } @@ -295,7 +295,7 @@ void EnCne01_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* ro OPEN_DISPS(play->state.gfxCtx); gSPSegment(POLY_OPA_DISP++, 0x06, play->objectCtx.slots[this->enHy.skelUpperObjectSlot].segment); - gSegments[0x06] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->enHy.skelUpperObjectSlot].segment); + gSegments[0x06] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->enHy.skelUpperObjectSlot].segment); CLOSE_DISPS(play->state.gfxCtx); } diff --git a/src/overlays/actors/ovl_En_Dnk/z_en_dnk.c b/src/overlays/actors/ovl_En_Dnk/z_en_dnk.c index 0dab8ff456..3f8318a375 100644 --- a/src/overlays/actors/ovl_En_Dnk/z_en_dnk.c +++ b/src/overlays/actors/ovl_En_Dnk/z_en_dnk.c @@ -210,7 +210,7 @@ s32 func_80A515C4(EnDnk* this) { void func_80A51648(EnDnk* this, PlayState* play) { if (SubS_IsObjectLoaded(this->objectSlot, play) == true) { - gSegments[0x06] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); + gSegments[0x06] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); this->actor.draw = func_80A52018; this->actor.objectSlot = this->objectSlot; ActorShape_Init(&this->actor.shape, 0.0f, NULL, 18.0f); diff --git a/src/overlays/actors/ovl_En_Fish2/z_en_fish2.c b/src/overlays/actors/ovl_En_Fish2/z_en_fish2.c index 645ad7300b..f8c10408ca 100644 --- a/src/overlays/actors/ovl_En_Fish2/z_en_fish2.c +++ b/src/overlays/actors/ovl_En_Fish2/z_en_fish2.c @@ -1120,7 +1120,7 @@ void func_80B2ADB0(EnFish2* this, Vec3f* vec, s16 arg2) { phi_v0 = gEffBubble1Tex; } - ptr->unk_20 = VIRTUAL_TO_PHYSICAL(SEGMENTED_TO_VIRTUAL(phi_v0)); + ptr->unk_20 = OS_K0_TO_PHYSICAL(SEGMENTED_TO_K0(phi_v0)); ptr->unk_00 = true; ptr->unk_04 = *vec; ptr->unk_04.x += Rand_CenteredFloat(ptr->unk_00 + (this->unk_330 * 4000.0f)); diff --git a/src/overlays/actors/ovl_En_Ge2/z_en_ge2.c b/src/overlays/actors/ovl_En_Ge2/z_en_ge2.c index f2f341a17f..eb9f21f554 100644 --- a/src/overlays/actors/ovl_En_Ge2/z_en_ge2.c +++ b/src/overlays/actors/ovl_En_Ge2/z_en_ge2.c @@ -772,7 +772,7 @@ void EnGe2_Draw(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); Gfx_SetupDL37_Opa(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(sEyeTextures[this->eyeIndex])); + gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_K0(sEyeTextures[this->eyeIndex])); func_800B8050(&this->picto.actor, play, 0); SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, EnGe2_OverrideLimbDraw, EnGe2_PostLimbDraw, &this->picto.actor); diff --git a/src/overlays/actors/ovl_En_Geg/z_en_geg.c b/src/overlays/actors/ovl_En_Geg/z_en_geg.c index 10c8b5037b..ea78222e44 100644 --- a/src/overlays/actors/ovl_En_Geg/z_en_geg.c +++ b/src/overlays/actors/ovl_En_Geg/z_en_geg.c @@ -416,12 +416,12 @@ s32 func_80BB1D64(EnGeg* this, PlayState* play) { } void EnGeg_UpdateSkelAnime(EnGeg* this, PlayState* play) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); SkelAnime_Update(&this->skelAnime); } void EnGeg_ChangeAnim(EnGeg* this, PlayState* play) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); SubS_ChangeAnimationByInfoS(&this->skelAnime, sAnimationInfo, this->animIndex); } diff --git a/src/overlays/actors/ovl_En_Go/z_en_go.c b/src/overlays/actors/ovl_En_Go/z_en_go.c index 6917033072..d1a9e123de 100644 --- a/src/overlays/actors/ovl_En_Go/z_en_go.c +++ b/src/overlays/actors/ovl_En_Go/z_en_go.c @@ -991,10 +991,10 @@ s32 EnGo_UpdateSkelAnime(EnGo* this, PlayState* play) { } if (extraObjIndex >= 0) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[extraObjIndex].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[extraObjIndex].segment); this->skelAnime.playSpeed = this->animPlaySpeed; isAnimFinished = SkelAnime_Update(&this->skelAnime); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); } return isAnimFinished; @@ -1051,11 +1051,11 @@ s32 EnGo_ChangeAnim(EnGo* this, PlayState* play, EnGoAnimation animIndex) { } if (extraObjIndex >= 0) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[extraObjIndex].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[extraObjIndex].segment); this->animIndex = animIndex; didAnimChange = SubS_ChangeAnimationByInfoS(&this->skelAnime, sAnimationInfo, animIndex); this->animPlaySpeed = this->skelAnime.playSpeed; - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); } return didAnimChange; diff --git a/src/overlays/actors/ovl_En_Guruguru/z_en_guruguru.c b/src/overlays/actors/ovl_En_Guruguru/z_en_guruguru.c index abe1fbc47f..7c5a3319e8 100644 --- a/src/overlays/actors/ovl_En_Guruguru/z_en_guruguru.c +++ b/src/overlays/actors/ovl_En_Guruguru/z_en_guruguru.c @@ -405,8 +405,8 @@ void EnGuruguru_Draw(Actor* thisx, PlayState* play) { Gfx_SetupDL25_Opa(play->state.gfxCtx); Gfx_SetupDL25_Xlu(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(sEyeTextures[this->texIndex])); - gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_VIRTUAL(sMouthTextures[this->texIndex])); + gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_K0(sEyeTextures[this->texIndex])); + gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_K0(sMouthTextures[this->texIndex])); SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, EnGuruguru_OverrideLimbDraw, NULL, &this->actor); diff --git a/src/overlays/actors/ovl_En_Kaizoku/z_en_kaizoku.c b/src/overlays/actors/ovl_En_Kaizoku/z_en_kaizoku.c index 46b37d2eee..b7310c1d3a 100644 --- a/src/overlays/actors/ovl_En_Kaizoku/z_en_kaizoku.c +++ b/src/overlays/actors/ovl_En_Kaizoku/z_en_kaizoku.c @@ -2142,7 +2142,7 @@ void EnKaizoku_Draw(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(sEyeTextures[this->eyeIndex])); + gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_K0(sEyeTextures[this->eyeIndex])); SkelAnime_DrawTransformFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, EnKaizoku_OverrideLimbDraw, EnKaizoku_PostLimbDraw, EnKaizoku_TransformLimbDraw, &this->picto.actor); diff --git a/src/overlays/actors/ovl_En_Ma4/z_en_ma4.c b/src/overlays/actors/ovl_En_Ma4/z_en_ma4.c index 516112d3df..6696215700 100644 --- a/src/overlays/actors/ovl_En_Ma4/z_en_ma4.c +++ b/src/overlays/actors/ovl_En_Ma4/z_en_ma4.c @@ -1083,8 +1083,8 @@ void EnMa4_Draw(Actor* thisx, PlayState* play) { Gfx_SetupDL25_Opa(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(sEyeTextures[this->eyeTexIndex])); - gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_VIRTUAL(sMouthTextures[this->mouthTexIndex])); + gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_K0(sEyeTextures[this->eyeTexIndex])); + gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_K0(sMouthTextures[this->mouthTexIndex])); SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, EnMa4_OverrideLimbDraw, EnMa4_PostLimbDraw, &this->actor); diff --git a/src/overlays/actors/ovl_En_Ma_Yts/z_en_ma_yts.c b/src/overlays/actors/ovl_En_Ma_Yts/z_en_ma_yts.c index 651f8115fb..41a764f1c7 100644 --- a/src/overlays/actors/ovl_En_Ma_Yts/z_en_ma_yts.c +++ b/src/overlays/actors/ovl_En_Ma_Yts/z_en_ma_yts.c @@ -551,8 +551,8 @@ void EnMaYts_Draw(Actor* thisx, PlayState* play) { Gfx_SetupDL25_Opa(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_VIRTUAL(sMouthTextures[this->mouthTexIndex])); - gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(sEyeTextures[this->eyeTexIndex])); + gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_K0(sMouthTextures[this->mouthTexIndex])); + gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_K0(sEyeTextures[this->eyeTexIndex])); SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, EnMaYts_OverrideLimbDraw, EnMaYts_PostLimbDraw, &this->actor); diff --git a/src/overlays/actors/ovl_En_Nwc/z_en_nwc.c b/src/overlays/actors/ovl_En_Nwc/z_en_nwc.c index 83a8be394b..d151f6aff6 100644 --- a/src/overlays/actors/ovl_En_Nwc/z_en_nwc.c +++ b/src/overlays/actors/ovl_En_Nwc/z_en_nwc.c @@ -248,14 +248,14 @@ void EnNwc_CheckFound(EnNwc* this, PlayState* play) { void EnNwc_LoadNiwSkeleton(EnNwc* this, PlayState* play) { if (Object_IsLoaded(&play->objectCtx, this->niwObjectSlot)) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->niwObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->niwObjectSlot].segment); SkelAnime_InitFlex(play, &this->niwSkeleton, &gNiwSkel, &gNiwIdleAnim, this->jointTable, this->morphTable, NIW_LIMB_MAX); Animation_Change(&this->niwSkeleton, &gNiwIdleAnim, 1.0f, 0.0f, Animation_GetLastFrame(&gNiwIdleAnim), ANIMMODE_LOOP, 0.0f); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->nwcObjectIndex].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->nwcObjectIndex].segment); this->state = NWC_STATE_NIW_LOADED; EnNwc_ToggleState(this); } diff --git a/src/overlays/actors/ovl_En_Pamera/z_en_pamera.c b/src/overlays/actors/ovl_En_Pamera/z_en_pamera.c index be1c956857..76dec27075 100644 --- a/src/overlays/actors/ovl_En_Pamera/z_en_pamera.c +++ b/src/overlays/actors/ovl_En_Pamera/z_en_pamera.c @@ -556,9 +556,9 @@ void EnPamera_Draw(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); Gfx_SetupDL25_Opa(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(D_80BDA604[this->unk_312])); - gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_VIRTUAL(D_80BDA610[this->unk_314])); - gSPSegment(POLY_OPA_DISP++, 0x0A, SEGMENTED_TO_VIRTUAL(D_80BDA5FC[this->unk_310])); + gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_K0(D_80BDA604[this->unk_312])); + gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_K0(D_80BDA610[this->unk_314])); + gSPSegment(POLY_OPA_DISP++, 0x0A, SEGMENTED_TO_K0(D_80BDA5FC[this->unk_310])); SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, EnPamera_OverrideLimbDraw, EnPamera_PostLimbDraw, &this->actor); diff --git a/src/overlays/actors/ovl_En_S_Goro/z_en_s_goro.c b/src/overlays/actors/ovl_En_S_Goro/z_en_s_goro.c index 0eb895e8c2..9c2aad8af6 100644 --- a/src/overlays/actors/ovl_En_S_Goro/z_en_s_goro.c +++ b/src/overlays/actors/ovl_En_S_Goro/z_en_s_goro.c @@ -788,7 +788,7 @@ s32 EnSGoro_UpdateCheerAnimation(EnSGoro* this, PlayState* play) { if (((EnJg*)this->otherGoron)->flags & 1) { this->objectSlot = Object_GetSlot(&play->objectCtx, OBJECT_TAISOU); if (this->objectSlot > OBJECT_SLOT_NONE) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); this->animInfoIndex = EN_S_GORO_ANIM_TAISOU_CHEER; SubS_ChangeAnimationByInfoS(&this->skelAnime, sAnimationInfo, this->animInfoIndex); return true; @@ -797,7 +797,7 @@ s32 EnSGoro_UpdateCheerAnimation(EnSGoro* this, PlayState* play) { } else if ((this->animInfoIndex == EN_S_GORO_ANIM_TAISOU_CHEER) && !(((EnJg*)this->otherGoron)->flags & 1)) { this->objectSlot = Object_GetSlot(&play->objectCtx, OBJECT_OF1D_MAP); if (this->objectSlot > OBJECT_SLOT_NONE) { - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); this->animInfoIndex = EN_S_GORO_ANIM_IDLE_STAND; SubS_ChangeAnimationByInfoS(&this->skelAnime, sAnimationInfo, this->animInfoIndex); this->skelAnime.curFrame = this->skelAnime.endFrame; @@ -1329,7 +1329,7 @@ void EnSGoro_Update(Actor* thisx, PlayState* play) { this->actionFunc(this, play); Actor_UpdateBgCheckInfo(play, &this->actor, 30.0f, 12.0f, 0.0f, UPDBGCHECKINFO_FLAG_1 | UPDBGCHECKINFO_FLAG_4); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); SkelAnime_Update(&this->skelAnime); if (this->animInfoIndex != EN_S_GORO_ANIM_SLEEPY) { EnSGoro_UpdateAttentionTarget(this, play); diff --git a/src/overlays/actors/ovl_En_Sob1/z_en_sob1.c b/src/overlays/actors/ovl_En_Sob1/z_en_sob1.c index a18d567539..5c7f95a95e 100644 --- a/src/overlays/actors/ovl_En_Sob1/z_en_sob1.c +++ b/src/overlays/actors/ovl_En_Sob1/z_en_sob1.c @@ -1345,7 +1345,7 @@ void EnSob1_Blink(EnSob1* this) { } void EnSob1_ChangeObject(EnSob1* this, PlayState* play) { - gSegments[0x06] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->shopkeeperAnimObjectSlot].segment); + gSegments[0x06] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->shopkeeperAnimObjectSlot].segment); } s32 EnSob1_AreObjectsLoaded(EnSob1* this, PlayState* play) { @@ -1364,7 +1364,7 @@ s32 EnSob1_AreObjectsLoaded(EnSob1* this, PlayState* play) { void EnSob1_ZoraShopkeeper_Init(EnSob1* this, PlayState* play) { SkelAnime_InitFlex(play, &this->skelAnime, &gZoraSkel, NULL, this->jointTable, this->morphTable, ZORA_LIMB_MAX); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->shopkeeperAnimObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->shopkeeperAnimObjectSlot].segment); Animation_Change(&this->skelAnime, &gZoraShopkeeperAnim, 1.0f, 0.0f, Animation_GetLastFrame(&gZoraShopkeeperAnim), ANIMMODE_LOOP, 0.0f); this->actor.draw = EnSob1_ZoraShopkeeper_Draw; @@ -1373,7 +1373,7 @@ void EnSob1_ZoraShopkeeper_Init(EnSob1* this, PlayState* play) { void EnSob1_GoronShopkeeper_Init(EnSob1* this, PlayState* play) { SkelAnime_InitFlex(play, &this->skelAnime, &gGoronSkel, NULL, this->jointTable, this->morphTable, GORON_LIMB_MAX); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->shopkeeperAnimObjectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->shopkeeperAnimObjectSlot].segment); Animation_Change(&this->skelAnime, &gGoronShopkeeperAnim, 1.0f, 0.0f, Animation_GetLastFrame(&gGoronShopkeeperAnim), ANIMMODE_LOOP, 0.0f); this->actor.draw = EnSob1_GoronShopkeeper_Draw; diff --git a/src/overlays/actors/ovl_En_Ssh/z_en_ssh.c b/src/overlays/actors/ovl_En_Ssh/z_en_ssh.c index c7006f0870..a4cec2e802 100644 --- a/src/overlays/actors/ovl_En_Ssh/z_en_ssh.c +++ b/src/overlays/actors/ovl_En_Ssh/z_en_ssh.c @@ -931,7 +931,7 @@ void EnSsh_Draw(Actor* thisx, PlayState* play) { Gfx_SetupDL25_Opa(play->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(D_80976178[this->blinkState])); + gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_K0(D_80976178[this->blinkState])); SkelAnime_DrawOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, EnSsh_OverrideLimbDraw, EnSsh_PostLimbDraw, &this->actor); diff --git a/src/overlays/actors/ovl_En_St/z_en_st.c b/src/overlays/actors/ovl_En_St/z_en_st.c index ba18280673..10f7c457c5 100644 --- a/src/overlays/actors/ovl_En_St/z_en_st.c +++ b/src/overlays/actors/ovl_En_St/z_en_st.c @@ -245,7 +245,7 @@ void func_808A54B0(EnSt* this, PlayState* play) { if ((this->unk_18C & 1) && (this->actor.colChkInfo.health != 0)) { OPEN_DISPS(play->state.gfxCtx); - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[this->objectSlot].segment); gSPSegment(POLY_XLU_DISP++, 0x06, play->objectCtx.slots[this->objectSlot].segment); diff --git a/src/overlays/effects/ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c b/src/overlays/effects/ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c index 41c9f0692b..38ef2b7098 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c +++ b/src/overlays/effects/ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c @@ -34,7 +34,7 @@ u32 EffectSsBubble_Init(PlayState* play, u32 index, EffectSs* this, void* initPa { TexturePtr tex = (Rand_ZeroOne() < 0.5f) ? gEffBubble1Tex : gEffBubble2Tex; - this->gfx = VIRTUAL_TO_PHYSICAL(SEGMENTED_TO_VIRTUAL(tex)); + this->gfx = OS_K0_TO_PHYSICAL(SEGMENTED_TO_K0(tex)); } this->pos.x = ((Rand_ZeroOne() - 0.5f) * initParams->xzPosRandScale) + initParams->pos.x; diff --git a/src/overlays/effects/ovl_Effect_Ss_D_Fire/z_eff_ss_d_fire.c b/src/overlays/effects/ovl_Effect_Ss_D_Fire/z_eff_ss_d_fire.c index 0cc62b42d5..c43c01afee 100644 --- a/src/overlays/effects/ovl_Effect_Ss_D_Fire/z_eff_ss_d_fire.c +++ b/src/overlays/effects/ovl_Effect_Ss_D_Fire/z_eff_ss_d_fire.c @@ -73,7 +73,7 @@ void EffectSsDFire_Draw(PlayState* play, u32 index, EffectSs* this) { OPEN_DISPS(gfxCtx); - gSegments[6] = VIRTUAL_TO_PHYSICAL(objectPtr); + gSegments[6] = OS_K0_TO_PHYSICAL(objectPtr); gSPSegment(POLY_XLU_DISP++, 0x06, objectPtr); scale = this->rScale / 100.0f; diff --git a/src/overlays/effects/ovl_Effect_Ss_Dt_Bubble/z_eff_ss_dt_bubble.c b/src/overlays/effects/ovl_Effect_Ss_Dt_Bubble/z_eff_ss_dt_bubble.c index 8a4c809801..094f8bbf9c 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Dt_Bubble/z_eff_ss_dt_bubble.c +++ b/src/overlays/effects/ovl_Effect_Ss_Dt_Bubble/z_eff_ss_dt_bubble.c @@ -50,7 +50,7 @@ u32 EffectSsDtBubble_Init(PlayState* play, u32 index, EffectSs* this, void* init { TexturePtr tex = (Rand_ZeroOne() < 0.5f) ? gEffBubble1Tex : gEffBubble2Tex; - this->gfx = VIRTUAL_TO_PHYSICAL(SEGMENTED_TO_VIRTUAL(tex)); + this->gfx = OS_K0_TO_PHYSICAL(SEGMENTED_TO_K0(tex)); } Math_Vec3f_Copy(&this->pos, &initParams->pos); diff --git a/src/overlays/effects/ovl_Effect_Ss_Extra/z_eff_ss_extra.c b/src/overlays/effects/ovl_Effect_Ss_Extra/z_eff_ss_extra.c index f8b20175bc..9c6a4c3416 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Extra/z_eff_ss_extra.c +++ b/src/overlays/effects/ovl_Effect_Ss_Extra/z_eff_ss_extra.c @@ -37,7 +37,7 @@ u32 EffectSsExtra_Init(PlayState* play, u32 index, EffectSs* this, void* initPar if ((objectSlot > OBJECT_SLOT_NONE) && (Object_IsLoaded(&play->objectCtx, objectSlot))) { void* segBackup = gSegments[6]; - gSegments[6] = VIRTUAL_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); + gSegments[6] = OS_K0_TO_PHYSICAL(play->objectCtx.slots[objectSlot].segment); this->pos = params->pos; this->velocity = params->velocity; @@ -66,7 +66,7 @@ void EffectSsExtra_Draw(PlayState* play, u32 index, EffectSs* this) { OPEN_DISPS(play->state.gfxCtx); - gSegments[6] = VIRTUAL_TO_PHYSICAL(objectPtr); + gSegments[6] = OS_K0_TO_PHYSICAL(objectPtr); gSPSegment(POLY_XLU_DISP++, 0x06, objectPtr); diff --git a/src/overlays/effects/ovl_Effect_Ss_Sibuki/z_eff_ss_sibuki.c b/src/overlays/effects/ovl_Effect_Ss_Sibuki/z_eff_ss_sibuki.c index 312ed5f2f0..93d221e094 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Sibuki/z_eff_ss_sibuki.c +++ b/src/overlays/effects/ovl_Effect_Ss_Sibuki/z_eff_ss_sibuki.c @@ -40,7 +40,7 @@ u32 EffectSsSibuki_Init(PlayState* play, u32 index, EffectSs* this, void* initPa { TexturePtr tex = (KREG(2) != 0) ? gEffBubble2Tex : gEffBubble1Tex; - this->gfx = VIRTUAL_TO_PHYSICAL(SEGMENTED_TO_VIRTUAL(tex)); + this->gfx = OS_K0_TO_PHYSICAL(SEGMENTED_TO_K0(tex)); } this->life = ((s32)((Rand_ZeroOne() * (500.0f + KREG(64))) * 0.01f)) + KREG(65) + 10; diff --git a/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope_NES.c b/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope_NES.c index 7b8f3d1b06..0782309caf 100644 --- a/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope_NES.c +++ b/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope_NES.c @@ -2860,7 +2860,7 @@ void KaleidoScope_Update(PlayState* play) { size0 = SEGMENT_ROM_SIZE(icon_item_static_syms); CmpDma_LoadAllFiles((uintptr_t)SEGMENT_ROM_START(icon_item_static_yar), pauseCtx->iconItemSegment, size0); - gSegments[0x08] = VIRTUAL_TO_PHYSICAL(pauseCtx->iconItemSegment); + gSegments[0x08] = OS_K0_TO_PHYSICAL(pauseCtx->iconItemSegment); for (itemId = 0; itemId <= ITEM_BOW_FIRE; itemId++) { if (!gPlayerFormItemRestrictions[GET_PLAYER_FORM][(s32)itemId]) { diff --git a/tools/disasm/files.txt b/tools/disasm/files.txt index 3afbc0bbe8..23539f5f0d 100644 --- a/tools/disasm/files.txt +++ b/tools/disasm/files.txt @@ -70,7 +70,7 @@ 0x80087B00 : "setcause", 0x80087B10 : "sendmesg", 0x80087C60 : "pfsfreeblocks", - 0x80087E00 : "viextend", + 0x80087E00 : "viextendvstart", 0x80087E10 : "stopthread", 0x80087ED0 : "recvmesg", 0x80088010 : "setintmask", @@ -192,7 +192,7 @@ 0x80092440 : "pfsisplug", 0x80092730 : "voicegetstatus", 0x80092920 : "cartrominit", - 0x80092A80 : "guS2DInitBg", + 0x80092A80 : "us2dex", 0x80092C00 : "pfsselectbank", 0x80092C80 : "contsetch", 0x80092CE0 : "setfpccsr", @@ -259,8 +259,8 @@ 0x80097500 : "system_heap", 0x80097520 : "fp", 0x80097530 : "rand", - 0x80097540 : "osViModeNtscHpf1", - 0x80097590 : "osViModePalLan1", + 0x80097540 : "vimodentschpf1", + 0x80097590 : "vimodepallan1", 0x800975E0 : "sins", 0x80097DE0 : "exceptasm", 0x80097E10 : "thread", @@ -270,6 +270,7 @@ 0x80097E70 : "pimgr", 0x80097EA0 : "piacs", 0x80097EB0 : "contpfs", + 0x80097EB0 : "vimodentschpn1", 0x80097F10 : "seteventmesg", 0x80097F20 : "xprintf", 0x80097F70 : "timerintr", @@ -277,11 +278,11 @@ 0x80097F90 : "rotate", 0x80097FA0 : "voiceinit", 0x80097FB0 : "contramread", - 0x80097FC0 : "osViModeNtscLan1", - 0x80097FC0 : "osViModeMpalLan1", + 0x80097FC0 : "vimodentsclan1", + 0x80097FC0 : "vimodempallan1", 0x80098060 : "vi", 0x800980D0 : "cartrominit", - 0x800980E0 : "guS2DInitBg", + 0x800980E0 : "vimodefpallan1", 0x80098130 : "xldtob", 0x80098160 : "vimgr", 0x80098180 : "voicecontrolgain", @@ -307,7 +308,7 @@ 0x800992F0 : "lookathil", 0x80099300 : "xprintf", 0x80099400 : "cosf", - 0x80099450 : "__libm_qnan_f", + 0x80099450 : "libm_vals", 0x80099460 : "xldtob", 0x800994C0 : "llcvt", 0x800994D0 : "build", @@ -336,6 +337,7 @@ 0x8009E410 : "contpfs", 0x8009E510 : "seteventmesg", 0x8009E590 : "timerintr", + 0x8009E5D0 : "pfsisplug", 0x8009E610 : "cartrominit", 0x8009E690 : "vimgr", }, diff --git a/tools/namefixer.py b/tools/namefixer.py index 49a67586f1..7abb9b2823 100755 --- a/tools/namefixer.py +++ b/tools/namefixer.py @@ -1324,6 +1324,9 @@ wordReplace = { "WEEKEVENTREG_52_20": "WEEKEVENTREG_CLEARED_STONE_TOWER_TEMPLE", "WEEKEVENTREG_55_80": "WEEKEVENTREG_CLEARED_GREAT_BAY_TEMPLE", + "VIRTUAL_TO_PHYSICAL": "OS_K0_TO_PHYSICAL", + "SEGMENTED_TO_VIRTUAL": "SEGMENTED_TO_K0", + # Enums "TRANS_TYPE_00": "TRANS_TYPE_WIPE", "TRANS_TYPE_01": "TRANS_TYPE_TRIFORCE", diff --git a/tools/sizes/boot_functions.csv b/tools/sizes/boot_functions.csv index 47bc17b62a..651eb9f088 100644 --- a/tools/sizes/boot_functions.csv +++ b/tools/sizes/boot_functions.csv @@ -241,7 +241,7 @@ asm/non_matchings/boot/printutils/Sleep_Sec.s,Sleep_Sec,0x80087AC0,0x10 asm/non_matchings/boot/setcause/__osSetCause.s,__osSetCause,0x80087B00,0x4 asm/non_matchings/boot/sendmesg/osSendMesg.s,osSendMesg,0x80087B10,0x54 asm/non_matchings/boot/pfsfreeblocks/osPfsFreeBlocks.s,osPfsFreeBlocks,0x80087C60,0x68 -asm/non_matchings/boot/viextend/osViExtendVStart.s,osViExtendVStart,0x80087E00,0x4 +asm/non_matchings/boot/viextendvstart/osViExtendVStart.s,osViExtendVStart,0x80087E00,0x4 asm/non_matchings/boot/stopthread/osStopThread.s,osStopThread,0x80087E10,0x30 asm/non_matchings/boot/recvmesg/osRecvMesg.s,osRecvMesg,0x80087ED0,0x50 asm/non_matchings/boot/setintmask/osSetIntMask.s,osSetIntMask,0x80088010,0x28 @@ -419,7 +419,7 @@ asm/non_matchings/boot/pfsisplug/__osPfsRequestData.s,__osPfsRequestData,0x80092 asm/non_matchings/boot/pfsisplug/__osPfsGetInitData.s,__osPfsGetInitData,0x80092680,0x2C asm/non_matchings/boot/voicegetstatus/__osVoiceGetStatus.s,__osVoiceGetStatus,0x80092730,0x7C asm/non_matchings/boot/cartrominit/osCartRomInit.s,osCartRomInit,0x80092920,0x58 -asm/non_matchings/boot/guS2DInitBg/guS2DInitBg.s,guS2DInitBg,0x80092A80,0x60 +asm/non_matchings/boot/us2dex/guS2DInitBg.s,guS2DInitBg,0x80092A80,0x60 asm/non_matchings/boot/pfsselectbank/__osPfsSelectBank.s,__osPfsSelectBank,0x80092C00,0x20 asm/non_matchings/boot/contsetch/osContSetCh.s,osContSetCh,0x80092C80,0x18 asm/non_matchings/boot/setfpccsr/__osSetFpcCsr.s,__osSetFpcCsr,0x80092CE0,0x4