Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text.s #222

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Text.s #222

wants to merge 10 commits into from

Conversation

DizzyEggg
Copy link
Contributor

WIP

const struct unkChar *ret;
const struct unkChar *strPtr = gCharmaps[gCurrentCharmap]->unk4;
// Fakematch? Or just magic numbers which will make more sense once this file is documented?
if (chr > 63487 && chr < 65535)
Copy link
Contributor

@mateon1 mateon1 Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 0xf800 to 0xfffe inclusive, which matches the logic within the block below. Looks like it accesses the raw character data by index in the kanji file (encoded as 0xf820..0xfffe, avoiding ASCII control characters), completely ignoring the 'charcode' field. I don't think this character encoding is used in the ROM, was likely used to test the fonts.

Also, the CharMapStruct corresponds to my struct_kanji in Ghidra, unk0 is s32 len, unk4 is a struct_kanji_char*.
That struct corresponds to your unkChar and is struct struct_kanji_char { u32 *data; u16 charcode; u16 width /* in pixels */; u8 unk8; u8 unk9; u8 flags; u8 fillB; }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And just verified in Ghidra, no control flow can reach this function with this range of values for chr, so this is effectively dead code.

src/text2.c Outdated
}
}

u32 sub_8007FA8(u32 a0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reverses the nybbles in a u32, AKA flips pixels horizontally in a tile's row of data.
Probably worth renaming appropriately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like FlipPixelsHorizontally works?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

u32 *r2, *r1;

CpuCopy(strPtr->unk28, strPtr->unk18, 0xD00);
// The reason for void casts is because we want to add 0xD00/r5 directly to pointers. Because pointers are u32, without the casts, it would multiply the value by 4.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely a part of the macro or inline that invokes CpuCopy. It advances the pointers (typed void* or u8*) by the amount of copied bytes.

@DizzyEggg DizzyEggg marked this pull request as ready for review October 1, 2024 10:36
@DizzyEggg
Copy link
Contributor Author

Ready for review

src/text2.c Outdated
break;
}
}
else if (chr == 0x60) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these chr comparisons in the last three functions should use actual chars, since they are meaningful characters.
You can use L'x' to make the char constant have a u32 value.

src/text2.c Outdated
sp.unk0 = sp.unkC;
sp.unk2 += 5;
}
else if (sp.unk34 == 0x60) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, use long char comparisons

src/text2.c Outdated

while (1)
{
if (*str == 0x2E) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'.'

sp->unk20 = 1;
break;
}
else if (str[1] == 0x7E) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these should be chars

if ((r1 % 8) != 0)
return (r1 / 8) + 1;
else
return r1 / 8;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to comment a way to possibly make this match with neater code, but realized they actually wrote this out like this.
If it was a u32, this would just be a ceiling division. This is not that. It's nonsense for negative numbers.

case 68:
case 78:
return 6;
case 87:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these a0 comparisons should use chars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants