summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRandom <28494085+Random06457@users.noreply.github.com>2020-05-13 05:05:55 +0200
committerGitHub <noreply@github.com>2020-05-12 23:05:55 -0400
commit08d9fee6e4ccff113287758d71b07a0afde5592e (patch)
tree67fcf7541a45a026a0d76a48e6ab39a54efa0381 /src
parent74a654ecae4359177cee27d1fb83373aae8b1524 (diff)
Decompile speed_meter.c and add VIEWPORT_INIT macro (#127)
* Decompile speed_meter.c and add VIEWPORT_INIT macro - speed_meter.c: OK - Add VIEWPORT_INIT(viewport, by, rx, ty, lx) macro * get rid of some magic numbers * use early return instead of a big if block in SpeedMeter_DrawTimeEntries
Diffstat (limited to 'src')
-rw-r--r--src/code/irqmgr.c6
-rw-r--r--src/code/speed_meter.c230
-rw-r--r--src/code/z_play.c5
-rw-r--r--src/code/z_sample.c5
4 files changed, 197 insertions, 49 deletions
diff --git a/src/code/irqmgr.c b/src/code/irqmgr.c
index d0124a203..ba47ef40e 100644
--- a/src/code/irqmgr.c
+++ b/src/code/irqmgr.c
@@ -3,7 +3,7 @@
volatile u32 gIrqMgrResetStatus = 0;
volatile OSTime sIrqMgrResetTime = 0;
-volatile OSTime sIrqMgrRetraceTime = 0;
+volatile OSTime gIrqMgrRetraceTime = 0;
u32 sIrqMgrRetraceCount = 0;
#define RETRACE_MSG 666
@@ -154,11 +154,11 @@ void IrqMgr_HandlePRENMI500(IrqMgr* this) {
}
void IrqMgr_HandleRetrace(IrqMgr* this) {
- if (sIrqMgrRetraceTime == 0ull) {
+ if (gIrqMgrRetraceTime == 0ull) {
if (this->retraceTime == 0) {
this->retraceTime = osGetTime();
} else {
- sIrqMgrRetraceTime = osGetTime() - this->retraceTime;
+ gIrqMgrRetraceTime = osGetTime() - this->retraceTime;
}
}
sIrqMgrRetraceCount++;
diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c
index ec5e93b07..35790bbf1 100644
--- a/src/code/speed_meter.c
+++ b/src/code/speed_meter.c
@@ -1,52 +1,206 @@
#include <ultra64.h>
#include <global.h>
+#include <vt.h>
-typedef struct {
- /* 0x00 */ char unk_00[0x18];
- /* 0x18 */ s32 unk_18;
- /* 0x1C */ s32 unk_1C;
-} struct_801664D0; // size = 0x20
+SpeedMeterTimeEntry sSpeedMeterTimeEntryArray[] = {
+ { &D_8016A520, 0, 0, GPACK_RGBA5551(0xFF, 0x00, 0x00, 1) },
+ { &D_8016A528, 0, 2, GPACK_RGBA5551(0xFF, 0xFF, 0x00, 1) },
+ { &D_8016A530, 0, 4, GPACK_RGBA5551(0x00, 0x00, 0xFF, 1) },
+ { &D_8016A538, 0, 6, GPACK_RGBA5551(0xFF, 0x80, 0x80, 1) },
+ { &D_8016A540, 0, 8, GPACK_RGBA5551(0x00, 0xFF, 0x00, 1) },
+ { &D_8016A548, 0, 10, GPACK_RGBA5551(0xFF, 0x00, 0xFF, 1) },
+};
-extern struct_801664D0 D_801664D0;
+#define DrawRec(gfx, color, ulx, uly, lrx, lry) \
+ gDPPipeSync(gfx); \
+ gDPSetFillColor(gfx, ((color) << 16) | (color)); \
+ gDPFillRectangle(gfx, (ulx), (uly), (lrx), (lry)); \
+ gDPPipeSync(gfx);
-void func_800C9940(struct_801664D0* arg0, u32 arg1, u32 arg2) {
- LogUtils_CheckNullPointer("this", arg0, "../speed_meter.c", 181);
- arg0->unk_18 = arg1;
- arg0->unk_1C = arg2;
+void SpeedMeter_InitImpl(SpeedMeter* this, u32 arg1, u32 y) {
+ LogUtils_CheckNullPointer("this", this, "../speed_meter.c", 181);
+ this->unk_18 = arg1;
+ this->y = y;
}
-void func_800C9998(struct_801664D0* arg0) {
- func_800C9940(arg0, 0x20, 0x16);
+void SpeedMeter_Init(SpeedMeter* this) {
+ SpeedMeter_InitImpl(this, 32, 22);
}
-void func_800C99BC(struct_801664D0* arg0) {
+void SpeedMeter_Destroy(SpeedMeter* this) {
}
-#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/func_800C99C4.s")
-
-typedef struct {
- /* 0x00 */ u32 unk_00;
- /* 0x04 */ u32 unk_04;
- /* 0x08 */ u16 unk_08;
- /* 0x0A */ u16 unk_0A;
- /* 0x0C */ u32 unk_0C;
- /* 0x10 */ u32 unk_10;
- /* 0x14 */ u32 unk_14;
- /* 0x18 */ u32 unk_18;
-} struct_800C9E08;
-
-void func_800C9E08(struct_800C9E08* arg0, u32 arg1, u32 arg2, u16 arg3, u16 arg4, u32 arg5, u32 arg6, u32 arg7,
- u32 arg8) {
- arg0->unk_00 = arg1;
- arg0->unk_04 = arg2;
- arg0->unk_08 = arg3;
- arg0->unk_0A = arg4;
- arg0->unk_0C = arg5;
- arg0->unk_10 = arg6;
- arg0->unk_14 = arg7;
- arg0->unk_18 = arg8;
+void SpeedMeter_DrawTimeEntries(SpeedMeter* this, GraphicsContext* gfxCtx) {
+ u32 pad[2];
+ u32 baseX = 32;
+ s32 temp;
+ s32 i;
+ s32 uly;
+ s32 lry;
+ View view;
+ u32 pad2[3];
+ Gfx* gfx;
+ Gfx* dispRefs[5];
+ Viewport viewport;
+
+ uly = this->y;
+ lry = this->y + 2;
+
+ Graph_OpenDisps(dispRefs, gfxCtx, "../speed_meter.c", 225);
+
+ /*! @bug if gIrqMgrRetraceTime is 0, the function won't call Graph_CloseDisps */
+ if (gIrqMgrRetraceTime == 0) {
+ return;
+ }
+
+ gSpeedMeterTimeEntryPtr = &sSpeedMeterTimeEntryArray;
+ for (i = 0; i < ARRAY_COUNT(sSpeedMeterTimeEntryArray); i++) {
+ temp = ((f64)*gSpeedMeterTimeEntryPtr->time / gIrqMgrRetraceTime) * 64.0;
+ gSpeedMeterTimeEntryPtr->x = temp + baseX;
+ gSpeedMeterTimeEntryPtr++;
+ }
+
+ View_Init(&view, gfxCtx);
+ view.flags = 0xA;
+
+ VIEWPORT_INIT(viewport, SCREEN_HEIGHT, SCREEN_WIDTH, 0, 0);
+ View_SetViewport(&view, &viewport);
+ gfx = gfxCtx->overlay.p;
+ func_800AB9EC(&view, 0xF, &gfx);
+
+ gDPPipeSync(gfx++);
+ gDPSetOtherMode(gfx++,
+ G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE |
+ G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_NPRIMITIVE,
+ G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2);
+
+ DrawRec(gfx++, GPACK_RGBA5551(0x00, 0x00, 0xFF, 1), baseX + 64 * 0, uly, baseX + 64 * 1, lry);
+ DrawRec(gfx++, GPACK_RGBA5551(0x00, 0xFF, 0x00, 1), baseX + 64 * 1, uly, baseX + 64 * 2, lry);
+ DrawRec(gfx++, GPACK_RGBA5551(0xFF, 0x00, 0x00, 1), baseX + 64 * 2, uly, baseX + 64 * 3, lry);
+ DrawRec(gfx++, GPACK_RGBA5551(0xFF, 0x00, 0xFF, 1), baseX + 64 * 3, uly, baseX + 64 * 4, lry);
+
+ gSpeedMeterTimeEntryPtr = sSpeedMeterTimeEntryArray;
+ for (i = 0; i < ARRAY_COUNT(sSpeedMeterTimeEntryArray); i++) {
+ DrawRec(gfx++, gSpeedMeterTimeEntryPtr->color, baseX, lry + gSpeedMeterTimeEntryPtr->y,
+ gSpeedMeterTimeEntryPtr->x, lry + gSpeedMeterTimeEntryPtr->y + 1);
+ gSpeedMeterTimeEntryPtr++;
+ }
+ gDPPipeSync(gfx++);
+
+ gfxCtx->overlay.p = gfx;
+ Graph_CloseDisps(dispRefs, gfxCtx, "../speed_meter.c", 276);
+}
+
+void SpeedMeter_InitAllocEntry(SpeedMeterAllocEntry* this, u32 maxval, u32 val, u16 backColor, u16 foreColor, u32 ulx,
+ u32 lrx, u32 uly, u32 lry) {
+ this->maxval = maxval;
+ this->val = val;
+ this->backColor = backColor;
+ this->foreColor = foreColor;
+ this->ulx = ulx;
+ this->lrx = lrx;
+ this->uly = uly;
+ this->lry = lry;
+}
+
+void SpeedMeter_DrawAllocEntry(SpeedMeterAllocEntry* this, GraphicsContext* gfxCtx) {
+ s32 usedOff;
+ View view;
+ Gfx* gfx;
+ Gfx* dispRefs[5];
+ Viewport viewport;
+ u32 pad2;
+
+ if (this->maxval == 0) {
+ osSyncPrintf(VT_FGCOL(RED));
+ LOG_NUM("this->maxval", this->maxval, "../speed_meter.c", 313);
+ osSyncPrintf(VT_RST);
+ } else {
+ Graph_OpenDisps(dispRefs, gfxCtx, "../speed_meter.c", 318);
+
+ View_Init(&view, gfxCtx);
+ view.flags = 0xA;
+
+ VIEWPORT_INIT(viewport, SCREEN_HEIGHT, SCREEN_WIDTH, 0, 0);
+
+ View_SetViewport(&view, &viewport);
+ gfx = gfxCtx->overlay.p;
+ func_800AB9EC(&view, 0xF, &gfx);
+
+ gDPPipeSync(gfx++);
+ gDPSetOtherMode(gfx++,
+ G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE |
+ G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_NPRIMITIVE,
+ G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2);
+
+ usedOff = ((this->lrx - this->ulx) * this->val) / this->maxval + this->ulx;
+ DrawRec(gfx++, this->backColor, usedOff, this->uly, this->lrx, this->lry);
+ DrawRec(gfx++, this->foreColor, this->ulx, this->uly, usedOff, this->lry);
+
+ gDPPipeSync(gfx++);
+
+ gfxCtx->overlay.p = gfx;
+ Graph_CloseDisps(dispRefs, gfxCtx, "../speed_meter.c", 339);
+ }
}
-#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/func_800C9E44.s")
+void SpeedMeter_DrawAllocEntries(SpeedMeter* meter, GraphicsContext* gfxCtx, GameState* state) {
+ u32 pad[2];
+ u32 ulx = 30;
+ u32 lrx = 290;
+ SpeedMeterAllocEntry entry;
+ u32 temp;
+ s32 y;
+ TwoHeadGfxArena* thga;
+ u32 zeldaFreeMax;
+ u32 zeldaFree;
+ u32 zeldaAlloc;
+ s32 sysFreeMax;
+ s32 sysFree;
+ s32 sysAlloc;
+
+ y = 212;
+ if (SREG(0) > 2) {
+ if (ZeldaArena_IsInitalized()) {
+ ZeldaArena_GetSizes(&zeldaFreeMax, &zeldaFree, &zeldaAlloc);
+ SpeedMeter_InitAllocEntry(&entry, zeldaFree + zeldaAlloc, zeldaAlloc, GPACK_RGBA5551(0x00, 0x00, 0xFF, 1),
+ GPACK_RGBA5551(0xFF, 0xFF, 0xFF, 1), ulx, lrx, y, y + 1);
+ SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
+ y++;
+ y++;
+ }
+ }
+
+ if (SREG(0) > 1) {
+ SystemArena_GetSizes(&sysFreeMax, &sysFree, &sysAlloc);
+ SpeedMeter_InitAllocEntry(&entry, sysFree + sysAlloc - state->tha.size, sysAlloc - state->tha.size,
+ GPACK_RGBA5551(0x00, 0x00, 0xFF, 1), GPACK_RGBA5551(0xFF, 0x80, 0x80, 1), ulx, lrx, y,
+ y);
+ SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
+ y++;
+ }
+
+ thga = (TwoHeadGfxArena*)&state->tha;
+ SpeedMeter_InitAllocEntry(&entry, thga->size, thga->size - THA_GetSize((TwoHeadArena*)thga),
+ GPACK_RGBA5551(0x00, 0x00, 0xFF, 1), GPACK_RGBA5551(0x00, 0xFF, 0x00, 1), ulx, lrx, y, y);
+ SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
+ y++;
-#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/func_800CA104.s")
+ thga = &gfxCtx->polyOpa;
+ SpeedMeter_InitAllocEntry(&entry, thga->size, thga->size - THGA_GetSize(thga), GPACK_RGBA5551(0x00, 0x00, 0xFF, 1),
+ GPACK_RGBA5551(0xFF, 0x00, 0xFF, 1), ulx, lrx, y, y);
+ SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
+ y++;
+
+ thga = &gfxCtx->polyXlu;
+ SpeedMeter_InitAllocEntry(&entry, thga->size, thga->size - THGA_GetSize(thga), GPACK_RGBA5551(0x00, 0x00, 0xFF, 1),
+ GPACK_RGBA5551(0xFF, 0xFF, 0x00, 1), ulx, lrx, y, y);
+ SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
+ y++;
+
+ thga = &gfxCtx->overlay;
+ SpeedMeter_InitAllocEntry(&entry, thga->size, thga->size - THGA_GetSize(thga), GPACK_RGBA5551(0x00, 0x00, 0xFF, 1),
+ GPACK_RGBA5551(0xFF, 0x00, 0x00, 1), ulx, lrx, y, y);
+ SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
+ y++;
+}
diff --git a/src/code/z_play.c b/src/code/z_play.c
index 21fd82f92..4d5dffd31 100644
--- a/src/code/z_play.c
+++ b/src/code/z_play.c
@@ -1140,10 +1140,7 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
View_Init(&view, gfxCtx);
view.flags = 2 | 8;
- // clang-format off
- viewport.bottomY = SCREEN_HEIGHT; viewport.rightX = SCREEN_WIDTH;
- viewport.topY = 0; viewport.leftX = 0;
- // clang-format on
+ VIEWPORT_INIT(viewport, SCREEN_HEIGHT, SCREEN_WIDTH, 0, 0);
View_SetViewport(&view, &viewport);
func_800AB9EC(&view, 15, &gfxP);
diff --git a/src/code/z_sample.c b/src/code/z_sample.c
index 0f6f01e20..aa2bfb1bc 100644
--- a/src/code/z_sample.c
+++ b/src/code/z_sample.c
@@ -61,10 +61,7 @@ void Sample_SetupView(SampleContext* this) {
gfxCtx = this->state.gfxCtx;
View_Init(view, gfxCtx);
- // clang-format off
- viewport.bottomY = SCREEN_HEIGHT; viewport.rightX = SCREEN_WIDTH;
- viewport.topY = 0; viewport.leftX = 0;
- // clang-format on
+ VIEWPORT_INIT(viewport, SCREEN_HEIGHT, SCREEN_WIDTH, 0, 0);
View_SetViewport(view, &viewport);
func_800AA460(view, 60, 10, 12800);