#include "game_types.h"

/* Sub_08011A20 @ 0x08011A20 (real 200B) -- sound channel slot setup with flag discipline. Mirrors src/matched/Sub_08011A20.c. */
/* Selects the channel slot (table 0x0802B9D4 by a, stride 8 in t),
   snapshots it to d when set, installs (b, c) or the (0x08011EF1, 0) idle
   pair with the sel flag set/cleared, then raises 0x2001 and the strobe. */
void Sub_08011A20(int a, int b, int c, int d)
{
    int *t = *(int **)0x020001F8;
    unsigned sel = *(unsigned short *)(0x0802B9D4 + a * 4);
    int *slot = (int *)((char *)t + a * 8);
    *(unsigned short *)0x04000208 = 0;
    if (d != 0) {
        *(int *)d = slot[0];
        *(int *)(d + 4) = slot[1];
    }
    if (b != 0) {
        slot[0] = b;
        slot[1] = c;
        *(unsigned short *)0x04000200 |= (unsigned short)sel;
    } else {
        slot[0] = 0x08011EF1;
        slot[1] = 0;
        *(unsigned short *)0x04000200 &= (unsigned short)~sel;
    }
    *(unsigned short *)0x04000200 |= 0x2001;
    *(unsigned short *)0x04000208 = 1;
}
