#pragma once

#include "kpi_decoder.h"
#include "kpi_impl.h"
#include "wsr_player_common/wsr_player_intf.h"

#pragma pack(push, 1) //構造体のアラインメント
struct WSR_FOOTER
{
    BYTE WSRF[4];//"WSRF"
    BYTE Version0;//=0
    BYTE FirstSongNo;
    BYTE Reserved1[10];
    BYTE Startup[5];
    BYTE Reserved2[1];
    WORD Maker;
    BYTE Title;
    BYTE Version;
    BYTE ROMSize;
    BYTE RAMSize;
    BYTE ROMWait;
    BYTE SubSystemLSI;
    WORD CheckSum;
};
#pragma pack(pop)

class KbWsrDecoder : public KbKpiUnknownImpl<IKpiDecoder>
{
private:
    static HINSTANCE     s_hDll;
    static WSRPlayerApi* s_pApi;
    static KbWsrDecoder* s_pActive;
    IKpiConfig *m_pConfig;
    KPI_MEDIAINFO m_MediaInfo;
    BYTE         *m_pROM;
    int           m_nROMSize;
    int           m_nROMBank;
    WSR_FOOTER   *m_pFooter;
    double        m_dVolume;
    short        *m_pBuffer;
public:
    DWORD  __fastcall Open(const KPI_MEDIAINFO *cpRequest, IKpiFile *pFile, IKpiFolder *pFolder);
    DWORD  WINAPI Select(DWORD dwNumber,
                         const KPI_MEDIAINFO **ppMediaInfo,
                         IKpiTagInfo *pTagInfo,
                         DWORD dwTagGetFlags);
    DWORD  WINAPI Render(BYTE *pBuffer, DWORD dwSizeSample);
    UINT64 WINAPI Seek(UINT64 qwPosSample, DWORD dwFlag);
    DWORD  WINAPI UpdateConfig(void *pvReserved);
    void __fastcall GetTagInfo(IKpiTagInfo *pTagInfo);
    static bool LoadCore(IKpiConfig *pConfig);
    static void UnloadCore(void);
    KbWsrDecoder(IKpiConfig *pConfig);
    ~KbWsrDecoder(void);
};
