Skip to content

Commit

Permalink
sub_803DEC8
Browse files Browse the repository at this point in the history
  • Loading branch information
DizzyEggg committed Sep 22, 2024
1 parent c07d06e commit 3c5cc45
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 134 deletions.
129 changes: 0 additions & 129 deletions asm/code_803D110.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,135 +6,6 @@
.text


thumb_func_start CalcStringWidth
CalcStringWidth:
push {r4,r5,lr}
adds r4, r0, 0
movs r5, 0
b _0803DEBA
_0803DE84:
ldrb r1, [r4]
adds r4, 0x1
cmp r1, 0x23
bne _0803DE90
adds r5, 0x8
b _0803DEBA
_0803DE90:
cmp r1, 0x20
bne _0803DE98
adds r5, 0xC
b _0803DEBA
_0803DE98:
movs r0, 0x80
ands r0, r1
cmp r0, 0
beq _0803DEAC
ldrb r0, [r4]
cmp r0, 0
beq _0803DEAC
lsls r1, 8
orrs r1, r0
adds r4, 0x1
_0803DEAC:
adds r0, r1, 0
bl sub_803DEC8
cmp r0, 0
beq _0803DEBA
ldrb r0, [r0, 0x6]
adds r5, r0
_0803DEBA:
ldrb r0, [r4]
cmp r0, 0
bne _0803DE84
adds r0, r5, 0
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end CalcStringWidth

thumb_func_start sub_803DEC8
sub_803DEC8:
push {r4,r5,lr}
adds r3, r0, 0
ldr r0, _0803DEFC
ldr r0, [r0]
ldr r0, [r0, 0x4]
ldr r5, [r0]
ldr r0, _0803DF00
adds r1, r3, r0
ldr r0, _0803DF04
cmp r1, r0
bhi _0803DF08
movs r2, 0xFF
ands r2, r3
movs r1, 0xFF
lsls r1, 8
ands r1, r3
asrs r1, 8
subs r2, 0x20
subs r1, 0xF8
lsls r0, r1, 3
subs r0, r1
lsls r0, 5
adds r0, r2
lsls r0, 3
adds r1, r5, r0
b _0803DF56
.align 2, 0
_0803DEFC: .4byte gDungeonNameBannerFontFile
_0803DF00: .4byte 0xffff0800
_0803DF04: .4byte 0x000007fe
_0803DF08:
movs r4, 0
ldr r0, _0803DF1C
ldr r0, [r0]
subs r2, r0, 0x1
cmp r4, r2
bge _0803DF48
lsrs r0, r2, 31
adds r0, r2, r0
b _0803DF3A
.align 2, 0
_0803DF1C: .4byte gDungeonNameBannerFont
_0803DF20:
lsls r0, r1, 3
adds r0, r5
ldrh r0, [r0, 0x4]
cmp r0, r3
bge _0803DF2E
adds r4, r1, 0x1
b _0803DF30
_0803DF2E:
adds r2, r1, 0
_0803DF30:
cmp r4, r2
bge _0803DF48
adds r0, r4, r2
lsrs r1, r0, 31
adds r0, r1
_0803DF3A:
asrs r1, r0, 1
lsls r0, r1, 3
adds r0, r5
ldrh r0, [r0, 0x4]
cmp r0, r3
bne _0803DF20
adds r4, r1, 0
_0803DF48:
lsls r0, r4, 3
adds r1, r5, r0
ldrh r0, [r1, 0x4]
cmp r0, r3
beq _0803DF56
adds r1, r5, 0
adds r1, 0x8
_0803DF56:
adds r0, r1, 0
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end sub_803DEC8

thumb_func_start sub_803DF60
sub_803DF60:
push {r4-r7,lr}
Expand Down
80 changes: 75 additions & 5 deletions src/code_803D110.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern const char gUnknown_80F6100[]; // "banfont"
extern struct FileArchive gDungeonFileArchive;
extern OpenedFile *gDungeonNameBannerPalette;
extern OpenedFile *gDungeonNameBannerFontFile;
extern void *gDungeonNameBannerFont;
extern s32 gDungeonNameBannerFont;

struct UnkDungeonFileData
{
Expand Down Expand Up @@ -533,7 +533,7 @@ void ShowDungeonNameBanner(void)

gDungeonNameBannerPalette = OpenFileAndGetFileDataPtr(gUnknown_80F60F8, &gDungeonFileArchive);
gDungeonNameBannerFontFile = OpenFileAndGetFileDataPtr(gUnknown_80F6100, &gDungeonFileArchive);
gDungeonNameBannerFont = ((u8**) gDungeonNameBannerFontFile->data)[1];
gDungeonNameBannerFont = (s32)(((u8**) gDungeonNameBannerFontFile->data)[1]);
for (i = 0; i < 16; i++) {
SetBGPaletteBufferColorArray(i + 224, (void*) &((u8**) gDungeonNameBannerPalette->data)[i]); // Todo: Fix when there is a better idea what to do with structs from opened files
}
Expand Down Expand Up @@ -604,12 +604,11 @@ s32 sub_803DC14(const u8 *dungName, s32 strWidth, s32 a2)
struct UnkStruct_sub_803DC6C
{
u8 *unk0;
u8 unk4;
u8 unk5;
u16 unk4;
u8 unk6;
};

struct UnkStruct_sub_803DC6C *sub_803DEC8(u32 chr);
struct UnkStruct_sub_803DC6C *sub_803DEC8(s32 chr);
void sub_803DD30(u8 *a0, u32 *a1);

extern const u32 gUnknown_80F6120[];
Expand Down Expand Up @@ -717,3 +716,74 @@ void sub_803DD30(u8 *a0, u32 *a1)
}
}

// Could be a misnomer?
s32 CalcStringWidth(const u8 *dungName)
{
s32 w = 0;

while (*dungName != '\0') {
u32 currChar = *(dungName++);
if (currChar == '#') {
w += 8;
}
else if (currChar == ' ') {
w += 12;
}
else {
struct UnkStruct_sub_803DC6C *strPtr;

if (currChar & 0x80 && *dungName != '\0') {
currChar = (currChar << 8) | *dungName;
dungName++;
}
strPtr = sub_803DEC8(currChar);
if (strPtr != NULL) {
w += strPtr->unk6;
}
}
}

return w;
}

struct UnkStruct_sub_803DC6C *sub_803DEC8(s32 chr)
{
s32 r2, r4;
struct UnkStruct_sub_803DC6C *ret;
struct UnkStruct_sub_803DC6C *strPtr = *((struct UnkStruct_sub_803DC6C **) gDungeonNameBannerFontFile->data);
// Fakematch? Or just magic numbers which will make more sense once this file is documented?
if (chr > 63487 && chr < 65535)
{
s32 r2 = chr & 0xFF;
s32 r1 = (chr & 0xFF00) / 256;
r2 -= 32;
r1 -= 248;
ret = &strPtr[r1 * 224 + r2];
}
else
{
r4 = 0;
r2 = gDungeonNameBannerFont - 1;
while (r4 < r2) {
s32 r1 = (r4 + r2) / 2;
if (strPtr[r1].unk4 == chr) {
r4 = r1;
break;
}
else if (strPtr[r1].unk4 < chr) {
r4 = r1 + 1;
}
else {
r2 = r1;
}
}

ret = &strPtr[r4];
if (ret->unk4 != chr)
ret = &strPtr[1];


}
return ret;
};

0 comments on commit 3c5cc45

Please sign in to comment.