read.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:30k
源码类别:

DVD

开发平台:

C/C++

  1. /*
  2.  *************************************************************************
  3.  * File Name:   read.h
  4.  * Created:     2003/8/1 12:49PM Maoyong 
  5.  * Description: Repeat reading implement C file
  6.  * Maintain:    Maoyong 2004.06.09 rewrite
  7.  ************************************************************************
  8.  */
  9. #include "user_init.h"
  10. #include "global.h"
  11. #ifdef SUPPORT_REP_READ
  12. #include "read.h"
  13. #include "osd.h"
  14. #include "func.h"
  15. #include "osd_arc.h"
  16. #include "stdlib.h"
  17. #include "cfont.h"
  18. #include "vpp.h"
  19. #include "ircmd.h"
  20. #include "emuio.h"
  21. #include "sio.h"
  22. #include "dsp3_def.h"
  23. #include "dsp3_if.h"
  24. /*
  25. ******************************************************************************
  26. *                           EXTERN FUNC TIONPROTOTYPES 
  27. ******************************************************************************
  28. */
  29. extern void osd_draw_rect(UINT32 xStart, UINT32 yStart, UINT32 xLen, UINT32 yLen, BYTE bkColor);
  30. extern void osd_draw_setup_button(BYTE xStart, BYTE yStart, BYTE xLen, BYTE color, BYTE bDown);
  31. extern void osd_DrawString(BYTE xStart, BYTE yStart, const BYTE *str, BYTE fontColor, BYTE bkColor);
  32. extern void osd_DrawRegionString(BYTE xStart, BYTE yStart, BYTE *str, BYTE fontColor, BYTE bkColor, BYTE r);
  33. extern void osd_DrawRegionLine(UINT32 xStart, UINT32 yStart, UINT32 xEnd, UINT32 yEnd, BYTE color, BYTE lineWidth, BYTE r);
  34. extern void osd_draw_button_outline(int x1, int y1, int x2, int y2, int bDown, unsigned mask, int r);
  35. extern void osd_draw_region_rect(UINT32 xStart, UINT32 yStart, UINT32 xLen, UINT32 yLen, BYTE bkColor, BYTE r);
  36. extern void osd_print_read_eq(UINT8 r, BYTE * p);
  37. extern void osd_draw_read_button(BYTE xStart, BYTE yStart, BYTE xLen, BYTE color, BYTE bDown);
  38. extern void osd_init_rep_reading(void);
  39. extern int IsOSDChinese();
  40. extern int is_menu(void);
  41. #ifdef SUPPORT_SOUND_EFFECT
  42. //2004AUDDRV extern int AudioIOControl(UINT16 wCode, UINT32 cType, UINT32 wParam);
  43. #else
  44. //2004AUDDRV extern int AudioIOControl(UINT16 wCode, BYTE cType, UINT16 wParam);
  45. #endif
  46. extern void setup_eq_display(UINT8 val);
  47. extern void add_input_num(int *v);
  48. extern UINT32 get_dsp3_pcm_value(unsigned x_off);
  49. extern void set_dsp3_pcm_value(unsigned x_off, unsigned value);
  50. #ifndef DVDRELEASE
  51. #define  READ_DBG
  52. #endif
  53. /*========================Begining of Implement Code ======================*/
  54. UINT8 uReadSel[MAX_READ_ITEM] = {REC_Q_MIDDLE, FUDO_REPEAT, 0, 0};  //for selection initialization
  55. const UINT8 uReadItem[MAX_READ_ITEM][MAX_ITEM_SEL]=
  56. {
  57.     {SET_FUNC, STR_OS_REC_MODE, STR_OS_HIGH, STR_OS_MIDDLE, STR_OS_LOW, 0,},
  58.     {SET_FUNC, STR_OS_READ_MODE, STR_OS_GENDU, STR_OS_REPEAT, STR_OS_COMPARE, 0,},
  59.     {SET_NM,   STR_OS_REP_TIMES, STR_OS_TIME_PROMP, 0, 0, 0},       
  60.     {SET_CHART, STR_OS_READ_EQ, 0, 0, 0, 0},
  61. };
  62. const char *const read_osd_str[MAX_READ_OSD_LANGS][MAX_OSD_STR] =  
  63. {
  64.     //English 
  65.     {
  66.         "REC MODE",             //0
  67.         "HIGH",                 //1 
  68.         "MIDDLE",               //2
  69.         "LOW",                  //3
  70.         "READ MODE",            //4 
  71.         "FOLLOW",               //5
  72.         "COMPARE",              //6
  73.         "REPEAT",               //7
  74.         "REP TIMES",            //8        
  75.         "EQ",                   //9
  76.         "__",                   //10
  77.     },
  78.     //Chinese
  79.     {
  80.         OS_REC_MODE,            //0   
  81.         OS_REC_HIGH,            //1  
  82.         OS_REC_MIDDLE,          //2  
  83.         OS_REC_LOW,             //3  
  84.         OS_READ_MODE,           //4  
  85.         OS_READ_GENDU,          //5  
  86.         OS_READ_COMPARE,        //6  
  87.         OS_READ_REPEAT,         //7  
  88.         OS_REP_TIMES,          //8  
  89.         OS_READ_EQ,             //9 
  90.         "__",                   //10
  91.     }, 
  92. };
  93. /*
  94. ******************************************************************************
  95. * Function: RepReadSendCmd()
  96. * Description: Send DSP command for record and rep reading control
  97. * Syntax: void RepReadSendCmd(UINT8 uCmdType);
  98. * Parameters: uCmdType-----type of rep read DSP command
  99. * Returns: none
  100. ******************************************************************************
  101. */
  102. int RepReadSendCmd(UINT8 uCmdType)
  103. {
  104.     int iRes;
  105.     
  106.     switch(uCmdType){
  107.         case FUDO_CMD_STOP:
  108.             //ClearReadMode();    
  109.             printf("=========send fudu stop command========n");
  110.             break;
  111.         case FUDO_CMD_REC:
  112.             //set_dsp3_pcm_value(22, 0);
  113.             SetReadRecording();           
  114.             printf("=========send fudu record command========n");
  115.             break;
  116.         case FUDO_CMD_PLAY:
  117.             SetReadPlayback();
  118.             printf("=========send fudu play command========n");
  119.             break;
  120.         case FUDO_CMD_PAUSE:
  121.             printf("=========send fudu pause command========n");
  122.             break;
  123.         case FUDO_CMD_Q_H:       
  124.             printf("=========send fudu high quality setting command========n");
  125.             break;
  126.         case FUDO_CMD_Q_M:       //middle record quality
  127.             printf("=========send fudu middle quality setting command========n");
  128.             break;
  129.         case FUDO_CMD_Q_L:
  130.             printf("=========send fudu low quality setting command========n");
  131.             break;
  132.         default: 
  133.             break; 
  134.     }   
  135.     iRes = DSP_AudioIOControl(RECORDMIC,uCmdType, 0);//2004AUDDRV AudioIOControl(RECORDMIC,uCmdType, 0);
  136.     return iRes;
  137. }
  138. /*
  139. ******************************************************************************
  140. * Function: SetRecordQuality()
  141. * Description: Setup rep read record quality
  142. * Syntax: void SetRecordQuality(UINT8 uType);
  143. * Parameters: uCmdType-----type of rep read DSP command
  144. * Returns: none
  145. ******************************************************************************
  146. */
  147. void SetRecordQuality(UINT8 uIndex)
  148. {
  149.     switch(uIndex){
  150.         case 0:
  151.             RepReadSendCmd(FUDO_CMD_Q_H);
  152.             break;
  153.         case 1:
  154.             RepReadSendCmd(FUDO_CMD_Q_M);
  155.             break;
  156.         case 2:
  157.             RepReadSendCmd(FUDO_CMD_Q_L);
  158.             break;
  159.         default:
  160.             break; 
  161.     }
  162. }
  163. /*
  164. ******************************************************************************
  165. * Function: InitRead()
  166. * Description: initial read related vars 
  167. * Syntax: void InitRead(void);
  168. * Returns: none
  169. ******************************************************************************
  170. */
  171. void InitRead(void)
  172. {
  173.     uRecordMode = uReadSel[REC_MODE_ITEM];
  174.     uFudoMode = uReadSel[READ_MODE_ITEM];
  175.     uPlaybackTimes = DEF_REP_TIMES;
  176.     uReadMenuLevel = 0;
  177.     uReadShowEq = 0;
  178.     setup_eq_display(0x0f);
  179.     ClearReadMode();
  180. }
  181. /*
  182. ******************************************************************************
  183. * Function: CancelRead()
  184. * Description: cancel fudo state
  185. * Syntax: void CancelRead(void);
  186. * Returns: none
  187. ******************************************************************************
  188. */
  189. void CancelRead(void)
  190. {
  191.     full_scrn = 0;
  192.     osd_init();
  193.     setup_eq_display(0x0f);
  194.     ClearReadMode();
  195.     AUDIF_Demute();//2004AUDDRV AudioDemute();
  196. }
  197. /*
  198. ******************************************************************************
  199. * Function: ClearReadMode()
  200. * Description: clear read related vars and state and do some action
  201. * Syntax: void ClearReadMode(void);
  202. * Returns: none
  203. ******************************************************************************
  204. */
  205. void ClearReadMode(void)
  206. {
  207.     uReadStatus = READ_ST_NONE; 
  208.     RepReadSendCmd(FUDO_CMD_STOP);
  209.     ReadShowPromptInfo(0);
  210.     uReadEqType = ORI_EQ;
  211.     uRealPBTimes = uPlaybackTimes;                
  212.     uPlaybackFlag = 0;   
  213. }
  214. /*
  215. ******************************************************************************
  216. * Function: GetReadBtnMode()
  217. * Description: Draw read panel item button
  218. * Syntax: UINT8 GetReadBtnMode(UINT8 uIndex, UINT8 uLevel);
  219. * Parameters: uIndex    ---------- button's index
  220.               uLevel    ---------- 0: Main Menu, 1: Sub Menu Level  
  221. * Returns: current button's mode of sub menu button
  222. ******************************************************************************
  223. */
  224. UINT8 GetReadBtnMode(UINT8 uIndex)
  225. {
  226.     if(uIndex == uReadSel[index_y] ){
  227.         if (uIndex == index_y2 )
  228.             return SEL_BTN_HL;
  229.         else
  230.             return SEL_BTN_NORM;
  231.     }else{
  232.         if (uIndex == index_y2 )
  233.             return UNSEL_BTN_HL;
  234.         else
  235.             return UNSEL_BTN_NORM;
  236.     }
  237. }
  238. /*
  239. ******************************************************************************
  240. * Function: DrawReadItem()
  241. * Description: Draw read panel item button
  242. * Syntax: void DrawReadItem(UINT8 uID, UINT8 uUpDown, UINT8 uDrawY, UINT8 uLevel);
  243. * Parameters:   draw_y    ----------    index in button vertical array   
  244.                 uLevel    ----------    0: Main Menu, 1: Sub Menu Level
  245.                 uMode     ----------    button's sel/unsel/hl...
  246. * Returns: none
  247. ******************************************************************************
  248. */
  249. void DrawReadItem(UINT8 uDrawY, UINT8 uLevel, UINT8 uMode)
  250. {
  251. const char   *str;
  252. UINT8 uCurrY ;
  253. UINT8 uBtnX;
  254. UINT8 uBtnStrX;
  255. UINT8 uBtnLen;
  256. UINT8 uUpDown;
  257. UINT8 uBgColor;
  258. UINT8 uFontColor;
  259. UINT8 uID;
  260. UINT8 uLangID = 0;
  261. if(IsOSDChinese())
  262.         uLangID = 1;
  263.  
  264. if(uLevel){ //sub level
  265.     uBtnX = READ_SUB_MENU_X;
  266.     uBtnStrX = READ_SUB_MENU_X + 1;
  267.     uCurrY = index_y2;
  268.     uBtnLen = READ_BTN_WIDTH;
  269.     uID = uReadItem[index_y][uDrawY + 2];
  270. }else{      //main level
  271.     uCurrY = index_y;
  272.     uBtnX = 1;
  273.     uBtnStrX = 2;
  274.     uBtnLen = READ_BTN_WIDTH;
  275.     uID = uReadItem[uDrawY][1];
  276.     }
  277. str=read_osd_str[uLangID][uID];    
  278.     
  279.     switch(uMode)
  280.     {
  281.         default:
  282.      case UNSEL_BTN_NORM:  
  283.      uFontColor = FONT_CLR; 
  284.      uBgColor = BG_CLR; 
  285.      uUpDown = BTN_UP;     
  286.      break;
  287.      case UNSEL_BTN_HL:
  288.      uFontColor = ANTI_FONT_CLR; 
  289.      uBgColor = ANTI_BG_CLR; 
  290.      uUpDown = BTN_UP;     
  291.      break;
  292.      case SEL_BTN_NORM:
  293.      uFontColor = SEL_FONT_CLR; 
  294.      uBgColor = BG_CLR; 
  295.      uUpDown = BTN_DOWN;     
  296.      break;
  297.      case SEL_BTN_HL:
  298.      uFontColor = ANTI_FONT_CLR; 
  299.      uBgColor = ANTI_BG_CLR; 
  300.      uUpDown = BTN_DOWN; 
  301.      break;
  302.     }    
  303.     if(uLevel)
  304.         uDrawY += index_y_start;
  305. osd_draw_read_button(uBtnX, uDrawY, uBtnLen,  uBgColor, uUpDown);
  306. osd_DrawRegionString(uBtnStrX, uDrawY*8 + 2, (BYTE *)str, uFontColor, uBgColor, READ_REGION);
  307. }
  308. /*
  309. ******************************************************************************
  310. * Function: DrawRead2ndMenu()
  311. * Description: Draw read panel item button
  312. * Syntax: void DrawRead2ndMenu(UINT8 uTypee);
  313. * Parameters:   type ----------  0: for info display 1: for sub menu display
  314. * Returns: none
  315. ******************************************************************************
  316. */
  317. void DrawRead2ndMenu(UINT8 uType)
  318. {
  319.     UINT8 uID, i;
  320.     const char *str;
  321.     
  322.     if(uType == 0){ //just show current setup information of every items
  323.         //show current record mode
  324.         uID = uReadItem[REC_MODE_ITEM][uRecordMode + 2];
  325.         str = read_osd_str[0][uID];
  326.         osd_DrawRegionString(READ_SUB_MENU_X + 1, REC_MODE_ITEM * 8 + 2, (BYTE *)str, 
  327.                              SEL_FONT_CLR, BG_CLR, READ_REGION);
  328.         
  329.         //show current record mode
  330.         uID = uReadItem[READ_MODE_ITEM][uFudoMode + 2];
  331.         str = read_osd_str[0][uID];
  332.         osd_DrawRegionString(READ_SUB_MENU_X + 1, READ_MODE_ITEM * 8 + 2, (BYTE *)str, 
  333.                              SEL_FONT_CLR, BG_CLR, READ_REGION);
  334.         
  335.         //show current playback times
  336.         psprintf(linebuf, "%02d", uPlaybackTimes);
  337.         osd_DrawRegionString(READ_SUB_MENU_X + 1, REPTIMES_ITEM * 8 + 2, linebuf, 
  338.                              SEL_FONT_CLR, BG_CLR, READ_REGION);
  339.                               
  340.     }else{  //draw sub menu for selection
  341.         osd_draw_region_rect( (READ_SUB_MENU_X - 1) * 16 , 8, (READ_BTN_WIDTH + 1)*16 + 4, 32*4, 
  342.                              BG_CLR, READ_REGION); //clear the old sub menu
  343.         osd_DrawRegionString(READ_SUB_MENU_X - 1, index_y * 8 + 2, Ch_arrorR,
  344.                              FONT_CLR, BG_CLR, READ_REGION);//draw arrow
  345.        
  346.         uReadSelMaxIndex = 0;
  347.         for(i = 2; i < MAX_ITEM_SEL; i++)
  348.         {
  349.             //show sub item except EQ item
  350.             if(uReadItem[index_y][0] != SET_CHART){ 
  351.                 
  352.                 uID = uReadItem[index_y][i];
  353.                 if(uID == 0)
  354.                     break;
  355.                     
  356.                 if( (i - 2) == uReadSel[index_y] ){
  357.                     if(uReadMenuLevel)
  358.                         DrawReadItem(i - 2, SUB_LEVEL, SEL_BTN_HL );
  359.                     else
  360.                         DrawReadItem(i - 2, SUB_LEVEL, SEL_BTN_NORM );
  361.                 }
  362.                 else
  363.                     DrawReadItem(i - 2, SUB_LEVEL, UNSEL_BTN_NORM );
  364.             }            
  365.         }
  366.         uReadSelMaxIndex = i - 2;
  367.     }
  368.     
  369. }
  370. /*
  371. ******************************************************************************
  372. * Function: ReadShowPromptInfo()
  373. * Description:  check if need to do fudo cmd and flow contrl 
  374. * Syntax: void ReadShowPromptInfo(UINT8 uShowHide);
  375. * Parameters:   uShowHide ---------- 0: Erase info, 1:Display info
  376. * Returns: none
  377. ******************************************************************************
  378. */
  379. void ReadShowPromptInfo(UINT8 uShowHide)
  380. {
  381.     UINT8 uLangID = 0;
  382.     BYTE ccTimes[10];
  383.     
  384.     if(!uReadShowEq)
  385.         return;
  386.         
  387. const char *ccInfo[MAX_READ_OSD_LANGS][3] = 
  388. {
  389.     { "RECORD...",      "READ...",      "PLAYING",}, 
  390.     { OS_PLEASE_REC, OS_PLEASE_READ, OS_PLAY_REC, },
  391. };
  392. if(IsOSDChinese())
  393.         uLangID = 1;
  394.     
  395.     //clear original information
  396.     osd_draw_region_rect(INFO_STR_X * 16 - 2, INFO_STR_Y*4-2, (READ_BTN_WIDTH - 1) *16, 30, BG_CLR, READ_REGION); 
  397.     
  398.     if(uShowHide){             
  399.         if( IsReadRecording() )
  400.             strcpy(linebuf, ccInfo[uLangID][0]);
  401.         else if( IsReadPlayback() ){  
  402.             psprintf(ccTimes, " %d",  uPlaybackTimes - uRealPBTimes + 1);                 
  403.             strcpy(linebuf, ccInfo[uLangID][2]);
  404.             strcat1(linebuf, ccTimes); 
  405.         }else if( IsReadGendu() && uPlaybackFlag ) 
  406.             strcpy(linebuf, ccInfo[uLangID][1]);
  407.         else
  408.             linebuf[0] = '';
  409.         osd_DrawRegionString(INFO_STR_X, INFO_STR_Y, linebuf, INFO_FONT_CLR, BG_CLR, READ_REGION);
  410.     }
  411. }
  412. /*
  413. ******************************************************************************
  414. * Function: ShowReadPage()
  415. * Description: Show Read operaton osd panel
  416. * Syntax: void ShowReadPage(void);
  417. * Returns: none
  418. ******************************************************************************
  419. */
  420. void ShowReadPage(void)
  421. {
  422.     UINT32  i;
  423.     
  424.     //initialization
  425.     uRecordMode = uReadSel[REC_MODE_ITEM];
  426.     uFudoMode = uReadSel[READ_MODE_ITEM];    
  427.     uReadMenuLevel = 0;
  428.     uReadShowEq = 0;    
  429.     setup_eq_display(0x0f);
  430.     index_y = MAX_READ_ITEM;
  431.     index_y2 = 0;
  432.     
  433.     ClearReadMode();      
  434.     RepReadSendCmd(FUDO_CMD_STOP);
  435.     SetRecordQuality(uRecordMode);
  436.     
  437.     //draw outline 
  438.     osd_init_rep_reading();            
  439.     osd_draw_region_rect(0, 0, READ_REG_W*16, READ_REG_H, BG_CLR, READ_REGION);           
  440.     osd_draw_button_outline(2, 2, READ_REG_W*16-2, READ_REG_H -2, BTN_UP, 0x0F, READ_REGION);
  441.             
  442.     //draw main buttons            
  443.     for(i = 0; i< MAX_READ_ITEM; i++)
  444.     {
  445.         DrawReadItem(i, MAIN_LEVEL, UNSEL_BTN_NORM);    
  446.     }
  447.     
  448.     //initialization for display eq
  449.     uReadShowEq = 1;            
  450.     uReadEqType = ORI_EQ;
  451.     setup_eq_display(1);
  452.     for(i=0;i<13;i++)
  453.         bEqEnergyMax[i]=0;
  454.     unEqMaxRef=0;
  455.     
  456.     //draw EQ background    
  457.     //osd_draw_region_rect( READ_SUB_MENU_X * 16 , EQ_BG_START_Y, READ_BTN_WIDTH * 16, 55, FONT_CLR, READ_REGION);   
  458. }
  459. /*
  460. ******************************************************************************
  461. * Function: ReadSaveSetup(void)
  462. * Description:  save rep read setup
  463. * Syntax: void ReadSaveSetup(void);
  464. * Returns: none
  465. ******************************************************************************
  466. */
  467. void ReadSaveSetup(void)
  468. {   
  469.     //Note: when do setup, we clear current read mode
  470.     if(index_y == REC_MODE_ITEM){
  471.         uReadSel[index_y] = index_y2;
  472.         uRecordMode = index_y2;
  473.         ClearReadMode();
  474.         AUDIF_Demute();//2004AUDDRV AudioDemute();
  475.         SetRecordQuality(uRecordMode);
  476.     }else if(index_y == READ_MODE_ITEM){
  477.         uReadSel[index_y] = index_y2;
  478.         uFudoMode = index_y2;
  479.         ClearReadMode();
  480.         AUDIF_Demute();//2004AUDDRV AudioDemute();
  481.     }else{
  482.         if(uPBTimesSetting){            
  483.             uPlaybackTimes = uPBTimesSetting;            
  484.             ClearReadMode();
  485.             AUDIF_Demute();//2004AUDDRV AudioDemute();
  486.         }
  487.     }
  488. }
  489. /*
  490. ******************************************************************************
  491. * FUDO UI OPERATION FUNCTIONS
  492. * Up/Down/Left/Right & Enter Operation process
  493. ******************************************************************************
  494. */
  495. void read_func_up(void)
  496. {
  497.     UINT8 uOldIndex;
  498.     
  499.     if(uReadMenuLevel == 0){
  500.         uOldIndex = index_y;
  501.         if(index_y >= MAX_READ_ITEM){
  502.             index_y = MAX_READ_ITEM - 1;            
  503.             DrawReadItem(index_y, MAIN_LEVEL, SEL_BTN_HL );
  504.         }else{
  505.             //current button index       
  506.             if(index_y == 0){
  507.                 index_y = MAX_READ_ITEM - 1;
  508.             }else{
  509.                 index_y--;
  510.             }      
  511.               
  512.             //change button status
  513.             DrawReadItem(uOldIndex, MAIN_LEVEL, UNSEL_BTN_NORM );
  514.             DrawReadItem(index_y, MAIN_LEVEL, SEL_BTN_HL );
  515.         }
  516.         //refresh sub menu
  517.         index_y_start = index_y;                //sub menu y start intilization
  518.         index_y2 = uReadSel[index_y]; 
  519.         uReadShowEq = 0;
  520.         if(index_y == EQ_ITEM){
  521.             //clear sub menu and draw EQ background
  522.             osd_draw_region_rect( (READ_SUB_MENU_X - 1) * 16 , 8, (READ_BTN_WIDTH + 1)*16 + 4, 32*4, BG_CLR, READ_REGION); 
  523.             //osd_draw_region_rect( READ_SUB_MENU_X * 16 , EQ_BG_START_Y, READ_BTN_WIDTH * 16, 110, FONT_CLR, READ_REGION);                                           
  524.             uReadShowEq = 1;                                        
  525.         }else
  526.             DrawRead2ndMenu(1);
  527.     }else{  /*second level*/
  528.         uOldIndex = index_y2;
  529.         if(index_y2 > 0)
  530.             index_y2--;
  531.             
  532.         //change sub button status
  533.         DrawReadItem(uOldIndex, SUB_LEVEL, GetReadBtnMode(uOldIndex) );
  534.         DrawReadItem(index_y2, SUB_LEVEL, GetReadBtnMode(index_y2) );
  535.     }
  536. }
  537. void read_func_down(void)
  538. {
  539.     UINT8 uOldIndex;
  540.     
  541.     if(uReadMenuLevel == 0){
  542.         uOldIndex = index_y;
  543.         if(index_y >= MAX_READ_ITEM){
  544.             index_y = 0;
  545.             DrawReadItem(index_y, MAIN_LEVEL, SEL_BTN_HL );
  546.         }else{
  547.             //current button index       
  548.             if(index_y == MAX_READ_ITEM - 1){
  549.                 index_y = 0;
  550.             }else{
  551.                 index_y++;
  552.             }        
  553.             //change sub button status
  554.             DrawReadItem(uOldIndex, MAIN_LEVEL, UNSEL_BTN_NORM );
  555.             DrawReadItem(index_y, MAIN_LEVEL, SEL_BTN_HL );
  556.         }
  557.         //refresh sub menu
  558.         index_y_start = index_y;                //sub menu y start intilization
  559.         index_y2 = uReadSel[index_y];    
  560.         uReadShowEq = 0;
  561.         if(index_y == EQ_ITEM){
  562.             //clear sub menu and draw EQ background
  563.             osd_draw_region_rect( (READ_SUB_MENU_X - 1) * 16 , 8, (READ_BTN_WIDTH + 1)*16 + 4, 32*4, BG_CLR, READ_REGION); 
  564.             //osd_draw_region_rect( READ_SUB_MENU_X * 16 , EQ_BG_START_Y, READ_BTN_WIDTH * 16, 110, FONT_CLR, READ_REGION);                                           
  565.             uReadShowEq = 1;                                        
  566.         }else
  567.             DrawRead2ndMenu(1);
  568.     }else{  /*second level*/
  569.         uOldIndex = index_y2;
  570.         if(index_y2 < (uReadSelMaxIndex - 1) )
  571.             index_y2++;
  572.         //change button status
  573.         DrawReadItem(uOldIndex, SUB_LEVEL, GetReadBtnMode(uOldIndex) );
  574.         DrawReadItem(index_y2, SUB_LEVEL, GetReadBtnMode(index_y2) );
  575.     }
  576. }
  577. void read_func_left(void)
  578. {
  579.     if(uReadMenuLevel){
  580.         uReadMenuLevel = 0;
  581.         DrawRead2ndMenu(1);
  582.         DrawReadItem(index_y, MAIN_LEVEL, SEL_BTN_HL);
  583.     }
  584. }
  585. void read_func_right(void)
  586. {
  587.     if( (uReadMenuLevel == 0) && (index_y != EQ_ITEM) )
  588.         read_func_select();
  589. }
  590. void read_func_select(void)
  591. {
  592.     if(index_y >= MAX_READ_ITEM)
  593.         return;
  594.         
  595.     if(uReadMenuLevel == 0){    
  596.         if(index_y != EQ_ITEM){   
  597.             DrawReadItem(index_y, MAIN_LEVEL, SEL_BTN_NORM);
  598.             index_y_start = index_y;                //sub menu y start intilization
  599.             index_y2 = uReadSel[index_y];  
  600.             uPBTimesSetting = 0;
  601.             uReadMenuLevel = 1;
  602.             DrawRead2ndMenu(1);
  603.             uReadShowEq = 0;
  604.         }
  605.     }else{  //sub menu 
  606.         uReadMenuLevel = 0; 
  607.         ReadSaveSetup();
  608.         DrawReadItem(index_y, MAIN_LEVEL, SEL_BTN_HL);
  609.              
  610.         //clear the  sub menu and draw EQ background
  611.         osd_draw_region_rect( (READ_SUB_MENU_X - 1) * 16 , 8, (READ_BTN_WIDTH + 1)*16 + 4, 32*4, BG_CLR, READ_REGION); 
  612.         //osd_draw_region_rect( READ_SUB_MENU_X * 16 , EQ_BG_START_Y, READ_BTN_WIDTH * 16, 110, FONT_CLR, READ_REGION);                                           
  613.         uReadShowEq = 1;                                               
  614.     }
  615. }
  616. void read_func_input(void)
  617. {
  618.     int iDispVal;
  619.     
  620.     iDispVal = uPBTimesSetting;
  621.     add_input_num(&iDispVal);
  622.     uPBTimesSetting = (iDispVal % 100);
  623.     if(uPBTimesSetting > 100)
  624.         uPBTimesSetting = 0;
  625.         
  626.     if(uPBTimesSetting == 0){
  627.         strcpy(linebuf, "__");        
  628.     }else{
  629.         psprintf(linebuf, "%02d", uPBTimesSetting);
  630.     }
  631.     osd_DrawRegionString(READ_SUB_MENU_X + 1, index_y*8 + 2, linebuf, WHITE_CLR, ANTI_BG_CLR, READ_REGION);
  632. }
  633. /*
  634. ******************************************************************************
  635. * Function: DisplayReadEq(void)
  636. * Description:  save rep read setup
  637. * Syntax: void DisplayReadEq(UINT8 type, BYTE r);
  638. * Parameters:  type ---------  ORI_EQ/REC_EQ, Eq type
  639.                r    ---------  region to diplay read eq 
  640. * Returns: none
  641. ******************************************************************************
  642. */
  643. void DisplayReadEq(UINT8 type, BYTE r)
  644. {
  645.     BYTE    i,j;
  646. BYTE bEqValue[7];
  647. BYTE  *p;
  648. if( (full_scrn & READ) && uReadShowEq ) {
  649.     if(bEqDisplay == 4){
  650.         if(type == ORI_EQ)
  651.                 p = (BYTE *)(SDRAM_BASE_CACHED+MEM_PCMYA*1024);
  652.             else    //Record voice's EQ
  653.                 p = (BYTE *)(SDRAM_BASE_CACHED+MEM_PCMYA*1024 + 23 *3);
  654.             
  655.             for (i=0, j=0;i<7;i++) 
  656.             {
  657.                 UINT32  eqSrc;
  658.                 UINT32  eqTemp;
  659.                 
  660.                 eqSrc = (((*p)<<8) | *(p+1));                
  661.                 p+=3;
  662.         
  663.                 if (eqSrc > unEqMaxRef)
  664.          unEqMaxRef = eqSrc;
  665.         
  666.                 //normalize value to 0 ~ 25
  667.                 if (unEqMaxRef==0) //EQ value range check, 
  668.                      eqTemp = 0;
  669.                 else{
  670.                     eqTemp = eqSrc*25/unEqMaxRef;
  671.                     bEqValue[i] = eqTemp;
  672.                     if (bEqValue[i]<4) {
  673.                         j++;
  674.                     }
  675.                 }
  676.             }
  677.             //adjust max refrence 
  678.             if ( (j>=6) && (unEqMaxRef>400) )
  679.                 unEqMaxRef=unEqMaxRef-(unEqMaxRef/8);
  680.             osd_print_read_eq(r, bEqValue);             
  681.             setup_eq_display(1);
  682.         }else
  683.             bEqDisplay++;
  684.     }
  685. }
  686. /*
  687. ******************************************************************************
  688. *           FUDO FLOW CONTROL FUNCTIONS
  689. ******************************************************************************
  690. */
  691. /*
  692. ******************************************************************************
  693. * Function: PollingRecBufStatus()
  694. * Description:  polling the buffer's statuas 
  695. * Syntax: UINT32 PollingRecBufStatus(void);
  696. * Returns: 1: buffer all used. 0: not used over
  697. * Side effect: when buffer used over, send REPEAT AB cmd       
  698. ******************************************************************************
  699. */
  700. UINT32 PollingRecBufStatus(void)
  701. {
  702.     UINT32 uRatio;
  703.    
  704.     uRatio = get_dsp3_pcm_value(22);
  705.         
  706.     if( (IsReadPlayback() && (uRatio <= 2)) || 
  707.       ( IsReadRecording() && (uRatio >= 98 )) ){
  708.         if(IsReadRecording())
  709.             uRecBufRatio = uRatio;
  710.         return 1;
  711.     }else
  712.         return 0;
  713. }
  714. /*
  715. ******************************************************************************
  716. * Function: ReadRecPlayback()
  717. * Description:  read flow control for record voice playback
  718. * Syntax: void ReadDoRecPlayback(void);
  719. ******************************************************************************
  720. */
  721. void ReadRecPlayback(void)
  722. {
  723.     SetReadPlayback(); 
  724.     RepReadSendCmd(FUDO_CMD_PLAY);
  725.     uReadEqType = REC_EQ;
  726.     ReadShowPromptInfo(1);           
  727. }
  728. /*
  729. ******************************************************************************
  730. * Function: MainLoopCtrlReadMode()
  731. * Description:  check if need to do special control mode in MediaMainLoop 
  732. * Parameters:   uFlag --------- befor/in/ou MediaMainLoop
  733. * Syntax: void MainLoopCtrlReadMode(UINT32 uFlag);
  734. * Returns: when in MainLoop, return 1 will break main loop
  735. ******************************************************************************
  736. */
  737. UINT32 MainLoopCtrlReadMode(UINT32 uFlag)
  738. {   
  739.     UINT32 uRes = 0; 
  740.           
  741.     if( (full_scrn & READ) ){
  742.         switch(uFlag)
  743.         {
  744.             case PRE_MAIN_LOOP: //avoid audio stop cmd, we send fudo cmd just before mainloop
  745.                 if( IsReadGendu() )
  746.                     break;
  747.                 
  748.                 if(uPlaybackFlag && uRealPBTimes){
  749.                     set_dsp3_pcm_value(22, uRecBufRatio);
  750.                     if( IsReadRepeat() ){
  751.                         ReadRecPlayback();
  752.                         uRealPBTimes--;
  753.                     }else if( IsReadCompare() ){
  754.                         if( IsReadPlayback() || IsReadRecording() ){                        
  755.                             uReadStatus = READ_ST_NONE;
  756.                             uReadEqType = ORI_EQ; 
  757.                             ReadShowPromptInfo(0);  
  758.                         }else{
  759.                             ReadRecPlayback();
  760.                             uRealPBTimes--;
  761.                         }
  762.                     }
  763.                 }else if(uRealPBTimes == 0) {   //playback repeat tiems over, clear read mode
  764.                     ClearReadMode();                                 
  765.                 }else if( IsReadRecording() ){                
  766.                     RepReadSendCmd(FUDO_CMD_REC);
  767.                     uReadEqType = REC_EQ;
  768.                     ReadShowPromptInfo(1);                     
  769.                 }
  770.                 break;
  771.             
  772.             case IN_MAIN_LOOP:  //for read and flow control 
  773.                 if( IsReadGendu() ){    //for gendu, jsut mute the origianal music
  774.                     if(uPlaybackFlag)
  775.                         AUDIF_Set_Volume(0);//AudioSetVolume(0);                               
  776.                 }else if( IsReadMode() ){
  777.                     AUDIF_Set_Volume(0);//AudioSetVolume(0);
  778.                     uReadEqType = REC_EQ; 
  779.                     if( PollingRecBufStatus() ){
  780.                         if( IsReadRecording() ) //set flag for playback control
  781.                             uPlaybackFlag = 1;
  782.                     
  783.                         //if between AB, buffer used over, should do REPEAT AB
  784.                         RepReadSendCmd(FUDO_CMD_STOP);                         
  785.                         ircmd_post_func( CMD_FUNC | CMD_FUNC_REPAB );
  786.                         uRes = 1;
  787.                     }
  788.                 }
  789.                 break;
  790.             
  791.             case  POST_MAIN_LOOP:  //for read and flow control  
  792.                 break;           
  793.         }
  794.     }
  795.     return uRes;
  796. }
  797. /*
  798. ******************************************************************************
  799. * Function: RepBCheckReadMode()
  800. * Description:  check if need to do fudo cmd and flow contrl 
  801. * Syntax: void RepBCheckReadMode(void);
  802. * Returns: none
  803. ******************************************************************************
  804. */
  805. void RepBCtrlReadMode(void)
  806. {    
  807.     if( (full_scrn & READ) ){
  808.         AUDIF_Set_Volume(0);//AudioSetVolume(0);
  809.        
  810.         switch(uFudoMode)      
  811.         {
  812.             case FUDO_GENDU:    
  813.                 //just toggle for EQ type and original/record voice
  814.                 uPlaybackFlag ^= 0x01;
  815.                 ReadShowPromptInfo(uPlaybackFlag);    
  816.                 uReadEqType = uPlaybackFlag;
  817.                 break;
  818.                 
  819.             case FUDO_REPEAT:  //just for record flag and when reach B, buffer not full, used the ratio for playback
  820.             case FUDO_COMPARE:
  821.                 RepReadSendCmd(FUDO_CMD_STOP);      
  822.                 if( IsReadRecording() ){
  823.                     uRecBufRatio = get_dsp3_pcm_value(0x22);
  824.                     uPlaybackFlag = 1;
  825.                 }
  826.                          
  827.                 if( (uRealPBTimes == uPlaybackTimes) && (uPlaybackFlag == 0) ){ //when playback record over, send record cmd again 
  828.                     SetReadRecording();                    
  829.                     set_dsp3_pcm_value(22, 0);    
  830.                 }
  831.                 break;
  832.                 
  833.             default:
  834.                 break;            
  835.         }// end switch...    
  836.     }// end if...     
  837. }
  838. #endif  //#ifdef SUPPORT_REP_READ