Decompile font.s -> font.c

This commit is contained in:
PikalaxALT 2022-03-09 13:36:04 -05:00
parent 3e31982dbe
commit 0094a464a7
8 changed files with 328 additions and 626 deletions

View File

@ -1,621 +0,0 @@
.include "asm/macros.inc"
.include "global.inc"
.rodata
_020F56C0:
.short 0x0000, 0x0000
.short 0x0001, 0x0000
.short 0x0002, 0x0000
.short 0x0003, 0x0000
.short 0x0004, 0x0000
.short 0x000A, 0x0000
_020F56D8:
.byte 0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02
.byte 0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02
.byte 0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02
.byte 0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02
.byte 0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02
.byte 0x0A, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.bss
_0211188C:
.space 4
_02111890:
.space 0xBC
.text
thumb_func_start sub_02002CA8
sub_02002CA8: ; 0x02002CA8
push {r4, lr}
ldr r0, _02002CE0 ; =_02111890
ldr r4, _02002CE4 ; =_0211188C
mov r1, #0
str r0, [r4]
add r2, r1, #0
add r0, r1, #0
_02002CB6:
ldr r3, [r4]
add r3, r3, r2
add r3, #0x84
str r0, [r3]
ldr r3, [r4]
add r3, r3, r2
add r3, #0x9c
str r0, [r3]
ldr r3, [r4]
add r2, r2, #4
add r3, r3, r1
add r3, #0xb4
add r1, r1, #1
strb r0, [r3]
cmp r1, #6
blo _02002CB6
ldr r0, _02002CE8 ; =_020F56D8
bl sub_0201FFE0
pop {r4, pc}
nop
_02002CE0: .word _02111890
_02002CE4: .word _0211188C
_02002CE8: .word _020F56D8
thumb_func_end sub_02002CA8
thumb_func_start sub_02002CEC
sub_02002CEC: ; 0x02002CEC
push {r3, r4, r5, lr}
add r5, r0, #0
ldr r0, _02002D34 ; =_0211188C
lsl r4, r5, #2
ldr r0, [r0]
add r2, r0, r4
add r2, #0x9c
ldr r2, [r2]
cmp r2, #0
bne _02002D28
str r1, [sp]
ldr r1, _02002D38 ; =_020F56C0
ldr r3, _02002D3C ; =_020F56C0 + 2
ldrh r1, [r1, r4]
ldrh r3, [r3, r4]
mov r0, #0x10 ; graphic/font.narc
mov r2, #1
bl FontData_new
ldr r2, _02002D34 ; =_0211188C
ldr r1, [r2]
add r1, r1, r4
add r1, #0x9c
str r0, [r1]
ldr r0, [r2]
mov r1, #1
add r0, r0, r5
add r0, #0xb4
strb r1, [r0]
pop {r3, r4, r5, pc}
_02002D28:
add r0, #0xb4
ldrsb r1, [r0, r5]
add r1, r1, #1
strb r1, [r0, r5]
pop {r3, r4, r5, pc}
nop
_02002D34: .word _0211188C
_02002D38: .word _020F56C0
_02002D3C: .word _020F56C0 + 2
thumb_func_end sub_02002CEC
thumb_func_start sub_02002D40
sub_02002D40: ; 0x02002D40
push {r3, r4, r5, lr}
add r4, r0, #0
add r5, r1, #0
cmp r4, #6
blt _02002D4E
bl GF_AssertFail
_02002D4E:
ldr r0, _02002D78 ; =_0211188C
lsl r4, r4, #2
ldr r0, [r0]
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
bne _02002D62
bl GF_AssertFail
_02002D62:
ldr r0, _02002D78 ; =_0211188C
mov r1, #0
ldr r0, [r0]
add r2, r5, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
bl FontData_ModeSwitch
pop {r3, r4, r5, pc}
nop
_02002D78: .word _0211188C
thumb_func_end sub_02002D40
thumb_func_start sub_02002D7C
sub_02002D7C: ; 0x02002D7C
push {r4, lr}
add r4, r0, #0
cmp r4, #6
blt _02002D88
bl GF_AssertFail
_02002D88:
ldr r0, _02002DB0 ; =_0211188C
lsl r4, r4, #2
ldr r0, [r0]
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
bne _02002D9C
bl GF_AssertFail
_02002D9C:
ldr r0, _02002DB0 ; =_0211188C
mov r1, #1
ldr r0, [r0]
mov r2, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
bl FontData_ModeSwitch
pop {r4, pc}
.balign 4, 0
_02002DB0: .word _0211188C
thumb_func_end sub_02002D7C
thumb_func_start sub_02002DB4
sub_02002DB4: ; 0x02002DB4
push {r3, r4, r5, r6, r7, lr}
add r4, r0, #0
cmp r4, #6
blt _02002DC0
bl GF_AssertFail
_02002DC0:
ldr r0, _02002E74 ; =_0211188C
ldr r0, [r0]
add r1, r0, r4
mov r0, #0xb4
ldrsb r0, [r1, r0]
cmp r0, #0
bne _02002DD2
bl GF_AssertFail
_02002DD2:
ldr r0, _02002E74 ; =_0211188C
ldr r1, [r0]
add r1, #0xb4
ldrsb r0, [r1, r4]
cmp r0, #0
ble _02002DE2
sub r0, r0, #1
strb r0, [r1, r4]
_02002DE2:
ldr r0, _02002E74 ; =_0211188C
ldr r6, [r0]
mov r0, #0xb4
add r1, r6, r4
ldrsb r0, [r1, r0]
cmp r0, #0
bne _02002E70
lsl r7, r4, #2
add r0, r6, r7
add r0, #0x84
ldr r0, [r0]
mov ip, r0
cmp r0, #0
beq _02002E50
ldr r2, _02002E78 ; =_020F56C0
mov r1, #0
ldrh r0, [r2, r7]
add r3, r6, #0
_02002E06:
cmp r1, r4
beq _02002E26
ldrh r5, [r2]
cmp r5, r0
bne _02002E26
add r5, r3, #0
add r5, #0x9c
ldr r5, [r5]
cmp r5, #0
beq _02002E26
lsl r0, r1, #2
add r2, r6, r0
add r2, #0x84
mov r0, ip
str r0, [r2]
b _02002E30
_02002E26:
add r1, r1, #1
add r2, r2, #4
add r3, r3, #4
cmp r1, #6
blo _02002E06
_02002E30:
cmp r1, #6
bne _02002E50
ldr r0, _02002E74 ; =_0211188C
lsl r5, r4, #2
ldr r0, [r0]
add r0, r0, r5
add r0, #0x84
ldr r0, [r0]
bl FreeToHeap
ldr r0, _02002E74 ; =_0211188C
mov r1, #0
ldr r0, [r0]
add r0, r0, r5
add r0, #0x84
str r1, [r0]
_02002E50:
ldr r0, _02002E74 ; =_0211188C
ldr r0, [r0]
add r0, r0, r7
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
beq _02002E70
bl FontData_delete
ldr r0, _02002E74 ; =_0211188C
mov r2, #0
ldr r1, [r0]
lsl r0, r4, #2
add r0, r1, r0
add r0, #0x9c
str r2, [r0]
_02002E70:
pop {r3, r4, r5, r6, r7, pc}
nop
_02002E74: .word _0211188C
_02002E78: .word _020F56C0
thumb_func_end sub_02002DB4
thumb_func_start sub_02002E7C
sub_02002E7C: ; 0x02002E7C
push {r3, lr}
ldr r2, _02002E94 ; =_0211188C
lsl r0, r0, #2
ldr r2, [r2]
add r0, r2, r0
add r0, #0x9c
ldr r0, [r0]
bl TryLoadGlyph
ldr r0, _02002E94 ; =_0211188C
ldr r0, [r0]
pop {r3, pc}
.balign 4, 0
_02002E94: .word _0211188C
thumb_func_end sub_02002E7C
thumb_func_start sub_02002E98
sub_02002E98: ; 0x02002E98
push {r4, lr}
add r3, r1, #0
add r3, #0x20
ldrb r2, [r3, #1]
lsl r2, r2, #0x18
lsr r2, r2, #0x1f
bne _02002EC0
ldrb r2, [r3]
mov r4, #0xf
lsl r0, r0, #0x18
bic r2, r4
lsr r4, r0, #0x18
mov r0, #0xf
and r0, r4
orr r0, r2
strb r0, [r3]
ldrb r2, [r3, #1]
mov r0, #0x80
orr r0, r2
strb r0, [r3, #1]
_02002EC0:
add r0, r1, #0
bl RenderText
pop {r4, pc}
thumb_func_end sub_02002E98
thumb_func_start sub_02002EC8
sub_02002EC8: ; 0x02002EC8
push {r4, r5, r6, lr}
lsl r4, r0, #2
ldr r0, _02002EF8 ; =_0211188C
add r5, r1, #0
ldr r0, [r0]
add r6, r2, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
bne _02002EE2
bl GF_AssertFail
_02002EE2:
ldr r0, _02002EF8 ; =_0211188C
add r1, r5, #0
ldr r0, [r0]
add r2, r6, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
bl GetStringWidth
pop {r4, r5, r6, pc}
nop
_02002EF8: .word _0211188C
thumb_func_end sub_02002EC8
thumb_func_start sub_02002EFC
sub_02002EFC: ; 0x02002EFC
push {r4, r5, r6, lr}
lsl r4, r0, #2
ldr r0, _02002F2C ; =_0211188C
add r5, r1, #0
ldr r0, [r0]
add r6, r2, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
bne _02002F16
bl GF_AssertFail
_02002F16:
ldr r0, _02002F2C ; =_0211188C
add r1, r5, #0
ldr r0, [r0]
add r2, r6, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
bl GetStringWidthFirstLine
pop {r4, r5, r6, pc}
nop
_02002F2C: .word _0211188C
thumb_func_end sub_02002EFC
thumb_func_start sub_02002F30
sub_02002F30: ; 0x02002F30
push {r4, r5, r6, lr}
lsl r4, r0, #2
ldr r0, _02002F64 ; =_0211188C
add r5, r1, #0
ldr r0, [r0]
add r6, r2, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
bne _02002F4A
bl GF_AssertFail
_02002F4A:
add r0, r5, #0
bl String_c_str
add r1, r0, #0
ldr r0, _02002F64 ; =_0211188C
add r2, r6, #0
ldr r0, [r0]
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
bl GetStringWidth
pop {r4, r5, r6, pc}
.balign 4, 0
_02002F64: .word _0211188C
thumb_func_end sub_02002F30
thumb_func_start sub_02002F68
sub_02002F68: ; 0x02002F68
push {r4, r5, r6, lr}
lsl r4, r0, #2
ldr r0, _02002FA8 ; =_0211188C
add r6, r1, #0
ldr r0, [r0]
add r5, r2, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
bne _02002F82
bl GF_AssertFail
_02002F82:
add r0, r5, #0
bl StringSetEmpty
add r0, r5, #0
add r1, r6, #0
bl StringCat_HandleTrainerName
add r0, r5, #0
bl String_c_str
add r1, r0, #0
ldr r0, _02002FA8 ; =_0211188C
ldr r0, [r0]
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
bl StringAllCharsValid
pop {r4, r5, r6, pc}
.balign 4, 0
_02002FA8: .word _0211188C
thumb_func_end sub_02002F68
thumb_func_start GetFontAttribute
GetFontAttribute: ; 0x02002FAC
mov r2, #0
cmp r1, #7
bhi _0200300C
add r1, r1, r1
add r1, pc
ldrh r1, [r1, #6]
lsl r1, r1, #0x10
asr r1, r1, #0x10
add pc, r1
_02002FBE: ; jump table
.short _02002FCE - _02002FBE - 2 ; case 0
.short _02002FD6 - _02002FBE - 2 ; case 1
.short _02002FDE - _02002FBE - 2 ; case 2
.short _02002FE6 - _02002FBE - 2 ; case 3
.short _02002FEE - _02002FBE - 2 ; case 4
.short _02002FF6 - _02002FBE - 2 ; case 5
.short _02002FFE - _02002FBE - 2 ; case 6
.short _02003006 - _02002FBE - 2 ; case 7
_02002FCE:
lsl r1, r0, #3
ldr r0, _02003010 ; =_020F56D8
ldrb r2, [r0, r1]
b _0200300C
_02002FD6:
lsl r1, r0, #3
ldr r0, _02003014 ; =_020F56D8 + 1
ldrb r2, [r0, r1]
b _0200300C
_02002FDE:
lsl r1, r0, #3
ldr r0, _02003018 ; =_020F56D8 + 2
ldrb r2, [r0, r1]
b _0200300C
_02002FE6:
lsl r1, r0, #3
ldr r0, _0200301C ; =_020F56D8 + 3
ldrb r2, [r0, r1]
b _0200300C
_02002FEE:
lsl r1, r0, #3
ldr r0, _02003020 ; =_020F56D8 + 4
ldrb r2, [r0, r1]
b _0200300C
_02002FF6:
lsl r1, r0, #3
ldr r0, _02003024 ; =_020F56D8 + 5
ldrb r2, [r0, r1]
b _0200300C
_02002FFE:
lsl r1, r0, #3
ldr r0, _02003028 ; =_020F56D8 + 6
ldrb r2, [r0, r1]
b _0200300C
_02003006:
lsl r1, r0, #3
ldr r0, _0200302C ; =_020F56D8 + 7
ldrb r2, [r0, r1]
_0200300C:
add r0, r2, #0
bx lr
.balign 4, 0
_02003010: .word _020F56D8
_02003014: .word _020F56D8 + 1
_02003018: .word _020F56D8 + 2
_0200301C: .word _020F56D8 + 3
_02003020: .word _020F56D8 + 4
_02003024: .word _020F56D8 + 5
_02003028: .word _020F56D8 + 6
_0200302C: .word _020F56D8 + 7
thumb_func_end GetFontAttribute
thumb_func_start sub_02003030
sub_02003030: ; 0x02003030
push {r4, lr}
sub sp, #8
add r4, r0, #0
mov r0, #0x20
str r0, [sp]
add r3, r1, #0
str r2, [sp, #4]
mov r0, #0x10
mov r1, #7
add r2, r4, #0
bl GfGfxLoader_GXLoadPal
add sp, #8
pop {r4, pc}
thumb_func_end sub_02003030
thumb_func_start sub_0200304C
sub_0200304C: ; 0x0200304C
push {r4, lr}
sub sp, #8
add r4, r0, #0
mov r0, #0x20
str r0, [sp]
add r3, r1, #0
str r2, [sp, #4]
mov r0, #0x10
mov r1, #8
add r2, r4, #0
bl GfGfxLoader_GXLoadPal
add sp, #8
pop {r4, pc}
thumb_func_end sub_0200304C
thumb_func_start sub_02003068
sub_02003068: ; 0x02003068
push {r4, r5, r6, lr}
lsl r4, r0, #2
ldr r0, _0200309C ; =_0211188C
add r5, r1, #0
ldr r0, [r0]
add r6, r2, #0
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
bne _02003082
bl GF_AssertFail
_02003082:
add r0, r5, #0
bl String_c_str
add r1, r0, #0
ldr r0, _0200309C ; =_0211188C
add r2, r6, #0
ldr r0, [r0]
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
bl GetStringWidthMultiline
pop {r4, r5, r6, pc}
.balign 4, 0
_0200309C: .word _0211188C
thumb_func_end sub_02003068
thumb_func_start sub_020030A0
sub_020030A0: ; 0x020030A0
push {r4, lr}
add r4, r3, #0
bl sub_02002F30
cmp r0, r4
bhs _020030B2
sub r0, r4, r0
lsr r0, r0, #1
pop {r4, pc}
_020030B2:
mov r0, #0
pop {r4, pc}
.balign 4, 0
thumb_func_end sub_020030A0
thumb_func_start FontI_GetGlyphWidth
FontI_GetGlyphWidth: ; 0x020030B8
push {r3, r4, r5, lr}
lsl r4, r0, #2
ldr r0, _020030E4 ; =_0211188C
add r5, r1, #0
ldr r0, [r0]
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
cmp r0, #0
bne _020030D0
bl GF_AssertFail
_020030D0:
ldr r0, _020030E4 ; =_0211188C
add r1, r5, #0
ldr r0, [r0]
add r0, r0, r4
add r0, #0x9c
ldr r0, [r0]
bl GetGlyphWidth
pop {r3, r4, r5, pc}
nop
_020030E4: .word _0211188C
thumb_func_end FontI_GetGlyphWidth

View File

@ -1,11 +1,26 @@
#ifndef POKEHEARTGOLD_FONT_H
#define POKEHEARTGOLD_FONT_H
typedef u8 FontID;
#include "font_types_def.h"
#define FONT_NUM 6
u32 FontI_GetGlyphWidth(FontID fontId, u16 character);
void sub_02002CA8(void);
void sub_02002CEC(int a0, HeapID heapId);
u32 sub_02002F30(u8 fontno, STRING *string, u32 letterSpacing);
void sub_02002CEC(FontID fontId, HeapID heapId);
void sub_02002D40(FontID fontId, HeapID heapId);
void sub_02002D7C(FontID fontId);
void sub_02002DB4(FontID fontId);
struct GlyphInfo *sub_02002E7C(FontID fontId, u16 glyphId);
BOOL sub_02002E98(u16 glyphId, struct TextPrinter *printer);
u32 sub_02002EC8(FontID fontId, const u16 *string, u32 letterSpacing);
u32 sub_02002EFC(FontID fontId, const u16 *string, u32 letterSpacing);
u32 sub_02002F30(FontID fontId, STRING *string, u32 letterSpacing);
BOOL sub_02002F68(FontID fontId, STRING *str0, STRING *str1);
u8 GetFontAttribute(FontID fontId, int attr);
void sub_02003030(int layer, u32 baseAddr, HeapID heapId);
void sub_0200304C(int layer, u32 baseAddr, HeapID heapId);
u32 sub_02003068(FontID fontId, STRING *string, u32 letterSpacing);
u32 sub_020030A0(FontID fontId, STRING *string, u32 letterSpacing, u32 windowWidth);
u32 FontI_GetGlyphWidth(FontID fontId, u16 glyph);
#endif //POKEHEARTGOLD_FONT_H

64
include/font_types_def.h Normal file
View File

@ -0,0 +1,64 @@
#ifndef POKEHEARTGOLD_FONT_TYPES_DEF_H
#define POKEHEARTGOLD_FONT_TYPES_DEF_H
#include "pm_string.h"
#include "window.h"
typedef u8 FontID;
struct FontData;
struct GlyphInfo {
u8 data[0x80];
u8 width;
u8 height;
};
struct FontInfo {
u8 maxLetterWidth;
u8 maxLetterHeight;
u8 letterSpacing;
u8 lineSpacing;
u8 unk;
u8 fgColor;
u8 bgColor;
u8 shadowColor;
};
union StrbufForPrint {
STRING *wrapped;
const u16 *raw;
};
struct TextPrinterTemplate {
union StrbufForPrint currentChar;
WINDOW *window;
u8 padding[1];
FontID fontId;
u8 x, y;
u16 currentX, currentY;
u16 letterSpacing, lineSpacing;
u8 unk14;
u8 fgColor, bgColor, shadowColor;
u16 unk18;
u8 unk1A;
u8 unk1B;
};
struct TextPrinter {
struct TextPrinterTemplate template;
u8 (*callback)(struct TextPrinterTemplate *, u16);
u8 subStructFields[7]; // x20
u8 active;
u8 state;
u8 textSpeedBottom:7; // x29
u8 textSpeedTop:1;
u8 delayCounter;
u8 scrollDistance;
u8 minLetterSpacing;
u8 Unk2D;
u16 Unk2E;
u16 *Unk30;
};
#endif //POKEHEARTGOLD_FONT_TYPES_DEF_H

18
include/render_text.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef POKEHEARTGOLD_RENDER_TEXT_H
#define POKEHEARTGOLD_RENDER_TEXT_H
#include "text.h"
struct TextPrinterSubStruct {
u8 glyphId : 4; // 0x14
u8 hasPrintBeenSpedUp : 1;
u8 unk : 3;
u8 downArrowDelay : 5;
u8 downArrowYPosIdx : 2;
u8 hasGlyphIdBeenSet : 1;
u8 autoScrollDelay : 8;
};
BOOL RenderText(struct TextPrinter *printer);
#endif //POKEHEARTGOLD_RENDER_TEXT_H

9
include/text.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef POKEHEARTGOLD_TEXT_H
#define POKEHEARTGOLD_TEXT_H
#include "font_types_def.h"
#include "window.h"
void sub_0201FFE0(const struct FontInfo *fontData);
#endif //POKEHEARTGOLD_TEXT_H

20
include/unk_02025E88.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef POKEHEARTGOLD_UNK_02025E88_H
#define POKEHEARTGOLD_UNK_02025E88_H
#include "filesystem.h"
#include "font_types_def.h"
#define FONTARC_MODE_DIRECT 0
#define FONTARC_MODE_LAZY 1
struct FontData *FontData_new(NarcId narcId, int fileId, int mode, int vwf, HeapID heapId);
void FontData_ModeSwitch(struct FontData *fontData, int mode, HeapID heapId);
void FontData_delete(struct FontData *fontData);
void TryLoadGlyph(struct FontData *fontData, u16 glyphId, struct GlyphInfo *dest);
u32 GetStringWidth(struct FontData *fontData, const u16 *string, u32 letterSpacing);
u32 GetStringWidthFirstLine(struct FontData *fontData, const u16 *string, u32 letterSpacing);
u32 GetStringWidthMultiline(struct FontData *fontData, const u16 *string, u32 letterSpacing);
u32 GetGlyphWidth(struct FontData *fontData, u16 glyph);
BOOL StringAllCharsValid(struct FontData *fontData, const u16 *string);
#endif //POKEHEARTGOLD_UNK_02025E88_H

View File

@ -15,7 +15,7 @@ Static main
Object asm/unk_02001AF4.o
Object src/string_util.o
Object asm/render_text.o
Object asm/font.o
Object src/font.o
Object asm/palette.o
Object src/sound.o
Object src/sound_radio_sys.o

197
src/font.c Normal file
View File

@ -0,0 +1,197 @@
#include "font.h"
#include "text.h"
#include "gf_gfx_loader.h"
#include "unk_02025E88.h"
#include "render_text.h"
struct FontWork {
struct GlyphInfo glyph_buffer;
void *unk_84[FONT_NUM];
struct FontData *unk_9C[FONT_NUM];
s8 unk_B4[FONT_NUM];
};
static struct FontWork *_0211188C = NULL;
static const u16 _020F56C0[][2] = {
{0x0000, 0x0000},
{0x0001, 0x0000},
{0x0002, 0x0000},
{0x0003, 0x0000},
{0x0004, 0x0000},
{0x000A, 0x0000},
};
static const struct FontInfo _020F56D8[] = {
{0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02},
{0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02},
{0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02},
{0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02},
{0x0B, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02},
{0x0A, 0x10, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x02},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
};
void sub_02002CA8(void) {
u32 i;
static struct FontWork _02111890;
_0211188C = &_02111890;
for (i = 0; i < FONT_NUM; i++) {
_0211188C->unk_84[i] = NULL;
_0211188C->unk_9C[i] = NULL;
_0211188C->unk_B4[i] = 0;
}
sub_0201FFE0(_020F56D8);
}
void sub_02002CEC(FontID fontId, HeapID heapId) {
if (_0211188C->unk_9C[fontId] == NULL) {
_0211188C->unk_9C[fontId] = FontData_new(NARC_graphic_font, _020F56C0[fontId][0], FONTARC_MODE_LAZY, _020F56C0[fontId][1], heapId);
_0211188C->unk_B4[fontId] = 1;
} else {
_0211188C->unk_B4[fontId]++;
}
}
void sub_02002D40(FontID fontId, HeapID heapId) {
GF_ASSERT((int)fontId < FONT_NUM);
GF_ASSERT(_0211188C->unk_9C[fontId] != NULL);
FontData_ModeSwitch(_0211188C->unk_9C[fontId], FONTARC_MODE_DIRECT, heapId);
}
void sub_02002D7C(FontID fontId) {
GF_ASSERT((int)fontId < FONT_NUM);
GF_ASSERT(_0211188C->unk_9C[fontId] != NULL);
FontData_ModeSwitch(_0211188C->unk_9C[fontId], FONTARC_MODE_LAZY, 0);
}
void sub_02002DB4(FontID fontId) {
u32 i;
void *ip;
GF_ASSERT((int)fontId < FONT_NUM);
GF_ASSERT(_0211188C->unk_B4[fontId] != 0);
if (_0211188C->unk_B4[fontId] > 0) {
_0211188C->unk_B4[fontId]--;
}
if (_0211188C->unk_B4[fontId] == 0) {
ip = _0211188C->unk_84[fontId];
if (ip != NULL) {
for (i = 0; i < FONT_NUM; i++) {
if (i != fontId && _020F56C0[i][0] == _020F56C0[fontId][0] && _0211188C->unk_9C[i] != NULL) {
_0211188C->unk_84[i] = ip;
break;
}
}
if (i == 6) {
FreeToHeap(_0211188C->unk_84[fontId]);
_0211188C->unk_84[fontId] = NULL;
}
}
if (_0211188C->unk_9C[fontId] != NULL) {
FontData_delete(_0211188C->unk_9C[fontId]);
_0211188C->unk_9C[fontId] = NULL;
}
}
}
struct GlyphInfo *sub_02002E7C(FontID fontId, u16 glyphId) {
TryLoadGlyph(_0211188C->unk_9C[fontId], glyphId, &_0211188C->glyph_buffer);
return &_0211188C->glyph_buffer;
}
BOOL sub_02002E98(u16 glyphId, struct TextPrinter *printer) {
struct TextPrinterSubStruct *sub;
sub = (struct TextPrinterSubStruct *)printer->subStructFields;
if (!sub->hasGlyphIdBeenSet) {
sub->glyphId = glyphId;
sub->hasGlyphIdBeenSet = TRUE;
}
return RenderText(printer);
}
u32 sub_02002EC8(FontID fontId, const u16 *string, u32 letterSpacing) {
GF_ASSERT(_0211188C->unk_9C[fontId] != NULL);
return GetStringWidth(_0211188C->unk_9C[fontId], string, letterSpacing);
}
u32 sub_02002EFC(FontID fontId, const u16 *string, u32 letterSpacing) {
GF_ASSERT(_0211188C->unk_9C[fontId] != NULL);
return GetStringWidthFirstLine(_0211188C->unk_9C[fontId], string, letterSpacing);
}
u32 sub_02002F30(FontID fontId, STRING *string, u32 letterSpacing) {
GF_ASSERT(_0211188C->unk_9C[fontId] != NULL);
return GetStringWidth(_0211188C->unk_9C[fontId], String_c_str(string), letterSpacing);
}
BOOL sub_02002F68(FontID fontId, STRING *str0, STRING *str1) {
GF_ASSERT(_0211188C->unk_9C[fontId] != NULL);
StringSetEmpty(str1);
StringCat_HandleTrainerName(str1, str0);
return StringAllCharsValid(_0211188C->unk_9C[fontId], String_c_str(str1));
}
u8 GetFontAttribute(FontID fontId, int attr) {
u8 ret = 0;
switch (attr) {
case 0:
ret = _020F56D8[fontId].maxLetterWidth;
break;
case 1:
ret = _020F56D8[fontId].maxLetterHeight;
break;
case 2:
ret = _020F56D8[fontId].letterSpacing;
break;
case 3:
ret = _020F56D8[fontId].lineSpacing;
break;
case 4:
ret = _020F56D8[fontId].unk;
break;
case 5:
ret = _020F56D8[fontId].fgColor;
break;
case 6:
ret = _020F56D8[fontId].bgColor;
break;
case 7:
ret = _020F56D8[fontId].shadowColor;
break;
}
return ret;
}
void sub_02003030(int layer, u32 baseAddr, HeapID heapId) {
GfGfxLoader_GXLoadPal(NARC_graphic_font, 7, layer, baseAddr, 0x20, heapId);
}
void sub_0200304C(int layer, u32 baseAddr, HeapID heapId) {
GfGfxLoader_GXLoadPal(NARC_graphic_font, 8, layer, baseAddr, 0x20, heapId);
}
u32 sub_02003068(FontID fontId, STRING *string, u32 letterSpacing) {
GF_ASSERT(_0211188C->unk_9C[fontId] != NULL);
return GetStringWidthMultiline(_0211188C->unk_9C[fontId], String_c_str(string), letterSpacing);
}
u32 sub_020030A0(FontID fontId, STRING *string, u32 letterSpacing, u32 windowWidth) {
u32 stringWidth = sub_02002F30(fontId, string, letterSpacing);
if (stringWidth < windowWidth) {
return (windowWidth - stringWidth) / 2;
} else {
return 0;
}
}
u32 FontI_GetGlyphWidth(FontID fontId, u16 glyph) {
GF_ASSERT(_0211188C->unk_9C[fontId] != NULL);
return GetGlyphWidth(_0211188C->unk_9C[fontId], glyph);
}