#include "game_types.h"

/* Image_ParseTileHeader @ 0x08013A7C (real 98B) -- magic-gated tile header stamp loop. Mirrors src/matched/Image_ParseTileHeader.c. */
/* When word 13 holds the magic, bumps it and runs DrawLineH over flagged
   entries (bit 128 set, bit 64 clear), stamping (bit, 2, 64, 22, 1) into
   +0/+15/+19/+25/+36. Restores the magic on exit. */
extern void Image_DrawLineH(int *e, int v);

void Image_ParseTileHeader(int *p)
{
    char *base;
    int n, i;
    if (p[13] != 0x68736D53)
        return;
    p[13]++;
    n = ((unsigned char *)p)[8];
    base = (char *)p[11];
    for (i = 0; i < n; i++, base += 80) {
        if ((base[0] & 128) == 0 || (base[0] & 64) != 0)
            continue;
        Image_DrawLineH((int *)base, base[0]);
        base[0] = (char)128;
        base[15] = 2;
        base[19] = 64;
        base[25] = 22;
        base[36] = 1;
    }
    p[13] = 0x68736D53;
}
