From 7941d78bf3814a266eaca8768f274709c6cfa915 Mon Sep 17 00:00:00 2001 From: abnormalhare Date: Thu, 23 Oct 2025 12:09:21 -0400 Subject: [PATCH 1/2] match Famicom/ks_nes_draw.cpp:ksNesDrawOBJI8ToEFB --- src/static/Famicom/ks_nes_draw.cpp | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/static/Famicom/ks_nes_draw.cpp b/src/static/Famicom/ks_nes_draw.cpp index 9685896e..a00b94d4 100644 --- a/src/static/Famicom/ks_nes_draw.cpp +++ b/src/static/Famicom/ks_nes_draw.cpp @@ -457,6 +457,62 @@ void ksNesDrawFlushEFBToRed8(u8* buf) { } void ksNesDrawOBJI8ToEFB(ksNesCommonWorkObj* wp, u8* buf) { + GXTexObj obj; + u32 i; + s32 u; + u8* work; + u32 cnt; + + GXSetNumChans(0); + GXSetNumTexGens(1); + GXSetNumTevStages(1); + GXSetNumIndStages(0); + GXSetBlendMode(GX_BM_LOGIC, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_COPY); + + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_S16, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U16, 8); + + GXInitTexObj(&obj, (void*)buf, 256, 228, GX_TF_I8, GX_CLAMP, GX_CLAMP, 0); + GXInitTexObjLOD(&obj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); + GXLoadTexObj(&obj, GX_TEXMAP0); + + GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, 60); + GXSetTexCoordScaleManually(GX_TEXCOORD0, GX_TRUE, 0x100, 0x100); + GXSetTexCoordBias(GX_TEXCOORD0, 0, 0); + + GXSetTevDirect(GX_TEVSTAGE0); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevOp(GX_TEVSTAGE0, GX_REPLACE); + + GXSetAlphaCompare(GX_GREATER, 0, GX_AOP_AND, GX_ALWAYS, 0); + + cnt = ksNesDrawMakeOBJAppearVtxList(wp); + if (cnt == 0) return; + + GXBegin(GX_QUADS, GX_VTXFMT0, cnt * 2); + + for (i = 0; i < cnt; i += 2) { + work = (u8*)wp + i; // if it works... + u = ((wp->work_priv._0B40[(u8)((u8*)wp)[i + 0x60]]._19 & 0x14) - 8) == 8 ? 8 : 0; + + // s32 y = -128 - ((work[0x60] & 0xFF)); + GXPosition2s16(u + 0x80, -128 - work[0x60]); + GXTexCoord2u16(u, work[0x60] - 8); + + GXPosition2s16(0x180, -128 - work[0x60]); + GXTexCoord2u16(0x100, work[0x60] - 8); + + GXPosition2s16(0x180, -128 - work[0x60] - work[0x61]); + GXTexCoord2u16(0x100, work[0x60] + work[0x61] - 8); + + GXPosition2s16(u + 0x80, -128 - work[0x60] - work[0x61]); + GXTexCoord2u16(u, work[0x60] + work[0x61] - 8); + } + + GXEnd(); } void ksNesDrawEmuResult(ksNesCommonWorkObj*) { From 32d7df15be2a8a6166739b95725822f1fe9aa385 Mon Sep 17 00:00:00 2001 From: abnormalhare Date: Thu, 23 Oct 2025 13:16:30 -0400 Subject: [PATCH 2/2] better calculation for u --- src/static/Famicom/ks_nes_draw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/Famicom/ks_nes_draw.cpp b/src/static/Famicom/ks_nes_draw.cpp index a00b94d4..480bec2c 100644 --- a/src/static/Famicom/ks_nes_draw.cpp +++ b/src/static/Famicom/ks_nes_draw.cpp @@ -496,7 +496,7 @@ void ksNesDrawOBJI8ToEFB(ksNesCommonWorkObj* wp, u8* buf) { for (i = 0; i < cnt; i += 2) { work = (u8*)wp + i; // if it works... - u = ((wp->work_priv._0B40[(u8)((u8*)wp)[i + 0x60]]._19 & 0x14) - 8) == 8 ? 8 : 0; + u = (wp->work_priv._0B40[(u8)((u8*)wp)[i + 0x60]]._19 & 0x14) == 0x10 ? 8 : 0; // s32 y = -128 - ((work[0x60] & 0xFF)); GXPosition2s16(u + 0x80, -128 - work[0x60]);