psd.c
上传用户:poi891205
上传日期:2013-07-15
资源大小:9745k
文件大小:45k
源码类别:

DVD

开发平台:

C/C++

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *         Copyright (c) 2002 by Sunplus Technology Co., Ltd.             *
  4.  *                                                                        *
  5.  *  This software is copyrighted by and is the property of Sunplus        *
  6.  *  Technology Co., Ltd. All rights are reserved by Sunplus Technology    *
  7.  *  Co., Ltd. This software may only be used in accordance with the       *
  8.  *  corresponding license agreement. Any unauthorized use, duplication,   *
  9.  *  distribution, or disclosure of this software is expressly forbidden.  *
  10.  *                                                                        *
  11.  *  This Copyright notice MUST not be removed or modified without prior   *
  12.  *  written consent of Sunplus Technology Co., Ltd.                       *
  13.  *                                                                        *
  14.  *  Sunplus Technology Co., Ltd. reserves the right to modify this        *
  15.  *  software without notice.                                              *
  16.  *                                                                        *
  17.  *  Sunplus Technology Co., Ltd.                                          *
  18.  *  19, Innovation First Road, Science-Based Industrial Park,             *
  19.  *  Hsin-Chu, Taiwan, R.O.C.                                              *
  20.  **************************************************************************/
  21. /*--------------------------------------------------------------------------
  22. |  File Name   :  psd.c
  23. |
  24. |  Description : .... VCD 2.0 psd functionality..                                        
  25. |
  26. |  Version    :  0.1  
  27. |  
  28. |  Rev    Date              Author(s)      Status & Comments
  29. |-----------------------------------------------------------------------------------------
  30. |  0.1                                     Creating
  31. |  0.1  2004/11/30          Linrc          Add Comments
  32. |-----------------------------------------------------------------------------------------*/
  33. #include "config.h"
  34. #include "global.h"
  35. #include "macro.h"
  36. #include "regmap.h"
  37. #include "util.h"
  38. #include "memmap0.h"
  39. #include "func.h"
  40. #include "cdfunc.h"
  41. #include "vfdfunc.h"
  42. #include "stc.h"
  43. #include "cfont.h"
  44. #include "osd.h"
  45. #include "psd.h"
  46. #include "svcd.h"   //Jeff 20010717
  47. #include "image.h"
  48. #include "fs96602.h"
  49. #include "stdlib.h"
  50. #include "user_if.h"
  51. #include "misc.h"
  52. #include "fsnav.h"
  53. #include "NesInit.h"
  54. #include "kernel.h"
  55. #ifdef SP1000_NO_DVD
  56. #include "psd_null.c"
  57. #else
  58. //#define AU_REGS   ((volatile struct au_regs *)regs0)
  59. /*************************************************/
  60. #ifndef DVDRELEASE
  61. //#define MONE_PSD
  62. //#define MONE_PSD_READ
  63. //#define MONE_PSD_LIST_CONTENT
  64. //#define SHOW_PSD_WAITING
  65. #endif
  66. #ifndef MONE_PSD
  67. #undef printf
  68. #undef print_block
  69. #define printf(f, a...) do {} while (0)
  70. #define print_block(x,y) do {} while (0)
  71. #endif
  72. #define psd_epp_write(s)    epp_write_wait(s)
  73. //
  74. // FUNCTION
  75. // rand()
  76. //
  77. #define rand()      (regs0->stc_15_0)
  78. //
  79. // PSD_MSF
  80. //
  81. // default PSD start MSF address in VCD 2.0
  82. //
  83. #define PSD_MSF     MSF(0,4,34)
  84. #define List        (pFsJpeg->List)
  85. /**************************************************************************
  86.  *  Function Name: int psd_getlist(int ListID)                            *                
  87.  *  Purposes:                                                             *
  88.  *    read a specified PSD list-table(play-list/selection-list...)        *
  89.  *    into memory                                                         *
  90.  *  Descriptions:                                                         *
  91.  *     read a specified PSD list-table into memory                        *
  92.  *  Arguments:                                                            *
  93.  *  Input:    ListID --> The PSD list ID that will play...                *                                       
  94.  *  Returns:  0->Get play list ID OK;                                     *
  95.  *            1->Get list fail turn back to PBC off                       *
  96.  *  See also: None                                                        *
  97.  **************************************************************************/
  98. int psd_getlist(int ListID)
  99. {
  100.     int   length;
  101.     UINT8   *p;
  102.     UINT32  offset = ListID * psd_st.psd_offset_multiplier;
  103.     //
  104.     // read in list
  105.     //
  106.     rep_run_this_menu=0;//terry,new setup menu to recover menu,0508
  107.     p=wb_loc(msf2l(PSD_MSF),offset);
  108.     if(nav_data_err==0)
  109.         memcpy((BYTE *)&List,p,8);
  110.     else
  111.         List.s.header=0;
  112.     //
  113.     // load specific length of reset of data
  114.     //
  115.     // for play-list
  116.     // for selection-list
  117.     //
  118.     if (List.s.header==0x10)
  119.     {
  120.         
  121.         // play-list 2*NOI+14
  122.         length = 2*List.p.noi + 14;
  123.         if(List.p.noi==0){//wangap add 2004/12/29
  124.           length = 8;     //when the list data is wrong eg.for some bad vcd20 disc 
  125.           return 1;       //we just jump the list to play(as get list fail turn back to PBC off) 
  126.         }
  127.         #ifdef  MONE_PSD_READ
  128.         psprintf(linebuf, "PLAY %x %xn", ListID, length);
  129.         psd_epp_write(linebuf);
  130.         printf("PSD PLAY LIST-ID %x length %xn", ListID, length);
  131.         #endif
  132.     }
  133.     else if( (List.s.header==0x18)||(List.s.header==0x1a) )
  134.     {
  135.         // selection-list 2*NOS+20
  136.         length = 2*List.s.nos + 20;
  137.         #ifdef  MONE_PSD_READ
  138.         psprintf(linebuf, "SELECT %x %xn", ListID, length);
  139.         psd_epp_write(linebuf);
  140.         #endif
  141.     }
  142.     else if (List.s.header==0x1f)
  143.     {
  144.         // end-list -> the 8-byte read are enough
  145.         length = 8;
  146.         #ifdef  MONE_PSD_READ
  147.         psprintf(linebuf, "END %x %xn", ListID, length);
  148.         psd_epp_write(linebuf);
  149.         #endif
  150.     }
  151.     else
  152.     {
  153.         length = 8;
  154.         #ifdef  MONE_PSD_READ
  155.         printf("list %x %xn", ListID, length);
  156.         #endif
  157.         return 1;  //Terry 891005 get list fail turn back to PBS off
  158.     }
  159.     //do_cdrom_read_msf(((BYTE *)&List), PSD_MSF, offset, length);//kenny mark it
  160.     memcpy((BYTE *)&List,p,length);
  161.     #ifdef  MONE_PSD_LIST_CONTENT
  162.     {
  163.         int i;
  164.         for (i=0; i<length;)
  165.         {
  166.             // psprintf(linebuf, "%02x",((BYTE *)&List)[i]);
  167.             // psd_epp_write(linebuf);
  168.             printf( "%02x",((BYTE *)&List)[i]);
  169.             i++;
  170.             //if ((i&0x0f)==0) psd_epp_write("n");
  171.             if ((i&0x0f)==0) printf("n");
  172.         }
  173.         //psd_epp_write("n");
  174.         printf("n");
  175.     }
  176.     #endif
  177.     //delay(5000);
  178.     switch(play_state)
  179.     {
  180.         case VCD_STATE_POWER:
  181.         case VCD_STATE_STOP:
  182.         case VCD_STATE_OPEN:
  183.         return 1;
  184.     }
  185.     return 0;
  186. }
  187. /**************************************************************************
  188.  *  Function Name: int psd_play_item(int item)                            *                
  189.  *  Purposes:                                                             *
  190.  *    prepare for a PSD item playback.                                    *
  191.  *  Descriptions:                                                         *
  192.  *     The playback PSD item is track-number or entry-id or segment_id    *
  193.  *  Arguments:                                                            *
  194.  *  Input:   item --> Playback item ID                                    *                                       
  195.  *                    0-1     none                                        *
  196.  *                    2-99    track-number                                *
  197.  *                    100-599 entry_id + 100                              *
  198.  *                    600-999 <reserved>                                  *
  199.  *                    1000-2979   segment_id + 1000                       *
  200.  *  Returns: -1->item is wrong;                                           *
  201.  *           -2->item nomber out of range                                 *
  202.  *           0 ->play item                                                *
  203.  *  See also: None                                                        *
  204.  **************************************************************************/
  205. int psd_play_item(int item)
  206. {
  207.     UINT8 new_psd_state =psd_state& 0xf0;
  208.     item=getUINT16_bi(&item);
  209.     //
  210.     // check if item is valid
  211.     //
  212.     //psd_st.psd_item_no = item;
  213.     ClearCommand();//terry,move to this by DTS check ,maybe it's worng?
  214.     //printf("item:%xn",item);
  215.     if (item<2)
  216.     {
  217.         return -1;
  218.     }
  219.     else if (item<100)
  220.     {
  221.         // check track
  222.         if (item>cd_trk_hi)
  223.             return -2;
  224.         psd_state = new_psd_state | PSD_PLAY_TRACK;
  225.     }
  226.     else if (item<600)
  227.     {
  228.         // check entry-point
  229.         int entries = get_entry(0) & 0xffff;
  230.         if ((item-99)>entries) return -2;
  231.         psd_state = new_psd_state | PSD_PLAY_ENTRY;
  232.     }
  233.     else if (item<1000)
  234.     {
  235.         return -1;
  236.     }
  237.     else if (item<2980)
  238.     {
  239.         // check valid-segment
  240.         BYTE seg_code = get_segment(item-999);
  241.         if ((seg_code&0x1f)==0) return -2;
  242.         psd_state = new_psd_state | PSD_PLAY_SEG;;
  243.     }
  244.     else
  245.     {
  246.         return -1;
  247.     }
  248.     if(goto_active==1)
  249.     {
  250.         s_msf=goto_time&0x00ffffff;
  251.         PlayLBA(msf2l(goto_time),0);
  252.     }else
  253.     if (item<100)
  254.     {
  255.         //
  256.         // ITEM: 1-99
  257.         // playback a track (item)
  258.         //
  259.         PlayTrack(item);
  260.     }
  261.     else if (item<600)
  262.     {
  263.         //
  264.         // ITEM: 1-99
  265.         // playback an entry (item-99)
  266.         //
  267.         PlayEntry(item-99);
  268.     }
  269.     else if (item<2980)
  270.     {
  271.         //
  272.         // ITEM: 1000-1999
  273.         // play segment (item-999)
  274.         //
  275.         //printf("=====PLAY SEGn");/*jhuang 891108*/
  276.         PlaySegment(item-999);
  277.     }
  278.     //  PictureCounter                = 0;
  279.     return 0;
  280. }
  281. /**************************************************************************
  282.  *  Function Name: int psd_timeout_value(int time)                        *     
  283.  *  Purposes:                                                             *
  284.  *    get the real time base on the timeout_value.                        *
  285.  *  Descriptions:                                                         *
  286.  *   This function call by psd timeout(),it return the real time out time *
  287.  *  Arguments:                                                            *
  288.  *  Input:   time --> 0-60     t seconds                                  *
  289.  *                    61-254   60 + 10 * (t-60) seconds                   *
  290.  *                    255      forever                                    *
  291.  *  Returns: 0-254->real time(seconds)                                    *
  292.  *           255->0                                                       *
  293.  *  See also: None                                                        *
  294.  **************************************************************************/
  295. int psd_timeout_value(int time)
  296. {
  297.     int s;
  298.     int t;
  299.     t = 0;
  300.     if (time!=0x00ff)
  301.     {
  302.         if (time<=60)
  303.             s = time;
  304.         else
  305.             s = time*10 - 540;
  306.         //t = (RTC_TICKS * s) / 16 + 1;
  307.         t = (RTC_TICKS * s)  + 1;//kenny 2001/7/27
  308.     }
  309.     return t;
  310. }
  311. /**************************************************************************
  312.  *  Function Name: int psd_search_entries(UINT32 msf_now)                 *                
  313.  *  Purposes:                                                             *
  314.  *    search psd entries.                                                 *
  315.  *  Descriptions:                                                         *
  316.  *    search entries from entry n to entry 0                              *
  317.  *  Arguments:                                                            *
  318.  *  Input:   msf_now --> msf entry now                                    *
  319.  *  Returns: entry                                                        *
  320.  *  See also:        ENTRY-n       ENTRY-o                                *
  321.  *                      +-------------+                                   *
  322.  *                          msf_now                                       *
  323.  **************************************************************************/
  324. int psd_search_entries(UINT32 msf_now)
  325. {
  326.     int entries;
  327.     msf_now = msf_now & 0x00ffffff; // don't compare TRK ??
  328.     entries = get_entry(0) & 0x0000ffff;
  329.     while (entries>0)
  330.     {
  331.         UINT32 msf = get_entry(entries)&0x00ffffff;
  332.         if (msf > msf_now)
  333.             entries--;
  334.     }
  335.     return entries;
  336. }
  337. /**************************************************************************
  338.  *  Function Name: UINT32  psd_callback_check(UINT32 func)                *                
  339.  *  Purposes:                                                             *
  340.  *    Check the IR_CMD function.                                          *
  341.  *  Descriptions:                                                         *
  342.  *   filter out special keys                                              *
  343.  *  Arguments:                                                            *
  344.  *  Input:   func --> cmd                                                 *
  345.  *  Returns: Cmd after function check                                     *
  346.  *  See also:CMD:CMD_FUNC_PLAY CMD_FUNC_DEFAULT CMD_FUNC_NEXT           *
  347.  *               CMD_FUNC_PREV CMD_FUNC_RETURN                           *
  348.  **************************************************************************/
  349. UINT32  psd_callback_check(UINT32 func)
  350. {
  351.     int c = func&0x00ff00;
  352.     int   bit15=0;
  353.     if (c == CMD_FUNC)
  354.     {
  355.         c = func&0x00ff;
  356.         if (List.p.header==LIST_PLAY)
  357.         {
  358.             //psd_state = PSD_PLAY_LIST;//terry , mark it,2001/10/2 09:26PM ,it will damage psd state machine
  359.             //
  360.             // PLAY:        no-effect
  361.             // PREV:        select list_prev
  362.             // NEXT:        select list_next
  363.             // RETURN:  select list_return
  364.             //
  365.             if(c==CMD_FUNC_PLAY)
  366.                 func=0;
  367.             else if(c==CMD_FUNC_NEXT)
  368.             {
  369.                 psd_st.psd_item_loop++;
  370.                 if(psd_st.psd_item_loop>=List.p.noi)
  371.                 {
  372.                     bit15=List.p.list_next;
  373.                     if(bit15&0x80)
  374.                         psd_st.psd_item_loop--;
  375.                 }
  376.             }else if(c==CMD_FUNC_PREV)
  377.             {
  378.                 if(psd_st.psd_item_loop==0)
  379.                     bit15=List.p.list_prev;
  380.             }else if(c==CMD_FUNC_RETURN)
  381.                 bit15=List.p.list_return;
  382.         }
  383.         else if (List.p.header==LIST_SELECTION)
  384.         {
  385.             //psd_state = PSD_SEL_LIST;
  386.             //
  387.             // PLAY:        select list_default
  388.             // PREV:        select list_prev
  389.             // NEXT:        select list_next
  390.             // RETURN:  select list_return
  391.             //
  392.             if(c==CMD_FUNC_NEXT)
  393.                 bit15=List.s.list_next;
  394.             else if(c==CMD_FUNC_PREV)
  395.                 bit15=List.s.list_prev;
  396.             else if(c==CMD_FUNC_RETURN)
  397.                 bit15=List.s.list_return;
  398.             else if( (c==CMD_FUNC_DEFAULT)||(c==CMD_FUNC_PLAY) )
  399.                 bit15=List.s.list_default;
  400.         }
  401.         if(bit15&0x80)
  402.             func=0;
  403.     }
  404.     else if (c == CMD_SELECT)
  405.     {
  406.         //psprintf(linebuf,"psd_state=%02xn",psd_state);
  407.         //epp_write_slow(linebuf);
  408.         c = func&CMD_MASK;
  409.         if (List.p.header!=LIST_SELECTION)
  410.         {
  411. //#ifndef FUSS_DVD
  412. //terry,2002/5/10 10:38