summaryrefslogtreecommitdiff
path: root/fx-sound.c
blob: 5a54a5e8f24d75c6c37a421ca027c678ceb269b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// original by MPoupe, modified by Casimo
#include "fxlib.h"
#include "7305.h"

#define DATAPACK 8080

unsigned char UserStack[DATAPACK];

//Conversion tables
#define X 0x10
#define _ 0x00

static const unsigned char LowTable[16]=
{
   _,_,_,_,//0
   X,_,_,_,//1
   X,_,X,_,//2
   _,X,X,X,//3
};

                               //0    1    2    3    4    5    6    7
static const unsigned char HighTable[8]={0x00,0x01,0x44,0x45,0x65,0x67,0xE7,0xEF};

#define gpBuffer UserStack

//static unsigned char *gpBuffer;
static unsigned int giBufIndex = 0;
static unsigned char giTableIndex = 0;
static unsigned char giSubSample = 0;
static unsigned char giFromHighTab = 0;

static int ComOpen()
{
   //unsigned char settings[5]={0,9,0,1,0};//115200,2xstop bits
   unsigned char settings[5]={0,9,0,0,0};//115200,1xstop bits
   if(Serial_Open(&settings))
   {
      return 1;
   }
      //SCIF2.SCSMR.BIT.SRC = 1;//1/5 (for 9860)

   //it has no SRC register (comparing to fx9860G), so actual speed is only ~ 460800
   //SCIF2.SCSMR.BIT.SRC = 0;//1/16 (for 9860)
   SCIF2.SCSMR.BIT.CKS = 0;//1/1
      //SCIF2.SCBRR = 2;//!override speed to 1959390 bps (for 9860)
   SCIF2.SCBRR = 0;//!override speed to 1836000 bps (for 9860)
   return  0;
}

int AddIn_main(int isAppli, unsigned short OptionNum)
{
   FONTCHARACTER path[] ={'\\','\\','f','l','s','0','\\','T','E','S','T','.','w','a','v',0};
   unsigned int i, size;
   unsigned int code1, code2;
   int hFile = Bfile_OpenFile(path, _OPENMODE_READ);
   //skip wav header
   if(Bfile_ReadFile(hFile,UserStack,44,-1) != 44)
   {
      return 0;
   }

   size = Bfile_GetFileSize(hFile);
   ComOpen();
   Bdisp_AllClr_VRAM();
   locate( 1, 1 );
   Print(&"Playing");
   Bdisp_PutDisp_DD();

   //read it
   for(i = 0; i < size; i+= DATAPACK)
   {
      Bfile_ReadFile(hFile,UserStack ,DATAPACK,-1);
      for(giBufIndex = 0; giBufIndex < DATAPACK;)
      {
         //it has only 16 B fifo :-(
         while ((SCIF2.SCFDR.WORD >> 8) < 16)
         {
            if(giTableIndex >= 4)
            {
               giSubSample = gpBuffer[giBufIndex++] >> 3;
               giFromHighTab = HighTable[giSubSample>>2];
               giSubSample = (giSubSample & 3) << 2;
               giTableIndex = 0;
            }
            SCIF2.SCFTDR = (unsigned char)LowTable[giSubSample|giTableIndex]|giFromHighTab;
            giTableIndex++;
         }
      }
      if(Bkey_GetKeyWait(&code1,&code2,KEYWAIT_HALTOFF_TIMEROFF,0,1,0) == KEYREP_KEYEVENT)
      {
         if(code1 == 4 && code2 == 8)
         break;
      }
   }
   Bfile_CloseFile(hFile);
   Serial_Close(1);
}

#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum)
{return INIT_ADDIN_APPLICATION(isAppli, OptionNum);}
#pragma section