#include "sys.h"
#include "sf64audio_provisional.h"

AudioTable gSampleBankTableInit = {
    { 4, 0, 0 },
    {
        { 0x000000, 0x0E1E30, MEDIUM_CART, CACHEPOLICY_4 },
        { 0x0E1E30, 0x0FF9D0, MEDIUM_CART, CACHEPOLICY_4 },
        { 0x1E1800, 0x497480, MEDIUM_CART, CACHEPOLICY_4 },
        { 0x678C80, 0x0C3900, MEDIUM_CART, CACHEPOLICY_4 },
    },
};

AudioTable gSeqTableInit = {
    { SEQ_ID_MAX, 0, 0 },
    {
        { 0x00000, 0x3AF0, MEDIUM_CART, CACHEPOLICY_0 },     { 0x03AF0, 0x56B0, MEDIUM_CART, CACHEPOLICY_0 },
        { 0x091A0, 0x2D80, MEDIUM_CART, CACHEPOLICY_3 },     { 0x0BF20, 0x1410, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x0D330, 0x1600, MEDIUM_CART, CACHEPOLICY_3 },     { 0x0E930, 0xF20, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x0F850, 0x13A0, MEDIUM_CART, CACHEPOLICY_3 },     { 0x10BF0, 0x1100, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x11CF0, 0x19E0, MEDIUM_CART, CACHEPOLICY_3 },     { 0x136D0, 0x13E0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x14AB0, 0x12F0, MEDIUM_CART, CACHEPOLICY_3 },     { SEQ_ID_SECTOR_Y, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x15DA0, 0xB70, MEDIUM_CART, CACHEPOLICY_3 },      { 0x16910, 0x2460, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x18D70, 0xD40, MEDIUM_CART, CACHEPOLICY_3 },      { SEQ_ID_FORTUNA, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_TITANIA, 0, MEDIUM_CART, CACHEPOLICY_3 },   { 0x19AB0, 0x7F0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x1A2A0, 0x1440, MEDIUM_CART, CACHEPOLICY_3 },     { 0x1B6E0, 0x1B20, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_BOSS_ME, 0, MEDIUM_CART, CACHEPOLICY_3 },   { SEQ_ID_BOSS_CO_1, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_BOSS_CO_1, 0, MEDIUM_CART, CACHEPOLICY_3 }, { SEQ_ID_BOSS_ME, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_BOSS_ME, 0, MEDIUM_CART, CACHEPOLICY_3 },   { 0x1D200, 0x1B30, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_BOSS_CO_1, 0, MEDIUM_CART, CACHEPOLICY_3 }, { SEQ_ID_BOSS_ME, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x1ED30, 0x10B0, MEDIUM_CART, CACHEPOLICY_3 },     { SEQ_ID_BOSS_BO, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_BOSS_ME, 0, MEDIUM_CART, CACHEPOLICY_3 },   { SEQ_ID_BOSS_BO, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_BOSS_ME, 0, MEDIUM_CART, CACHEPOLICY_3 },   { 0x1FDE0, 0x1410, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x211F0, 0xF30, MEDIUM_CART, CACHEPOLICY_3 },      { 0x22120, 0x2B30, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x24C50, 0x7F0, MEDIUM_CART, CACHEPOLICY_3 },      { 0x25440, 0x13B0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x267F0, 0xC70, MEDIUM_CART, CACHEPOLICY_3 },      { 0x27460, 0x180, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x275E0, 0x5C0, MEDIUM_CART, CACHEPOLICY_3 },      { SEQ_ID_TITLE, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x27BA0, 0x4E40, MEDIUM_CART, CACHEPOLICY_3 },     { 0x2C9E0, 0x14E0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x2DEC0, 0x400, MEDIUM_CART, CACHEPOLICY_3 },      { 0x2E2C0, 0x800, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x2EAC0, 0x1AB0, MEDIUM_CART, CACHEPOLICY_3 },     { 0x30570, 0x1AA0, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_BOSS_ME, 0, MEDIUM_CART, CACHEPOLICY_3 },   { 0x32010, 0x1370, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x33380, 0xB80, MEDIUM_CART, CACHEPOLICY_3 },      { 0x33F00, 0x5C0, MEDIUM_CART, CACHEPOLICY_3 },
        { SEQ_ID_CO_INTRO, 0, MEDIUM_CART, CACHEPOLICY_3 },  { SEQ_ID_CO_INTRO, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x344C0, 0x550, MEDIUM_CART, CACHEPOLICY_3 },      { 0x34A10, 0x360, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x34D70, 0x620, MEDIUM_CART, CACHEPOLICY_3 },      { SEQ_ID_VS_MENU, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x35390, 0xA70, MEDIUM_CART, CACHEPOLICY_3 },      { SEQ_ID_STAR_WOLF, 0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x35E00, 0xAB0, MEDIUM_CART, CACHEPOLICY_3 },      { 0x368B0, 0x13D0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x37C80, 0x250, MEDIUM_CART, CACHEPOLICY_3 },      { 0x37ED0, 0x6F0, MEDIUM_CART, CACHEPOLICY_3 },
        { 0x385C0, 0xFB0, MEDIUM_CART, CACHEPOLICY_3 },      { 0x39570, 0x1780, MEDIUM_CART, CACHEPOLICY_3 },
    },
};
#define SOUNDFONT_ENTRY(offset, size, medium, cachePolicy, bank1, bank2, numInst, numDrums) \
    {                                                                                       \
        offset, size, medium, cachePolicy, (((bank1) &0xFF) << 8) | ((bank2) &0xFF),        \
            (((numInst) &0xFF) << 8) | ((numDrums) &0xFF)                                   \
    }

AudioTable gSoundFontTableInit = {
    { 33, 0, 0 },
    {
        SOUNDFONT_ENTRY(0x00000, 0x2F00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_SFX, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x02F00, 0x0FE0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_MAP, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x03EE0, 0x0640, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x04520, 0x1560, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x05A80, 0x0C00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x06680, 0x0DE0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x07460, 0x1200, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x08660, 0x1040, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x096A0, 0x0E40, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x0A4E0, 0x0C20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x0B100, 0x1920, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x0CA20, 0x0A20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x0D440, 0x0A00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x0DE40, 0x0D60, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x0EBA0, 0x0C20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x0F7C0, 0x0F00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x106C0, 0x0F20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x115E0, 0x0E20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x12400, 0x10A0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x134A0, 0x2580, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x15A20, 0x09E0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0),
        SOUNDFONT_ENTRY(0x16400, 0x1220, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 16, 64),
        SOUNDFONT_ENTRY(0x17620, 0x0180, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 3, 0),
        SOUNDFONT_ENTRY(0x177A0, 0x11C0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 16, 64),
        SOUNDFONT_ENTRY(0x18960, 0x0940, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
        SOUNDFONT_ENTRY(0x192A0, 0x09E0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
        SOUNDFONT_ENTRY(0x19C80, 0x0920, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
        SOUNDFONT_ENTRY(0x1A5A0, 0x09E0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
        SOUNDFONT_ENTRY(0x1AF80, 0x09E0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
        SOUNDFONT_ENTRY(0x1B960, 0x0A10, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
        SOUNDFONT_ENTRY(0x1C370, 0x09E0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
        SOUNDFONT_ENTRY(0x1CD50, 0x0A00, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
        SOUNDFONT_ENTRY(0x1D750, 0x08D0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64),
    },
};

#define AS_BYTES(x) (((x) >> 8) & 0xFF), ((x) &0xFF)

// clang-format off

u8 gSeqFontTableInit[283] = {
    // Offset into this table for sequence sound font list
    AS_BYTES(132), AS_BYTES(134), AS_BYTES(155), AS_BYTES(157), AS_BYTES(159), AS_BYTES(161), AS_BYTES(163),
    AS_BYTES(165), AS_BYTES(167), AS_BYTES(169), AS_BYTES(171), AS_BYTES(173), AS_BYTES(175), AS_BYTES(177),
    AS_BYTES(179), AS_BYTES(181), AS_BYTES(183), AS_BYTES(185), AS_BYTES(187), AS_BYTES(189), AS_BYTES(191),
    AS_BYTES(193), AS_BYTES(195), AS_BYTES(197), AS_BYTES(199), AS_BYTES(201), AS_BYTES(203), AS_BYTES(205),
    AS_BYTES(207), AS_BYTES(209), AS_BYTES(211), AS_BYTES(213), AS_BYTES(215), AS_BYTES(217), AS_BYTES(219),
    AS_BYTES(221), AS_BYTES(223), AS_BYTES(225), AS_BYTES(227), AS_BYTES(229), AS_BYTES(231), AS_BYTES(233),
    AS_BYTES(235), AS_BYTES(237), AS_BYTES(239), AS_BYTES(241), AS_BYTES(243), AS_BYTES(245), AS_BYTES(247),
    AS_BYTES(249), AS_BYTES(251), AS_BYTES(253), AS_BYTES(255), AS_BYTES(257), AS_BYTES(259), AS_BYTES(261),
    AS_BYTES(263), AS_BYTES(265), AS_BYTES(267), AS_BYTES(269), AS_BYTES(271), AS_BYTES(273), AS_BYTES(275),
    AS_BYTES(277), AS_BYTES(279), AS_BYTES(281),

    // sound font for SFX sequence
    1,  0,
    // sound fonts voice sequence
    20, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9,  8, 7,  6, 5,  4, 3,  1, 2,
    // sound fonts for BGM sequences. Each sequence has a single sound font.
    1, 24, 1, 29, 1, 25, 1, 26, 1, 28, 1, 25, 1, 25, 1, 29, 1, 24, 1, 29, 1, 28, 1, 25, 1, 30, 1, 24, 1, 25, 1, 28,
    1, 28, 1, 31, 1, 31, 1, 28, 1, 28, 1, 31, 1, 31, 1, 31, 1, 28, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 32,
    1, 21, 1, 21, 1, 22, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 23, 1, 25, 1, 21, 1, 21, 1, 29, 1, 25, 1, 31, 1, 21,
    1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 27, 1, 25, 1, 21, 1, 25, 1, 25, 1, 25, 1, 21, 1, 31
};

// clang-format on
