diff --git a/include/ultra64/convert.h b/include/ultra64/convert.h index 02024d17fa..13679fc5b0 100644 --- a/include/ultra64/convert.h +++ b/include/ultra64/convert.h @@ -15,7 +15,4 @@ #define OS_PHYSICAL_TO_K0(x) (void*)(((u32)(x)+0x80000000)) #define OS_PHYSICAL_TO_K1(x) (void*)(((u32)(x)+0xA0000000)) -#define OS_MSEC_TO_CYCLES(n) OS_USEC_TO_CYCLES((n) * 1000) -#define OS_SEC_TO_CYCLES(n) OS_MSEC_TO_CYCLES((n) * 1000) - #endif diff --git a/include/ultra64/rcp.h b/include/ultra64/rcp.h index 86387ef5e8..9c97e8bd9f 100644 --- a/include/ultra64/rcp.h +++ b/include/ultra64/rcp.h @@ -529,7 +529,7 @@ #define VI_CTRL_ANTIALIAS_MODE_2 0x00200 // Bit [9:8] anti-alias mode: AA disabled, resampling enabled, operate as if everything is covered #define VI_CTRL_ANTIALIAS_MODE_3 0x00300 // Bit [9:8] anti-alias mode: AA disabled, resampling disabled, replicate pixels #define VI_CTRL_PIXEL_ADV_MASK 0x0F000 // [15:12] pixel advance mode -#define VI_CTRL_PIXEL_ADV(n) (((n) << 12) & VI_CTRL_PIXEL_ADV_MASK) // Bit [15:12] pixel advance mode: Always 3 on N64 +#define VI_CTRL_PIXEL_ADV_3 0x03000 // Bit [15:12] pixel advance mode: Always 3 on N64 #define VI_CTRL_DITHER_FILTER_ON 0x10000 // 16: dither-filter mode /* diff --git a/include/variables.h b/include/variables.h index fa09f0f54f..f7fc97a230 100644 --- a/include/variables.h +++ b/include/variables.h @@ -7,10 +7,10 @@ extern Mtx D_01000000; -extern u32 osTvType; -extern u32 osRomBase; -extern u32 osResetType; -extern u32 osCicId; +extern void* osRomBase; +extern s32 osTvType; +extern s32 osResetType; +extern s32 osCicId; extern u32 osMemSize; extern u8 osAppNMIBuffer[0x40]; diff --git a/include/z64math.h b/include/z64math.h index 7ed235e587..95a494a693 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -7,6 +7,11 @@ #define SQ(x) ((x)*(x)) #define VEC_SET(V,X,Y,Z) (V).x=(X);(V).y=(Y);(V).z=(Z) +typedef union FloatInt { + f32 f; + u32 i; +} FloatInt; + typedef struct Vec2f { f32 x, y; } Vec2f; // size = 0x08 diff --git a/src/code/fault_gc.c b/src/code/fault_gc.c index d3e16ac59c..66bb0b0fa9 100644 --- a/src/code/fault_gc.c +++ b/src/code/fault_gc.c @@ -144,7 +144,8 @@ void Fault_ClientRunTask(FaultClientTask* task) { // Await done while (true) { - osSetTimer(&timer, OS_SEC_TO_CYCLES(1), 0, &queue, (OSMesg)timerMsgVal); + // Wait for 1 second + osSetTimer(&timer, OS_USEC_TO_CYCLES(1000000), 0, &queue, (OSMesg)timerMsgVal); osRecvMesg(&queue, &recMsg, OS_MESG_BLOCK); if (recMsg != (OSMesg)666) { @@ -653,7 +654,7 @@ void Fault_Wait5Seconds(void) { do { Fault_Sleep(1000 / 60); - } while ((osGetTime() - start) < OS_SEC_TO_CYCLES(5) + 1); + } while ((osGetTime() - start) <= OS_USEC_TO_CYCLES(5000000)); // 5 seconds sFaultInstance->autoScroll = true; } diff --git a/src/code/game.c b/src/code/game.c index e00bc74066..6cf7a875d4 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -302,22 +302,22 @@ void GameState_Update(GameState* gameState) { gfxCtx->xScale = gViConfigXScale; gfxCtx->yScale = gViConfigYScale; - if (SREG(63) == 6 || (SREG(63) == 2u && osTvType == OS_TV_NTSC)) { + if (SREG(63) == 6 || (SREG(63) == 2u && (u32)osTvType == OS_TV_NTSC)) { gfxCtx->viMode = &osViModeNtscLan1; gfxCtx->yScale = 1.0f; } - if (SREG(63) == 5 || (SREG(63) == 2u && osTvType == OS_TV_MPAL)) { + if (SREG(63) == 5 || (SREG(63) == 2u && (u32)osTvType == OS_TV_MPAL)) { gfxCtx->viMode = &osViModeMpalLan1; gfxCtx->yScale = 1.0f; } - if (SREG(63) == 4 || (SREG(63) == 2u && osTvType == OS_TV_PAL)) { + if (SREG(63) == 4 || (SREG(63) == 2u && (u32)osTvType == OS_TV_PAL)) { gfxCtx->viMode = &osViModePalLan1; gfxCtx->yScale = 1.0f; } - if (SREG(63) == 3 || (SREG(63) == 2u && osTvType == OS_TV_PAL)) { + if (SREG(63) == 3 || (SREG(63) == 2u && (u32)osTvType == OS_TV_PAL)) { gfxCtx->viMode = &osViModeFpalLan1; gfxCtx->yScale = 0.833f; } diff --git a/src/code/graph.c b/src/code/graph.c index 1f9ba5e30d..2b4777ea63 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -179,6 +179,7 @@ void Graph_TaskSet00(GraphicsContext* gfxCtx) { { CfbInfo* cfb; + // Schedule a message to be handled in 3 seconds, for RCP timeout osSetTimer(&timer, OS_USEC_TO_CYCLES(3000000), 0, &gfxCtx->queue, (OSMesg)666); osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_BLOCK); diff --git a/src/code/irqmgr.c b/src/code/irqmgr.c index 7f630981b3..d623ddad88 100644 --- a/src/code/irqmgr.c +++ b/src/code/irqmgr.c @@ -164,7 +164,7 @@ void IrqMgr_HandlePreNMI(IrqMgr* irqMgr) { sIrqMgrResetTime = irqMgr->resetTime = osGetTime(); // Schedule a PRENMI450 message to be handled in 450ms - osSetTimer(&irqMgr->timer, OS_MSEC_TO_CYCLES(450), 0, &irqMgr->queue, (OSMesg)IRQ_PRENMI450_MSG); + osSetTimer(&irqMgr->timer, OS_USEC_TO_CYCLES(450000), 0, &irqMgr->queue, (OSMesg)IRQ_PRENMI450_MSG); IrqMgr_JamMesgToClients(irqMgr, (OSMesg)&irqMgr->prenmiMsg); } @@ -190,7 +190,7 @@ void IrqMgr_HandlePreNMI450(IrqMgr* irqMgr) { irqMgr->resetStatus = IRQ_RESET_STATUS_NMI; // Schedule a PRENMI480 message to be handled in 30ms - osSetTimer(&irqMgr->timer, OS_MSEC_TO_CYCLES(30), 0, &irqMgr->queue, (OSMesg)IRQ_PRENMI480_MSG); + osSetTimer(&irqMgr->timer, OS_USEC_TO_CYCLES(30000), 0, &irqMgr->queue, (OSMesg)IRQ_PRENMI480_MSG); // Send the NMI event to clients IrqMgr_SendMesgToClients(irqMgr, (OSMesg)&irqMgr->nmiMsg); } @@ -199,7 +199,7 @@ void IrqMgr_HandlePreNMI480(IrqMgr* irqMgr) { u32 result; // Schedule a PRENMI500 message to be handled in 20ms - osSetTimer(&irqMgr->timer, OS_MSEC_TO_CYCLES(20), 0, &irqMgr->queue, (OSMesg)IRQ_PRENMI500_MSG); + osSetTimer(&irqMgr->timer, OS_USEC_TO_CYCLES(20000), 0, &irqMgr->queue, (OSMesg)IRQ_PRENMI500_MSG); result = osAfterPreNMI(); if (result != 0) { @@ -207,7 +207,7 @@ void IrqMgr_HandlePreNMI480(IrqMgr* irqMgr) { // osAfterPreNMI failed, try again in 1ms //! @bug setting the same timer for a second time without letting the first one complete breaks //! the timer linked list - osSetTimer(&irqMgr->timer, OS_MSEC_TO_CYCLES(1), 0, &irqMgr->queue, (OSMesg)IRQ_PRENMI480_MSG); + osSetTimer(&irqMgr->timer, OS_USEC_TO_CYCLES(1000), 0, &irqMgr->queue, (OSMesg)IRQ_PRENMI480_MSG); } } diff --git a/src/code/rand.c b/src/code/rand.c index 378f0456e9..d6199b1890 100644 --- a/src/code/rand.c +++ b/src/code/rand.c @@ -42,6 +42,7 @@ * @note Original name: qrand.c */ #include "rand.h" +#include "z64math.h" #define RAND_MULTIPLIER 1664525 #define RAND_INCREMENT 1013904223 @@ -59,7 +60,7 @@ static u32 sRandInt = 1; * * @note Orignal name: __qrand_itemp */ -static fu sRandFloat; +static FloatInt sRandFloat; #endif /** diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 570da1ab01..38fb383124 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -5,7 +5,7 @@ #include "macros.h" #include "sys_math3d.h" -#pragma increment_block_number "gc-eu:106 gc-eu-mq:106 gc-jp:106 gc-jp-ce:106 gc-jp-mq:106 gc-us:106 gc-us-mq:106" +#pragma increment_block_number "gc-eu:103 gc-eu-mq:103 gc-jp:103 gc-jp-ce:103 gc-jp-mq:103 gc-us:103 gc-us-mq:103" s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA); diff --git a/src/code/z_camera.c b/src/code/z_camera.c index f368e964de..7cb7e712c6 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -4,7 +4,7 @@ #include "terminal.h" #include "overlays/actors/ovl_En_Horse/z_en_horse.h" -#pragma increment_block_number "gc-eu:0 gc-eu-mq:0 gc-jp:0 gc-jp-ce:0 gc-jp-mq:0 gc-us:0 gc-us-mq:0" +#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:0 gc-jp-ce:0 gc-jp-mq:0 gc-us:0 gc-us-mq:0" s16 Camera_RequestSettingImpl(Camera* camera, s16 requestedSetting, s16 flags); s32 Camera_RequestModeImpl(Camera* camera, s16 requestedMode, u8 forceModeChange); diff --git a/src/code/z_vimode.c b/src/code/z_vimode.c index d9478867fb..8abcb62e79 100644 --- a/src/code/z_vimode.c +++ b/src/code/z_vimode.c @@ -85,7 +85,7 @@ void ViMode_Configure(ViMode* viMode, s32 type, s32 tvType, s32 loRes, s32 antia yScaleHiOddField = modeF ? (loResInterlaced ? (F210(0.75) << 16) : (F210(0.5) << 16)) : 0; viMode->customViMode.type = type; - viMode->customViMode.comRegs.ctrl = VI_CTRL_PIXEL_ADV(3) | VI_CTRL_GAMMA_ON | VI_CTRL_GAMMA_DITHER_ON | + viMode->customViMode.comRegs.ctrl = VI_CTRL_PIXEL_ADV_3 | VI_CTRL_GAMMA_ON | VI_CTRL_GAMMA_DITHER_ON | (!loResDeinterlaced ? VI_CTRL_SERRATE_ON : 0) | (antialiasOn ? VI_CTRL_DIVOT_ON : 0) | (fb32Bit ? VI_CTRL_TYPE_32 : VI_CTRL_TYPE_16); diff --git a/src/libultra/io/vimodefpallan1.c b/src/libultra/io/vimodefpallan1.c index 5fb019cdfb..37cb5ff557 100644 --- a/src/libultra/io/vimodefpallan1.c +++ b/src/libultra/io/vimodefpallan1.c @@ -16,15 +16,15 @@ OSViMode osViModeFpalLan1 = { { // 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 + 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/io/vimodempallan1.c b/src/libultra/io/vimodempallan1.c index 23d53987b0..bcc4273afb 100644 --- a/src/libultra/io/vimodempallan1.c +++ b/src/libultra/io/vimodempallan1.c @@ -16,15 +16,15 @@ OSViMode osViModeMpalLan1 = { { // 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(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_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/vimodentsclan1.c b/src/libultra/io/vimodentsclan1.c index 19a7160ac8..a29d15129f 100644 --- a/src/libultra/io/vimodentsclan1.c +++ b/src/libultra/io/vimodentsclan1.c @@ -16,15 +16,15 @@ OSViMode osViModeNtscLan1 = { { // 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(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_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/vimodepallan1.c b/src/libultra/io/vimodepallan1.c index 7a8db603f4..d656dc4f94 100644 --- a/src/libultra/io/vimodepallan1.c +++ b/src/libultra/io/vimodepallan1.c @@ -16,15 +16,15 @@ OSViMode osViModePalLan1 = { { // 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 + 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/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c index 17cb04f174..1ac2d871e1 100644 --- a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c +++ b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c @@ -100,13 +100,13 @@ static ColliderCylinderInit sLightBallCylinderInit = { static u8 D_808E4C58[] = { 0, 12, 10, 12, 14, 16, 12, 14, 16, 12, 14, 16, 12, 14, 16, 10, 16, 14 }; static Vec3f sZeroVec = { 0.0f, 0.0f, 0.0f }; -#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" +#pragma increment_block_number "gc-eu:0 gc-eu-mq:0 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" static EnGanonMant* sCape; // TODO: There's probably a way to match BSS ordering with less padding by spreading the variables out and moving // data around. It would be easier if we had more options for controlling BSS ordering in debug. -#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" +#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" static s32 sSeed1; static s32 sSeed2; diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index 802ed831ab..34237596e5 100644 --- a/src/overlays/actors/ovl_Fishing/z_fishing.c +++ b/src/overlays/actors/ovl_Fishing/z_fishing.c @@ -14,7 +14,7 @@ #include "cic6105.h" #endif -#pragma increment_block_number "gc-eu:157 gc-eu-mq:157 gc-jp:159 gc-jp-ce:159 gc-jp-mq:159 gc-us:159 gc-us-mq:159" +#pragma increment_block_number "gc-eu:154 gc-eu-mq:154 gc-jp:156 gc-jp-ce:156 gc-jp-mq:156 gc-us:156 gc-us-mq:156" #define FLAGS ACTOR_FLAG_4 diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index bd30f5bff7..2bd876a32d 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -354,19 +354,19 @@ void Player_Action_CsAction(Player* this, PlayState* play); // .bss part 1 -#pragma increment_block_number "gc-eu:0 gc-eu-mq:0 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" +#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" static s32 D_80858AA0; // TODO: There's probably a way to match BSS ordering with less padding by spreading the variables out and moving // data around. It would be easier if we had more options for controlling BSS ordering in debug. -#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:192 gc-jp-ce:192 gc-jp-mq:192 gc-us:192 gc-us-mq:192" +#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:192 gc-jp-ce:192 gc-jp-mq:192 gc-us:192 gc-us-mq:192" static s32 D_80858AA4; static Vec3f sInteractWallCheckResult; static Input* sControlInput; -#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:224 gc-jp-ce:224 gc-jp-mq:224 gc-us:224 gc-us-mq:224" +#pragma increment_block_number "gc-eu:224 gc-eu-mq:224 gc-jp:224 gc-jp-ce:224 gc-jp-mq:224 gc-us:224 gc-us-mq:224" // .data