#include "game_types.h"

/* Image_Decompress @ 0x08012FC4 (real 56B) -- walks the node chain, masking bytes and unlinking ends. Mirrors src/matched/Image_Decompress.c. */
/* Walks the node chain from src[8]: sets bit 6 on bytes with any of bits
   0,1,2,6,7 (tst #199), unlinks each node, and clears a node that points to
   itself; zeroes dst[0] at the end. (agbcc never emits tst -- naked.) */
extern void Image_DrawMasked(int *node);

void Image_Decompress(int *dst, int *src)
{
    int *n = (int *)src[8];
    while (n != 0) {
        if (((unsigned char *)n)[0] & 199)
            ((unsigned char *)n)[0] |= 64;
        Image_DrawMasked(n);
        {
            int *next = (int *)n[13];
            if (next == n) {
                n[13] = 0;
                next = 0;
            }
            n = next;
        }
    }
    ((unsigned char *)dst)[0] = 0;
}
