#include "game_types.h"

/* Image_FillRect @ 0x08013D20 (real 88B) -- call-heavy rect init through log/ellipse chain. Mirrors src/matched/Image_FillRect.c. */
/* Draws the circle, derives the table index from bits 16-23, and fills the
   0x03007FF0 block (flag byte, table word, log quotients) before drawing the
   ellipse. The stale-r1 varargs shape is verbatim. */
extern void Image_DrawCircle(int x);
extern void Image_DrawEllipse(void);
extern unsigned Math_Log2(unsigned a, unsigned b);

void Image_FillRect(int x)
{
    int *r5 = *(int **)0x03007FF0;
    int v = (x & 0xF00000) >> 16;
    int h;
    Image_DrawCircle(x);
    ((unsigned char *)r5)[8] = (unsigned char)v;
    h = *(unsigned short *)(0x08546FCC + (v - 1) * 2);
    r5[4] = h;
    ((unsigned char *)r5)[11] = (unsigned char)Math_Log2(1584, (unsigned)h);
    r5[5] = (int)Math_Log2(0x91D1Bu * (unsigned)h + 0x1388u, 0x2710u);
    r5[6] = ((int)Math_Log2(0x1000000u, (unsigned)h) + 1) >> 1;
    Image_DrawEllipse();
}
