d_a_tag_shop_camera OK, d_a_tag_watchge OK, JUTFader OK, JUtility work from Pikmin 2 (#292)

This commit is contained in:
Pheenoh
2023-02-18 16:17:35 -07:00
committed by GitHub
parent 0aaa6fed7a
commit 3acf288950
37 changed files with 642 additions and 1601 deletions
+262 -295
View File
@@ -6,6 +6,7 @@
#include "JSystem/JUtility/JUTResFont.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/gx/GX.h"
//
// Forward References:
@@ -119,18 +120,18 @@ JUTResFont::~JUTResFont() {
/* 802DF08C-802DF0B0 2D99CC 0024+00 3/3 3/3 0/0 .text deleteMemBlocks_ResFont__10JUTResFontFv */
void JUTResFont::deleteMemBlocks_ResFont() {
delete[] field_0x50;
delete[] mMemBlocks;
}
/* 802DF0B0-802DF0DC 2D99F0 002C+00 5/5 3/3 0/0 .text initialize_state__10JUTResFontFv */
void JUTResFont::initialize_state() {
mResFont = NULL;
field_0x50 = NULL;
mWid1Ptr = NULL;
mGly1Ptr = NULL;
mMap1Ptr = NULL;
field_0x1c = NULL;
field_0x20 = NULL;
mMemBlocks = NULL;
mpWidthBlocks = NULL;
mpGlyphBlocks = NULL;
mpMapBlocks = NULL;
mWidth = NULL;
mHeight = NULL;
field_0x44 = -1;
}
@@ -150,53 +151,40 @@ bool JUTResFont::initiate(ResFONT const* param_0, JKRHeap* param_1) {
/* 802DF13C-802DF248 2D9A7C 010C+00 1/1 0/0 0/0 .text
* protected_initiate__10JUTResFontFPC7ResFONTP7JKRHeap */
// regalloc
#ifdef NONMATCHING
bool JUTResFont::protected_initiate(ResFONT const* param_0, JKRHeap* param_1) {
void** p;
delete_and_initialize();
JUTFont::initialize_state();
if (!param_0) {
return false;
} else {
mResFont = param_0;
mValid = true;
countBlock();
void* tmp = new (param_1, 0) void*[mWid1BlockNum + mGly1BlockNum + mMap1BlockNum];
field_0x50 = tmp;
if (!field_0x50) {
return false;
} else {
if (mWid1BlockNum != 0) {
mWid1Ptr = (ResFONT::WID1*)tmp;
(int*)tmp += mWid1BlockNum;
}
if (mGly1BlockNum != 0) {
mGly1Ptr = (ResFONT::GLY1*)tmp;
(int*)tmp += mGly1BlockNum;
}
if (mMap1BlockNum != 0) {
mMap1Ptr = (ResFONT::MAP1*)tmp;
}
setBlock();
return true;
}
}
mResFont = param_0;
mValid = true;
countBlock();
mMemBlocks = new (param_1, 0) void*[mWid1BlockNum + mGly1BlockNum + mMap1BlockNum];
p = mMemBlocks;
if (!mMemBlocks) {
return false;
} else {
if (mWid1BlockNum != 0) {
mpWidthBlocks = (ResFONT::WID1**)p;
p += mWid1BlockNum;
}
if (mGly1BlockNum != 0) {
mpGlyphBlocks = (ResFONT::GLY1**)p;
p += mGly1BlockNum;
}
if (mMap1BlockNum != 0) {
mpMapBlocks = (ResFONT::MAP1**)p;
}
setBlock();
return true;
}
return false;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm bool JUTResFont::protected_initiate(ResFONT const* param_0, JKRHeap* param_1) {
nofralloc
#include "asm/JSystem/JUtility/JUTResFont/protected_initiate__10JUTResFontFPC7ResFONTP7JKRHeap.s"
}
#pragma pop
#endif
/* ############################################################################################## */
/* 8039D45C-8039D45C 029ABC 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */
@@ -206,6 +194,33 @@ SECTION_DEAD static char const* const stringBase_8039D45C = "JUTResFont: Unknown
#pragma pop
/* 802DF248-802DF344 2D9B88 00FC+00 1/1 0/0 0/0 .text countBlock__10JUTResFontFv */
#ifdef NONMATCHING
void JUTResFont::countBlock() {
mWidthBlockCount = 0;
mGlyphBlockCount = 0;
mMapBlockCount = 0;
u8* pData = (u8*)&mResource->mData;
for (u32 i = 0; i < mResource->mChunkNum; i++, pData += ((BlockHeader*)pData)->mSize) {
int magic = ((BlockHeader*)pData)->mMagic;
switch (magic) {
case 'WID1':
mWidthBlockCount++;
break;
case 'GLY1':
mGlyphBlockCount++;
break;
case 'MAP1':
mMapBlockCount++;
break;
case 'INF1':
// mInf1Ptr;
break;
default:
JUTReportConsole("JUTResFont: Unknown data block\n");
}
};
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -214,6 +229,7 @@ asm void JUTResFont::countBlock() {
#include "asm/JSystem/JUtility/JUTResFont/countBlock__10JUTResFontFv.s"
}
#pragma pop
#endif
/* ############################################################################################## */
/* 8039D390-8039D39C -00001 000C+00 1/1 1/1 0/0 .rodata saoAboutEncoding___10JUTResFont */
@@ -309,6 +325,75 @@ SECTION_SDATA2 static f64 lit_651 = 4503599627370496.0 /* cast u32 to float */;
/* 802DF7C4-802DFBE8 2DA104 0424+00 1/0 1/0 0/0 .text drawChar_scale__10JUTResFontFffffib
*/
#ifdef NONMATCHING
// still missing a bunch of stuff
f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, int str_int,
bool flag) {
JUTFont::TWidth width;
f32 width_val;
f32 pos_height, ascent, ascent_val, scaled_height;
f32 sca_wid;
loadFont(str_int, GX_TEXMAP0, &width);
if ((mFixed) || (!flag)) {
width_val = pos_x;
} else {
width_val = (pos_x - width.field_0x0 * (scale_x / getCellWidth()));
}
f32 retval = mFixedWidth * (scale_x / getCellWidth());
if (mFixed == false) {
if (!flag) {
retval = (width.field_0x1 + width.field_0x0) * (scale_x / getCellWidth());
} else {
retval = width.field_0x1 * (scale_x / getCellWidth());
}
}
sca_wid = width_val + scale_x;
ascent_val = pos_y - getAscent() * (scale_y / getHeight());
scaled_height = scale_y / getHeight();
f32 descent = getDescent();
f32 ascent_calc = descent * ascent_val;
f32 deshei = descent * scaled_height + pos_y;
ResFONT::GLY1* used_glyphs = mpGlyphBlocks[field_0x66];
u16 tex_width = used_glyphs->textureWidth;
u16 tex_height = used_glyphs->textureHeight;
int t_width = mWidth;
int t_height = mHeight;
int shift_width = (t_width + used_glyphs->cellHeight) << 15;
int div_width = (t_width << 15) / tex_width;
int div_height = (t_height << 15) / tex_height;
u16 sumWidth = t_width + used_glyphs->cellWidth;
int shift_height = t_height + used_glyphs->cellHeight << 15;
u16 sumHeight = t_height + used_glyphs->cellHeight;
s32 width_ratio = shift_width / tex_width;
s32 height_ratio = shift_height / tex_height;
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GXBegin(GX_QUADS, GX_VTXFMT0, 4);
GXPosition3f32(width_val,ascent_val,0.0f);
GXColor1u32(mColor1);
i_GXTexCoord2u16(div_width,div_height);
GXPosition3f32(sca_wid,ascent_val,0.0f);
GXColor1u32(mColor2);
i_GXTexCoord2u16(width_ratio,div_height);
GXPosition3f32(sca_wid,deshei,0.0f);
GXColor1u32(mColor4);
i_GXTexCoord2u16(width_ratio,height_ratio);
GXPosition3f32(width_val,deshei,0.0f);
GXColor1u32(mColor3);
i_GXTexCoord2u16(div_width,height_ratio);
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
return retval;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -318,6 +403,7 @@ asm f32 JUTResFont::drawChar_scale(f32 param_0, f32 param_1, f32 param_2, f32 pa
#include "asm/JSystem/JUtility/JUTResFont/drawChar_scale__10JUTResFontFffffib.s"
}
#pragma pop
#endif
/* 802DFBE8-802DFC64 2DA528 007C+00 1/1 0/0 0/0 .text
* loadFont__10JUTResFontFi11_GXTexMapIDPQ27JUTFont6TWidth */
@@ -332,62 +418,54 @@ void JUTResFont::loadFont(int param_0, _GXTexMapID param_1, JUTFont::TWidth* par
/* 802DFC64-802DFD0C 2DA5A4 00A8+00 1/0 1/0 0/0 .text
* getWidthEntry__10JUTResFontCFiPQ27JUTFont6TWidth */
#ifdef NONMATCHING
void JUTResFont::getWidthEntry(int param_0, JUTFont::TWidth* param_1) const {
void JUTResFont::getWidthEntry(int param_0, JUTFont::TWidth* i_width) const {
int code = getFontCode(param_0);
int tmp = 0;
param_1->field_0x0 = 0;
param_1->field_0x1 = mInf1Ptr->width;
i_width->field_0x0 = 0;
i_width->field_0x1 = mInf1Ptr->width;
for (int i = mWid1BlockNum; i > 0; i--) {
if (i = 0) {
return;
for (int i = 0; i < mWid1BlockNum; i++) {
if (mpWidthBlocks[i]->startCode <= code && code <= mpWidthBlocks[i]->endCode) {
u8* ptr = &mpWidthBlocks[i]->mChunkNum[(code - mpWidthBlocks[i]->startCode) * 2];
i_width->field_0x0 = ptr[0];
i_width->field_0x1 = ptr[1];
break;
}
ResFONT::WID1* tmp2 = mWid1Ptr + tmp;
if (tmp2->startCode <= code && code <= tmp2->endCode) {
break;
}
tmp += 4;
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void JUTResFont::getWidthEntry(int param_0, JUTFont::TWidth* param_1) const {
nofralloc
#include "asm/JSystem/JUtility/JUTResFont/getWidthEntry__10JUTResFontCFiPQ27JUTFont6TWidth.s"
}
#pragma pop
#endif
/* 802DFD0C-802DFD58 2DA64C 004C+00 1/0 1/0 0/0 .text getCellWidth__10JUTResFontCFv */
// regalloc
#ifdef NONMATCHING
int JUTResFont::getCellWidth() const {
u16 width;
if (mGly1Ptr && mGly1Ptr->magic != 0) {
width = mGly1Ptr->cellWidth;
} else {
width = getWidth();
if (mpGlyphBlocks) {
ResFONT::GLY1* glyphBlock = *mpGlyphBlocks;
if (glyphBlock) {
return glyphBlock->cellWidth;
}
}
return width;
return getWidth();
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm int JUTResFont::getCellWidth() const {
nofralloc
#include "asm/JSystem/JUtility/JUTResFont/getCellWidth__10JUTResFontCFv.s"
}
#pragma pop
#endif
/* 802DFD58-802DFDA4 2DA698 004C+00 1/0 1/0 0/0 .text getCellHeight__10JUTResFontCFv */
#ifdef NONMATCHING
// casting issue on the return
int JUTResFont::getCellHeight() const {
u16 height;
if (mpGlyphBlocks) {
ResFONT::GLY1* glyphBlock = *mpGlyphBlocks;
if (glyphBlock) {
return glyphBlock->cellHeight;
}
}
return getHeight();
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -396,217 +474,91 @@ asm u16 JUTResFont::getCellHeight() const {
#include "asm/JSystem/JUtility/JUTResFont/getCellHeight__10JUTResFontCFv.s"
}
#pragma pop
#endif
/* 802DFDA4-802DFDD8 2DA6E4 0034+00 1/0 1/0 0/0 .text isLeadByte__10JUTResFontCFi */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm bool JUTResFont::isLeadByte(int param_0) const {
nofralloc
#include "asm/JSystem/JUtility/JUTResFont/isLeadByte__10JUTResFontCFi.s"
bool JUTResFont::isLeadByte(int param_0) const {
return (*mIsLeadByte)(param_0);
}
#pragma pop
/* ############################################################################################## */
/* 8039D39C-8039D45C 0299FC 00BE+02 1/1 0/0 0/0 .rodata halftofull$726 */
SECTION_RODATA static u8 const halftofull[190 + 2 /* padding */] = {
0x81,
0x40,
0x81,
0x49,
0x81,
0x68,
0x81,
0x94,
0x81,
0x90,
0x81,
0x93,
0x81,
0x95,
0x81,
0x66,
0x81,
0x69,
0x81,
0x6A,
0x81,
0x96,
0x81,
0x7B,
0x81,
0x43,
0x81,
0x7C,
0x81,
0x44,
0x81,
0x5E,
0x82,
0x4F,
0x82,
0x50,
0x82,
0x51,
0x82,
0x52,
0x82,
0x53,
0x82,
0x54,
0x82,
0x55,
0x82,
0x56,
0x82,
0x57,
0x82,
0x58,
0x81,
0x46,
0x81,
0x47,
0x81,
0x83,
0x81,
0x81,
0x81,
0x84,
0x81,
0x48,
0x81,
0x97,
0x82,
0x60,
0x82,
0x61,
0x82,
0x62,
0x82,
0x63,
0x82,
0x64,
0x82,
0x65,
0x82,
0x66,
0x82,
0x67,
0x82,
0x68,
0x82,
0x69,
0x82,
0x6A,
0x82,
0x6B,
0x82,
0x6C,
0x82,
0x6D,
0x82,
0x6E,
0x82,
0x6F,
0x82,
0x70,
0x82,
0x71,
0x82,
0x72,
0x82,
0x73,
0x82,
0x74,
0x82,
0x75,
0x82,
0x76,
0x82,
0x77,
0x82,
0x78,
0x82,
0x79,
0x81,
0x6D,
0x81,
0x8F,
0x81,
0x6E,
0x81,
0x4F,
0x81,
0x51,
0x81,
0x65,
0x82,
0x81,
0x82,
0x82,
0x82,
0x83,
0x82,
0x84,
0x82,
0x85,
0x82,
0x86,
0x82,
0x87,
0x82,
0x88,
0x82,
0x89,
0x82,
0x8A,
0x82,
0x8B,
0x82,
0x8C,
0x82,
0x8D,
0x82,
0x8E,
0x82,
0x8F,
0x82,
0x90,
0x82,
0x91,
0x82,
0x92,
0x82,
0x93,
0x82,
0x94,
0x82,
0x95,
0x82,
0x96,
0x82,
0x97,
0x82,
0x98,
0x82,
0x99,
0x82,
0x9A,
0x81,
0x6F,
0x81,
0x62,
0x81,
0x70,
0x81,
0x60,
/* padding */
0x00,
0x00,
static const u16 halftofull[95] = {
0x8140, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193,
0x8195, 0x8166, 0x8169, 0x816A, 0x8196, 0x817B,
0x8143, 0x817C, 0x8144, 0x815E, 0x824F, 0x8250,
0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256,
0x8257, 0x8258, 0x8146, 0x8147, 0x8183, 0x8181,
0x8184, 0x8148, 0x8197, 0x8260, 0x8261, 0x8262,
0x8263, 0x8264, 0x8265, 0x8266, 0x8267, 0x8268,
0x8269, 0x826A, 0x826B, 0x826C, 0x826D, 0x826E,
0x826F, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274,
0x8275, 0x8276, 0x8277, 0x8278, 0x8279, 0x816D,
0x818F, 0x816E, 0x814F, 0x8151, 0x8165, 0x8281,
0x8282, 0x8283, 0x8284, 0x8285, 0x8286, 0x8287,
0x8288, 0x8289, 0x828A, 0x828B, 0x828C, 0x828D,
0x828E, 0x828F, 0x8290, 0x8291, 0x8292, 0x8293,
0x8294, 0x8295, 0x8296, 0x8297, 0x8298, 0x8299,
0x829A, 0x816F, 0x8162, 0x8170, 0x8160,
};
COMPILER_STRIP_GATE(0x8039D39C, &halftofull);
/* 802DFDD8-802DFF60 2DA718 0188+00 2/2 0/0 0/0 .text getFontCode__10JUTResFontCFi */
#ifdef NONMATCHING
// still many issues
int JUTResFont::getFontCode(int param_0) const {
int ret = mInf1Ptr->width;
if ((getFontType() == 2) && (mMaxCode >= 0x8000U) && (param_0 >= 0x20) && (param_0 < 0x7FU)) {
param_0 = halftofull[param_0 - 32];
}
int j = 0;
for (int i = mMap1BlockNum; i > 0; j++, i--) {
if ((mpMapBlocks[j]->endCode <= param_0) && (param_0 <= mpMapBlocks[j]->numEntries)) {
ResFONT::MAP1* temp_r4 = mpMapBlocks[j];
if (temp_r4->startCode == 0) {
ret = param_0 - temp_r4->endCode;
break;
} else if (temp_r4->startCode == 2) {
ret = *(&mpMapBlocks[j]->mLeading + ((param_0 - mpMapBlocks[j]->endCode)));
break;
} else if (temp_r4->startCode == 3) {
u16* leading_temp = &temp_r4->mLeading;
int phi_r5 = 0;
int phi_r6_2 = temp_r4->numEntries - 1;
while (phi_r6_2 >= phi_r5) {
u32 temp_r3 = phi_r6_2 + phi_r5;
int temp_r7 = (int)((temp_r3 >> 0x1FU) + phi_r6_2 + phi_r5) >> 1;
if (param_0 < leading_temp[temp_r7 * 2]) {
phi_r6_2 = temp_r7 - 1;
continue;
}
if (param_0 > leading_temp[temp_r7 * 2]) {
phi_r5 = temp_r7 + 1;
continue;
}
ret = leading_temp[temp_r7 * 2 + 1];
break;
}
} else if (temp_r4->startCode == 1) {
u16* phi_r5_2 = NULL;
if (temp_r4->numEntries == 1) {
phi_r5_2 = &temp_r4->mLeading;
}
ret = convertSjis(param_0, phi_r5_2);
break;
}
break;
}
}
return ret;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -615,8 +567,14 @@ asm int JUTResFont::getFontCode(int param_0) const {
#include "asm/JSystem/JUtility/JUTResFont/getFontCode__10JUTResFontCFi.s"
}
#pragma pop
#endif
/* 802DFF60-802E00C4 2DA8A0 0164+00 1/0 0/0 0/0 .text loadImage__10JUTResFontFi11_GXTexMapID */
#ifdef NONMATCHING
asm void JUTResFont::loadImage(int param_0, _GXTexMapID param_1) {
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -625,16 +583,25 @@ asm void JUTResFont::loadImage(int param_0, _GXTexMapID param_1) {
#include "asm/JSystem/JUtility/JUTResFont/loadImage__10JUTResFontFi11_GXTexMapID.s"
}
#pragma pop
#endif
/* 802E00C4-802E0108 2DAA04 0044+00 1/1 0/0 0/0 .text convertSjis__10JUTResFontCFiPUs */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void JUTResFont::convertSjis(int param_0, u16* param_1) const {
nofralloc
#include "asm/JSystem/JUtility/JUTResFont/convertSjis__10JUTResFontCFiPUs.s"
int JUTResFont::convertSjis(int inChr, u16* inLead) const {
int tmp = inChr >> 8 & 0xFF;
int tmp2 = (u8)inChr - 0x40;
if (0x40 <= tmp2) {
tmp2--;
}
u16 lead = 0x31c;
if (inLead) {
lead = *inLead;
}
return tmp2 + (tmp - 0x88) * 0xbc + -0x5e + lead;
}
#pragma pop
/* 802E0108-802E0110 2DAA48 0008+00 1/0 0/0 0/0 .text isLeadByte_1Byte__7JUTFontFi */
bool JUTFont::isLeadByte_1Byte(int param_0) {