Finished decompiling font.c

This commit is contained in:
David Benepe
2022-10-02 17:20:43 -04:00
parent 2072a266b8
commit 51bdb867cf
2 changed files with 198 additions and 188 deletions
+8 -8
View File
@@ -113,15 +113,15 @@ s32 is_drumstick_unlocked(void) {
}
```
As of September 27th, 2022, this is our current score:
As of October 2nd, 2022, this is our current score:
```
========================================================
ADVENTURE ONE (ASM -> C Decompilation)
------------------- 31.46% Complete --------------------
# Decompiled functions: 1273
# GLOBAL_ASM remaining: 561
# NON_MATCHING functions: 15
# NON_EQUIVALENT WIP functions: 101
------------------- 31.77% Complete --------------------
# Decompiled functions: 1275
# GLOBAL_ASM remaining: 558
# NON_MATCHING functions: 14
# NON_EQUIVALENT WIP functions: 100
--------------------- Game Status ----------------------
Balloons: 16/47, Keys: 2/4, Trophies: 1/5
T.T. Amulets: 1/4, Wizpig Amulets: 1/4
@@ -131,13 +131,13 @@ As of September 27th, 2022, this is our current score:
ADVENTURE TWO (Cleanup & Documentation)
------------------- 5.39% Complete --------------------
# Documented functions: 195
# Undocumented remaining: 1639
# Undocumented remaining: 1638
--------------------- Game Status ----------------------
Balloons: 3/47, Keys: 0/4, Trophies: 0/5
T.T. Amulets: 0/4, Wizpig Amulets: 0/4
--------------------------------------------------------
We are collecting the fourth balloon on Timber's Island.
========================================================
========================================================
```
---
+190 -180
View File
@@ -262,171 +262,183 @@ UNUSED void func_800C4510(Gfx **displayList, s32 dialogueBoxID, s32 xpos, s32 yp
}
}
#ifdef NON_MATCHING
//A few minor regalloc differences are all that's left.
void func_800C45A4(Gfx **dlist, DialogueBoxBackground *arg1, char *text, AlignmentFlags alignmentFlags, f32 arg4) {
s32 temp_f4;
s32 temp_t9;
s32 ypos;
s32 xpos;
TextureHeader *texture;
s32 textureLrx;
s32 textureLry;
s32 textureS;
s32 textureT;
s32 textureUlx;
s32 textureUly;
s32 textureWidth;
s32 textureHeight;
s32 xAlignmentDiff;
s32 yAlignmentDiff;
s32 newTempY;
s32 var_t0;
s32 newData;
s32 textureIndex;
s32 lastTextureIndex;
FontData *fontData;
s32 charIndex;
char curChar;
lastTextureIndex = -1;
xAlignmentDiff = -1;
if (text != NULL) {
xpos = arg1->xpos;
ypos = arg1->ypos;
fontData = &gFonts[arg1->font];
gSPDisplayList((*dlist)++, dDialogueBoxBegin);
if (arg1 != gDialogueBoxBackground) {
temp_f4 = (((arg1->y2 - arg1->y1) + 1) / (f32)2) * arg4;
temp_t9 = (arg1->y1 + arg1->y2) >> 1;
gDPSetScissor((*dlist)++,
G_SC_NON_INTERLACE,
arg1->x1,
temp_t9 - temp_f4,
arg1->x2,
temp_t9 + temp_f4
);
}
if (alignmentFlags & 5) {
xAlignmentDiff = func_800C4DA0(text, xpos, arg1->font);
if (alignmentFlags & 1) {
xpos = (xpos - xAlignmentDiff) + 1;
} else {
xpos -= xAlignmentDiff >> 1;
}
}
if (alignmentFlags & 2) {
ypos = (ypos - fontData->unk22) + 1;
}
if (alignmentFlags & 8) {
ypos -= fontData->unk22 >> 1;
}
if (arg1->textBGColourA != 0) {
gDPSetEnvColor((*dlist)++, arg1->textBGColourR, arg1->textBGColourG, arg1->textBGColourB, arg1->textBGColourA);
if (xAlignmentDiff == -1) {
xAlignmentDiff = func_800C4DA0(text, xpos, arg1->font);
}
newTempY = (fontData->unk22 + ypos - 1);
gDkrDmaDisplayList((*dlist)++, OS_K0_TO_PHYSICAL(dDialogueBoxDrawModes[1]), 2);
gDPFillRectangle((*dlist)++,
(xpos + arg1->x1),
(ypos + arg1->y1),
(xpos + arg1->x1 + (0, xAlignmentDiff) - 1), //0 comma operator is likely a fakematch
(newTempY + arg1->y1)
);
gDPPipeSync((*dlist)++);
}
gDPSetPrimColor((*dlist)++, 0, 0, 255, 255, 255, arg1->opacity);
gDPSetEnvColor((*dlist)++, arg1->textColourR, arg1->textColourG, arg1->textColourB, arg1->textColourA);
gDkrDmaDisplayList((*dlist)++, OS_K0_TO_PHYSICAL(dDialogueBoxDrawModes[0]), 2);
gDPPipeSync((*dlist)++);
xpos += arg1->unk20;
ypos += arg1->unk22;
for (charIndex = 0; text[charIndex] != '\0' && arg1->y2 >= ypos; xpos += var_t0, charIndex++) {
curChar = text[charIndex];
newData = 0;
var_t0 = 0;
//Check the ASCII Range
if ((curChar < 0x21) || (curChar >= 0x80)) {
switch (curChar ) {
case ' ': //Space
xpos += fontData->unk24;
break;
case '\n': //Line Feed
xpos = arg1->unk20;
ypos += fontData->unk22;
break;
case '\t': //Tab
xpos += fontData->unk26 - ((xpos - arg1->unk20) % fontData->unk26);
break;
case '\v': //VT - Vertical Tab
ypos += fontData->unk22;
break;
case '\r': //Carriage Return
xpos = arg1->unk20;
break;
default:
xpos += fontData->unk24;
break;
}
} else {
curChar -= 0x20; //Convert lowercase to upper case
textureIndex = fontData->unk100[curChar].unk0;
if (textureIndex != 0xFF) {
newData = 1;
if (lastTextureIndex != textureIndex) {
lastTextureIndex = textureIndex;
texture = fontData->texturePointers[textureIndex];
gDkrDmaDisplayList((*dlist)++, OS_PHYSICAL_TO_K0(texture->cmd), texture->numberOfCommands);
}
textureWidth = fontData->unk100[curChar].unk2;
textureHeight = fontData->unk100[curChar].unk3;
textureS = fontData->unk100[curChar].unk4;
textureT = fontData->unk100[curChar].unk5;
xAlignmentDiff = fontData->unk100[curChar].unk6;
yAlignmentDiff = fontData->unk100[curChar].unk7;
var_t0 = (fontData->unk20 == 0) ? fontData->unk100[curChar].unk1 : fontData->unk20;
}
}
if (newData) {
textureUlx = ((arg1->x1 + xpos) + textureWidth) * 4;
textureUly = (arg1->y1 + ypos + textureHeight) * 4;
textureLrx = (xAlignmentDiff * 4) + textureUlx;
textureLry = (yAlignmentDiff * 4) + textureUly;
textureS *= 32; //upper left coordinate for the texture derived from X
textureT *= 32; //upper left coordinate for the texture derived from Y
if ((textureUlx < 0) && (textureLrx > 0)) {
textureS += -textureUlx * 8;
textureUlx = 0;
}
if ((textureUly < 0) && (textureLry > 0)) {
textureT += -textureUly * 8;
textureUly = 0;
}
gSPTextureRectangle((*dlist)++, textureUlx, textureUly, textureLrx, textureLry, 0, textureS, textureT, 1024, 1024);
}
if (D_8012A7F0 && (var_t0 != 0)) {
var_t0--;
}
}
arg1->xpos = xpos - arg1->unk20;
arg1->ypos = ypos - arg1->unk22;
gDPPipeSync((*dlist)++);
if (arg1 != gDialogueBoxBackground) {
func_80067A3C(dlist);
}
func_8007B3D0(dlist);
gDPPipeSync((*dlist)++);
void func_800C45A4(Gfx **dlist, DialogueBoxBackground *arg1, char *text, AlignmentFlags alignmentFlags, f32 arg4)
{
s32 temp_f4;
s32 temp_t9;
s32 ypos;
s32 xpos;
TextureHeader *texture;
s32 textureLrx;
s32 textureLry;
s32 textureS;
s32 textureT;
s32 textureUlx;
s32 textureUly;
s32 textureWidth;
s32 textureHeight;
s32 xAlignmentDiff;
s32 yAlignmentDiff;
s32 lastTextureIndex;
s32 charIndex;
s32 var_t0;
s32 newData;
s32 textureIndex;
FontData *fontData;
s32 newTempX;
s32 newTempY;
char curChar;
xAlignmentDiff = -1;
lastTextureIndex = -1;
if (text != ((void *) 0))
{
textureLry = 0;
xpos = arg1->xpos;
ypos = arg1->ypos;
fontData = &gFonts[arg1->font];
gSPDisplayList((*dlist)++, dDialogueBoxBegin);
if (arg1 != gDialogueBoxBackground)
{
temp_f4 = (((arg1->y2 - arg1->y1) + 1) / ((f32) 2)) * arg4;
temp_t9 = (arg1->y1 + arg1->y2) >> 1;
gDPSetScissor((*dlist)++, 0, arg1->x1, temp_t9 - temp_f4, arg1->x2, temp_t9 + temp_f4);
}
if (alignmentFlags & 5)
{
xAlignmentDiff = func_800C4DA0(text, xpos, arg1->font);
if (alignmentFlags & 1)
{
xpos = (xpos - xAlignmentDiff) + 1;
}
else
{
xpos -= xAlignmentDiff >> 1;
}
}
if (alignmentFlags & 2)
{
ypos = (ypos - fontData->unk22) + 1;
}
if (alignmentFlags & 8)
{
ypos -= fontData->unk22 >> 1;
}
if (arg1->textBGColourA != 0)
{
gDPSetEnvColor((*dlist)++, arg1->textBGColourR, arg1->textBGColourG, arg1->textBGColourB, arg1->textBGColourA);
if (xAlignmentDiff == -1)
{
xAlignmentDiff = func_800C4DA0(text, xpos, arg1->font);
}
newTempX = xpos + xAlignmentDiff - 1;
newTempY = (ypos + fontData->unk22 - 1); // Need to make newTempY t1 instead of a1.
gDkrDmaDisplayList((*dlist)++, (u32) (((char *) dDialogueBoxDrawModes[1]) - 0x80000000), 2);
gDPFillRectangle((*dlist)++, xpos + arg1->x1, ypos + arg1->y1, newTempX + arg1->x1, newTempY + arg1->y1);
gDPPipeSync((*dlist)++);
}
gDPSetPrimColor((*dlist)++, textureLry, 0, 255, 255, 255, arg1->opacity);
gDPSetEnvColor((*dlist)++, arg1->textColourR, arg1->textColourG, arg1->textColourB, arg1->textColourA);
gDkrDmaDisplayList((*dlist)++, (u32) (((char *) dDialogueBoxDrawModes[0]) - 0x80000000), 2);
gDPPipeSync((*dlist)++);
xpos += arg1->unk20;
ypos += arg1->unk22;
for (charIndex = 0; (text[charIndex] != '\0') && (arg1->y2 >= ypos); xpos += var_t0, charIndex++)
{
curChar = text[charIndex];
newData = 0;
var_t0 = 0;
if ((curChar < 0x21) || (curChar >= 0x80))
{
switch (curChar)
{
case ' ':
xpos += fontData->unk24;
break;
case '\n':
xpos = arg1->unk20;
ypos += fontData->unk22;
break;
case '\t':
xpos += fontData->unk26 - ((xpos - arg1->unk20) % fontData->unk26);
break;
case '\v':
ypos += fontData->unk22;
break;
case '\r':
xpos = arg1->unk20;
break;
default:
xpos += fontData->unk24;
break;
}
}
else
{
curChar -= 0x20;
textureIndex = fontData->unk100[curChar].unk0;
if (textureIndex != 0xFF)
{
newData = 1;
if (lastTextureIndex != textureIndex)
{
lastTextureIndex = textureIndex;
texture = fontData->texturePointers[textureIndex];
gDkrDmaDisplayList((*dlist)++, OS_PHYSICAL_TO_K0(texture->cmd), texture->numberOfCommands);
}
textureWidth = fontData->unk100[curChar].unk2;
textureHeight = fontData->unk100[curChar].unk3;
textureS = fontData->unk100[curChar].unk4;
textureT = fontData->unk100[curChar].unk5;
xAlignmentDiff = fontData->unk100[curChar].unk6;
yAlignmentDiff = fontData->unk100[curChar].unk7;
var_t0 = (fontData->unk20 == 0) ? (fontData->unk100[curChar].unk1) : (fontData->unk20);
newData = 1;
}
}
if (newData)
{
textureUlx = ((arg1->x1 + xpos) + textureWidth) * 4;
textureUly = ((arg1->y1 + ypos) + textureHeight) * 4;
textureLrx = (xAlignmentDiff * 4) + textureUlx;
newTempY = (yAlignmentDiff * 4) + textureUly;
textureS *= 32;
textureT *= 32;
if ((textureUlx < 0) && (textureLrx > 0))
{
textureS += (-textureUlx) * 8;
textureUlx = 0;
}
if ((textureUly <= (0 - 1)) && (newTempY > 0))
{
textureT += (-textureUly) * 8;
textureUly = 0;
}
gSPTextureRectangle((*dlist)++, textureUlx, textureUly, textureLrx, newTempY, 0, textureS, textureT, 1024, 1024);
if(lastTextureIndex);
}
if (D_8012A7F0 && var_t0) {
var_t0--;
}
}
arg1->xpos = xpos - arg1->unk20;
arg1->ypos = ypos - arg1->unk22;
gDPPipeSync((*dlist)++);
if (arg1 != gDialogueBoxBackground)
{
func_80067A3C(dlist);
}
func_8007B3D0(dlist);
gDPPipeSync((*dlist)++);
}
}
#else
GLOBAL_ASM("asm/non_matchings/font/func_800C45A4.s")
#endif
s32 func_800C4DA0(char *text, s32 x, s32 font) {
s32 diffX, thisDiffX;
@@ -564,15 +576,16 @@ void func_800C510C(s32 dialogueBoxID, char *text, s32 arg2, s32 arg3) {
render_dialogue_text(dialogueBoxID, gDialogueBoxBackground[dialogueBoxID].xpos, gDialogueBoxBackground[dialogueBoxID].ypos, text, arg2, arg3);
}
#ifdef NON_EQUIVALENT
void *render_dialogue_text(s32 dialogueBoxID, s32 posX, s32 posY, char *text, s32 arg4, s32 flags) {
char parsedNumber;
DialogueBox *textBox;
FontData *fontData;
s32 temp_v0_2;
s32 i;
s32 var_a0;
char buffer[256];
unk8012A7EC *ret;
DialogueBox *textBox;
s32 i;
DialogueBoxBackground *bg;
FontData *fontData;
DialogueBox **textBoxPtr;
if (text == NULL) {
return NULL;
@@ -595,8 +608,8 @@ void *render_dialogue_text(s32 dialogueBoxID, s32 posX, s32 posY, char *text, s3
if (bg->font != FONT_UNK_FF) {
fontData = &gFonts[bg->font];
if (flags & 5) {
parse_string_with_number(text, &parsedNumber, arg4);
temp_v0_2 = func_800C4DA0(&parsedNumber, posX, bg->font);
parse_string_with_number(text, &buffer, arg4);
temp_v0_2 = func_800C4DA0(&buffer, posX, bg->font);
if (flags & 1) {
posX = (posX - temp_v0_2) + 1;
} else {
@@ -614,21 +627,21 @@ void *render_dialogue_text(s32 dialogueBoxID, s32 posX, s32 posY, char *text, s3
bg->textBox = (DialogueBox *) ret;
ret->nextBox = NULL;
} else {
textBox = bg->textBox;
//Feels like this should be a while loop, but it matches worse
if ((bg->textBox != NULL) && (arg4 < bg->textBox->textNum)) {
do {
textBox = textBox->nextBox;
} while (textBox != NULL && arg4 < textBox->textNum);
textBoxPtr = &bg->textBox;
textBox = *textBoxPtr;
while (textBox != NULL && arg4 < textBox->textNum) {
textBoxPtr = &textBox->nextBox;
textBox = textBox->nextBox;
}
*textBoxPtr = ret;
ret->nextBox = textBox;
}
ret->unk1 = arg4;
ret->text = text;
ret->posX = posX;
ret->posY = posY;
ret->unkC = 0;
ret->unkE = 0;
ret->posY = posY;
ret->textColourR = bg->textColourR;
ret->textColourG = bg->textColourG;
ret->textColourB = bg->textColourB;
@@ -644,9 +657,6 @@ void *render_dialogue_text(s32 dialogueBoxID, s32 posX, s32 posY, char *text, s3
return ret;
}
#else
GLOBAL_ASM("asm/non_matchings/font/render_dialogue_text.s")
#endif
/**
* Unused function that moved a dialogue box ID to the front of the stack.