#include "game_types.h"

/* Level_MoveDirectional @ 0x08005D10 (real 116B) -- directional move with masked tile stores. Mirrors src/matched/Level_MoveDirectional.c. */
/* Applies the emitter-table delta to (p[21], p[22]), bumps the counter at
   base+0x998, and writes the masked tile stores ((155-y)&255, (x-4)&0x1FF,
   0xC7F2) into the counter-selected slot. */
void Level_MoveDirectional(int *p)
{
    int *tab = *(int **)0x0200005C + 416 / 4;
    int x = p[21] - ((tab[0] >> 12) - (tab[19] / 2));
    int y = p[22] - ((tab[1] >> 12) - (tab[20] / 2));
    unsigned short *ctr = (unsigned short *)(*(int *)0x02000134 + 0x998);
    int h = *ctr;
    int *slot;
    *ctr = (unsigned short)(h + 1);
    slot = (int *)((char *)*(int **)((char *)ctr + 4) + (short)h * 8);
    *(unsigned short *)slot = (unsigned short)((155 - y) & 255);
    *(unsigned short *)((char *)slot + 2) = (unsigned short)((x - 4) & 0x1FF);
    *(unsigned short *)((char *)slot + 4) = 0xC7F2;
}
