#include "game_types.h"

/* BG_SetMultiPalette @ 0x08014A74 (real 110B) -- bit-loop tile-attr stamp (+23) over flagged entries. Mirrors src/matched/BG_SetMultiPalette.c. */
/* Twin of BG_SetMultiAttr stamping at entry+23 instead of +25. */
extern void BG_ResetTileFlags(char *base);

void BG_SetMultiPalette(int *p, unsigned x, unsigned y)
{
    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 ((x & (1u << i)) != 0 && (base[0] & 128) != 0) {
            base[23] = (char)y;
            if (y == 0)
                BG_ResetTileFlags(base);
        }
    }
    p[13] = 0x68736D53;
}
