#include "p_apps.h"

#define __LOAD_SDRAM

#include "dsp\G729Main.h"
#include "dsp\G729EnIn.h"
#include "dsp\G729Enc1.h"
#include "dsp\G729Enc2.h"
#include "dsp\G729Enc3.h"
#include "dsp\G729Enc4.h"
#include "dsp\G729Enc5.h"
#include "dsp\G729Enc6.h"
#include "dsp\G729Enc7.h"
#include "dsp\G729Enc8.h"
#include "dsp\G729Enc9.h"
#include "dsp\G729En10.h"
#include "dsp\G729En11.h"
#include "dsp\G729En12.h"
#include "dsp\G729En13.h"
#include "dsp\G729En14.h"

#include "dsp\G729DeIn.h"
#include "dsp\G729Dec1.h"
#include "dsp\G729Dec2.h"
#include "dsp\G729Dec3.h"
#include "dsp\G729Dec4.h"
#include "dsp\G729Dec5.h"
#include "dsp\G729Dec6.h"

#include "dsp\page1tab.h"
#include "dsp\page2tab.h"
#include "dsp\page3tab.h"
#include "dsp\page4tab.h"
#include "dsp\page5tab.h"
#include "dsp\page8tab.h"
#include "dsp\page9tab.h"
#include "dsp\page11tb.h"
#include "dsp\page12tb.h"
#include "dsp\page13tb.h"

#include "dsp\paged0tb.h"
#include "dsp\paged1tb.h"
#include "dsp\paged2tb.h"
#include "dsp\paged3tb.h"
#include "dsp\paged4tb.h"
#include "dsp\paged5tb.h"

// g.723.1 data
#include "dsp\combin.h"
#include "dsp\dpg7tab.h"

void main(void)
{
	BootIndication(8);

	Led_On(SECOND_LIGHT);

	sdram_read(SDRAM_CHECK_HI, SDRAM_CHECK_LO, SRAM_DMA_HALF_DWORD);
	if (XBYTE[Sdram_pDataCache+SDRAM_CHECK_POS] & SDRAM_CHECK_G729_OK)	goto End;

	SdramLoadCompressedCode(G729MAIN_CODE, 0x0a00, G729MAIN_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENIN_CODE, 0x0a10, G729ENIN_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC1_CODE, 0x0a20, G729ENC1_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC2_CODE, 0x0a30, G729ENC2_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC3_CODE, 0x0a40, G729ENC3_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC4_CODE, 0x0a50, G729ENC4_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC5_CODE, 0x0a60, G729ENC5_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC6_CODE, 0x0a70, G729ENC6_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC7_CODE, 0x0a80, G729ENC7_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC8_CODE, 0x0a90, G729ENC8_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729ENC9_CODE, 0x0aa0, G729ENC9_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729EN10_CODE, 0x0ab0, G729EN10_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729EN11_CODE, 0x0ac0, G729EN11_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729EN12_CODE, 0x0ad0, G729EN12_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729EN13_CODE, 0x0ae0, G729EN13_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729EN14_CODE, 0x0af0, G729EN14_COMPRESSED_SIZE);

	SdramLoadCompressedCode(G729DEIN_CODE, 0x0b00, G729DEIN_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729DEC1_CODE, 0x0b10, G729DEC1_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729DEC2_CODE, 0x0b20, G729DEC2_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729DEC3_CODE, 0x0b30, G729DEC3_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729DEC4_CODE, 0x0b40, G729DEC4_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729DEC5_CODE, 0x0b50, G729DEC5_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G729DEC6_CODE, 0x0b60, G729DEC6_COMPRESSED_SIZE);

	SdramLoadData((PCCHAR)TABLE1, 0x0b70, TABLE1_SIZE*2);
	SdramLoadData((PCCHAR)TABLE2, 0x0b74, TABLE2_SIZE*2);
	SdramLoadData((PCCHAR)TABLE3, 0x0b9c, TABLE3_SIZE*2);
	SdramLoadData((PCCHAR)TABLE4, 0x0b75, TABLE4_SIZE*2);
	SdramLoadData((PCCHAR)TABLE5, 0x0b76, TABLE5_SIZE*2);
	SdramLoadData((PCCHAR)TABLE8, 0x0b78, TABLE8_SIZE*2);
	SdramLoadData((PCCHAR)TABLE9, 0x0b80, TABLE9_SIZE*2);
	SdramLoadData((PCCHAR)TABLE11, 0x0b82, TABLE11_SIZE*2);
	SdramLoadData((PCCHAR)TABLE12, 0x0b83, TABLE12_SIZE*2);
	SdramLoadData((PCCHAR)TABLE13, 0x0b8c, TABLE13_SIZE*2);

	SdramLoadData((PCCHAR)DE_TABLE0, 0x0b8e, DE_TABLE0_SIZE*2);
	SdramLoadData((PCCHAR)DE_TABLE1, 0x0b8f, DE_TABLE1_SIZE*2);
	SdramLoadData((PCCHAR)DE_TABLE2, 0x0b92, DE_TABLE2_SIZE*2);
	SdramLoadData((PCCHAR)DE_TABLE3, 0x0b94, DE_TABLE3_SIZE*2);
	SdramLoadData((PCCHAR)DE_TABLE4, 0x0b95, DE_TABLE4_SIZE*2);
	SdramLoadData((PCCHAR)DE_TABLE5, 0x0b9a, DE_TABLE5_SIZE*2);

	// g.723.1 data
	SdramLoadData((PCCHAR)G723_combinatorialtable, 0x09e2, G723_combinatorialtable_SIZE*2);
	SdramLoadData((PCCHAR)G723_DEC_TABLE7, 0x09e5, G723_DEC_TABLE7_SIZE*2);

End:
	Led_Off(SECOND_LIGHT);

	BootIndication(9);

	SwitchPage(1);	// continue to load other data

	// to avoid warning
	Led_Blink(SECOND_LIGHT);
}
