Merge pull request #57 from cawtds/text-sync

Text sync
This commit is contained in:
cawtds
2025-02-14 21:47:45 +01:00
committed by GitHub
4 changed files with 786 additions and 596 deletions

View File

@@ -3,10 +3,6 @@
#include "constants/characters.h"
#define NUM_TEXT_PRINTERS 32
#define TEXT_SPEED_INSTANT 0
// Given as a text speed when all the text should be
// loaded at once but not copied to vram yet.
#define TEXT_SKIP_DRAW 0xFF
@@ -59,27 +55,28 @@ enum
FONTATTR_COLOR_SHADOW
};
struct GlyphInfo
struct TextGlyph
{
u8 pixels[0x80];
u32 gfxBufferTop[16];
u32 gfxBufferBottom[16];
u8 width;
u8 height;
};
extern struct GlyphInfo gGlyphInfo;
extern struct TextGlyph gCurGlyph;
struct TextPrinterSubStruct
{
u8 glyphId:4; // 0x14
u8 fontId:4; // 0x14
bool8 hasPrintBeenSpedUp:1;
u8 font_type_5:3;
u8 unk:3;
u8 downArrowDelay:5;
u8 downArrowYPosIdx:2;
u8 hasGlyphIdBeenSet:1;
bool8 hasFontIdBeenSet:1;
u8 autoScrollDelay;
};
struct TextPrinterTemplate // TODO: Better name
struct TextPrinterTemplate
{
const u8 *currentChar;
u8 windowId;
@@ -99,11 +96,10 @@ struct TextPrinterTemplate // TODO: Better name
struct TextPrinter
{
struct TextPrinterTemplate printerTemplate;
void (*callback)(struct TextPrinterTemplate *, u16); // 0x10
union {
struct TextPrinterSubStruct sub;
u8 fields[7];
} subUnion;
u8 subStructFields[7]; // always cast to struct TextPrinterSubStruct... so why bother
u8 active;
u8 state; // 0x1C
u8 textSpeed;
@@ -150,30 +146,25 @@ extern u8 gStringVar4[1000];
extern const u8 gKeypadIconTiles[];
void SetFontsPointer(const struct FontInfo *fonts);
void DeactivateAllTextPrinters(void);
u16 AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16));
bool16 AddTextPrinter(struct TextPrinterTemplate *textSubPrinter, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16));
bool32 AddTextPrinter(struct TextPrinterTemplate *textSubPrinter, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16));
void RunTextPrinters(void);
bool16 IsTextPrinterActive(u8 id);
u32 RenderFont(struct TextPrinter *textPrinter);
bool32 IsTextPrinterActive(u8 id);
void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor);
void SaveTextColors(u8 *fgColor, u8 *bgColor, u8 *shadowColor);
void RestoreTextColors(u8 *fgColor, u8 *bgColor, u8 *shadowColor);
void DecompressGlyphTile(const u16 *src, u16 *dest);
u8 GetLastTextColor(u8 colorType);
void DecompressGlyphTile(const void *src_, void *dest_);
void CopyGlyphToWindow(struct TextPrinter *x);
void ClearTextSpan(struct TextPrinter *textPrinter, u32 width);
void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter);
void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter);
void TextPrinterClearDownArrow(struct TextPrinter *textPrinter);
bool8 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter);
bool16 TextPrinterWaitWithDownArrow(struct TextPrinter *textPrinter);
bool16 TextPrinterWait(struct TextPrinter *textPrinter);
void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool8 drawArrow, u8 *counter, u8 *yCoordIndex);
u16 RenderText(struct TextPrinter *textPrinter);
u32 (*GetFontWidthFunc(u8 glyphId))(u16, bool32);
bool32 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter);
bool32 TextPrinterWaitWithDownArrow(struct TextPrinter *textPrinter);
bool32 TextPrinterWait(struct TextPrinter *textPrinter);
void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool32 drawArrow, u8 *counter, u8 *yCoordIndex);
s32 GetGlyphWidth(u16 glyphId, bool32 isJapanese, u8 fontId);
s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing);
s32 GetStringLineWidth(u8 fontId, const u8 *str, s16 letterSpacing, u32 lineNum, u32 strSize);

View File

@@ -7,39 +7,41 @@
// This file handles the braille font.
// For printing braille messages, see ScrCmd_braillemessage
ALIGNED(4)
static const u8 sScrollDistances[] = {
[OPTIONS_TEXT_SPEED_SLOW] = 1,
[OPTIONS_TEXT_SPEED_MID] = 2,
[OPTIONS_TEXT_SPEED_FAST] = 4,
};
static const u16 sBrailleGlyphs[] = INCBIN_U16("graphics/fonts/braille.fwjpnfont");
static const u16 sFont_Braille[] = INCBIN_U16("graphics/fonts/braille.fwjpnfont");
static void DecompressGlyph_Braille(u16);
u16 FontFunc_Braille(struct TextPrinter *textPrinter)
{
u16 char_;
struct TextPrinterSubStruct *sub = &textPrinter->subUnion.sub;
struct TextPrinterSubStruct *subStruct;
subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
switch (textPrinter->state)
{
case RENDER_STATE_HANDLE_CHAR:
if (JOY_HELD(A_BUTTON | B_BUTTON) && sub->hasPrintBeenSpedUp)
if (JOY_HELD(A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp)
{
textPrinter->delayCounter = 0;
}
if (textPrinter->delayCounter && textPrinter->textSpeed)
{
textPrinter->delayCounter--;
textPrinter->delayCounter --;
if (gTextFlags.canABSpeedUpPrint && JOY_NEW(A_BUTTON | B_BUTTON))
{
sub->hasPrintBeenSpedUp = TRUE;
subStruct->hasPrintBeenSpedUp = TRUE;
textPrinter->delayCounter = 0;
}
return RENDER_UPDATE;
}
if (gTextFlags.autoScroll)
textPrinter->delayCounter = 1;
textPrinter->delayCounter = 3;
else
textPrinter->delayCounter = textPrinter->textSpeed;
@@ -83,7 +85,7 @@ u16 FontFunc_Braille(struct TextPrinter *textPrinter)
textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_FONT:
sub->glyphId = *textPrinter->printerTemplate.currentChar;
subStruct->fontId = *textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_RESET_FONT:
@@ -95,7 +97,7 @@ u16 FontFunc_Braille(struct TextPrinter *textPrinter)
case EXT_CTRL_CODE_PAUSE_UNTIL_PRESS:
textPrinter->state = RENDER_STATE_WAIT;
if (gTextFlags.autoScroll)
sub->autoScrollDelay = 0;
subStruct->autoScrollDelay = 0;
return RENDER_UPDATE;
case EXT_CTRL_CODE_WAIT_SE:
textPrinter->state = RENDER_STATE_WAIT_SE;
@@ -135,7 +137,7 @@ u16 FontFunc_Braille(struct TextPrinter *textPrinter)
}
DecompressGlyph_Braille(char_);
CopyGlyphToWindow(textPrinter);
textPrinter->printerTemplate.currentX += gGlyphInfo.width + textPrinter->printerTemplate.letterSpacing;
textPrinter->printerTemplate.currentX += gCurGlyph.width + textPrinter->printerTemplate.letterSpacing;
return RENDER_PRINT;
case RENDER_STATE_WAIT:
if (TextPrinterWait(textPrinter))
@@ -185,7 +187,7 @@ u16 FontFunc_Braille(struct TextPrinter *textPrinter)
return RENDER_UPDATE;
case RENDER_STATE_PAUSE:
if (textPrinter->delayCounter)
textPrinter->delayCounter--;
textPrinter->delayCounter --;
else
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
return RENDER_UPDATE;
@@ -195,18 +197,16 @@ u16 FontFunc_Braille(struct TextPrinter *textPrinter)
static void DecompressGlyph_Braille(u16 glyph)
{
const u16 *glyphs;
glyphs = sBrailleGlyphs + 0x100 * (glyph / 8) + 0x10 * (glyph % 8);
DecompressGlyphTile(glyphs, (u16 *)gGlyphInfo.pixels);
DecompressGlyphTile(glyphs + 0x8, (u16 *)(gGlyphInfo.pixels + 0x20));
DecompressGlyphTile(glyphs + 0x80, (u16 *)(gGlyphInfo.pixels + 0x40));
DecompressGlyphTile(glyphs + 0x88, (u16 *)(gGlyphInfo.pixels + 0x60));
gGlyphInfo.width = 16;
gGlyphInfo.height = 16;
const u16 *glyphs = sFont_Braille + 0x100 * (glyph / 8) + 0x10 * (glyph % 8);
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8);
DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom);
DecompressGlyphTile(glyphs + 0x88, gCurGlyph.gfxBufferBottom + 8);
gCurGlyph.width = 16;
gCurGlyph.height = 16;
}
u32 GetGlyphWidth_Braille(u16 font_type, bool32 isJapanese)
u32 GetGlyphWidth_Braille(u16 glyphId, bool32 isJapanese)
{
return 16;
}

View File

@@ -402,7 +402,7 @@ void HelpSystemRenderText(u8 fontId, u8 * dest, const u8 * src, u8 x, u8 y, u8 w
return;
case CHAR_NEWLINE:
x = orig_x;
y += gGlyphInfo.height + 1;
y += gCurGlyph.height + 1;
break;
case PLACEHOLDER_BEGIN:
curChar = *src;
@@ -419,11 +419,11 @@ void HelpSystemRenderText(u8 fontId, u8 * dest, const u8 * src, u8 x, u8 y, u8 w
// This is required to match a dummy [sp+#0x24] read here
if (fontId == FONT_SMALL)
{
x += gGlyphInfo.width;
x += gCurGlyph.width;
}
else
{
x += gGlyphInfo.width + ZERO;
x += gCurGlyph.width + ZERO;
}
}
}
@@ -449,11 +449,11 @@ void HelpSystemRenderText(u8 fontId, u8 * dest, const u8 * src, u8 x, u8 y, u8 w
}
if (fontId == FONT_SMALL)
{
x += gGlyphInfo.width;
x += gCurGlyph.width;
}
else
{
x += gGlyphInfo.width + ZERO;
x += gCurGlyph.width + ZERO;
}
}
}
@@ -461,7 +461,7 @@ void HelpSystemRenderText(u8 fontId, u8 * dest, const u8 * src, u8 x, u8 y, u8 w
case CHAR_PROMPT_SCROLL:
case CHAR_PROMPT_CLEAR:
x = orig_x;
y += gGlyphInfo.height + 1;
y += gCurGlyph.height + 1;
break;
case EXT_CTRL_CODE_BEGIN:
curChar = *src;
@@ -550,11 +550,11 @@ void HelpSystemRenderText(u8 fontId, u8 * dest, const u8 * src, u8 x, u8 y, u8 w
DecompressAndRenderGlyph(fontId, curChar, &srcBlit, &destBlit, dest, x, y, width, height);
if (fontId == FONT_SMALL)
{
x += gGlyphInfo.width;
x += gCurGlyph.width;
}
else
{
x += gGlyphInfo.width + ZERO;
x += gCurGlyph.width + ZERO;
}
}
break;
@@ -570,13 +570,13 @@ void DecompressAndRenderGlyph(u8 fontId, u16 glyph, struct Bitmap *srcBlit, stru
DecompressGlyph_Female(glyph, FALSE);
else
DecompressGlyph_Normal(glyph, FALSE);
srcBlit->pixels = gGlyphInfo.pixels;
srcBlit->pixels = (u8*) gCurGlyph.gfxBufferTop;
srcBlit->width = 16;
srcBlit->height = 16;
destBlit->pixels = destBuffer;
destBlit->width = width * 8;
destBlit->height = height * 8;
BlitBitmapRect4Bit(srcBlit, destBlit, 0, 0, x, y, gGlyphInfo.width, gGlyphInfo.height, 0);
BlitBitmapRect4Bit(srcBlit, destBlit, 0, 0, x, y, gCurGlyph.width, gCurGlyph.height, 0);
}
void HelpSystem_PrintTextInTopLeftCorner(const u8 * str)

1277
src/text.c

File diff suppressed because it is too large Load Diff