1
0
mirror of https://github.com/blawar/ooot.git synced 2024-06-25 22:09:34 +00:00

cleaned up vismono

This commit is contained in:
Blake Warner 2022-04-01 16:10:56 -04:00
parent e7fa28c4db
commit 4c0699eb8a
8 changed files with 113 additions and 103 deletions

View File

@ -1,3 +1,4 @@
#pragma once
void SysCfb_Init(s32 n64dd);
uintptr_t SysCfb_GetFbPtr(s32 idx);

View File

@ -4,6 +4,6 @@ struct VisMono;
void VisMono_Destroy(VisMono* pthis);
void VisMono_Draw(VisMono* pthis, Gfx** gfxp);
void VisMono_DrawOld(VisMono* pthis);
Gfx* VisMono_DrawTexture(VisMono* pthis, Gfx* gfx);
Gfx* VisMono_DesaturateDList(VisMono* pthis, Gfx* gfx);
void VisMono_Init(VisMono* pthis);
void VisMono_UpdateTexture(VisMono* pthis, u16* tex);
void VisMono_DesaturateTLUT(VisMono* pthis, u16* tex);

View File

@ -394,8 +394,8 @@ void func_800ACE90(struct_801664F0* thiss);
void func_800ACE98(struct_801664F0* thiss, Gfx** gfxp);
void VisMono_Init(VisMono* thiss);
void VisMono_Destroy(VisMono* thiss);
void VisMono_UpdateTexture(VisMono* thiss, u16* tex);
Gfx* VisMono_DrawTexture(VisMono* thiss, Gfx* gfx);
void VisMono_DesaturateTLUT(VisMono* thiss, u16* tex);
Gfx* VisMono_DesaturateDList(VisMono* thiss, Gfx* gfx);
void VisMono_Draw(VisMono* thiss, Gfx** gfxp);
void VisMono_DrawOld(VisMono* thiss);
void func_800AD920(struct_80166500* thiss);

View File

@ -244,6 +244,7 @@
#define GPACK_RGBA5551(r, g, b, a) ((((r)<<8) & 0xf800) | \
(((g)<<3) & 0x7c0) | \
(((b)>>2) & 0x3e) | ((a) & 0x1))
#define GPACK_IA16(i, a) (((i) << 8) | (a))
#define GPACK_ZDZ(z, dz) ((z) << 2 | (dz))
/*

View File

@ -9,7 +9,7 @@ struct VisMono {
/* 0x08 */ Color_RGBA8 primColor;
/* 0x0C */ Color_RGBA8 envColor;
/* 0x10 */ u16* tlut;
/* 0x14 */ Gfx* monoDl;
/* 0x14 */ Gfx* dList;
}; // size = 0x18
struct struct_80166500 {

View File

@ -20,6 +20,7 @@
#include "def/TwoHeadArena.h"
#include "def/audio.h"
#include "def/createmesgqueue.h"
#include "def/sys_cfb.h"
#include "def/fault.h"
#include "def/game.h"
#include "def/gettime.h"
@ -51,8 +52,6 @@ FaultClient sGraphFaultClient;
CfbInfo sGraphCfbInfos[3];
FaultClient sGraphUcodeFaultClient;
uintptr_t SysCfb_GetFbPtr(s32 idx);
bool isRunning();
void Graph_DisassembleUCode(Gfx* workBuf) {

View File

@ -11,7 +11,7 @@
Gfx D_8012AFB0[] = {
gsDPPipeSync(),
gsDPSetCycleType(G_CYC_FILL),
gsDPSetColorImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, 0x0F000000),
gsDPSetColorImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, SEGMENT_ADDRESS(0x0F000000)),
gsDPSetFillColor((GPACK_RGBA5551(65, 65, 65, 1) << 16) | GPACK_RGBA5551(65, 65, 65, 1)),
gsDPFillRectangle(0, 0, 319, 239),
gsDPPipeSync(),

View File

@ -1,130 +1,139 @@
#define INTERNAL_SRC_CODE_Z_VISMONO_C
#include "global.h"
#include "gfx.h"
#include "z_vismono.h"
#include "def/graph.h"
#include "def/system_malloc.h"
#include "def/z_vismono.h"
#include "def/sys_cfb.h"
// (Note: 80 = SCREEN_HEIGHT/3, see VisMono_DrawTexture)
// pthis may not have been kept up-to-date with the code, 1+1+1+80*(7+2+2+3)+1+1 makes more sense
#define DLSIZE (1 + 3 + 1 + 1 + 80 * (7 + 2 + 2 + 3) + 1)
void enableFbEffects();
// framebuffer
static u16 D_0F000000[SCREEN_HEIGHT * SCREEN_WIDTH * 4];
#define VISMONO_CFBFRAG_HEIGHT (0x800 / (SCREEN_WIDTH * G_IM_SIZ_16b_BYTES))
#define VISMONO_DLSIZE (3 + SCREEN_HEIGHT / VISMONO_CFBFRAG_HEIGHT * (7 + 2 + 2 + 3) + 2 + 2)
void VisMono_Init(VisMono* pthis) {
bzero(pthis, sizeof(VisMono));
pthis->unk_00 = 0;
pthis->setScissor = false;
pthis->primColor.r = 255;
pthis->primColor.g = 255;
pthis->primColor.b = 255;
pthis->primColor.a = 255;
pthis->envColor.r = 0;
pthis->envColor.g = 0;
pthis->envColor.b = 0;
pthis->envColor.a = 0;
#define VISMONO_FAC_RED 2
#define VISMONO_FAC_GREEN 4
#define VISMONO_FAC_BLUE 1
#define VISMONO_FAC_NORM (0x1F * VISMONO_FAC_RED + 0x1F * VISMONO_FAC_GREEN + 0x1F * VISMONO_FAC_BLUE)
void VisMono_Init(VisMono* pthis)
{
bzero(pthis, sizeof(VisMono));
pthis->unk_00 = 0;
pthis->setScissor = false;
pthis->primColor.r = 255;
pthis->primColor.g = 255;
pthis->primColor.b = 255;
pthis->primColor.a = 255;
pthis->envColor.r = 0;
pthis->envColor.g = 0;
pthis->envColor.b = 0;
pthis->envColor.a = 0;
}
void VisMono_Destroy(VisMono* pthis) {
SystemArena_FreeDebug(pthis->monoDl, "../z_vismono.c", 137);
void VisMono_Destroy(VisMono* pthis)
{
SystemArena_FreeDebug(pthis->dList, "../z_vismono.c", 137);
}
void VisMono_UpdateTexture(VisMono* pthis, u16* tex) {
s32 i;
void VisMono_DesaturateTLUT(VisMono* pthis, u16* tlut)
{
s32 i;
for (i = 0; i < 256; i++) {
tex[i] = ((((i >> 3 & 0x1F) * 2 + (i << 2 & 0x1F) * 4) * 0xFF / 0xD9) << 8) |
(((i >> 6 & 0x1F) * 4 + (i >> 1 & 0x1F)) * 0xFF / 0xD9);
}
for(i = 0; i < 256; i++)
{
tlut[i] = GPACK_IA16(((i >> 3 & 0x1F) * VISMONO_FAC_RED + (i << 2 & 0x1F) * VISMONO_FAC_GREEN) * 255 / VISMONO_FAC_NORM, ((i >> 6 & 0x1F) * VISMONO_FAC_GREEN + (i >> 1 & 0x1F) * VISMONO_FAC_BLUE) * 255 / VISMONO_FAC_NORM);
}
}
Gfx* VisMono_DrawTexture(VisMono* pthis, Gfx* gfx) {
s32 y;
s32 height = 3;
u16* tex = D_0F000000;
Gfx* VisMono_DesaturateDList(VisMono* pthis, Gfx* gfx)
{
s32 y;
s32 height = VISMONO_CFBFRAG_HEIGHT;
u16* cfbFrag = (u16*)SEGMENT_ADDRESS(0x0F000000); // color frame buffer
gDPPipeSync(gfx++);
gDPSetOtherMode(gfx++,
G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_IA16 | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_2CYCLE | G_PM_1PRIMITIVE,
G_AC_NONE | G_ZS_PRIM | GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) | G_RM_CLD_SURF2);
gDPSetCombineLERP(gfx++, 1, 0, TEXEL1_ALPHA, TEXEL0, 0, 0, 0, 1, PRIMITIVE, ENVIRONMENT, COMBINED, ENVIRONMENT, 0,
0, 0, PRIMITIVE);
gDPPipeSync(gfx++);
gDPSetOtherMode(
gfx++, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_IA16 | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_2CYCLE | G_PM_1PRIMITIVE,
G_AC_NONE | G_ZS_PRIM | GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) | G_RM_CLD_SURF2);
for (y = 0; y <= SCREEN_HEIGHT - height; y += height) {
gDPLoadTextureBlock(gfx++, tex, G_IM_FMT_CI, G_IM_SIZ_8b, SCREEN_WIDTH * 2, height, 0,
G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK,
G_TX_NOLOD, G_TX_NOLOD);
gDPSetCombineLERP(gfx++, 1, 0, TEXEL1_ALPHA, TEXEL0, 0, 0, 0, 1, PRIMITIVE, ENVIRONMENT, COMBINED, ENVIRONMENT, 0, 0, 0, PRIMITIVE);
gDPSetTile(gfx++, G_IM_FMT_CI, G_IM_SIZ_8b, 80, 0x0, G_TX_RENDERTILE, 0, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0,
G_TX_NOMIRROR | G_TX_CLAMP, 0, 0);
gDPSetTileSize(gfx++, G_TX_RENDERTILE, (2 << 2), 0, ((SCREEN_WIDTH * 2 + 1) << 2), (2 << 2));
for(y = 0; y <= SCREEN_HEIGHT - height; y += height)
{
gDPLoadTextureBlock(gfx++, cfbFrag, G_IM_FMT_CI, G_IM_SIZ_8b, SCREEN_WIDTH * 2, height, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gDPSetTile(gfx++, G_IM_FMT_CI, G_IM_SIZ_8b, SCREEN_WIDTH * 2 * G_IM_SIZ_8b_LINE_BYTES / 8, 0x0, G_TX_RENDERTILE, 0, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0);
gDPSetTileSize(gfx++, G_TX_RENDERTILE, 2 << 2, 0, (SCREEN_WIDTH * 2 + 1) << 2, (VISMONO_CFBFRAG_HEIGHT - 1) << 2);
gDPSetTile(gfx++, G_IM_FMT_CI, G_IM_SIZ_8b, SCREEN_WIDTH * 2 * G_IM_SIZ_8b_LINE_BYTES / 8, 0x0, 1, 1, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0);
gDPSetTileSize(gfx++, 1, 1 << 2, 0, (SCREEN_WIDTH * 2) << 2, (VISMONO_CFBFRAG_HEIGHT - 1) << 2);
gSPTextureRectangle(gfx++, 0, y << 2, SCREEN_WIDTH << 2, (y + height) << 2, G_TX_RENDERTILE, 2 << 5, 0, 2 << 10, 1 << 10);
cfbFrag += SCREEN_WIDTH * height;
}
gDPSetTile(gfx++, G_IM_FMT_CI, G_IM_SIZ_8b, 80, 0x0, 1, 1, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0,
G_TX_NOMIRROR | G_TX_CLAMP, 0, 0);
gDPSetTileSize(gfx++, 1, (1 << 2), 0, ((SCREEN_WIDTH * 2) << 2), (2 << 2));
gSPTextureRectangle(gfx++, 0, y << 2, (SCREEN_WIDTH << 2), (y + height) << 2, G_TX_RENDERTILE, 2 << 5, 0,
2 << 10, 1 << 10);
tex += SCREEN_WIDTH * height;
}
gDPPipeSync(gfx++);
gSPEndDisplayList(gfx++);
return gfx;
gDPPipeSync(gfx++);
gSPEndDisplayList(gfx++);
return gfx;
}
void VisMono_Draw(VisMono* pthis, Gfx** gfxp) {
Gfx* gfx = *gfxp;
u16* tlut;
Gfx* monoDL;
Gfx* glistpEnd;
void VisMono_Draw(VisMono* pthis, Gfx** gfxp)
{
Gfx* gfx = *gfxp;
u16* tlut;
Gfx* dList;
Gfx* dListEnd;
if (pthis->tlut) {
tlut = pthis->tlut;
} else {
tlut = (u16*)Graph_DlistAlloc(&gfx, 256 * sizeof(u16));
VisMono_UpdateTexture(pthis, tlut);
}
if(pthis->tlut)
{
tlut = pthis->tlut;
}
else
{
tlut = (u16*)Graph_DlistAlloc(&gfx, 256 * G_IM_SIZ_16b_BYTES);
VisMono_DesaturateTLUT(pthis, tlut);
}
if (pthis->monoDl) {
monoDL = pthis->monoDl;
} else {
monoDL = (Gfx*)Graph_DlistAlloc(&gfx, DLSIZE * sizeof(Gfx));
glistpEnd = VisMono_DrawTexture(pthis, monoDL);
if(pthis->dList)
{
dList = pthis->dList;
}
else
{
dList = (Gfx*)Graph_DlistAlloc(&gfx, VISMONO_DLSIZE * sizeof(Gfx));
dListEnd = VisMono_DesaturateDList(pthis, dList);
}
ASSERT(glistpEnd <= monoDL + DLSIZE, "glistp_end <= mono_dl + DLSIZE", "../z_vismono.c", 262);
}
gDPPipeSync(gfx++);
if(pthis->setScissor == true)
{
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
gDPPipeSync(gfx++);
if (pthis->setScissor == true) {
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
gDPSetColor(gfx++, G_SETPRIMCOLOR, pthis->primColor.r, pthis->primColor.g, pthis->primColor.b, pthis->primColor.a);
gDPSetColor(gfx++, G_SETENVCOLOR, pthis->envColor.r, pthis->envColor.g, pthis->envColor.b, pthis->envColor.a);
gDPSetColor(gfx++, G_SETPRIMCOLOR, pthis->primColor.r, pthis->primColor.g, pthis->primColor.b, pthis->primColor.a);
gDPSetColor(gfx++, G_SETENVCOLOR, pthis->envColor.r, pthis->envColor.g, pthis->envColor.b, pthis->envColor.a);
gDPLoadTLUT_pal256(gfx++, tlut);
gDPLoadTLUT_pal256(gfx++, tlut);
gSPDisplayList(gfx++, dList);
gDPPipeSync(gfx++);
gSPDisplayList(gfx++, monoDL);
gDPPipeSync(gfx++);
*gfxp = gfx;
*gfxp = gfx;
}
void VisMono_DrawOld(VisMono* pthis) {
Gfx* glistpEnd;
void VisMono_DrawOld(VisMono* pthis)
{
Gfx* glistpEnd;
if (!pthis->tlut) {
pthis->tlut = (u16*)SystemArena_MallocDebug(256 * sizeof(u16), "../z_vismono.c", 283);
VisMono_UpdateTexture(pthis, pthis->tlut);
}
if(!pthis->tlut)
{
pthis->tlut = (u16*)SystemArena_MallocDebug(256 * sizeof(u16), "../z_vismono.c", 283);
VisMono_DesaturateTLUT(pthis, pthis->tlut);
}
if (!pthis->monoDl) {
pthis->monoDl = (Gfx*)SystemArena_MallocDebug(DLSIZE * sizeof(Gfx), "../z_vismono.c", 289);
glistpEnd = VisMono_DrawTexture(pthis, pthis->monoDl);
ASSERT(glistpEnd <= pthis->monoDl + DLSIZE, "glistp_end <= pthis->mono_dl + DLSIZE", "../z_vismono.c", 292);
}
if(!pthis->dList)
{
pthis->dList = (Gfx*)SystemArena_MallocDebug(VISMONO_DLSIZE * sizeof(Gfx), "../z_vismono.c", 289);
glistpEnd = VisMono_DesaturateDList(pthis, pthis->dList);
}
}