#include "game_types.h"

/* Text_ProcessData @ 0x0801490C (real 100B) -- bit-loop data stamp (+19) over flagged entries. Mirrors src/matched/Text_ProcessData.c. */
/* When word 13 holds the magic, stamps (y >> 2) at entry+19 and ORs 3 into
   entry[0] for each of the n = p[8] entries (80-byte stride) selected by the
   u16 bitmask x whose flag byte has bit 128. */
void Text_ProcessData(int *p, unsigned x, unsigned y)
{
    char *base;
    int n, i;
    unsigned bit = 1;
    if (p[13] != 0x68736D53)
        return;
    p[13]++;
    n = ((unsigned char *)p)[8];
    base = (char *)p[11];
    for (i = 0; i < n; i++, base += 80, bit <<= 1) {
        if ((x & bit) != 0 && (base[0] & 128) != 0) {
            base[19] = (char)(y >> 2);
            base[0] = (char)(base[0] | 3);
        }
    }
    p[13] = 0x68736D53;
}
