#include "game_types.h"

/* Text_UpdateFromAnimation @ 0x080023F4 (real 162B) -- animation-driven queue entries plus slot draws. Mirrors src/matched/Text_UpdateFromAnimation.c. */
/* Folds the animation deltas into the +260/+264 accumulators, posts two
   queue entries (channels 14/15), then draws/updates the 6 slots at +60
   (32-byte stride) by each slot's halfword mode (0 = draw frame,
   1 = update all). */
extern int TextQueue_AddEntry(int a, int b, int c, int d, int e);
extern void Render_DrawFrame(int a, int b);
extern void Render_UpdateAll(int a, int b);

void Text_UpdateFromAnimation(int *a)
{
    int *o = (int *)a[64];
    int i;
    if (o != 0) {
        int v0, v1;
        a[65] += o[11];
        a[66] += o[13];
        v0 = ((unsigned)a[65] >> 12) & 15;
        v1 = ((unsigned)a[66] >> 12) & 15;
        TextQueue_AddEntry(1, 0, 14, o[10] + (v0 << 5), 16);
        TextQueue_AddEntry(1, 0, 15, o[12] + (v1 << 5), 16);
    }
    for (i = 0; i < 6; i++) {
        char *s = (char *)a + 60 + i * 32;
        int *q = (int *)((char *)a + 60 + i * 32);
        int mode;
        if (s[0] == 0)
            continue;
        mode = *(short *)(s + 16);
        if (mode == 0)
            Render_DrawFrame((int)a, (int)q);
        else if (mode == 1)
            Render_UpdateAll((int)a, (int)q);
    }
}
