Mode_Detect.lst
上传用户:xmyjxjd
上传日期:2013-05-04
资源大小:1517k
文件大小:371k
开发平台:

C/C++

  1. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 1   
  2. C51 COMPILER V7.06, COMPILATION OF MODULE MODE_DETECT
  3. OBJECT MODULE PLACED IN .OutputMode_Detect.obj
  4. COMPILER INVOKED BY: C:KeilC51BINC51.EXE CodeMode_Detect.c OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND CODE SYMBOLS
  5.                     - PRINT(.OutputMode_Detect.lst) PREPRINT(.OutputMode_Detect.i) OBJECT(.OutputMode_Detect.obj)
  6. stmt level    source
  7.    1          
  8.    2          #define __MODEDETECT__
  9.    3          
  10.    4          #include "HeaderLcd_func.h"
  11.    5          #include "HeaderLcd_Main.h"
  12.    6          #include "HeaderAccess.h"
  13.    7          #include "Headerconfig.h"
  14.    8          #include "HeaderOSD.h"
  15.    9          #include "HeaderLcd_Auto.h"
  16.   10          #include "HeaderFrame_Sync.h"
  17.   11          #include "HeaderSrc_Ctrl.h"
  18.   12          #include "HeaderLCD_OSD.h"
  19.   13          
  20.   14          
  21.   15          /////////////////////////////////////////////////////////
  22.   16          //-------------------  Mode Detector  -----------------//
  23.   17          /////////////////////////////////////////////////////////
  24.   18          void Mode_Detector(void)
  25.   19          {
  26.   20   1      
  27.   21   1          switch (stGUD1.INPUT_SOURCE & 0x07)
  28.   22   1          {
  29.   23   2          case SOURCE_VGA :
  30.   24   2              case SOURCE_DVI :
  31.   25   2              // Save previous values of ucMode_Curr, bHpole_Curr and bVpole_Curr
  32.   26   2              bHpole_Prev = bHpole_Curr;
  33.   27   2              bVpole_Prev = bVpole_Curr;
  34.   28   2              
  35.   29   2              if ((MODE_NOSIGNAL == ucMode_Curr) || (MODE_NOSUPPORT == ucMode_Curr))
  36.   30   2                  Detect_Input_Mode();
  37.   31   2              else
  38.   32   2                  Check_Input_Mode();
  39.   33   2              break;
  40.   34   2      
  41.   35   2         default :
  42.   36   2              if ((MODE_NOSIGNAL == ucMode_Curr) || (MODE_NOSUPPORT == ucMode_Curr))
  43.   37   2                  Detect_Video_Mode();        // Set default polarity 
  44.   38   2              else
  45.   39   2                  Check_Video_Mode();         // Set polarity after measure
  46.   40   2              break;
  47.   41   2          }
  48.   42   1      
  49.   43   1          Measure_Mode();     // Measure mode-timing
  50.   44   1      }
  51.   45          
  52.   46          void Measure_Mode(void)
  53.   47          {
  54.   48   1      
  55.   49   1          
  56.   50   1          switch (stGUD1.INPUT_SOURCE & 0x07)
  57.   51   1          {
  58.   52   2                  RTDSetByte(SYNC_CTRL_4A,0x00);
  59.   53   2              case SOURCE_VGA :
  60.   54   2                      RTDSetByte(SYNC_POR_4C, (SYNC_SS == ucSync_Type) ? 0x02 : 0x32);
  61. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 2   
  62.   55   2              break;
  63.   56   2              
  64.   57   2              case SOURCE_DVI :
  65.   58   2      /*//eric 0729 test issue:DVI source change              
  66.   59   2      #if (TMDS_ENABLE)
  67.   60   2              if (0 == ucTMDS_SEARCH_COUNTER && MODE_NOSIGNAL == ucMode_Curr) // V101C modified
  68.   61   2              {
  69.   62   2                  RTDCodeW(TMDS_MANUAL_ON);
  70.   63   2      
  71.   64   2                  ucTMDS_SEARCH_COUNTER  = 0x08;
  72.   65   2              }        
  73.   66   2              ucTMDS_SEARCH_COUNTER -= 0x01;
  74.   67   2      #endif
  75.   68   2      */
  76.   69   2                      RTDSetByte(SYNC_POR_4C, 0x02);
  77.   70   2              break;
  78.   71   2              
  79.   72   2              default :
  80.   73   2                      RTDSetByte(SYNC_POR_4C, 0x02);
  81.   74   2              break;
  82.   75   2          }
  83.   76   1              
  84.   77   1      }
  85.   78          
  86.   79          #if(SOURCE_AUTO_SCAN)
  87.   80          /////////////////////////////////////////////////////////
  88.   81          //---Detect which source with valid signal-------------//
  89.   82          /////////////////////////////////////////////////////////
  90.   83          void Measure_Source(unsigned char SOURCE)
  91.   84          {
  92.   85   1         switch(SOURCE)
  93.   86   1         {
  94.   87   2         case SOURCE_VGA:
  95.   88   2                      RTDSetByte(SYNC_CTRL_4A,0x01);
  96.   89   2                      break;
  97.   90   2         case SOURCE_DVI:
  98.   91   2                      RTDSetByte(SYNC_CTRL_4A,0x03);
  99.   92   2                      break;
  100.   93   2         case SOURCE_AV:
  101.   94   2              I2CWrite(V_ENABLE);
  102.   95   2              I2CWrite(AV_DETECT);
  103.   96   2              break;
  104.   97   2         case SOURCE_SV:
  105.   98   2              I2CWrite(V_ENABLE);
  106.   99   2              I2CWrite(SV_DETECT);
  107.  100   2                      break;
  108.  101   2         }
  109.  102   1         //RTDSetByte(SYNC_POR_4C, 0x32);
  110.  103   1         //RTDSetByte(SYNC_POR_4C, 0x02);
  111.  104   1         //RTDSetByte(SYNC_POR_4C, (stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA ? 0x32 : 0x02);
  112.  105   1         
  113.  106   1         if(((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA) && (SYNC_SS != ucSync_Type))
  114.  107   1             RTDSetByte(SYNC_POR_4C,0x32);
  115.  108   1         else
  116.  109   1             RTDSetByte(SYNC_POR_4C,0x02);
  117.  110   1         
  118.  111   1         Delay_Xms(35);
  119.  112   1         //Delay_Xms(24);
  120.  113   1         
  121.  114   1      
  122.  115   1      }
  123.  116          #endif
  124. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 3   
  125.  117          
  126.  118          unsigned char VGA_Mode_Search(unsigned int HS_Pulse)
  127.  119          {
  128.  120   1        unsigned char ucMode_Temp,m;
  129.  121   1        Data[0] = HS_Pulse * 12 / usHsync;    // 0 : 720x350; 1 : 640x350;
  130.  122   1      
  131.  123   1        ucMode_Temp = MODE_NOSUPPORT;
  132.  124   1      
  133.  125   1        // Search for Standard Mode
  134.  126   1        m   = MODE_1280x1024x75HZ;            //anson
  135.  127   1      //  m   = MODE_1600x1200x60HZ;
  136.  128   1        do
  137.  129   1        {
  138.  130   2                if ((usHsync > VGA_Mode[m][0]) && (usHsync < VGA_Mode[m][1]))
  139.  131   2                {   
  140.  132   3                        if ((usVsync >= VGA_Mode[m][2]) && (usVsync <= VGA_Mode[m][3]))
  141.  133   3                        {
  142.  134   4                                if (MODE_1280x1024x75HZ == m)
  143.  135   4                                {
  144.  136   5                                        if (0 == (bVpole_Curr | bHpole_Curr))   m   = MODE_1280x1024x76HZ;  // SUN 1024-76
  145.  137   5                                }                            
  146.  138   4                                else if (MODE_1024x0768x75HZ == m)
  147.  139   4                                {
  148.  140   5                                        if (0 == (bVpole_Curr | bHpole_Curr))   m   = MODE_1024x0768x74HZ;  // MAC768-75
  149.  141   5                                }         
  150.  142   4                                else if (MODE_0640x0480x60HZ == m && bVpole_Curr != bHpole_Curr)
  151.  143   4                                {
  152.  144   5                                        // MODE_VGA350x60Hz         : 640x350 60Hz
  153.  145   5                                        // MODE_VGA350x60Hz | 0x40  : 720x350 60Hz
  154.  146   5                                        // MODE_VGA400x60Hz         : 640x400 60Hz
  155.  147   5                                        // MODE_VGA400x60Hz | 0x40  : 720x400 60Hz
  156.  148   5                                        if (bHpole_Curr)
  157.  149   5                                                m   = Data[0] ? MODE_VGA350x60Hz : MODE_VGA350x60Hz | 0x40;
  158.  150   5                                        else
  159.  151   5                                                m   = (stGUD1.FUNCTION & 0x10) ? MODE_VGA400x60Hz : MODE_VGA400x60Hz | 0x40;
  160.  152   5                                        //m   = (stGUD1.INPUT_SOURCE & 0x80) ? MODE_VGA400x60Hz : MODE_VGA400x60Hz | 0x40;
  161.  153   5                                }
  162.  154   4                                else if (MODE_0640x0480x50HZ == m && bVpole_Curr != bHpole_Curr)
  163.  155   4                                {
  164.  156   5                                        // MODE_VGA350x50Hz         : 640x350 50Hz
  165.  157   5                                        // MODE_VGA350x50Hz | 0x40  : 720x350 50Hz
  166.  158   5                                        // MODE_VGA400x50Hz         : 640x400 50Hz
  167.  159   5                                        // MODE_VGA400x50Hz | 0x40  : 720x400 50Hz
  168.  160   5                                        if (bHpole_Curr)
  169.  161   5                                                m   = Data[0] ? MODE_VGA350x50Hz : MODE_VGA350x50Hz | 0x40;
  170.  162   5                                        else
  171.  163   5                                                m   = (stGUD1.FUNCTION & 0x10) ? MODE_VGA400x50Hz : MODE_VGA400x50Hz | 0x40;
  172.  164   5                                        //m   = (stGUD1.INPUT_SOURCE & 0x80) ? MODE_VGA400x50Hz : MODE_VGA400x50Hz | 0x40;
  173.  165   5                                }
  174.  166   4                                else if (MODE_0720x0400x85HZ == m)
  175.  167   4                                {
  176.  168   5                                        if (1 == bHpole_Curr && 0 == bVpole_Curr)
  177.  169   5                                                m   = MODE_0640x0350x85HZ;
  178.  170   5                                        else if (stGUD1.FUNCTION & 0x10)     //else if (stGUD1.INPUT_SOURCE & 0x80)     
  179.  171   5                                                m   = MODE_0640x0400x85HZ;
  180.  172   5                                }
  181.  173   4                                else if (MODE_0720x0400x70HZ == m)
  182.  174   4                                {
  183.  175   5                                        if (1 == bHpole_Curr && 0 == bVpole_Curr)
  184.  176   5                                                m   = Data[0] ? MODE_0640x0350x70HZ : MODE_0720x0350x70HZ;
  185.  177   5                                        else if ((stGUD1.FUNCTION & 0x10)==0)     //else if (stGUD1.INPUT_SOURCE & 0x80)              //anson
  186.  178   5      //                                else if (stGUD1.FUNCTION & 0x10)     //else if (stGUD1.INPUT_SOURCE & 0x80)
  187. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 4   
  188.  179   5                                                m   = MODE_0640x0400x70HZ;
  189.  180   5                                }
  190.  181   4                                else if (MODE_1024x0768x59HZ == m)
  191.  182   4                                {
  192.  183   5                                        if(HS_Pulse > 45)
  193.  184   5                                                m = MODE_1024x0768x60HZ;
  194.  185   5                                }
  195.  186   4                                else if (MODE_1024x0768x60HZ == m)
  196.  187   4                                {
  197.  188   5                                        if(HS_Pulse <= 45)
  198.  189   5                                                m = MODE_1024x0768x59HZ;                                         
  199.  190   5                                }
  200.  191   4                                else if(MODE_1024x0768x72HZ == m)                     //anson 05_0321
  201.  192   4                                {
  202.  193   5                                        if(ucRefresh <= 71)
  203.  194   5                                         m = MODE_1024x0768x70HZ;
  204.  195   5                                }
  205.  196   4      
  206.  197   4                                ucMode_Temp     = m;
  207.  198   4                        }
  208.  199   3                }
  209.  200   2        }
  210.  201   1        while ((0 != --m) && (MODE_NOSUPPORT == ucMode_Temp));
  211.  202   1        
  212.  203   1        // Search for User Mode
  213.  204   1        if (MODE_NOSUPPORT == ucMode_Temp)
  214.  205   1        {
  215.  206   2                usIPV_ACT_LEN   = 0;
  216.  207   2      
  217.  208   2                m   = MODE_USER1280x1024;             //anson
  218.  209   2      //        m   = MODE_USER1600x1200;
  219.  210   2                do
  220.  211   2                {
  221.  212   3                        if ((usVsync >= VGA_Mode[m][2]) && (usVsync <= VGA_Mode[m][3]))
  222.  213   3                        {
  223.  214   4                                usIPV_ACT_LEN   = CAP_WIN[m][4];
  224.  215   4                                
  225.  216   4                                if ((usHsync >= VGA_Mode[m][0]) && (usHsync <= VGA_Mode[m][1]))
  226.  217   4                                {
  227.  218   5                                        ucMode_Temp     = m;    // Support User Mode
  228.  219   5                                }
  229.  220   4                        }
  230.  221   3                }
  231.  222   2                while ((MODE_USER720x400 <= --m) && (MODE_NOSUPPORT == ucMode_Temp));
  232.  223   2        }
  233.  224   1      
  234.  225   1        return ucMode_Temp;
  235.  226   1      
  236.  227   1      }
  237.  228          
  238.  229          unsigned char Partial_Display(void)
  239.  230          {
  240.  231   1              unsigned char ucMode_Temp;
  241.  232   1      
  242.  233   1              if (DISP_LEN < usIPV_ACT_LEN)   // V Scale-down
  243.  234   1              {
  244.  235   2                      // Estimate display clock rate for full screen
  245.  236   2                      // DCLK = (24.576MHz / usHsync) * DCLK per display line * (display image lines / input image lines)
  246.  237   2                      ((unsigned int *)Data)[0]   = (unsigned long)2458 * Mode_Preset[MODE_UNDEFINED1][0] * DISP_LEN 
  247.  238   2                              / ((unsigned long)100 * usIPV_ACT_LEN * usHsync);
  248.  239   2      
  249.  240   2                      if (MAX_DCLK < ((unsigned int *)Data)[0])
  250. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 5   
  251.  241   2                      {
  252.  242   3                              // If clock rate for full-screen display is too high, we can try partial-V display.
  253.  243   3                              // Estimate clock for partial-V display
  254.  244   3                              // DCLK = (24.576MHz / usHsync) * DCLK per display line * (min. display total lines / input total lines
  255.              -)
  256.  245   3                              ((unsigned int *)Data)[1]   = (unsigned long)2458 * Mode_Preset[MODE_UNDEFINED1][0] * MIN_DV_TOTAL
  257.  246   3                                      / ((unsigned long)100 * (usVsync - 1) * usHsync);
  258.  247   3      
  259.  248   3                              if (MAX_DCLK < ((unsigned int *)Data)[1])
  260.  249   3                              {
  261.  250   4                                      // Decrease usIPV_ACT_LEN to DISP_LEN and go further to check if it can be displayed.
  262.  251   4                                      usIPV_ACT_LEN   = DISP_LEN;
  263.  252   4                              }
  264.  253   3                              else
  265.  254   3                              {
  266.  255   4                                      ucMode_Temp     = MODE_UNDEFINED1 | 0x80;   // Scale-down and partial-V display
  267.  256   4                              }
  268.  257   3                      }
  269.  258   2                      else
  270.  259   2                              ucMode_Temp     = MODE_UNDEFINED1;              // Scale-down and full-V display
  271.  260   2              }
  272.  261   1              
  273.  262   1              if (DISP_LEN >= usIPV_ACT_LEN)  // V Scale-up
  274.  263   1              {
  275.  264   2                      ((unsigned int *)Data)[0]   = (unsigned long)2458 * Mode_Preset[MODE_UNDEFINED0][0] * DISP_LEN 
  276.  265   2                              / ((unsigned long)100 * usIPV_ACT_LEN * usHsync);
  277.  266   2      
  278.  267   2                      if (MAX_DCLK < ((unsigned int *)Data)[0])
  279.  268   2                      {
  280.  269   3                              if (MIN_DV_TOTAL >= (usVsync - 1))
  281.  270   3                              {
  282.  271   4                                      ((unsigned int *)Data)[1]   = (unsigned long)2458 * Mode_Preset[MODE_UNDEFINED0][0] * MIN_DV_TOTAL
  283.  272   4                                              / ((unsigned long)100 * (usVsync - 1) * usHsync);
  284.  273   4                              }
  285.  274   3                              else
  286.  275   3                              {
  287.  276   4                                      ((unsigned int *)Data)[1]   = (unsigned long)2458 * Mode_Preset[MODE_UNDEFINED0][0]
  288.  277   4                                              / ((unsigned long)100 * usHsync);
  289.  278   4                              }
  290.  279   3                              
  291.  280   3                              if (MAX_DCLK < ((unsigned int *)Data)[1])   
  292.  281   3                                      ucMode_Temp = MODE_NOSUPPORT;           // Cannot display
  293.  282   3                              else
  294.  283   3                                      ucMode_Temp = MODE_UNDEFINED0 | 0x80;   // Scale-up and partial-V display
  295.  284   3                      }
  296.  285   2                      else
  297.  286   2                              ucMode_Temp = MODE_UNDEFINED0;              // Scale-up and full-V display
  298.  287   2              }
  299.  288   1      
  300.  289   1              return ucMode_Temp;
  301.  290   1      
  302.  291   1      }
  303.  292          
  304.  293          void Sync_Type_Switch(void)
  305.  294          {
  306.  295   1              if (MODE_NOSIGNAL == ucMode_Curr)
  307.  296   1              {
  308.  297   2                      if (SYNC_CS == ucSync_Type)         // CS->SS
  309.  298   2                      {
  310.  299   3                              RTDCodeW(VGA_SET_SS);
  311.  300   3      
  312.  301   3                              bVpole_Curr = 1;
  313. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 6   
  314.  302   3                              bHpole_Curr = 1;
  315.  303   3                              ucSync_Type = SYNC_SS;
  316.  304   3                              
  317.  305   3                      }
  318.  306   2                      else if (SYNC_SS == ucSync_Type)    // SS->SOG
  319.  307   2                      {
  320.  308   3                              RTDCodeW(VGA_SET_SOG);
  321.  309   3      
  322.  310   3                              bVpole_Curr = 1;
  323.  311   3                              bHpole_Curr = 1;
  324.  312   3                              ucSync_Type = SYNC_SOG;
  325.  313   3                              
  326.  314   3                              
  327.  315   3      
  328.  316   3                      }
  329.  317   2                      else                                // SOG->CS
  330.  318   2                      {
  331.  319   3                              RTDCodeW(VGA_SET_CS);
  332.  320   3      
  333.  321   3                              bVpole_Curr = 1;
  334.  322   3                              bHpole_Curr = 1;
  335.  323   3                              ucSync_Type = SYNC_CS;
  336.  324   3                              
  337.  325   3                              
  338.  326   3      
  339.  327   3                      }
  340.  328   2              }
  341.  329   1      }
  342.  330          
  343.  331          void Sync_Type_Confirm(void)
  344.  332          {
  345.  333   1        
  346.  334   1      #if(SOURCE_AUTO_SCAN == _FALSE)
  347.               unsigned char m;
  348.                           
  349.               // To prevent from mistaking CS (with VS) for SS, we check SYNC type once when finding a mode in SS.
  350.                           
  351.                     if (SYNC_SS == ucSync_Type)
  352.                         {           
  353.                                 RTDSetByte(SYNC_CTRL_4B, 0x55);
  354.               
  355.                                 RTDSetByte(SYNC_POR_4C, 0x22);
  356.               
  357.                                 m   = (MODE_DETECT_FREQ + 1) * 20;       
  358.                                 do
  359.                                 {   
  360.                                         Delay_Xms(1);
  361.                                         RTDRead(SYNC_POR_4C, 0x05, Y_INC);
  362.                                 }
  363.                                 while ((Data[0] & 0x02) && (--m));
  364.                                 
  365.                                 Data[5] = Data[3];
  366.                                 Data[4] = Data[4] & 0x87;
  367.                                 Data[3] = Data[1];
  368.                                 Data[2] = Data[2] & 0x8f;
  369.               
  370.                                 if ((0 == ((unsigned int *)Data)[1]) || (0x07ff <= ((unsigned int *)Data)[1]) ||
  371.                                         (0 == ((unsigned int *)Data)[2]) || (0x07ff <= ((unsigned int *)Data)[2]) ||
  372.                                         (0 == m))
  373.                                 {
  374.                                         ucSync_Type = SYNC_SS;
  375.               
  376. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 7   
  377.                                         RTDSetByte(SYNC_CTRL_4B, 0x14);
  378.                                 }
  379.                                 else
  380.                                 {
  381.                                         ucSync_Type = SYNC_CS;
  382.               
  383.                                         RTDCodeW(VGA_SET_CS);
  384.               
  385.                                         bVpole_Curr = 1;
  386.                                         bHpole_Curr = 1;
  387.                                 }
  388.                         }
  389.                         else if (SYNC_SOG == ucSync_Type)
  390.                         {
  391.                                 RTDSetByte(SYNC_CTRL_4B, 0x14);
  392.                                 Delay_Xms(8);
  393.               
  394.                                 RTDSetByte(SYNC_POR_4C, 0x00);
  395.                                 RTDSetByte(SYNC_POR_4C, 0x02);
  396.                                 
  397.               
  398.                                 m   = (MODE_DETECT_FREQ + 1) * 20;       
  399.                                 do
  400.                                 {   
  401.                                         Delay_Xms(1);
  402.                                         RTDRead(SYNC_POR_4C, 0x05, Y_INC);
  403.                                 }
  404.                                 while ((Data[0] & 0x02) && (--m));
  405.                                 
  406.                                 Data[5] = Data[3];
  407.                                 Data[4] = Data[4] & 0x87;
  408.                                 Data[3] = Data[1];
  409.                                 Data[2] = Data[2] & 0x8f;
  410.               
  411.                                 if ((0 == ((unsigned int *)Data)[1]) || (0x07ff <= ((unsigned int *)Data)[1]) ||
  412.                                         (0 == ((unsigned int *)Data)[2]) || (0x07ff <= ((unsigned int *)Data)[2]) ||
  413.                                         (0 == m))
  414.                                 {
  415.                                         ucSync_Type = SYNC_SOG;
  416.               
  417.                                         
  418.                                         RTDSetByte(SYNC_CTRL_4B, 0x57);
  419.                                         //RTDSetByte(VGIP_SIGINV_05, 0x40);
  420.                                         Delay_Xms(8);
  421.                                         
  422.                                         RTDSetByte(SYNC_POR_4C,0x32);
  423.                                         Delay_Xms(20);
  424.                                         RTDSetByte(SYNC_POR_4C, 0x00);
  425.                                         
  426.                                 }
  427.                                 else
  428.                                 {
  429.                                         ucSync_Type = SYNC_SS;
  430.               
  431.                                         RTDCodeW(VGA_SET_SS);
  432.               
  433.                                         bVpole_Curr = 1;
  434.                                         bHpole_Curr = 1;
  435.                                 }
  436.                         }
  437.               #endif
  438.  425   1      
  439. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 8   
  440.  426   1      }
  441.  427          /////////////////////////////////////////////////////////
  442.  428          //------------  Detect VGA & DVI Mode  ----------------//
  443.  429          /////////////////////////////////////////////////////////
  444.  430          void Detect_Input_Mode(void)
  445.  431          {
  446.  432   1          unsigned char   ucMode_Temp;
  447.  433   1          unsigned int    usHS_Pulse;
  448.  434   1      
  449.  435   1          RTDRead(SYNC_POR_4C, 0x09, Y_INC);
  450.  436   1      
  451.  437   1          if (Data[0] & 0x02)
  452.  438   1          {
  453.  439   2              // Reset Sync Processor when sync signal timeout
  454.  440   2              RTDSetByte(SYNC_POR_4C, ((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA) ? 0x20 : 0x00);
  455.  441   2      
  456.  442   2              // Treat sync signal timeout as no signal
  457.  443   2              ucMode_Temp     = MODE_NOSIGNAL;
  458.  444   2          }
  459.  445   1          else                        
  460.  446   1          {
  461.  447   2                
  462.  448   2      //        ucMode_Temp = (Data[8] & 0xe0 ) >> 5;
  463.  449   2      
  464.  450   2      //        if(ucMode_Temp == 0 || ucMode_Temp >=4) //Test which edge of Hsync to latch Vsync will be safe
  465.  451   2      //              {
  466.  452   2      //           RTDSetBit(MEAS_VS_HI_54,0xf7,0x08);  //Use positive edge of Hsync to latch Vsync
  467.  453   2      //                 ucDebug_Value0 = 0x08;
  468.  454   2      //              }
  469.  455   2      //              else
  470.  456   2      //              {
  471.  457   2      //                 RTDSetBit(MEAS_VS_HI_54,0xf7,0x00);  //Use negtive edge of Hsync to latch Vsync
  472.  458   2      //                 ucDebug_Value0 = 0x18;
  473.  459   2      //              }
  474.  460   2      
  475.  461   2              
  476.  462   2              usStdHS   = usHsync;  // Save previous usHsync in usStdHS
  477.  463   2              usStdVS   = usVsync;  // Save previous usVsync in usStdVS
  478.  464   2      
  479.  465   2              bVpole_Curr = (bit)(Data[0] & 0x08);    // Save current usVsync polarity
  480.  466   2              bHpole_Curr = (bit)(Data[0] & 0x04);    // Save current usHsync polarity
  481.  467   2      
  482.  468   2              Data[7] = Data[5];
  483.  469   2              Data[6] = Data[6] & 0x0f;
  484.  470   2              Data[5] = Data[3];
  485.  471   2              Data[4] = Data[4] & 0x87;
  486.  472   2              Data[3] = Data[1];
  487.  473   2              Data[2] = Data[2] & 0x8f;
  488.  474   2      
  489.  475   2              usHsync     = ((unsigned int *)Data)[1];    // Current HSYNC timing
  490.  476   2              usVsync     = ((unsigned int *)Data)[2];    // Current VSYNC timing
  491.  477   2      
  492.  478   2              if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA)
  493.  479   2                  usHS_Pulse  = ((unsigned int *)Data)[3];    // Current HSYNC pulse width
  494.  480   2      
  495.  481   2              // Calculate Vertical Refresh Rate
  496.  482   2              // Original Formula :
  497.  483   2              // ucRefresh = 24.576M / (usHsync * usVsync)
  498.  484   2              // Use Data[0~3] as a temporary long variable
  499.  485   2              ((unsigned long *)Data)[0]  = (unsigned long)usHsync * usVsync;
  500.  486   2              ucRefresh   = (unsigned long)49152000 / ((unsigned long *)Data)[0];
  501.  487   2              ucRefresh   = (ucRefresh & 0x01) ? ((ucRefresh + 1) >> 1) : (ucRefresh >> 1);
  502. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 9   
  503.  488   2      
  504.  489   2              // Treat small change of usHsync/usVsync as no change
  505.  490   2              if (usStdHS <= usHsync && (usStdHS + 2) >= usHsync)     usHsync = usStdHS;
  506.  491   2              if (usStdVS <= usVsync && (usStdVS + 2) >= usVsync)     usVsync = usStdVS;
  507.  492   2      
  508.  493   2              // Polarity must be correct
  509.  494   2              if ((bVpole_Curr != bVpole_Prev) || (bHpole_Curr != bHpole_Prev))
  510.  495   2              {  
  511.  496   3                  RTDRead(VGIP_SIGINV_05, 0x01, N_INC);
  512.  497   3                
  513.  498   3                  if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA)
  514.  499   3                  {
  515.  500   4                     Data[0] &= 0xd7;  // HS_RAW & VS positive
  516.  501   4      
  517.  502   4                     if (!bHpole_Curr)    Data[0] |= 0x20;
  518.  503   4                  
  519.  504   4                     if (!bVpole_Curr && SYNC_SS == ucSync_Type)     Data[0] |= 0x08;    // Seperate sync
  520.  505   4      
  521.  506   4                                 ucMode_Temp     = MODE_NOSUPPORT;
  522.  507   4                  }
  523.  508   3                  else if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_DVI)
  524.  509   3                  {
  525.  510   4                     Data[0] &= 0xf3;  // VS & HS positive
  526.  511   4      
  527.  512   4                     if (!bVpole_Curr)    Data[0] |= 0x08;
  528.  513   4                     if (!bHpole_Curr)    Data[0] |= 0x04;
  529.  514   4                  }            
  530.  515   3                  RTDSetByte(VGIP_SIGINV_05, Data[0]);
  531.  516   3      
  532.  517   3                  
  533.  518   3              }
  534.  519   2              else
  535.  520   2              {
  536.  521   3                  if (0x07ff <= usHsync || 0x07ff <= usVsync || 0 == usHsync || 0 == usVsync)
  537.  522   3                  {
  538.  523   4                      ucMode_Temp     = MODE_NOSIGNAL;        // Treat overflow as no signal
  539.  524   4                  }
  540.  525   3                  else
  541.  526   3                  {
  542.  527   4                      ucMode_Temp = ((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA) ? VGA_Mode_Search(usHS_Pulse) :
  543.              - MODE_NOSUPPORT;
  544.  528   4                                      
  545.  529   4      
  546.  530   4                      if (48 > ucRefresh || MAX_RATE < ucRefresh)
  547.  531   4                      {
  548.  532   5                          ucMode_Temp = MODE_NOSUPPORT;   // We don't support vertical refresh rate lower than 5
  549.              -0Hz
  550.  533   5                      }
  551.  534   4                      else if (MODE_NOSUPPORT == ucMode_Temp && (0 != usIPV_ACT_LEN) && ((stGUD1.INPUT_SOURCE & 
  552.              -0x07) == SOURCE_VGA))
  553.  535   4                      {                           
  554.  536   5                                              ucMode_Temp = Partial_Display();
  555.  537   5                                      }
  556.  538   4                                      else if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_DVI)
  557.  539   4                                            ucMode_Temp = Seek_DVI_Mode(ucMode_Temp);
  558.  540   4      
  559.  541   4      //                              ucDebug_Value0 = ucMode_Temp;
  560.  542   4                      }
  561.  543   3              }
  562.  544   2          }
  563.  545   1      
  564.  546   1              if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA)
  565. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 10  
  566.  547   1              {
  567.  548   2              if (SYNC_SOG == ucSync_Type && 0 != (usHS_Pulse * 7 / usHsync))
  568.  549   2              {
  569.  550   3                // To prevent from SOG mode mistake
  570.  551   3                // HSYNC pulse width will never longer than 1/7*HSYNC period
  571.  552   3                ucMode_Temp = MODE_NOSIGNAL;
  572.  553   3              }
  573.  554   2              }
  574.  555   1      
  575.  556   1          //-------------Check result-----------------------------------------
  576.  557   1          if (MODE_NOSUPPORT == ucMode_Temp || MODE_NOSIGNAL == ucMode_Temp)
  577.  558   1          {
  578.  559   2              // Treat illegal signal as no signal when SOG
  579.  560   2                      if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA)
  580.  561   2                      {
  581.  562   3                 if (SYNC_SOG == ucSync_Type)    
  582.  563   3                             ucMode_Temp = MODE_NOSIGNAL;
  583.  564   3                       }
  584.  565   2      
  585.  566   2              if (MODE_NOSUPPORT != ucMode_Found && MODE_NOSIGNAL != ucMode_Found)    ucMode_Times    = 0;
  586.  567   2      
  587.  568   2              ucMode_Found    = ucMode_Temp;
  588.  569   2      
  589.  570   2              if (NO_MODE_TIMES > ucMode_Times)
  590.  571   2              {
  591.  572   3                  // Wait for signal stable
  592.  573   3                  ucMode_Times ++;
  593.  574   3      
  594.  575   3                              if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_DVI)
  595.  576   3                              {
  596.  577   4                                 //Enable the TMDS Hsync & Vsync error correction to improve the long cable image quality
  597.  578   4                     RTDSetByte(TMDS_CORRECTION_FF,0x03);
  598.  579   4                              }
  599.  580   3              }
  600.  581   2              else
  601.  582   2              {
  602.  583   3                          if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_DVI)
  603.  584   3                              {
  604.  585   4                                 //Disable the TMDS Hsync & Vsync error correction
  605.  586   4                     RTDSetByte(TMDS_CORRECTION_FF,0x00);
  606.  587   4                              }
  607.  588   3      
  608.  589   3                  bStable         = (ucMode_Curr == ucMode_Found) ? 1 : 0;    // bStable must be cleared when mo
  609.              -de changed
  610.  590   3                  ucMode_Curr     = ucMode_Found;
  611.  591   3                  ucMode_Times    = NO_MODE_TIMES - 2;
  612.  592   3      
  613.  593   3                              if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA)
  614.  594   3                                  Sync_Type_Switch();
  615.  595   3                  
  616.  596   3              }
  617.  597   2          }
  618.  598   1          else
  619.  599   1          {
  620.  600   2              if (ucMode_Found != ucMode_Temp)
  621.  601   2              {
  622.  602   3                  ucMode_Times    = 1;
  623.  603   3                  ucMode_Found    = ucMode_Temp;
  624.  604   3      
  625.  605   3                              if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA)
  626.  606   3                                  Sync_Type_Confirm();
  627.  607   3              }
  628. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 11  
  629.  608   2              else
  630.  609   2              {   
  631.  610   3                          Data[0] = ((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA) ? VGA_SEARCH_TIMES : DVI_SEARCH_TIMES;
  632.  611   3                  //if (VGA_SEARCH_TIMES > ucMode_Times)
  633.  612   3                              if (Data[0] > ucMode_Times)
  634.  613   3                  {
  635.  614   4                      ucMode_Times ++;
  636.  615   4                  }
  637.  616   3                  else
  638.  617   3                  {
  639.  618   4      
  640.  619   4                      bLIGHT_PWR  = LIGHT_OFF;        // Turn off BackLight for reset display
  641.  620   4                    
  642.  621   4                      RTDSetByte(HOSTCTRL_02, 0x40);  // Wake RTD up
  643.  622   4                      RTDOSDW(OSD_Reset);            // Clear OSD
  644.  623   4      
  645.  624   4                      ucMode_Curr     = ucMode_Found; // Supported mode found
  646.  625   4                      ucMode_Times    = 0;            // Reset mode timer
  647.  626   4                      bStable         = 0;            // bStable must be cleared when mode changed
  648.  627   4      
  649.  628   4                                      if((stGUD1.INPUT_SOURCE & 0x07)== SOURCE_VGA)
  650.  629   4                          Display_VGA_Set();              // Set VGA Mode registers
  651.  630   4                                      else
  652.  631   4                                          Display_DVI_Set();
  653.  632   4      
  654.  633   4                                      
  655.  634   4      #if (RTDDEBUG)
  656.                               if (ucMode_PrevAct == ucMode_Curr)
  657.                               {
  658.                                   if (0xff > ucMode_QuitCnt)      ucMode_QuitCnt += 1;
  659.                               }
  660.                               else
  661.                               {
  662.                                   ucMode_PrevAct  = ucMode_Curr;
  663.                                   ucMode_QuitCnt  = 0;
  664.                                   ucDebug         = 0;
  665.                               }
  666.               #endif                
  667.  646   4                  }
  668.  647   3              }
  669.  648   2          }
  670.  649   1      }
  671.  650          
  672.  651          //-------------------  Check VGA & DVI Mode  -------------------//
  673.  652          void Check_Input_Mode(void)
  674.  653          {    
  675.  654   1          RTDRead(SYNC_POR_4C, 0x05, Y_INC);
  676.  655   1      
  677.  656   1          if (Data[0] & 0x02)
  678.  657   1          {
  679.  658   2              RTDSetByte(SYNC_POR_4C, ((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA) ? 0x20 : 0x00);          // I
  680.              -nput signal time-out. Reset sync-processor
  681.  659   2      
  682.  660   2              ucMode_Found    = MODE_NOSUPPORT;
  683.  661   2          }
  684.  662   1          else                        
  685.  663   1          {
  686.  664   2              bVpole_Curr = (bit)(Data[0] & 0x08);    // Current usVsync polarity
  687.  665   2              bHpole_Curr = (bit)(Data[0] & 0x04);    // Current usHsync polarity
  688.  666   2      
  689.  667   2              Data[5] = Data[3];
  690.  668   2              Data[4] = Data[4] & 0x87;
  691. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 12  
  692.  669   2              Data[3] = Data[1];
  693.  670   2              Data[2] = Data[2] & 0x8f;
  694.  671   2              usHsync = ((unsigned int *)Data)[1];    // Current usHsync timing
  695.  672   2              usVsync = ((unsigned int *)Data)[2];    // Current usVsync timing
  696.  673   2      
  697.  674   2              // Polarity must be correct
  698.  675   2              if ((bVpole_Curr != bVpole_Prev) || (bHpole_Curr != bHpole_Prev))
  699.  676   2              {
  700.  677   3                  RTDRead(VGIP_SIGINV_05, 0x01, N_INC);
  701.  678   3                  /*
  702.  679   3                  Data[0] &= 0xd7;    // HS_RAW & VS positive
  703.  680   3      
  704.  681   3                  if (!bHpole_Curr)   Data[0] |= 0x20;
  705.  682   3      
  706.  683   3                  if (!bVpole_Curr && SYNC_SS == ucSync_Type)     Data[0] |= 0x08;    // Seperate sync
  707.  684   3                  */
  708.  685   3                  
  709.  686   3      
  710.  687   3                  if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA)
  711.  688   3                  {
  712.  689   4                       Data[0] &= 0xd7;    // HS_RAW & VS positive
  713.  690   4      
  714.  691   4                       if (!bHpole_Curr)   Data[0] |= 0x20;
  715.  692   4      
  716.  693   4                       if (!bVpole_Curr && SYNC_SS == ucSync_Type)     Data[0] |= 0x08;    // Seperate sync
  717.  694   4                  }
  718.  695   3                  else if((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_DVI)
  719.  696   3                  {
  720.  697   4                       Data[0] &= 0xf3;  // VS & HS positive
  721.  698   4      
  722.  699   4                       if (!bVpole_Curr)    Data[0] |= 0x08;
  723.  700   4                       if (!bHpole_Curr)    Data[0] |= 0x04;
  724.  701   4                  }
  725.  702   3      
  726.  703   3                  RTDSetByte(VGIP_SIGINV_05, Data[0]);
  727.  704   3      
  728.  705   3                  ucMode_Found    = MODE_NOSUPPORT;
  729.  706   3              }
  730.  707   2              else
  731.  708   2              {
  732.  709   3                  if (0x07ff <= usHsync || 0x07ff <= usVsync || 0 == usHsync || 0 == usVsync)     // Check overf
  733.              -low
  734.  710   3                  {
  735.  711   4                      ucMode_Found    = MODE_NOSUPPORT;
  736.  712   4                  }
  737.  713   3                  else
  738.  714   3                  {
  739.  715   4                      if ((usHsync < (usStdHS - 1)) || (usHsync > (usStdHS + 3)) ||
  740.  716   4                          (usVsync < (usStdVS - 1)) || (usVsync > (usStdVS + 3)))
  741.  717   4                      {   
  742.  718   5                          ucMode_Found    = MODE_NOSUPPORT;
  743.  719   5                      }
  744.  720   4                      else
  745.  721   4                      {
  746.  722   5                          ucMode_Found    = ucMode_Curr;
  747.  723   5                      }
  748.  724   4                  }
  749.  725   3              }
  750.  726   2          }
  751.  727   1          
  752.  728   1          if (MODE_NOSUPPORT == ucMode_Found)
  753.  729   1                      Reset_Mode();
  754. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 13  
  755.  730   1          else
  756.  731   1              {
  757.  732   2              bStable = 1;    // Set bStable to 1 when signal timing is stable.
  758.  733   2      #if(AS_NON_FRAMESYNC)
  759.                       RTDSetByte(STATUS0_01, 0x00);  // Clear status
  760.                       RTDSetByte(STATUS1_1F, 0x00);  // Clear status
  761.               
  762.                       if(bFrameSync)
  763.                          RTDSetBit(ODD_CTRL_8E,0xef,0x10);
  764.               #endif
  765.  740   2          }
  766.  741   1      
  767.  742   1      }
  768.  743          
  769.  744          
  770.  745          
  771.  746          
  772.  747          unsigned char Seek_DVI_Mode(unsigned char mode)
  773.  748          {
  774.  749   1      #if(TMDS_ENABLE)
  775.  750   1          unsigned char   Wait_Time_Cnt;
  776.  751   1      
  777.  752   1          RTDSetByte(SYNC_POR_4C, 0x03);  // Measure data enable width and height
  778.  753   1      
  779.  754   1          Wait_Time_Cnt  = 60;       
  780.  755   1          do
  781.  756   1          {   
  782.  757   2              Delay_Xms(1);
  783.  758   2              RTDRead(SYNC_POR_4C, 0x07, Y_INC);
  784.  759   2          }
  785.  760   1          while ((Data[0] & 0x02) && (--Wait_Time_Cnt));
  786.  761   1      
  787.  762   1          Data[7] = Data[5];
  788.  763   1          Data[6] = Data[6] & 0x0f;
  789.  764   1          Data[5] = Data[3];
  790.  765   1          Data[4] = Data[4] & 0x87;
  791.  766   1          Data[3] = Data[1];
  792.  767   1          Data[2] = Data[2] & 0x8f;
  793.  768   1      
  794.  769   1          // Measure Failed !!!
  795.  770   1          if ((0 == ((unsigned int *)Data)[1]) || (0x07ff <= ((unsigned int *)Data)[1]) ||
  796.  771   1              (0 == ((unsigned int *)Data)[2]) || (0x07ff <= ((unsigned int *)Data)[2]) ||
  797.  772   1              (0 == Wait_Time_Cnt))
  798.  773   1          {
  799.  774   2              RTDSetByte(SYNC_POR_4C, 0x00);
  800.  775   2      
  801.  776   2              return MODE_NOSUPPORT;
  802.  777   2          }
  803.  778   1      
  804.  779   1          // Save IH_TOTAL in usADC_Clock
  805.  780   1          usADC_Clock     = ((unsigned int *)Data)[1] * 2;
  806.  781   1      
  807.  782   1          // Save input data enable width and height
  808.  783   1          usIPV_ACT_LEN   = ((unsigned int *)Data)[2];
  809.  784   1          usIPH_ACT_WID   = ((unsigned int *)Data)[3] * 2;
  810.  785   1      
  811.  786   1          // We don't support input image less than 350 active lines
  812.  787   1          if (350 > usIPV_ACT_LEN)    return MODE_NOSUPPORT;
  813.  788   1      
  814.  789   1          // We only support 8N active width
  815.  790   1          usIPH_ACT_WID   = (2 < (usIPH_ACT_WID & 0x0007)) ? ((usIPH_ACT_WID + 8) & 0xfff8) : (usIPH_ACT_WID & 0
  816.              -xfff8);
  817. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 14  
  818.  791   1      
  819.  792   1          // We only support active width not larger than 1280
  820.  793   1          if (1280 < usIPH_ACT_WID)   usIPH_ACT_WID   = 1280;
  821.  794   1      
  822.  795   1          // Calculate maximum usIPV_ACT_LEN limitation
  823.  796   1          ((unsigned int *)Data)[0]   = (unsigned long)(usVsync - 1) * DISP_LEN / MIN_DV_TOTAL;
  824.  797   1      
  825.  798   1          if (((unsigned int *)Data)[0] < usIPV_ACT_LEN)      usIPV_ACT_LEN   = ((unsigned int *)Data)[0];
  826.  799   1      
  827.  800   1          mode    = MODE_UNDEFINED0;
  828.  801   1        
  829.  802   1          if (MODE_UNDEFINED0 == mode)
  830.  803   1          {
  831.  804   2              // First, we try user-mode to fit the undefined mode for full-screen display.
  832.  805   2              Wait_Time_Cnt   = MODE_USER720x400;
  833.  806   2              do
  834.  807   2              {
  835.  808   3                  if (Mode_Preset[Wait_Time_Cnt][2] < CAP_WIN[Wait_Time_Cnt][4])   // V scale-down
  836.  809   3                  {
  837.  810   4                      // Larger scale-down ratio may need a larger DH_TOTAL. 
  838.  811   4                      // So usIPV_ACT_LEN should not be too larger than pre-set capture window length
  839.  812   4                      if (Mode_Preset[Wait_Time_Cnt][2] > usIPV_ACT_LEN || (CAP_WIN[Wait_Time_Cnt][4] + 24) < us
  840.              -IPV_ACT_LEN)   continue;
  841.  813   4                  }
  842.  814   3                  else
  843.  815   3                  {
  844.  816   4                      if (Mode_Preset[Wait_Time_Cnt][2] < usIPV_ACT_LEN)   continue;
  845.  817   4                  }
  846.  818   3      
  847.  819   3                  ((unsigned int *)Data)[0]   = (unsigned long)2458 * Mode_Preset[Wait_Time_Cnt][0] * Mode_Prese
  848.              -t[Wait_Time_Cnt][2]
  849.  820   3                                              / ((unsigned long)100 * usIPV_ACT_LEN * usHsync);
  850.  821   3                  
  851.  822   3                  // Return if we find out a suitable user-mode.
  852.  823   3                  if (MAX_DCLK > ((unsigned int *)Data)[0])   return Wait_Time_Cnt;
  853.  824   3              }
  854.  825   2              while (MODE_USER1600x1200 >= ++Wait_Time_Cnt);
  855.  826   2      
  856.  827   2                      mode = Partial_Display();
  857.  828   2              // If failed, we try partial-screen display.
  858.  829   2      
  859.  830   2          }
  860.  831   1              
  861.  832   1      
  862.  833   1          return  mode;
  863.  834   1      #else
  864.                   mode    = MODE_UNDEFINED0;
  865.                   return  0;
  866.               #endif
  867.  838   1      }
  868.  839          
  869.  840          /////////////////////////////////////////////////////////
  870.  841          //------------------ Detect VIDEO Mode ----------------//
  871.  842          /////////////////////////////////////////////////////////
  872.  843          void Detect_Video_Mode(void)
  873.  844          {
  874.  845   1      #if(VIDEO_CHIP != VDC_NONE)
  875.                   I2CRead(ADDR_VIDEO, 0x1f, 0x01);
  876.               
  877.                   //------ Check Horizontal Lock & Frequency ------
  878.                   if (0 == (Data[0] & 0x40))
  879.                   {   
  880. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 15  
  881.                       if ((Data[0] & 0x20) && (0x01 != (ucAV_Mode & 0x0f)))
  882.                       {
  883.                           // Field rate changed to 60Hz
  884.                           ucAV_Mode       = 0x01;
  885.                           ucMode_Found    = MODE_NOSUPPORT;
  886.                           ucMode_Times    = 0;
  887.               
  888.                           Data[0] = 4;
  889.                           Data[1] = ADDR_VIDEO;
  890.                           Data[2] = 0x0e;
  891.                           Data[3] = 0x08;     // Start color search from NTSC-M
  892.                           I2CWrite(Data);
  893.                       }
  894.                       else if ((0 == (Data[0] & 0x20)) && (0x02 != (ucAV_Mode & 0x02)))
  895.                       {
  896.                           // Field rate changed to 50Hz
  897.                           ucAV_Mode       = 0x02; 
  898.                           ucMode_Found    = MODE_NOSUPPORT;
  899.                           ucMode_Times    = 0;
  900.                           
  901.                           Data[0] = 4;
  902.                           Data[1] = ADDR_VIDEO;
  903.                           Data[2] = 0x0e;
  904.                           Data[3] = 0x08;     // Start color search from PAL-BDGHI
  905.                           I2CWrite(Data);
  906.                       }
  907.                       else
  908.                       {    
  909.                           //------ Check Lock Color ------
  910.                           if (0x01 == (Data[0] & 0x01))
  911.                           {   
  912.                               // Lock Color
  913.                               if (ucAV_Mode & 0x01)
  914.                               {
  915.                                   if (MODE_VIDEO60HZ == ucMode_Found)
  916.                                   {
  917.                                       ucMode_Times ++;
  918.                                   }
  919.                                   else
  920.                                   {
  921.                                       ucMode_Found    = MODE_VIDEO60HZ;
  922.                                       ucMode_Times    = 0;
  923.                                   }
  924.                               }
  925.                               else
  926.                               {
  927.                                   if (MODE_VIDEO50HZ == ucMode_Found)
  928.                                   {
  929.                                       ucMode_Times ++;
  930.                                   }
  931.                                   else
  932.                                   {
  933.                                       ucMode_Found    = MODE_VIDEO50HZ;
  934.                                       ucMode_Times    = 0;
  935.                                   }
  936.                               }
  937.                           }
  938.                           else
  939.                           {
  940.                               // Non Lock Color
  941.                               if (MODE_NOSUPPORT != ucMode_Found)
  942.                               {
  943. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 16  
  944.                                   ucMode_Found    = MODE_NOSUPPORT;
  945.                                   ucMode_Times    = 0;
  946.                               }
  947.                               
  948.                               Data[0] = 4;
  949.                               Data[1] = ADDR_VIDEO;
  950.                               Data[2] = 0x0e;
  951.                               
  952.                               if (0x03 == (ucAV_Mode & 0x03))
  953.                               {
  954.                                   // SECAM -> PAL-BDGHI(50Hz)
  955.                                   Data[3] = 0x08;
  956.                                   I2CWrite(Data);                    
  957.                                   ucAV_Mode   = 0x02;
  958.                               }
  959.                               else
  960.                               {
  961.                                   if (ucMode_Times & 0x01)    // Every 2-times , change color
  962.                                   {
  963.                                       switch (ucAV_Mode & 0x70)
  964.                                       {
  965.                                       case 0x00:  
  966.                                           Data[3] = 0x18; // NTSC-4.43(50Hz)  // PAL-4.43(60Hz)
  967.                                           I2CWrite(Data);
  968.                                           ucAV_Mode   = (ucAV_Mode & 0x0f) | 0x10;
  969.                                           break;
  970.                                       case 0x10:
  971.                                           Data[3] = 0x28; // PAL-N(50Hz)      // NTSC-4.43(60Hz)
  972.                                           I2CWrite(Data);
  973.                                           ucAV_Mode   = (ucAV_Mode & 0x0f) | 0x20;
  974.                                           break;
  975.                                       case 0x20:
  976.                                           Data[3] = 0x38; // NTSC-N(50Hz)     // PAL-M(60Hz)
  977.                                           I2CWrite(Data);
  978.                                           ucAV_Mode   = (ucAV_Mode & 0x0f) | 0x30;
  979.                                           break;
  980.                                       case 0x30:
  981.                                           if (ucAV_Mode & 0x02)
  982.                                           {
  983.                                               // NTSC-N -> SECAM (50Hz)
  984.                                               Data[3]     = 0x5c;
  985.                                               I2CWrite(Data);
  986.                                               ucAV_Mode   = 0x03;
  987.                                           }
  988.                                           else
  989.                                           {   
  990.                                               // PAL-M -> NTSC_M (60Hz)
  991.                                               Data[3]     = 0x08;
  992.                                               I2CWrite(Data);
  993.                                               ucAV_Mode   = ucAV_Mode & 0x0f | 0x00;
  994.                                           }    
  995.                                       default:
  996.                                           break;
  997.                                       }//end of "switch (ucAV_Mode & 0x70)"
  998.                                   }//end of "if (ucMode_Times & 0x01)"        
  999.                               }//end of "if (0x03 == (ucAV_Mode & 0x03)) else"
  1000.                           }//end of "Non Lock color
  1001.                       }//end of "Check Lock Color"
  1002.                   }//end of "if (0==(Data[0] & 0x40))"
  1003.                   else
  1004.                   {   
  1005.                       // Non Horizontal Lock
  1006. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 17  
  1007.                       ucAV_Mode   = 0;
  1008.                       
  1009.                       if (ucMode_Found != MODE_NOSUPPORT)
  1010.                       {
  1011.                           ucMode_Found    = MODE_NOSUPPORT;
  1012.                           ucMode_Times    = 0;
  1013.                       }
  1014.                   }
  1015.                   
  1016.                   //-------------Check result--------------
  1017.                   if (MODE_NOSUPPORT != ucMode_Found)
  1018.                   {   
  1019.                       if (VIDEO_SEARCH_TIMES < ucMode_Times)
  1020.                       {
  1021.               
  1022.                           bLIGHT_PWR  = LIGHT_OFF;        // Turn off BackLight for reset display
  1023.                           
  1024.                           RTDSetByte(HOSTCTRL_02, 0x40);  // Wake RTD up
  1025.                           RTDOSDW(OSD_Reset);            // Clear OSD
  1026.                           
  1027.                           if (SOURCE_YUV == (stGUD1.INPUT_SOURCE & 0x07))
  1028.                               ucMode_Curr = (ucAV_Mode & 0x02) ? MODE_YUV50HZ : MODE_YUV60HZ;
  1029.                           else
  1030.                               ucMode_Curr = ucMode_Found;
  1031.                                   
  1032.                           ucMode_Times    = 0;
  1033.                           bStable         = 0;            // bStable must be cleared when mode changed
  1034.               
  1035.                           Display_Video_Set();            
  1036.                       }
  1037.                   }
  1038.                   else
  1039.                   {
  1040.                       ucMode_Times ++;
  1041.                       
  1042.                       if (ucAV_Mode)
  1043.                       {
  1044.                           // Force to display although we cannot lock color
  1045.                           if (VIDEO_SEARCH_TIMES < ucMode_Times 
  1046.                               && (NO_COLOR_TIMES < ucMode_Times || SOURCE_YUV == (stGUD1.INPUT_SOURCE & 0x07)))
  1047.                           {
  1048.               
  1049.                               bLIGHT_PWR  = LIGHT_OFF;        // Turn off BackLight for reset display
  1050.               
  1051.                               RTDSetByte(HOSTCTRL_02, 0x40);  // Wake RTD up
  1052.                               RTDOSDW(OSD_Reset);            // Clear OSD
  1053.                               
  1054.                               ucAV_Mode       = (ucAV_Mode & 0x02) ? 0x82 : 0x81;
  1055.               
  1056.                               if (SOURCE_YUV != (stGUD1.INPUT_SOURCE & 0x07))
  1057.                                   ucMode_Curr = (ucAV_Mode & 0x02) ? MODE_VIDEO50HZ : MODE_VIDEO60HZ;
  1058.                               else
  1059.                                   ucMode_Curr = (ucAV_Mode & 0x02) ? MODE_YUV50HZ : MODE_YUV60HZ;
  1060.               
  1061.                               ucMode_Times    = 0;
  1062.                               bStable         = 0;    // bStable must be cleared when mode changed
  1063.               
  1064.                               Display_Video_Set();
  1065.                           }
  1066.                       }
  1067.                       else
  1068.                       {
  1069. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 18  
  1070.                           if (NO_MODE_TIMES < ucMode_Times)
  1071.                           {
  1072.                               bStable         = 1;    // Set bStable to 1 when signal timing is stable.
  1073.               
  1074.                               ucMode_Times    = NO_MODE_TIMES - 1;
  1075.                           }
  1076.                       }
  1077.                   }
  1078.               #else
  1079. 1046   1          Display_Video_Set();
  1080. 1047   1      #endif
  1081. 1048   1      }
  1082. 1049          
  1083. 1050          
  1084. 1051          //-------------------  Check AV Mode  -------------------//
  1085. 1052          void Check_Video_Mode(void)
  1086. 1053          {   
  1087. 1054   1      #if(VIDEO_CHIP != VDC_NONE)
  1088.                   I2CRead(ADDR_VIDEO, 0x1f, 0x01);
  1089.                   
  1090.                   // Check color
  1091.                   if (0 == (ucAV_Mode & 0x80))
  1092.                   {
  1093.                       if (0 == (Data[0] & 0x01))      ucMode_Curr = MODE_NOSIGNAL;    // Color standard changed
  1094.                   }
  1095.                   else
  1096.                   {
  1097.                       if (0 == (Data[0] & 0x01))
  1098.                       {
  1099.                           ucMode_Times    = 0;
  1100.                       }
  1101.                       else
  1102.                       {
  1103.                           // When we cannot lock color, we set color standard to PAL-BDGHI if field rate is 50Hz, 
  1104.                           // and to NTSC-M if it is 60Hz.
  1105.                           // If we find color is locked, we should update ucAV_Mode to indicate we now get color.
  1106.                           if (VIDEO_SEARCH_TIMES < ++ucMode_Times)    ucAV_Mode = ucAV_Mode & 0x0f;
  1107.                       }
  1108.                   }
  1109.               
  1110.                   // Check field rate
  1111.                   if (Data[0] & 0x40)
  1112.                   {
  1113.                       ucMode_Curr = MODE_NOSIGNAL;
  1114.                   }
  1115.                   else
  1116.                   {
  1117.                       if (ucAV_Mode & 0x02)       // 50Hz
  1118.                       {   
  1119.                           if (0x00 != (Data[0] & 0x20))   ucMode_Curr = MODE_NOSIGNAL;
  1120.                       } 
  1121.                       else                        // 60Hz
  1122.                       {
  1123.                           if (0x00 == (Data[0] & 0x20))   ucMode_Curr = MODE_NOSIGNAL;
  1124.                       }
  1125.                   }
  1126.                  
  1127.                   // Check result
  1128.                   if (MODE_NOSIGNAL == ucMode_Curr)
  1129.                       Reset_Mode();
  1130.                   else
  1131.                       bStable = 1;    // Set bStable to 1 when signal timing is stable.
  1132. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 19  
  1133.               #endif
  1134. 1100   1      }
  1135. 1101          
  1136. 1102          
  1137. 1103          void Calculate_IVS2DVS_Delay(unsigned char integer, unsigned char fraction, unsigned int DVStart)
  1138. 1104          {
  1139. 1105   1             if ((usIPV_ACT_STA + integer) < (DVStart >> 6))
  1140. 1106   1              {
  1141. 1107   2                  // You should never get into this code ....
  1142. 1108   2                  usIPV_ACT_STA   = ( DVStart >> 6) - integer;
  1143. 1109   2      
  1144. 1110   2                  RTDSetByte(IPV_ACT_STA_0A, (unsigned char)usIPV_ACT_STA);
  1145. 1111   2                  RTDSetByte(IPV_ACT_STA_0A + 1, (unsigned char)(usIPV_ACT_STA >> 8));
  1146. 1112   2              }
  1147. 1113   1      
  1148. 1114   1              ((unsigned int*)Data)[0] = ((usIPV_ACT_STA + integer) << 6) + ((unsigned int)fraction << 6)/10 - D
  1149.              -VStart;
  1150. 1115   1      
  1151. 1116   1              
  1152. 1117   1                      ucDV_Delay = (unsigned char)(((unsigned int*)Data)[0] >> 6);
  1153. 1118   1      
  1154. 1119   1                      Data[6] = ((unsigned int*)Data)[0] - (ucDV_Delay << 6);
  1155. 1120   1      
  1156. 1121   1                      Data[6] = (unsigned long)usADC_Clock * Data[6] / 1024;//512;
  1157. 1122   1      
  1158. 1123   1                      RTDSetByte(FS_FT_DELAY_1E, Data[6]);
  1159. 1124   1      
  1160. 1125   1             
  1161. 1126   1      }
  1162. 1127          
  1163. 1128          void Set_Dclk(unsigned int DispLen)
  1164. 1129          {
  1165. 1130   1          if (Mode_Preset[ucMode_Curr][3])
  1166. 1131   1          {
  1167. 1132   2              // Use preset DCLK M/N code
  1168. 1133   2              Data[0] = 6;
  1169. 1134   2              Data[1] = Y_INC;
  1170. 1135   2              Data[2] = DPLL_CTRL_D0;
  1171. 1136   2              Data[3] = 0x11;
  1172. 1137   2              Data[4] = (unsigned char)(Mode_Preset[ucMode_Curr][3] >> 8);
  1173. 1138   2              Data[5] = (unsigned char)Mode_Preset[ucMode_Curr][3];
  1174. 1139   2              Data[6] = 0;
  1175. 1140   2              RTDWrite(Data);
  1176. 1141   2          }
  1177. 1142   1          else
  1178. 1143   1          {
  1179. 1144   2           
  1180. 1145   2      //        if (VGA_Mode[ucMode_Curr][4])
  1181. 1146   2      //        {
  1182. 1147   2      //            ((unsigned int *)Data)[0]   = (unsigned long)8 * usDH_Total * USER_MODE_NCODE * usDispLen 
  1183. 1148   2      //                                        / ((unsigned long)usIPV_ACT_LEN * VGA_Mode[ucMode_Curr][4]);
  1184. 1149   2      //        }
  1185. 1150   2      //        else
  1186. 1151   2      //        {
  1187. 1152   2      
  1188. 1153   2                  ((unsigned int *)Data)[0]   = (unsigned long)8 * usDH_Total * USER_MODE_NCODE * DispLen 
  1189. 1154   2                                              / ((unsigned long)usIPV_ACT_LEN * usHsync);
  1190. 1155   2      //        }
  1191. 1156   2      
  1192. 1157   2      
  1193. 1158   2              //Original Formula : DPM/Ich = 17.6 must be constant
  1194. 1159   2                      //Ich = DPM * 10 / 176
  1195. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 20  
  1196. 1160   2                      //2*Ich = DPM * 20 / 176 , set D0[0] to 0, then I = 2 * Ich
  1197. 1161   2                      //I  = 2 * Ich = 2.5u + D0[3]*2.5u + D0[4]*5u + D0[5]*10u + D0[6]*20u + D0[7]*30u(A)
  1198. 1162   2                      //2I = 4 * Ich = 5u + D0[3]*5u + D0[4]*10u + D0[5]*20u + D0[6]*40u + D0[7]*60u(A)
  1199. 1163   2              Data[15] = ((unsigned int *)Data)[0] >> 2;
  1200. 1164   2                      Data[5] = (unsigned int)Data[15] * 40 / 176 - 5; //Calculate the 4*Ich,
  1201. 1165   2                      Data[6] = 0x00;
  1202. 1166   2                      if(Data[5] > 60)
  1203. 1167   2                      {
  1204. 1168   3                          Data[5] -= 60;
  1205. 1169   3                              Data[6] |= 0x80; 
  1206. 1170   3                      }
  1207. 1171   2      
  1208. 1172   2                      if(Data[5] > 40)
  1209. 1173   2                      {
  1210. 1174   3                          Data[5] -= 40;
  1211. 1175   3                              Data[6] |= 0x40;
  1212. 1176   3                      }
  1213. 1177   2                       
  1214. 1178   2                  if(Data[5] > 20)
  1215. 1179   2                      {
  1216. 1180   3                          Data[5] -= 20;
  1217. 1181   3                              Data[6] |= 0x20;
  1218. 1182   3                      }
  1219. 1183   2      
  1220. 1184   2                      if(Data[5] > 10)
  1221. 1185   2                      {
  1222. 1186   3                          Data[5] -= 10;
  1223. 1187   3                              Data[6] |= 0x10;
  1224. 1188   3                      }
  1225. 1189   2      
  1226. 1190   2                      if(Data[5] > 5)
  1227. 1191   2                      {
  1228. 1192   3                          Data[5] -= 5;
  1229. 1193   3                              Data[6] |= 0x08;
  1230. 1194   3                      }
  1231. 1195   2                      
  1232. 1196   2      
  1233. 1197   2                      Data[0] = 7;
  1234. 1198   2                      Data[1] = Y_INC;
  1235. 1199   2                      Data[2] = DPLL_CTRL_D0;
  1236. 1200   2                      Data[3] = Data[6];
  1237. 1201   2                      Data[4] = Data[15] - 2;
  1238. 1202   2                      Data[5] = 0x10 | (USER_MODE_NCODE - 2);//Offset Frequency Direction set to Downward
  1239. 1203   2                      //Data[5] = (USER_MODE_NCODE - 2);//Offset Frequency Direction set to Downward
  1240. 1204   2                      Data[6] = 0x04;
  1241. 1205   2                      Data[7] = 0;
  1242. 1206   2                      RTDWrite(Data);
  1243. 1207   2      
  1244. 1208   2       
  1245. 1209   2      //        ucDebug_Value0 = Data[4];
  1246. 1210   2         //     ucDebug_Value1 = Data[5];
  1247. 1211   2             
  1248. 1212   2              //More precise Dclk in KHz
  1249. 1213   2                      ((unsigned long*)Data)[0] = (unsigned long)24576000 / usIPV_ACT_LEN * DispLen / usHsync * usDH_Total ;
  1250. 1214   2              //((unsigned long*)Data)[0] = (unsigned long)49152000 / usIPV_ACT_LEN * usDispLen / usHsync * usDH
  1251.              -_Total ;
  1252. 1215   2                      //set M/N code Dclk
  1253. 1216   2                      ((unsigned long*)Data)[1] = (unsigned long)12288000 * (Data[15] + 1) / USER_MODE_NCODE;
  1254. 1217   2              //((unsigned long*)Data)[1] = (unsigned long)24576000 * (Data[15] + 1) / USER_MODE_NCODE;
  1255. 1218   2                      ((unsigned long*)Data)[2] = ((unsigned long*)Data)[1] - ((unsigned long*)Data)[0]; //Dclk offset
  1256. 1219   2                      ((unsigned long*)Data)[3] = ((unsigned long*)Data)[1] >> 15; //Offset resolution equal to (Dclk / 2^15)
  1257. 1220   2              
  1258. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 21  
  1259. 1221   2                      ((unsigned long*)Data)[3] = ((((unsigned long*)Data)[2] << 1)/ ((unsigned long*)Data)[3]) & 0x00000fff; 
  1260.              -//Calculate the Dclk offset
  1261. 1222   2              //((unsigned long*)Data)[3] = (((unsigned long*)Data)[2] / ((unsigned long*)Data)[3]) & 0x00000fff
  1262.              -; //Calculate the Dclk offset
  1263. 1223   2      
  1264. 1224   2                      RTDSetByte(DCLK_OFFSET_LSB_9A,(unsigned char)((unsigned long*)Data)[3]);  //Set the Dclk offset
  1265. 1225   2      //        ucDebug_Value0 = (unsigned char)(((unsigned long*)Data)[3]);
  1266. 1226   2                      //RTDSetBit(DCLK_OFFSET_MSB_9B,0xf0,(unsigned char)(((unsigned long*)Data)[3] >> 8) | 0x20);
  1267. 1227   2                      RTDSetBit(DCLK_OFFSET_MSB_9B,0xf0,(unsigned char)(((unsigned long*)Data)[3] >> 8) | 0x20);
  1268. 1228   2      //        ucDebug_Value1 = (unsigned char)((((unsigned long*)Data)[3] >> 8) | 0x20);
  1269. 1229   2              RTDSetBit(FX_LST_LEN_H_5A,0xff,0x08); //Enable DDS Spread Spectrum Output Function
  1270. 1230   2                      RTDSetBit(DPLL_N_D2,0xff,0x20); //DPLL Spread Spectrum Enable
  1271. 1231   2                      RTDSetBit(DPLL_FILTER_D3,0x7f,0x00); //Enable DPll output
  1272. 1232   2              }
  1273. 1233   1      }
  1274. 1234          
  1275. 1235          void Initial_Mode(void)
  1276. 1236          {
  1277. 1237   1          unsigned char   ucOption;
  1278. 1238   1          unsigned int    usDispLen;
  1279. 1239   1      
  1280. 1240   1          // bit 7 of ucMode_Curr : partial-V display.
  1281. 1241   1          // bit 6 of ucMode_Curr : select 720x350 or 720x400 for VGA-50Hz and VGA-60Hz
  1282. 1242   1          ucOption    = ucMode_Curr & 0xc0;
  1283. 1243   1          ucMode_Curr = ucMode_Curr & 0x3f;
  1284. 1244   1      
  1285. 1245   1          
  1286. 1246   1              RTDSetBit(SD_CTRL_70, 0xf9, VGA_ICLK_DELAY);
  1287. 1247   1          if (SOURCE_DVI == (stGUD1.INPUT_SOURCE & 0x07))
  1288. 1248   1          {
  1289. 1249   2              RTDSetBit(SD_CTRL_70, 0xf9, TMDS_ICLK_DELAY);
  1290. 1250   2      
  1291. 1251   2              usIPH_ACT_STA   = CAP_WIN[ucMode_Curr][1];
  1292. 1252   2          }
  1293. 1253   1          else
  1294. 1254   1          {
  1295. 1255   2      
  1296. 1256   2              if (ucOption & 0x40)
  1297. 1257   2              {
  1298. 1258   3                      // Only VGA-50Hz and VGA-60Hz mode will set bit 6 of ucMode_Curr to indicate 720-pixel capture width
  1299. 1259   3                      // In these case, we should use 720 horizontal settings instead of 640 horizontal settings in table.
  1300. 1260   3                      usADC_Clock     = CAP_WIN[MODE_0720x0400x70HZ][0];
  1301. 1261   3                      usIPH_ACT_STA   = CAP_WIN[MODE_0720x0400x70HZ][1];
  1302. 1262   3                      usIPH_ACT_WID   = CAP_WIN[MODE_0720x0400x70HZ][2];
  1303. 1263   3              }
  1304. 1264   2              else
  1305. 1265   2              {
  1306. 1266   3                      usADC_Clock     = CAP_WIN[ucMode_Curr][0];
  1307. 1267   3                      usIPH_ACT_STA   = CAP_WIN[ucMode_Curr][1];
  1308. 1268   3                      usIPH_ACT_WID   = CAP_WIN[ucMode_Curr][2];
  1309. 1269   3      
  1310. 1270   3                      // Calculate pixel clock rate (round to MHz)
  1311. 1271   3                      usDispLen   = (unsigned long)24576 * usADC_Clock / ((unsigned long)usHsync * 500);
  1312. 1272   3                      usDispLen   = (usDispLen >> 1) + (usDispLen & 0x01);
  1313. 1273   3      
  1314. 1274   3                      // Use ADC to do H scale-down if pixel clock rate is over spec.
  1315. 1275   3                      if (MAX_ADC_FREQ < usDispLen && MODE_USER1152x864 <= ucMode_Curr && MODE_USER1600x1200 >= ucMode_Curr)
  1316. 1276   3                      {
  1317. 1277   4                              usADC_Clock     = ADC_SD_SET[ucMode_Curr - MODE_USER1152x864][0];
  1318. 1278   4                              usIPH_ACT_STA   = ADC_SD_SET[ucMode_Curr - MODE_USER1152x864][1];
  1319. 1279   4                              usIPH_ACT_WID   = ADC_SD_SET[ucMode_Curr - MODE_USER1152x864][2];
  1320. 1280   4                      }
  1321. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 22  
  1322. 1281   3      
  1323. 1282   3              } //if (ucOption & 0x40)
  1324. 1283   2      
  1325. 1284   2              // Calculate pixel clock rate (round to MHz)
  1326. 1285   2              usDispLen   = (unsigned long)24576 * usADC_Clock / ((unsigned long)usHsync * 500);
  1327. 1286   2              usDispLen   = (usDispLen >> 1) + (usDispLen & 0x01);
  1328. 1287   2      
  1329. 1288   2      
  1330. 1289   2              // To improve ADC performance ,when the data rate is slow, use single channel,otherwise, use dual channel
  1331. 1290   2              RTDSetBit(ADC_REG_CLK_EA,0xe0,(45 > usDispLen) ? 0x10 | (ADC_RED_PHASE_FT & 0x0c) |( ADC_BLUE_PHASE_FT & 
  1332.              -0x03): 
  1333. 1291   2                                                               0x00 | (ADC_RED_PHASE_FT & 0x0c) |( ADC_BLUE_PHASE_FT & 
  1334.              -0x03)); 
  1335. 1292   2      
  1336. 1293   2      
  1337. 1294   2              // To imporve the FIFO efficiency only when input data rate is slow, and display data rate is high.
  1338. 1295   2      //      RTDSetBit(VGIP_CTRL_04, 0xe3, (40 > usDispLen) ? 0x14 : 0x00);
  1339. 1296   2          RTDSetBit(VGIP_CTRL_04, 0xf3, (60 > usDispLen) ? 0x08 : 0x00);
  1340. 1297   2      
  1341. 1298   2              RTDSetByte(PE_CONTROL_3C, 0x00);    // HSYNC positive/negtive tracking
  1342. 1299   2              
  1343. 1300   2          RTDSetByte(ADC_FRAME_MODULE_EB,0x06);
  1344. 1301   2      //  RTDSetByte(ADC_FRAME_MODULE_EB,(usIPH_ACT_WID == 1280) ? 0x04 : 0x00);
  1345. 1302   2      
  1346. 1303   2      
  1347. 1304   2        // Set ADC bandwidth to reduce high frequency noise
  1348. 1305   2      //  RTDSetByte(ADC_REG_TEST_E9, (35 > usDispLen) ? 0x08 : (150 > usDispLen) ? 0x10 : 0x18);
  1349. 1306   2              
  1350. 1307   2      
  1351. 1308   2      
  1352. 1309   2      #if(ADC_DEFFERENTIAL)
  1353. 1310   2          RTDSetBit(ADC_DIFF_MODE_EC,0xff,0x40); //Differential mode
  1354. 1311   2      #else
  1355.                   RTDSetBit(ADC_DIFF_MODE_EC,0xbf,0x00); //Single endded mode
  1356.               #endif
  1357. 1314   2      
  1358. 1315   2      
  1359. 1316   2      
  1360. 1317   2      
  1361. 1318   2              RTDSetByte(ADC_REG_CUR_H_E8, 0x0d | (ADC_GREEN_PHASE_FT & 0x30));
  1362. 1319   2      
  1363. 1320   2      
  1364. 1321   2      
  1365. 1322   2          RTDSetBit(ADC_FRAME_MODULE_EB,0xc7, ((ADC_RED_PHASE_FT & 0x10) << 1) | ((ADC_GREEN_PHASE_FT & 0x40) <<
  1366.              - 2) 
  1367. 1323   2                                                 |((ADC_BLUE_PHASE_FT & 0x04) << 1));
  1368. 1324   2      
  1369. 1325   2      
  1370. 1326   2      
  1371. 1327   2          RTDSetBit(TMDS_CORRECTION_FF,0xff,0x04); //Enable the ADC digital filter
  1372. 1328   2      
  1373. 1329   2      
  1374. 1330   2          if(ucMode_Curr < MODE_1024x0768x70HZ)
  1375. 1331   2              RTDSetByte(ADC_REG_TEST_E9, 0x08);
  1376. 1332   2          else 
  1377. 1333   2              RTDSetByte(ADC_REG_TEST_E9, 0x10);
  1378. 1334   2      
  1379. 1335   2      
  1380. 1336   2              // Get usIPV_ACT_LEN
  1381. 1337   2              if (MODE_UNDEFINED0 > ucMode_Curr)
  1382. 1338   2              {
  1383. 1339   3                      // We've already decided usIPV_ACT_LEN in Detect_VGA_Mode() for undefined SU/SD mode.
  1384. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 23  
  1385. 1340   3                      // Only defined modes need to decide usIPV_ACT_LEN here.
  1386. 1341   3                      usIPV_ACT_LEN   = CAP_WIN[ucMode_Curr][4];
  1387. 1342   3              }
  1388. 1343   2          
  1389. 1344   2          } //if (SOURCE_DVI == (stGUD1.INPUT_SOURCE & 0x07))
  1390. 1345   1      
  1391. 1346   1          // Get standard usIPV_ACT_STA 
  1392. 1347   1      
  1393. 1348   1          RTDSetByte(IVS_DELAY_8C, PROGRAM_VDELAY);
  1394. 1349   1      
  1395. 1350   1          usIPV_ACT_STA   = CAP_WIN[ucMode_Curr][3] - PROGRAM_VDELAY - 1;
  1396. 1351   1      
  1397. 1352   1      
  1398. 1353   1          RTDSetByte(IHS_DELAY_8D, PROGRAM_HDELAY);
  1399. 1354   1      
  1400. 1355   1      //    usIPH_ACT_STA   = usIPH_ACT_STA + CAPTURE_HDELAY - PROGRAM_HDELAY;
  1401. 1356   1          if(ucMode_Curr < MODE_0800x0600x75HZ)
  1402. 1357   1                      Data[0] = 2;
  1403. 1358   1          else if(ucMode_Curr < MODE_1280x1024x75HZ)
  1404. 1359   1                      Data[0] = 5;
  1405. 1360   1          else
  1406. 1361   1                      Data[0] = 3;
  1407. 1362   1      
  1408. 1363   1      //    Data[0] = 5;
  1409. 1364   1          usIPH_ACT_STA   = usIPH_ACT_STA + Data[0] - PROGRAM_HDELAY;
  1410. 1365   1      
  1411. 1366   1          // Decide display length (height) and store to usDispLen
  1412. 1367   1      
  1413. 1368   1          usDispLen   = Mode_Preset[ucMode_Curr][2];
  1414. 1369   1      
  1415. 1370   1          if (MODE_UNDEFINED0 == ucMode_Curr)         // partical-screen scale-up mode
  1416. 1371   1          {
  1417. 1372   2              if (ucOption & 0x80)    // partial-V
  1418. 1373   2              {           
  1419. 1374   3                              if (MIN_DV_TOTAL > (usVsync - 1))
  1420. 1375   3                      usDispLen   = (unsigned long)usIPV_ACT_LEN * MIN_DV_TOTAL / (usVsync - 1);
  1421. 1376   3                  else
  1422. 1377   3                      usDispLen   = usIPV_ACT_LEN;    // No V scale-up
  1423. 1378   3              }
  1424. 1379   2          }
  1425. 1380   1          else if (MODE_UNDEFINED1 == ucMode_Curr)    // partial-screen scale-down mode
  1426. 1381   1          {
  1427. 1382   2              if (ucOption & 0x80)    // partial-V
  1428. 1383   2              {
  1429. 1384   3                  usDispLen   = (unsigned long)usIPV_ACT_LEN * MIN_DV_TOTAL / (usVsync - 1);
  1430. 1385   3              }
  1431. 1386   2          } //if (MODE_UNDEFINED0 == ucMode_Curr)         // partical-screen scale-up mode
  1432. 1387   1      
  1433. 1388   1          if (Mode_Preset[ucMode_Curr][2] < usDispLen)    usDispLen   = Mode_Preset[ucMode_Curr][2];
  1434. 1389   1      
  1435. 1390   1          // This F/W do not support V scale-up(or bypass) and H scale-down simultaneously
  1436. 1391   1          if (usDispLen >= usIPV_ACT_LEN && Mode_Preset[ucMode_Curr][1] < usIPH_ACT_WID)
  1437. 1392   1          {
  1438. 1393   2              usIPH_ACT_WID   = Mode_Preset[ucMode_Curr][1];
  1439. 1394   2          }
  1440. 1395   1      
  1441. 1396   1          if (usDispLen > usIPV_ACT_LEN)                      ucOption    |= 0x01;    // bit 0 : V scale-up
  1442. 1397   1          if (usDispLen < usIPV_ACT_LEN)                      ucOption    |= 0x02;    // bit 1 : V scale-down
  1443. 1398   1          if (Mode_Preset[ucMode_Curr][1] > usIPH_ACT_WID)    ucOption    |= 0x04;    // bit 2 : H scale-up
  1444. 1399   1          if (Mode_Preset[ucMode_Curr][1] < usIPH_ACT_WID)    ucOption    |= 0x08;    // bit 3 : H scale-down
  1445. 1400   1      
  1446. 1401   1          // Set capture window
  1447. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 24  
  1448. 1402   1          Data[0]     = 11;
  1449. 1403   1          Data[1]     = Y_INC;
  1450. 1404   1          Data[2]     = IPH_ACT_STA_06;
  1451. 1405   1          Data[3]     = (unsigned char)usIPH_ACT_STA;
  1452. 1406   1          Data[4]     = (unsigned char)(usIPH_ACT_STA >> 8);
  1453. 1407   1          Data[5]     = (unsigned char)usIPH_ACT_WID;
  1454. 1408   1          Data[6]     = (unsigned char)(usIPH_ACT_WID >> 8);
  1455. 1409   1          Data[7]     = (unsigned char)usIPV_ACT_STA;
  1456. 1410   1          Data[8]     = (unsigned char)(usIPV_ACT_STA >> 8);
  1457. 1411   1          Data[9]     = (unsigned char)usIPV_ACT_LEN;
  1458. 1412   1          Data[10]    = (unsigned char)(usIPV_ACT_LEN >> 8);
  1459. 1413   1          Data[11]    = 0;
  1460. 1414   1          RTDWrite(Data);
  1461. 1415   1      
  1462. 1416   1          // Set window size before scale-up
  1463. 1417   1          Data[0] = 7;
  1464. 1418   1          Data[1] = Y_INC;
  1465. 1419   1          Data[2] = DRW_BSU_40;
  1466. 1420   1      
  1467. 1421   1          if (ucOption & 0x08)
  1468. 1422   1          {
  1469. 1423   2              // H scale-down
  1470. 1424   2              Data[3] = (unsigned char)Mode_Preset[ucMode_Curr][1];
  1471. 1425   2              Data[4] = (unsigned char)(Mode_Preset[ucMode_Curr][1] >> 8);
  1472. 1426   2          }
  1473. 1427   1          else
  1474. 1428   1          {
  1475. 1429   2              // No H scale-down
  1476. 1430   2              Data[3] = Data[5];  // (unsigned char)usIPH_ACT_WID;
  1477. 1431   2              Data[4] = Data[6];  // (unsigned char)(usIPH_ACT_WID >> 8);
  1478. 1432   2          }
  1479. 1433   1      
  1480. 1434   1          if (ucOption & 0x02)
  1481. 1435   1          {
  1482. 1436   2              // V scale-down
  1483. 1437   2              Data[5] = (unsigned char)usDispLen;
  1484. 1438   2              Data[6] = (unsigned char)(usDispLen >> 8);
  1485. 1439   2          }
  1486. 1440   1          else
  1487. 1441   1          {
  1488. 1442   2              // No V scale-down
  1489. 1443   2              Data[5] = Data[9];  // (unsigned char)usIPV_ACT_LEN;
  1490. 1444   2              Data[6] = Data[10]; // (unsigned char)(usIPV_ACT_LEN >> 8);
  1491. 1445   2          }
  1492. 1446   1          Data[7] = 0;
  1493. 1447   1          RTDWrite(Data);
  1494. 1448   1      
  1495. 1449   1          // Config scaling
  1496. 1450   1          if (ucOption & 0x0a)
  1497. 1451   1              RTDSetBit(SD_CTRL_70, 0xff, 0x01);      // Turn on scale-down
  1498. 1452   1          else
  1499. 1453   1              RTDSetBit(SD_CTRL_70, 0xfe, 0x00);      // Turn off scale-down
  1500. 1454   1      
  1501. 1455   1          if (ucOption & 0x01)
  1502. 1456   1              RTDSetBit(SCALE_CTRL_15, 0xff, 0x02);   // Turn on V scale-up
  1503. 1457   1          else
  1504. 1458   1              RTDSetBit(SCALE_CTRL_15, 0xfd, 0x00);   // Turn off V scale-up
  1505. 1459   1      
  1506. 1460   1          if (ucOption & 0x04)
  1507. 1461   1              RTDSetBit(SCALE_CTRL_15, 0xff, 0x01);   // Turn on H scale-up
  1508. 1462   1          else
  1509. 1463   1              RTDSetBit(SCALE_CTRL_15, 0xfe, 0x00);   // Turn off H scale-up
  1510. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 25  
  1511. 1464   1      
  1512. 1465   1          // Set scale-down coefficient
  1513. 1466   1          Data[0] = 7;
  1514. 1467   1          Data[1] = Y_INC;
  1515. 1468   1          Data[2] = H_SCALE_DL_71;
  1516. 1469   1      
  1517. 1470   1          if (ucOption & 0x08)    // H scale-down
  1518. 1471   1          {
  1519. 1472   2              // Data[12~15]
  1520. 1473   2              ((unsigned long *)Data)[3]  = (unsigned long)256 * 4096 * usIPH_ACT_WID / Mode_Preset[ucMode_Curr]
  1521.              -[1];
  1522. 1474   2      
  1523. 1475   2              // Data[4~5]
  1524. 1476   2              ((unsigned int *)Data)[2]   = (((unsigned long *)Data)[3] >> 8) + 2;
  1525. 1477   2      
  1526. 1478   2              // H scale-down factor is stored in Data[4] (high-byte) and Data[5] (low-byte)
  1527. 1479   2              Data[3] = Data[5];
  1528. 1480   2      
  1529. 1481   2              RTDSetBit(VGIP_CTRL_04, 0xff, 0x40);    // Enable H scale-down compensation
  1530. 1482   2          }
  1531. 1483   1          else
  1532. 1484   1          {
  1533. 1485   2              Data[3] = 0x00;
  1534. 1486   2              Data[4] = 0x10;
  1535. 1487   2      
  1536. 1488   2              RTDSetBit(VGIP_CTRL_04, 0xbf, 0x00);    // Diable H scale-down compensation
  1537. 1489   2          }
  1538. 1490   1      
  1539. 1491   1          if (ucOption & 0x02)    // V scale-down
  1540. 1492   1          {
  1541. 1493   2              // Data[12~15]
  1542. 1494   2              ((unsigned long *)Data)[3]  = (unsigned long)256 * 4096 * usIPV_ACT_LEN / usDispLen;
  1543. 1495   2      
  1544. 1496   2              // Data[6~7]
  1545. 1497   2              ((unsigned int *)Data)[3]   = (((unsigned long *)Data)[3] >> 8);
  1546. 1498   2      
  1547. 1499   2              if (0 == Data[15])      ((unsigned int *)Data)[3]   = ((unsigned int *)Data)[3] - 1;
  1548. 1500   2      
  1549. 1501   2              // V scale-down factor is stored in Data[6] (high-byte) and Data[7] (low-byte)
  1550. 1502   2              Data[5] = Data[7];
  1551. 1503   2      
  1552. 1504   2              RTDSetBit(VGIP_CTRL_04, 0xff, 0x80);    // Enable V scale-down compensation
  1553. 1505   2          }
  1554. 1506   1          else
  1555. 1507   1          {
  1556. 1508   2              Data[5] = 0x00;
  1557. 1509   2              Data[6] = 0x10;
  1558. 1510   2      
  1559. 1511   2              RTDSetBit(VGIP_CTRL_04, 0x7f, 0x00);    // Diable V scale-down compensation
  1560. 1512   2          }
  1561. 1513   1          Data[7] = 0;
  1562. 1514   1          RTDWrite(Data);
  1563. 1515   1      
  1564. 1516   1          // Set scale-up coefficient
  1565. 1517   1          Data[0] = 8;
  1566. 1518   1          Data[1] = Y_INC;
  1567. 1519   1          Data[2] = HOR_SCA_16;
  1568. 1520   1      
  1569. 1521   1          if (ucOption & 0x04)    // H scale-up
  1570. 1522   1          {
  1571. 1523   2              // Data[12~15]
  1572. 1524   2              ((unsigned long *)Data)[3]  = (unsigned long)2 * 262144 * usIPH_ACT_WID / Mode_Preset[ucMode_Curr]
  1573. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 26  
  1574.              -[1];
  1575. 1525   2              ((unsigned long *)Data)[3]  = ((((unsigned long *)Data)[3] >> 1) + (((unsigned long *)Data)[3] & 0
  1576.              -x01)) << 6;
  1577. 1526   2      
  1578. 1527   2              Data[3] = Data[14];
  1579. 1528   2              Data[4] = Data[13];
  1580. 1529   2              Data[7] = Data[15];
  1581. 1530   2          }
  1582. 1531   1          else
  1583. 1532   1          {
  1584. 1533   2              Data[3] = 0xff;
  1585. 1534   2              Data[4] = 0xff;
  1586. 1535   2              Data[7] = 0;
  1587. 1536   2          }
  1588. 1537   1      
  1589. 1538   1          if (ucOption & 0x01)    // V scale-up
  1590. 1539   1          {
  1591. 1540   2              // Data[12~15]
  1592. 1541   2              ((unsigned long *)Data)[3]  = (unsigned long)2 * 262144 * usIPV_ACT_LEN / usDispLen;
  1593. 1542   2              ((unsigned long *)Data)[3]  = ((((unsigned long *)Data)[3] >> 1) + (((unsigned long *)Data)[3] & 0
  1594.              -x01)) << 6;
  1595. 1543   2      
  1596. 1544   2              Data[5] = Data[14];                     //anson 05_0315
  1597. 1545   2      //        Data[5] = 0x90;
  1598. 1546   2              Data[6] = Data[13];
  1599. 1547   2      //        Data[6] = 0xc0;
  1600. 1548   2              Data[7] = Data[7] | (Data[15] >> 4);
  1601. 1549   2          }
  1602. 1550   1          else
  1603. 1551   1          {
  1604. 1552   2              Data[5] = 0xff;
  1605. 1553   2              Data[6] = 0xff;
  1606. 1554   2          }
  1607. 1555   1          Data[8] = 0;
  1608. 1556   1          RTDWrite(Data);
  1609. 1557   1      
  1610. 1558   1          // Set RTD display
  1611. 1559   1      
  1612. 1560   1          // Switch to FrameSync 1 mode and diable display
  1613. 1561   1          RTDSetByte(VDIS_CTRL_20, 0x28 | DISP_BIT | DISPLAY_PORT);
  1614. 1562   1      
  1615. 1563   1          Data[0]     = 5;
  1616. 1564   1          Data[1]     = Y_INC;
  1617. 1565   1      
  1618. 1566   1      #if (DISP_ALIGN)
  1619.               
  1620.                   Data[2]     = DH_ACT_STA_27;
  1621.               
  1622.                   // DH_ACT_STA store in Data[4~5] (H~L)
  1623.                   ((unsigned int *)Data)[2]   = (unsigned int)DH_ACT_END_POS - Mode_Preset[ucMode_Curr][1];
  1624.               
  1625.                   Data[3]     = Data[5];
  1626.               
  1627.               #else
  1628. 1576   1      
  1629. 1577   1          Data[2]     = DH_ACT_END_29;
  1630. 1578   1      
  1631. 1579   1          // DH_ACT_STA store in Data[4~5] (H~L)
  1632. 1580   1          ((unsigned int *)Data)[2]   = (unsigned int)DH_ACT_STA_POS + Mode_Preset[ucMode_Curr][1];
  1633. 1581   1      
  1634. 1582   1          Data[3]     = Data[5];
  1635. 1583   1      
  1636. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 27  
  1637. 1584   1      #endif
  1638. 1585   1      
  1639. 1586   1          Data[5]     = 5;
  1640. 1587   1          Data[6]     = Y_INC;
  1641. 1588   1          Data[7]     = DV_ACT_END_34;
  1642. 1589   1      
  1643. 1590   1          // DV_ACT_END store in Data[10~11] (H~L)
  1644. 1591   1          ((unsigned int *)Data)[5]   = (unsigned int)DV_ACT_STA_POS + usDispLen;
  1645. 1592   1      
  1646. 1593   1          Data[8]     = Data[11];
  1647. 1594   1          Data[9]     = Data[10];
  1648. 1595   1          Data[10]    = 0;
  1649. 1596   1          RTDWrite(Data);
  1650. 1597   1      
  1651. 1598   1          // Get standard DH_TOTAL
  1652. 1599   1          usDH_Total  = Mode_Preset[ucMode_Curr][0];
  1653. 1600   1      
  1654. 1601   1          // Switch to FrameSync 1 mode and enable display
  1655. 1602   1      //    if (PANEL_OFF == bPANEL_PWR)
  1656. 1603   1          if (_OFF == bPanel_Status)
  1657. 1604   1              RTDSetByte(VDIS_CTRL_20, 0x29 | DISP_BIT | DISPLAY_PORT);
  1658. 1605   1          else
  1659. 1606   1              RTDSetByte(VDIS_CTRL_20, 0x2b | DISP_BIT | DISPLAY_PORT);
  1660. 1607   1      
  1661. 1608   1              Set_Dclk(usDispLen);
  1662. 1609   1         
  1663. 1610   1          //usDH_Total  = usDH_Total - 2;
  1664. 1611   1      
  1665. 1612   1          // Set DH_TOTAL
  1666. 1613   1          Data[0] = 5;
  1667. 1614   1          Data[1] = Y_INC;
  1668. 1615   1          Data[2] = DH_TOTAL_22;
  1669. 1616   1          Data[3] = (unsigned char)(usDH_Total - 2);
  1670. 1617   1          Data[4] = (unsigned char)((usDH_Total - 2) >> 8);
  1671. 1618   1          Data[5] = 0;
  1672. 1619   1          RTDWrite(Data);
  1673. 1620   1      
  1674. 1621   1      
  1675. 1622   1      
  1676. 1623   1          //Calculate DV_TOTAL
  1677. 1624   1              if((ucOption & 0x01) || (ucOption & 0x02))    // V scale up or scale down
  1678. 1625   1              {
  1679. 1626   2      
  1680. 1627   2      #if(DISP_SIZE == DISP_800x600)          
  1681.                                       usDV_Total = (unsigned long)usVsync * 600 / (unsigned long)usIPV_ACT_LEN + 64;
  1682.               #endif
  1683. 1630   2      
  1684. 1631   2      #if(DISP_SIZE == DISP_1024x768)         
  1685.                                       usDV_Total = (unsigned long)usVsync * 768 / (unsigned long)usIPV_ACT_LEN + 64;
  1686.               #endif
  1687. 1634   2      
  1688. 1635   2      #if(DISP_SIZE == DISP_1280x1024)                
  1689. 1636   2      
  1690. 1637   2                              usDV_Total = (unsigned long)usVsync * 1024 / (unsigned long)usIPV_ACT_LEN + 64;
  1691. 1638   2      #endif
  1692. 1639   2                      
  1693. 1640   2                      
  1694. 1641   2              }
  1695. 1642   1              else
  1696. 1643   1                      usDV_Total = usVsync + 64;
  1697. 1644   1      
  1698. 1645   1          //Set DV_TOTAL
  1699. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 28  
  1700. 1646   1              Data[0] = 5;
  1701. 1647   1              Data[1] = Y_INC;
  1702. 1648   1              Data[2] = DV_TOTAL_2D;
  1703. 1649   1              Data[3] = (unsigned char)usDV_Total;
  1704. 1650   1              Data[4] = (unsigned char)((usDV_Total >> 8) & 0x07);
  1705. 1651   1              Data[5] = 0;
  1706. 1652   1              RTDWrite(Data);
  1707. 1653   1      
  1708. 1654   1      
  1709. 1655   1      
  1710. 1656   1      
  1711. 1657   1          // Calculate suitable IVS to DVS delay
  1712. 1658   1          // CR[38] : IVS to DVS delay in IHS lines
  1713. 1659   1          // CR[1E] : IVS to DVS delay in ICLK * 16
  1714. 1660   1          //((unsigned int *)Data)[0]   = (unsigned long)64 * DV_ACT_STA_POS * usIPV_ACT_LEN / usDispLen;
  1715. 1661   1              ((unsigned int *)Data)[0]   = (unsigned long)64 * DV_ACT_STA_POS * usIPV_ACT_LEN / usDispLen;
  1716. 1662   1      
  1717. 1663   1          if (ucOption & 0x01)
  1718. 1664   1          {
  1719. 1665   2                  Calculate_IVS2DVS_Delay(2,5,((unsigned int*)Data)[0]);  // V scale-up. Target 2.5~2.6 IHS delay
  1720. 1666   2      
  1721. 1667   2          }
  1722. 1668   1          else
  1723. 1669   1          {
  1724. 1670   2      #if (FULL_LINE_BUFFER)
  1725.                       Calculate_IVS2DVS_Delay(3,8,((unsigned int*)Data)[0]);  // V no scale-up. Target 3.8~4.0 IHS delay
  1726.               #else
  1727. 1673   2              if (ucOption & 0x02)
  1728. 1674   2              {
  1729. 1675   3                          // V scale-down            
  1730. 1676   3                          Calculate_IVS2DVS_Delay(2,6,((unsigned int*)Data)[0]);   // V scale-down. Target 2.5~2.6 IHS delay
  1731. 1677   3                      }
  1732. 1678   2              else
  1733. 1679   2              {
  1734. 1680   3      
  1735. 1681   3                  Calculate_IVS2DVS_Delay(1,9,((unsigned int*)Data)[0]);                  // V no scale-up. Targ
  1736.              -et 1.9 IHS delay
  1737. 1682   3              }
  1738. 1683   2      
  1739. 1684   2      #endif
  1740. 1685   2          }
  1741. 1686   1      
  1742. 1687   1      #if (FULL_LINE_BUFFER)
  1743.                   // Turn on full-line buffer when no V scale-up
  1744.                   RTDSetBit(OP_CRC_CTRL_68, 0xfc, (ucOption & 0x01) ? 0x00 : 0x02);
  1745.               #else
  1746. 1691   1          RTDSetBit(OP_CRC_CTRL_68, 0xfc, 0x00);
  1747. 1692   1      #endif
  1748. 1693   1      
  1749. 1694   1          // Set ucDV_Delay
  1750. 1695   1          RTDSetByte(IV_DV_LINES_38, ucDV_Delay);
  1751. 1696   1      
  1752. 1697   1              RTDSetByte(STATUS0_01, 0x00);  // Clear status
  1753. 1698   1          RTDSetByte(STATUS1_1F, 0x00);  // Clear status
  1754. 1699   1      
  1755. 1700   1          // Switch to FrameSync 1 mode and enable display
  1756. 1701   1      //    if (PANEL_OFF == bPANEL_PWR)
  1757. 1702   1      //        RTDSetByte(VDIS_CTRL_20, 0x29 | DISP_BIT | DISPLAY_PORT);
  1758. 1703   1      //    else
  1759. 1704   1      //        RTDSetByte(VDIS_CTRL_20, 0x2b | DISP_BIT | DISPLAY_PORT);
  1760. 1705   1      
  1761. 1706   1          // Input Run Enable
  1762. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 29  
  1763. 1707   1          RTDSetBit(VGIP_CTRL_04, 0xff, 0x01);
  1764. 1708   1      
  1765. 1709   1      }
  1766. 1710          
  1767. 1711          void Display_VGA_Set(void)
  1768. 1712          {
  1769. 1713   1          unsigned char   Wait_Time_Cnt;
  1770. 1714   1      //      unsigned char   ucI_Corr0,ucI_Corr1;
  1771. 1715   1      
  1772. 1716   1      
  1773. 1717   1          Initial_Mode();
  1774. 1718   1              Sharpness();
  1775. 1719   1      
  1776. 1720   1          if((usIPH_ACT_WID == 1280) && (DISP_SIZE == DISP_1280x1024) && (stGUD1.FILTER == 0x02))
  1777. 1721   1               RTDSetBit(SCALE_CTRL_15, 0xff, 0x01);   // Turn on H scale-up
  1778. 1722   1          
  1779. 1723   1      
  1780. 1724   1          PowerDown_ADC();
  1781. 1725   1          //Device_Power(ADC_POWER,OFF);
  1782. 1726   1      
  1783. 1727   1          // Set user's ADC gain and offset settings
  1784. 1728   1          SetADC_GainOffset();
  1785. 1729   1      
  1786. 1730   1          Set_Gamma();
  1787. 1731   1          Set_Dithering();
  1788. 1732   1          Set_Bright_Contrast();
  1789. 1733   1      //    Sharpness();
  1790. 1734   1      
  1791. 1735   1          Load_MUD(ucMode_Curr);      // Read mode default settings from 24C04
  1792. 1736   1      
  1793. 1737   1          // For jitter adjust
  1794. 1738   1          ucPE_Level      = 0;
  1795. 1739   1      //    ucPE_Count      = 0;
  1796. 1740   1      
  1797. 1741   1          // Check Clock
  1798. 1742   1          if (28 > stMUD.CLOCK || 228 < stMUD.CLOCK)      stMUD.CLOCK = 128;
  1799. 1743   1      
  1800. 1744   1          
  1801. 1745   1          // Update Clock Twice
  1802. 1746   1          Set_Clock();
  1803. 1747   1      // Calculate the P correction and I correction according to the CE value
  1804. 1748   1          Delay_Xms(6);
  1805. 1749   1              
  1806. 1750   1          if(ucCE_Value ==  0)
  1807. 1751   1          {
  1808. 1752   2             RTDRead(I_CODE_MB_CA,1,N_INC);
  1809. 1753   2                 RTDSetByte(I_CODE_MB_CA, 0x0d);
  1810. 1754   2                 Delay_Xms(4);
  1811. 1755   2                 RTDRead(PLL_CALIBRATION_CE,1,N_INC);
  1812. 1756   2                 ucP_Corr = (unsigned char)((unsigned int)(Data[0] * 200) >> (29 - P_Code));
  1813. 1757   2                 ucCE_Value = Data[0];  //CE value  
  1814. 1758   2      
  1815. 1759   2              }
  1816. 1760   1      
  1817. 1761   1              if(ucI_Code == 0)
  1818. 1762   1                 Adjust_I_Code();
  1819. 1763   1          
  1820. 1764   1              
  1821. 1765   1          Set_Clock();
  1822. 1766   1      
  1823. 1767   1      
  1824. 1768   1          // Check Phase
  1825. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 30  
  1826. 1769   1      //    stMUD.PHASE &= 0x7c;    // Phase 0~31
  1827. 1770   1      
  1828. 1771   1          // Update Phase
  1829. 1772   1      //    Set_Phase(stMUD.PHASE);
  1830. 1773   1      
  1831. 1774   1          ucH_Max_Margin  = 128 + 50;
  1832. 1775   1          ucH_Min_Margin  = 128 - 50;
  1833. 1776   1              
  1834. 1777   1              //Read the usIPH_ACT_STA offset
  1835. 1778   1          I2CRead(ADDR_EROM1,(ucMode_Curr - 1),0x01);
  1836. 1779   1              if(Data[0] > 228)
  1837. 1780   1                 Data[0] = 0;
  1838. 1781   1      
  1839. 1782   1          usIPH_ACT_STA   = (Data[0] & 0x80) ? usIPH_ACT_STA - 50 - (Data[0] - 0x80) : usIPH_ACT_STA + Data[0] -
  1840.              - 50;
  1841. 1783   1              
  1842. 1784   1          Data[0] = 5;
  1843. 1785   1          Data[1] = Y_INC;
  1844. 1786   1          Data[2] = IPH_ACT_STA_06;
  1845. 1787   1          Data[3] = (unsigned char)usIPH_ACT_STA;
  1846. 1788   1          Data[4] = (unsigned char)(usIPH_ACT_STA >> 8);
  1847. 1789   1          Data[5] = 0;    
  1848. 1790   1          RTDWrite(Data);
  1849. 1791   1      
  1850. 1792   1          // Check H-Position
  1851. 1793   1          if (ucH_Max_Margin < stMUD.H_POSITION)
  1852. 1794   1              stMUD.H_POSITION    = ucH_Max_Margin;
  1853. 1795   1          else if (ucH_Min_Margin > stMUD.H_POSITION)
  1854. 1796   1              stMUD.H_POSITION    = ucH_Min_Margin;
  1855. 1797   1      
  1856. 1798   1          // Update H-Position
  1857. 1799   1          Set_H_Position();
  1858. 1800   1      
  1859. 1801   1             // Check Phase
  1860. 1802   1          stMUD.PHASE &= 0x7c;    // Phase 0~31
  1861. 1803   1      
  1862. 1804   1          // Update Phase
  1863. 1805   1          Set_Phase(stMUD.PHASE);
  1864. 1806   1      
  1865. 1807   1          // Start auto-tracking function once
  1866. 1808   1          RTDSetByte(AUTO_ADJ_CTRL_7F, 0x01);
  1867. 1809   1          Delay_Xms(40);
  1868. 1810   1      
  1869. 1811   1          // Force to stop auto-tracking function
  1870. 1812   1          RTDSetByte(AUTO_ADJ_CTRL_7F, 0x00);
  1871. 1813   1          Delay_Xms(40);
  1872. 1814   1      
  1873. 1815   1          // Measure actual number of scan line in each frame
  1874. 1816   1          Data[0]     = 14;
  1875. 1817   1          Data[1]     = Y_INC;
  1876. 1818   1          Data[2]     = H_BND_STA_L_75;
  1877. 1819   1          Data[3]     = 0x00;
  1878. 1820   1          Data[4]     = 0xff;
  1879. 1821   1          Data[5]     = 0x07;
  1880. 1822   1          Data[6]     = 0x00;
  1881. 1823   1          Data[7]     = 0x00;
  1882. 1824   1          Data[8]     = 0x00;
  1883. 1825   1          Data[9]     = 0x00;
  1884. 1826   1          Data[10]    = 0x00;
  1885. 1827   1          Data[11]    = 0x00;
  1886. 1828   1          Data[12]    = 0x00;
  1887. 1829   1          Data[13]    = 0x01;
  1888. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 31  
  1889. 1830   1          Data[14]    = 0;
  1890. 1831   1          RTDWrite(Data);
  1891. 1832   1      
  1892. 1833   1          Wait_Time_Cnt  = 60;    // Tracking timeout 60ms        
  1893. 1834   1          do
  1894. 1835   1          {   
  1895. 1836   2              Delay_Xms(1);
  1896. 1837   2              RTDRead(AUTO_ADJ_CTRL_7F, 0x01, N_INC);
  1897. 1838   2          }
  1898. 1839   1          while ((Data[0] & 0x01) && (--Wait_Time_Cnt));
  1899. 1840   1      
  1900. 1841   1          RTDSetByte(AUTO_ADJ_CTRL_7F, 0x00);
  1901. 1842   1          
  1902. 1843   1          if (Wait_Time_Cnt)
  1903. 1844   1          {
  1904. 1845   2              RTDRead(VER_START_80, 0x04, Y_INC);
  1905. 1846   2              Data[0] = Data[3] & 0x0f;
  1906. 1847   2              Data[1] = Data[2];
  1907. 1848   2      
  1908. 1849   2              usVer_End   = (usVsync < ((unsigned int *)Data)[0]) ? ((unsigned int *)Data)[0] : usVsync;
  1909. 1850   2          }
  1910. 1851   1          else
  1911. 1852   1          {
  1912. 1853   2              usVer_End   = usVsync;
  1913. 1854   2          }
  1914. 1855   1      
  1915. 1856   1          // Update to reasonable usIPV_ACT_STA for user mode
  1916. 1857   1          if (MODE_USER720x400 <= ucMode_Curr)
  1917. 1858   1          {
  1918. 1859   2              ((unsigned int *)Data)[0]   = usVer_End - VGA_Mode[ucMode_Curr][2];
  1919. 1860   2      
  1920. 1861   2              if (254 < ((unsigned int *)Data)[0] + ucDV_Delay)   ((unsigned int *)Data)[0]   = 254 - ucDV_Delay
  1921.              -;
  1922. 1862   2      
  1923. 1863   2              usIPV_ACT_STA   += ((unsigned int *)Data)[0];
  1924. 1864   2              ucDV_Delay      += ((unsigned int *)Data)[0];
  1925. 1865   2          }
  1926. 1866   1      
  1927. 1867   1          // Set the ucV_Min_Margin/ucV_Max_Margin
  1928. 1868   1          ucV_Min_Margin  = (128 < usIPV_ACT_STA) ? 0 : 128 - usIPV_ACT_STA + 1;
  1929. 1869   1      
  1930. 1870   1          if ((128 - 50) > ucV_Min_Margin)    ucV_Min_Margin  = 128 - 50;
  1931. 1871   1      
  1932. 1872   1          ((unsigned int *)Data)[0]   = (usVer_End + 128 - 2) - (usIPV_ACT_STA + usIPV_ACT_LEN);
  1933. 1873   1      
  1934. 1874   1          ucV_Max_Margin  = (((unsigned int *)Data)[0] > 0x00ff) ? 0xff : ((unsigned int *)Data)[0];
  1935. 1875   1      
  1936. 1876   1          // Check ucV_Min_Margin/ucV_Max_Margin :
  1937. 1877   1          // ucDV_Delay can only range from 0 to 254
  1938. 1878   1          // Original Formula :
  1939. 1879   1          // 128 - ucV_Min_Margin >= ucDV_Delay
  1940. 1880   1          // ucV_Max_Margin - 128 >= 254 - ucDV_Delay
  1941. 1881   1      
  1942. 1882   1          if ((unsigned int)128 > ((unsigned int)ucV_Min_Margin + ucDV_Delay))    ucV_Min_Margin  = 128 - ucDV_D
  1943.              -elay;
  1944. 1883   1          if ((unsigned int)382 < ((unsigned int)ucV_Max_Margin + ucDV_Delay))    ucV_Max_Margin  = 382 - ucDV_D
  1945.              -elay;
  1946. 1884   1      
  1947. 1885   1          if ((128 + 50) < ucV_Max_Margin)    ucV_Max_Margin  = 128 + 50;
  1948. 1886   1      
  1949. 1887   1          // Check V-Position
  1950. 1888   1          if (ucV_Min_Margin > stMUD.V_POSITION)
  1951. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 32  
  1952. 1889   1              stMUD.V_POSITION    = ucV_Min_Margin;
  1953. 1890   1          else if ((unsigned int)256 - ucV_Min_Margin < stMUD.V_POSITION)
  1954. 1891   1              stMUD.V_POSITION    = (unsigned int)256 - ucV_Min_Margin;
  1955. 1892   1      
  1956. 1893   1          // Update V-Position
  1957. 1894   1          Set_V_Position();
  1958. 1895   1      
  1959. 1896   1          // Re-calculate actual refresh rate
  1960. 1897   1          ((unsigned long *)Data)[0]  = (unsigned long)usHsync * usVer_End;
  1961. 1898   1          ucRefresh   = (unsigned long)49152000 / ((unsigned long *)Data)[0];
  1962. 1899   1          ucRefresh   = (ucRefresh & 0x01) ? ((ucRefresh + 1) >> 1) : (ucRefresh >> 1);
  1963. 1900   1          
  1964. 1901   1              if(ucRefresh > V_OVERSPEC_FREQ)
  1965. 1902   1                  bOverSpec = _TRUE;
  1966. 1903   1      
  1967. 1904   1              if((unsigned int)24576/usHsync > H_OVERSPEC_FREQ)
  1968. 1905   1                  bOverSpec = _TRUE;
  1969. 1906   1      
  1970. 1907   1          Data[0] = Frame_Sync();
  1971. 1908   1      
  1972. 1909   1          if (1 == Data[0])
  1973. 1910   1          {
  1974. 1911   2             Delay_Xms(10);
  1975. 1912   2             Data[0] = Frame_Sync();     // Fail. Try again             
  1976. 1913   2          }
  1977. 1914   1      
  1978. 1915   1          bFrameSync      = Data[0] ? 0 : 1;              // 0 : fail, 1 : pass
  1979. 1916   1          ucSyncErrorCnt  = 0;
  1980. 1917   1      
  1981. 1918   1          RTDSetBit(OVL_CTRL_6D,0x3f,0x00);
  1982. 1919   1          RTDSetByte(BGCOLOR_CONTROL_6C,0x00);
  1983. 1920   1              RTDSetBit(OVL_CTRL_6D,0x3f,0x40);
  1984. 1921   1          RTDSetByte(BGCOLOR_CONTROL_6C,0x00);
  1985. 1922   1              RTDSetBit(OVL_CTRL_6D,0x3f,0x80);
  1986. 1923   1          RTDSetByte(BGCOLOR_CONTROL_6C,0x00);
  1987. 1924   1      
  1988. 1925   1      //    RTDSetBit(VDIS_CTRL_20, 0x5f, DHS_MASK);        // Normal display
  1989. 1926   1            RTDSetBit(VDIS_CTRL_20, 0x7f, 0x20 | DHS_MASK);        // Normal display
  1990. 1927   1      
  1991. 1928   1      #if(AS_PLL_NONLOCK)
  1992. 1929   1         if(bFrameSync)
  1993. 1930   1              RTDSetBit(ODD_CTRL_8E,0xdf,0x20);
  1994. 1931   1      #endif
  1995. 1932   1      
  1996. 1933   1          //anson 05_0314
  1997. 1934   1          ucfrist = (ucMode_Curr - 1 ) / 8 ;
  1998. 1935   1          I2CRead(ADDR_EROM1, ucfrist , 1);
  1999. 1936   1          ucfrist = ucMode_Curr - (ucfrist*8) ;
  2000. 1937   1          ucfrist  = Data[0] >> (ucfrist-1) ;
  2001. 1938   1          ucfrist  = ucfrist & 0x01;
  2002. 1939   1          stGUD1.OSD_INPUT = stGUD1.OSD_INPUT | 0x20; //First Time Into This Mode
  2003. 1940   1      
  2004. 1941   1      
  2005. 1942   1      }
  2006. 1943          
  2007. 1944          void Display_DVI_Set(void)
  2008. 1945          {
  2009. 1946   1      #if(TMDS_ENABLE)
  2010. 1947   1          unsigned char   Wait_Time_Cnt;
  2011. 1948   1      
  2012. 1949   1          Initial_Mode();
  2013. 1950   1      
  2014. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 33  
  2015. 1951   1          // Set the ucV_Min_Margin/ucV_Max_Margin
  2016. 1952   1          ucV_Min_Margin  = (128 < usIPV_ACT_STA) ? 0 : 128 - usIPV_ACT_STA + 1;
  2017. 1953   1      
  2018. 1954   1          // Use Data[8],Data[9] as a temporary 16-bit variable.
  2019. 1955   1          ((unsigned int *)Data)[4]   = (usVsync + 128 - 2) - (usIPV_ACT_STA + usIPV_ACT_LEN);
  2020. 1956   1      
  2021. 1957   1          ucV_Max_Margin  = (0x00ff <  ((unsigned int *)Data)[4]) ? 0xff :  ((unsigned int *)Data)[4];
  2022. 1958   1      
  2023. 1959   1          // Check ucV_Min_Margin/ucV_Max_Margin :
  2024. 1960   1          // ucDV_Delay can only range from 0 to 254
  2025. 1961   1          // Original Formula :
  2026. 1962   1          // 128 - ucV_Min_Margin <= ucDV_Delay
  2027. 1963   1          // ucV_Max_Margin - 128 <= 254 - ucDV_Delay
  2028. 1964   1      
  2029. 1965   1          if ((unsigned int)128 > ((unsigned int)ucV_Min_Margin + ucDV_Delay))    ucV_Min_Margin  = 128 - ucDV_D
  2030.              -elay;
  2031. 1966   1          if ((unsigned int)382 < ((unsigned int)ucV_Max_Margin + ucDV_Delay))    ucV_Max_Margin  = 382 - ucDV_D
  2032.              -elay;
  2033. 1967   1      
  2034. 1968   1          // Read mode default settings from 24C04
  2035. 1969   1          Load_MUD(ucMode_Curr);
  2036. 1970   1      
  2037. 1971   1          Set_Gamma();
  2038. 1972   1          Set_Dithering();
  2039. 1973   1          Set_Bright_Contrast();
  2040. 1974   1          Sharpness();
  2041. 1975   1      
  2042. 1976   1          // Issac :
  2043. 1977   1          // RTD controller can support both digital mode and analog mode to capture input image data.
  2044. 1978   1          // In digital mode, input image data is captured according to input data enable (IDEN) signal;
  2045. 1979   1          // In analog mode, input image data is captured according to capture window settings;
  2046. 1980   1          // Although can support both of them, I always use analog mode to capture input image in this F/W.
  2047. 1981   1          // Because RTD controller can measure the position and size of IDEN signal, we can just set our
  2048. 1982   1          // capture window to be the same size and position as IDEN.
  2049. 1983   1      
  2050. 1984   1          Data[0]     = 14;
  2051. 1985   1          Data[1]     = Y_INC;
  2052. 1986   1          Data[2]     = H_BND_STA_L_75;
  2053. 1987   1          Data[3]     = 0x02;
  2054. 1988   1          Data[4]     = usADC_Clock - 2;
  2055. 1989   1          Data[5]     = (usADC_Clock - 2) >> 8;
  2056. 1990   1          Data[6]     = 0x02;
  2057. 1991   1          Data[7]     = usVsync - 2;
  2058. 1992   1          Data[8]     = (usVsync - 2) >> 8;
  2059. 1993   1          Data[9]     = 0;
  2060. 1994   1          Data[10]    = 0;
  2061. 1995   1          Data[11]    = 0;
  2062. 1996   1          Data[12]    = 0;
  2063. 1997   1          Data[13]    = 0x81;     // Measure IDEN position
  2064. 1998   1          Data[14]    = 0;
  2065. 1999   1      
  2066. 2000   1      
  2067. 2001   1          RTDWrite(Data);
  2068. 2002   1      
  2069. 2003   1          Wait_Time_Cnt  = 60;    // Tracking timeout 60ms        
  2070. 2004   1          do
  2071. 2005   1          {   
  2072. 2006   2              Delay_Xms(1);
  2073. 2007   2              RTDRead(AUTO_ADJ_CTRL_7F, 0x01, N_INC);
  2074. 2008   2          }
  2075. 2009   1          while ((Data[0] & 0x01) && (--Wait_Time_Cnt));
  2076. 2010   1          
  2077. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 34  
  2078. 2011   1          if (0 == Wait_Time_Cnt)
  2079. 2012   1          {
  2080. 2013   2              RTDSetByte(AUTO_ADJ_CTRL_7F, 0x00);
  2081. 2014   2              Reset_Mode();
  2082. 2015   2          }
  2083. 2016   1          else
  2084. 2017   1          {
  2085. 2018   2              // Read IDEN position information
  2086. 2019   2              RTDRead(VER_START_80, 0x08, Y_INC);
  2087. 2020   2              
  2088. 2021   2              // IDEN horizontal Start
  2089. 2022   2              usIPH_ACT_STA   = (unsigned int)Data[4] + ((unsigned int)Data[5] << 8) - 2;
  2090. 2023   2      
  2091. 2024   2              // IDEN vertical Start
  2092. 2025   2              ((unsigned int *)Data)[0]   = (unsigned int)Data[0] + ((unsigned int)Data[1] << 8) - 1;
  2093. 2026   2      
  2094. 2027   2              if (((unsigned int *)Data)[0] > (usIPV_ACT_STA + ucV_Max_Margin - 0x80))
  2095. 2028   2              {
  2096. 2029   3                  ((unsigned int *)Data)[1]   = (usVsync + 128 - 2) - (usIPV_ACT_STA + usIPV_ACT_LEN);    // Act
  2097.              -ual V max. Margin
  2098. 2030   3      
  2099. 2031   3                  ucDV_Delay      = (unsigned char)((unsigned int)ucDV_Delay + ucV_Max_Margin - 0x80);
  2100. 2032   3                  usIPV_ACT_STA   = usIPV_ACT_STA + ucV_Max_Margin - 0x80;
  2101. 2033   3      
  2102. 2034   3                  if (ucV_Max_Margin < ((unsigned int *)Data)[1])
  2103. 2035   3                  {
  2104. 2036   4                      // We have to increase IVS delay to fix ucV_Max_Margin
  2105. 2037   4                      if ((((unsigned int *)Data)[1] - ucV_Max_Margin) >= (((unsigned int *)Data)[0] - usIPV_ACT
  2106.              -_STA))
  2107. 2038   4                          ((unsigned int *)Data)[1]   = ((unsigned int *)Data)[0] - usIPV_ACT_STA + PROGRAM_VDEL
  2108.              -AY;
  2109. 2039   4                      else
  2110. 2040   4                          ((unsigned int *)Data)[1]   = usIPV_ACT_STA + ((unsigned int *)Data)[1] - ucV_Max_Marg
  2111.              -in + PROGRAM_VDELAY;
  2112. 2041   4      
  2113. 2042   4                      if (126 < ((unsigned int *)Data)[1])    ((unsigned int *)Data)[1]  = 126;
  2114. 2043   4      
  2115. 2044   4                      RTDSetByte(IVS_DELAY_8C, 0x80 | ((unsigned int *)Data)[1]);
  2116. 2045   4                  }
  2117. 2046   3              }
  2118. 2047   2              else if (((unsigned int *)Data)[0] < (usIPV_ACT_STA + ucV_Min_Margin - 0x80))
  2119. 2048   2              {
  2120. 2049   3                  ucDV_Delay      = (unsigned char)((unsigned int)ucDV_Delay + ucV_Min_Margin - 0x80);
  2121. 2050   3                  usIPV_ACT_STA   = usIPV_ACT_STA + ucV_Min_Margin - 0x80;
  2122. 2051   3      
  2123. 2052   3                  ((unsigned int *)Data)[1]   = usIPV_ACT_STA - ((unsigned int *)Data)[0];
  2124. 2053   3      
  2125. 2054   3                  // We have to decrease IVS delay to fix ucV_Min_Margin
  2126. 2055   3                  if (PROGRAM_VDELAY <= ((unsigned int *)Data)[1])
  2127. 2056   3                      RTDSetByte(IVS_DELAY_8C, 0x00);
  2128. 2057   3                  else
  2129. 2058   3                      RTDSetByte(IVS_DELAY_8C, 0x80 | (PROGRAM_VDELAY - ((unsigned int *)Data)[1]));
  2130. 2059   3              }
  2131. 2060   2              else
  2132. 2061   2              {
  2133. 2062   3                  ucDV_Delay      = ((unsigned int *)Data)[0] + ucDV_Delay - usIPV_ACT_STA ;
  2134. 2063   3                  usIPV_ACT_STA   = ((unsigned int *)Data)[0];
  2135. 2064   3              }
  2136. 2065   2      
  2137. 2066   2                      RTDRead(TMDS_CORRECTION_FF,0x01,N_INC);
  2138. 2067   2      
  2139. 2068   2                      if(Data[0] & 0x03)
  2140. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 35  
  2141. 2069   2                          usIPH_ACT_STA -= 14;//if TMDS error correction enable, then compensate the IPH_ACT_STA offset.
  2142. 2070   2      
  2143. 2071   2              Data[0]     = 5;
  2144. 2072   2              Data[1]     = Y_INC;
  2145. 2073   2              Data[2]     = IPH_ACT_STA_06;
  2146. 2074   2              Data[3]     = (unsigned char)(usIPH_ACT_STA & 0x00ff);
  2147. 2075   2              Data[4]     = (unsigned char)((usIPH_ACT_STA >> 8) & 0x00ff);
  2148. 2076   2              Data[5]     = 5;
  2149. 2077   2              Data[6]     = Y_INC;
  2150. 2078   2              Data[7]     = IPV_ACT_STA_0A;
  2151. 2079   2              Data[8]     = (unsigned char)(usIPV_ACT_STA & 0x00ff);
  2152. 2080   2              Data[9]     = (unsigned char)((usIPV_ACT_STA >> 8) & 0x00ff);
  2153. 2081   2              Data[10]    = 4;
  2154. 2082   2              Data[11]    = N_INC;
  2155. 2083   2              Data[12]    = IV_DV_LINES_38;
  2156. 2084   2              Data[13]    = ucDV_Delay;
  2157. 2085   2              Data[14]    = 0;
  2158. 2086   2              RTDWrite(Data);
  2159. 2087   2      
  2160. 2088   2              Wait_For_Event(EVENT_DVS);
  2161. 2089   2      
  2162. 2090   2              Data[0] = Frame_Sync();
  2163. 2091   2              
  2164. 2092   2              if (1 == Data[0])   Data[0] = Frame_Sync();     // Fail. Try again
  2165. 2093   2      
  2166. 2094   2              bFrameSync      = Data[0] ? 0 : 1;              // 0 : fail, 1 : pass
  2167. 2095   2              ucSyncErrorCnt  = 0;
  2168. 2096   2      
  2169. 2097   2              //RTDSetBit(VDIS_CTRL_20, 0x5f, DHS_MASK);        // Normal display
  2170. 2098   2                      RTDSetBit(VDIS_CTRL_20, 0x7f, 0x20 | DHS_MASK);        // Normal display
  2171. 2099   2          }
  2172. 2100   1      #else
  2173.                   Seek_DVI_Mode(0);
  2174.               #endif
  2175. 2103   1      }
  2176. 2104          
  2177. 2105          void Set_Video_Mode(void)
  2178. 2106          {
  2179. 2107   1      #if(VIDEO_CHIP != VDC_NONE)
  2180.               
  2181.               #if (VIDEO_CHIP == VDC_SAA7114 || VIDEO_CHIP == VDC_SAA7115 || VIDEO_CHIP == VDC_SAA7118)
  2182.                   I2CWrite(V_DISABLE);
  2183.                   I2CWrite(VIDEO_ALL);
  2184.                   I2CWrite((ucAV_Mode & 0x02) ? VIDEO_50 : VIDEO_60);
  2185.               #endif
  2186.               
  2187.                   RTDCodeW((ucAV_Mode & 0x02) ? RTD_VIDEO_50 : RTD_VIDEO_60);
  2188.               
  2189.               //    if (PANEL_OFF == MCU_ReadPanelPower())
  2190.                   if (OFF == bPanel_Status)
  2191.                   {
  2192.               
  2193.                       RTDSetByte(VDIS_SIGINV_21, 0x00 | DISP_EO_SWAP | DISP_RB_SWAP | DISP_ML_SWAP);       // DHS, DVS, 
  2194.              -DEN, DCLK MUST NOT be inverted.
  2195.               
  2196.                       RTDSetBit(VDIS_CTRL_20, 0xfd, 0x01);    // DHS, DVS, DEN, DCLK and data are clamped to 0
  2197.                   }
  2198.               
  2199.               
  2200.               #if (VIDEO_CHIP == VDC_SAA7118)
  2201.                   if (SOURCE_YUV == (stGUD1.INPUT_SOURCE & 0x07))
  2202.                   {
  2203. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 36  
  2204.                       I2CWrite(VIDEO_YUV);
  2205.                   }
  2206.                   else
  2207.               #endif
  2208.                   {
  2209.                       Data[0] = (SOURCE_SV == (stGUD1.INPUT_SOURCE & 0x07)) ? 0 : 1;
  2210.               
  2211.                       switch (ucAV_Mode)
  2212.                       {
  2213.                       case 0x01:          //(60Hz) NTSC-M, JAPAN(7111A)
  2214.                       case 0x81:          //(60Hz) Default
  2215.                           I2CWrite(Data[0] ? AV_60_0 : SV_60_0);
  2216.                           break;
  2217.                       case 0x11:          //(60Hz) PAL-4.43
  2218.                           I2CWrite(Data[0] ? AV_60_1 : SV_60_1);
  2219.                           break;
  2220.                       case 0x21:          //(60Hz) NTSC-4.43
  2221.                           I2CWrite(Data[0] ? AV_60_2 : SV_60_2);
  2222.                           break;
  2223.                       case 0x31:          //(60Hz) PAL-M
  2224.                           I2CWrite(Data[0] ? AV_60_3 : SV_60_3);
  2225.                           break;
  2226.                       case 0x41:          //(60Hz) NTSC-JAPAN(7114)
  2227.                           I2CWrite(Data[0] ? AV_60_4 : SV_60_4);
  2228.                           break;
  2229.                       case 0x02:          //(50Hz) PAL-BGHI
  2230.                       case 0x82:          //(50Hz) Default
  2231.                           I2CWrite(Data[0] ? AV_50_0 : SV_50_0);
  2232.                           RTDSetBit(VGIP_SIGINV_05,0xff,0x10);
  2233.                           break;
  2234.                       case 0x12:          //(50Hz) NTSC-4.43
  2235.                           I2CWrite(Data[0] ? AV_50_1 : SV_50_1);
  2236.                           break;
  2237.                       case 0x22:          //(50Hz) PAL-N
  2238.                           I2CWrite(Data[0] ? AV_50_2 : SV_50_2);
  2239.                           break;
  2240.                       case 0x32:          //(50Hz) NTSC-N
  2241.                           I2CWrite(Data[0] ? AV_50_3 : SV_50_3);
  2242.                           break;
  2243.                       case 0x42:          //Reserved
  2244.                           I2CWrite(Data[0] ? AV_50_4 : SV_50_4);
  2245.                           break;
  2246.                       case 0x03:          //(50Hz) SECAM
  2247.                           I2CWrite(Data[0] ? AV_SECAM : SV_SECAM);
  2248.                                       RTDSetBit(VGIP_SIGINV_05,0xff,0x10);
  2249.                           break;
  2250.                       default:    
  2251.                           break;
  2252.                       }
  2253.                   }
  2254.               #endif
  2255. 2181   1      }
  2256. 2182          
  2257. 2183          void Display_Video_Set(void)
  2258. 2184          {    
  2259. 2185   1      #if(VIDEO_CHIP != VDC_NONE)
  2260.                   unsigned char ucCounter;
  2261.               
  2262.                   Load_MUD(ucMode_Curr);      // Read mode default settings from 24C04
  2263.               
  2264.                   Set_Video_Mode();
  2265.               
  2266. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 37  
  2267.                   if (SOURCE_TV == (stGUD1.INPUT_SOURCE & 0x07))      I2CWrite(TV_SOURCE_SEL);
  2268.               
  2269.                   // Read H,V Standard Start Position and H Width
  2270.                   RTDRead(IPH_ACT_STA_06, 0x08, Y_INC);
  2271.                   usIPH_ACT_STA   = (unsigned int)Data[0] + ((unsigned int)Data[1] << 8);
  2272.                   usIPH_ACT_STA   = usIPH_ACT_STA & 0x07ff;
  2273.                   usIPH_ACT_WID   = (unsigned int)Data[2] + ((unsigned int)Data[3] << 8);
  2274.                   usIPH_ACT_WID   = usIPH_ACT_WID & 0x07ff;
  2275.                   usIPV_ACT_STA   = (unsigned int)Data[4] + ((unsigned int)Data[5] << 8);
  2276.                   usIPV_ACT_STA   = usIPV_ACT_STA & 0x07ff;
  2277.                   usIPV_ACT_LEN   = (unsigned int)Data[6] + ((unsigned int)Data[7] << 8);
  2278.                   usIPV_ACT_LEN   = usIPV_ACT_LEN & 0x07ff;
  2279.               
  2280.                   // Read ucDH_TOTAL
  2281.                   RTDRead(DH_TOTAL_22, 2, Y_INC);
  2282.                   usDH_Total  = ((unsigned int)(Data[1] & 0x07) << 8) + Data[0];
  2283.                   
  2284.                   // Read ucDV_Delay
  2285.                   RTDRead(IV_DV_LINES_38, 1, N_INC);
  2286.                   ucDV_Delay  = Data[0];
  2287.               
  2288.                   ucV_Max_Margin  = 0x80;
  2289.                   ucV_Min_Margin  = 0x80;
  2290.               
  2291.                   Set_Gamma();
  2292.                   Set_Dithering();
  2293.                   Set_Bright_Contrast();
  2294.                   Sharpness();
  2295.               
  2296.                   // Update VDC's Contrast/Brightness/Hue/Saturation
  2297.                   SetVDC_Color();
  2298.               
  2299.                   ucCounter   = 28;
  2300.                   do
  2301.                   {
  2302.                       RTDSetByte(SYNC_POR_4C, 0x00);  // Reset Sync Processor
  2303.               
  2304.                       Measure_Mode();
  2305.               
  2306.                       Delay_Xms(80);
  2307.               
  2308.                       RTDRead(SYNC_POR_4C, 0x05, Y_INC);
  2309.               
  2310.                       if (Data[0] & 0x02)
  2311.                       {
  2312.                           usHsync = 0;
  2313.                           usVsync = 0;
  2314.                       }
  2315.                       else
  2316.                       {
  2317.                           Data[5] = Data[3];
  2318.                           Data[4] = Data[4] & 0x87;
  2319.                           Data[3] = Data[1];
  2320.                           Data[2] = Data[2] & 0x8f;
  2321.               
  2322.                           usHsync = ((unsigned int *)Data)[1];    // Current usHsync timing
  2323.                           usVsync = ((unsigned int *)Data)[2];    // Current usVsync timing
  2324.               
  2325.                           if (0x07ff <= usHsync || 0x07ff <= usVsync || 0 == usHsync || 0 == usVsync)
  2326.                           {
  2327.                               usHsync = 0;
  2328.                               usVsync = 0;
  2329. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 38  
  2330.                           }
  2331.                           else
  2332.                           {
  2333.                               break;
  2334.                           }
  2335.                       }
  2336.                   }
  2337.                   while (--ucCounter);
  2338.               
  2339.                       RTDSetByte(STATUS0_01, 0x00);  // Clear status  
  2340.                   RTDSetByte(STATUS1_1F, 0x00);  // Clear status
  2341.                       
  2342.                       Data[0] = Frame_Sync();
  2343.               
  2344.                   if (1 == Data[0])   Data[0] = Frame_Sync();     // Fail. Try again
  2345.               
  2346.                   bFrameSync      = Data[0] ? 0 : 1;              // 0 : fail, 1 : pass
  2347.                       
  2348.               
  2349.                   ucSyncErrorCnt  = 0;
  2350.               
  2351.               //      RTDSetBit(VDIS_CTRL_20, 0x5f, DHS_MASK);        // Normal display
  2352.                   RTDSetBit(VDIS_CTRL_20, 0x7f, 0x20 | DHS_MASK);        // Normal display
  2353.               #else
  2354. 2278   1          Set_Video_Mode();
  2355. 2279   1      #endif
  2356. 2280   1      }
  2357. 2281          
  2358. 2282          void Input_Mode_Detector(void)
  2359. 2283          {
  2360. 2284   1       RTDRead(SYNC_POR_4C, 0x01, N_INC);
  2361. 2285   1                  
  2362. 2286   1                  if (0 == (Data[0] & 0x02))      ucModeCnt   = 0;
  2363. 2287   1      
  2364. 2288   1                  if (ucModeCnt)
  2365. 2289   1                  {                  
  2366. 2290   2                              ucModeCnt   -= 1;
  2367. 2291   2                  }
  2368. 2292   1                  else
  2369. 2293   1                  {
  2370. 2294   2                      ucModeCnt   = MODE_DETECT_FREQ;
  2371. 2295   2      
  2372. 2296   2      #if(SOURCE_AUTO_SCAN) 
  2373. 2297   2                      Source_Auto_Scan();
  2374. 2298   2      #else
  2375.                               Mode_Detector();
  2376.               #endif                          
  2377. 2301   2                                      
  2378. 2302   2                      if (!bStable)
  2379. 2303   2                      {
  2380. 2304   3                          bReload     = 1;            // Reload user's font
  2381. 2305   3      
  2382. 2306   3                          Set_Task(STATE_MODECHANGE); // Notify Task State Machine
  2383. 2307   3                      }
  2384. 2308   2                  }
  2385. 2309   1      }
  2386. 2310          
  2387. 2311          ///////////////////////////////////////////////////////////////////////////////////
  2388. 2312          //anson 05_0314
  2389. 2313          ///////////////////////////////////////////////////////////////////////////////////
  2390. 2314          void New_Mode_Auto(void)
  2391. 2315          {
  2392. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 39  
  2393. 2316   1      
  2394. 2317   1              if      (bStable && 
  2395. 2318   1                      bFrameSync && 
  2396. 2319   1                      ((stGUD1.OSD_INPUT & 0x20) == 0x20) && 
  2397. 2320   1                      (MODE_NOSIGNAL != ucMode_Curr) &&
  2398. 2321   1                      (MODE_NOSUPPORT != ucMode_Curr) && 
  2399. 2322   1                      ucfrist 
  2400. 2323   1                      )
  2401. 2324   1              {
  2402. 2325   2                      OSD_Position(OSD_ENABLE);
  2403. 2326   2                      OSD_Position(OSD_ENABLE);
  2404. 2327   2                      RTDSetBit(OVL_CTRL_6D, 0xfe, 0x00);
  2405. 2328   2                      RTDOSDW(OSD_Reset);
  2406. 2329   2                      RTDSetBit(OVL_CTRL_6D, 0xfe, 0x01);
  2407. 2330   2                      RTDOSDW(OSD_AUTO);
  2408. 2331   2                      RTDOSDW(strTabAuto_Atb[stGUD1.FUNCTION & 0x07]);                //anson
  2409. *** WARNING C214 IN LINE 2331 OF CODEMODE_DETECT.C: 'Argument': conversion: non-pointer to pointer
  2410. 2332   2                      Auto_Config();
  2411. 2333   2                      RTDSetBit(OVL_CTRL_6D, 0xfe, 0x00);
  2412. 2334   2                      RTDOSDW(OSD_Reset);
  2413. 2335   2      
  2414. 2336   2                      stGUD1.OSD_INPUT &= 0xdf;//Clear "First Time Into Mode" Bit
  2415. 2337   2                      Save_GUD1();
  2416. 2338   2                      ucfrist = (ucMode_Curr - 1 ) / 8 ;                
  2417. 2339   2                      I2CRead(ADDR_EROM1, ucfrist , 1);
  2418. 2340   2                      Data[1] = 0x01;
  2419. 2341   2                      Data[1] = Data[1] << (ucMode_Curr - 1 - (ucfrist*8)) ; 
  2420. 2342   2                      Data[3] = Data[0] & ~Data[1];
  2421. 2343   2                      
  2422. 2344   2                      Data[0] = 4;
  2423. 2345   2                      Data[1] = ADDR_EROM1;
  2424. 2346   2                      Data[2] = ucfrist;                                                                             
  2425. 2347   2                      I2CWrite(Data);
  2426. 2348   2                      Delay_Xms(SET_2404_DELAY);
  2427. 2349   2                      ucfrist = 0;
  2428. 2350   2              }
  2429. 2351   1      
  2430. 2352   1      }
  2431. 2353          
  2432. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 40  
  2433. ASSEMBLY LISTING OF GENERATED OBJECT CODE
  2434.              ; FUNCTION Com0188 (BEGIN)
  2435. 0000         L?0393:
  2436. 0000         L?0394:
  2437. 0000 7800        R     MOV     R0,#LOW ucMode_Curr
  2438. 0002 E6                MOV     A,@R0
  2439. 0003 75F00A            MOV     B,#0AH
  2440. 0006 A4                MUL     AB
  2441. 0007 2400        E     ADD     A,#LOW Mode_Preset+02H
  2442. 0009 F582              MOV     DPL,A
  2443. 000B E5F0              MOV     A,B
  2444. 000D 3400        E     ADDC    A,#HIGH Mode_Preset+02H
  2445. 000F         L?0395:
  2446. 000F F583              MOV     DPH,A
  2447. 0011         L?0396:
  2448. 0011 E4                CLR     A
  2449. 0012 93                MOVC    A,@A+DPTR
  2450. 0013 FE                MOV     R6,A
  2451. 0014 7401              MOV     A,#01H
  2452. 0016 93                MOVC    A,@A+DPTR
  2453. 0017 22                RET     
  2454. 0018         L?0397:
  2455. 0018         L?0398:
  2456. 0018 7800        R     MOV     R0,#LOW usHsync
  2457. 001A         L?0399:
  2458. 001A A905              MOV     R1,AR5
  2459. 001C AA06              MOV     R2,AR6
  2460. 001E AB07              MOV     R3,AR7
  2461. 0020         L?0400:
  2462. 0020 E6                MOV     A,@R0
  2463. 0021         L?0401:
  2464. 0021 FE                MOV     R6,A
  2465. 0022 08                INC     R0
  2466. 0023 E6                MOV     A,@R0
  2467. 0024 FF                MOV     R7,A
  2468. 0025 E4                CLR     A
  2469. 0026 FC                MOV     R4,A
  2470. 0027 FD                MOV     R5,A
  2471. 0028 22                RET     
  2472. 0029         L?0402:
  2473. 0029 75F00C            MOV     B,#0CH
  2474. 002C EE                MOV     A,R6
  2475. 002D A4                MUL     AB
  2476. 002E 2400        E     ADD     A,#LOW VGA_Mode+04H
  2477. 0030 F582              MOV     DPL,A
  2478. 0032 E5F0              MOV     A,B
  2479. 0034 3400        E     ADDC    A,#HIGH VGA_Mode+04H
  2480. 0036 F583              MOV     DPH,A
  2481. 0038 7800        R     MOV     R0,#LOW usVsync
  2482. 003A         L?0403:
  2483. 003A E6                MOV     A,@R0
  2484. 003B FC                MOV     R4,A
  2485. 003C 08                INC     R0
  2486. 003D D3                SETB    C
  2487. 003E         L?0404:
  2488. 003E E6                MOV     A,@R0
  2489. 003F FD                MOV     R5,A
  2490. 0040         L?0405:
  2491. 0040 7401              MOV     A,#01H
  2492. 0042 93                MOVC    A,@A+DPTR
  2493. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 41  
  2494. 0043 9D                SUBB    A,R5
  2495. 0044 E4                CLR     A
  2496. 0045 93                MOVC    A,@A+DPTR
  2497. 0046 9C                SUBB    A,R4
  2498. 0047 22                RET     
  2499. 0048         L?0406:
  2500. 0048 EF                MOV     A,R7
  2501. 0049 2B                ADD     A,R3
  2502. 004A FF                MOV     R7,A
  2503. 004B EE                MOV     A,R6
  2504. 004C 3A                ADDC    A,R2
  2505. 004D FE                MOV     R6,A
  2506. 004E ED                MOV     A,R5
  2507. 004F 39                ADDC    A,R1
  2508. 0050 FD                MOV     R5,A
  2509. 0051 EC                MOV     A,R4
  2510. 0052 38                ADDC    A,R0
  2511. 0053 FC                MOV     R4,A
  2512. 0054 7806              MOV     R0,#06H
  2513. 0056 120000      E     LCALL   ?C?LSHL
  2514. 0059         L?0407:
  2515. 0059 8F00        E     MOV     Data+0FH,R7
  2516. 005B 8E00        E     MOV     Data+0EH,R6
  2517. 005D 8D00        E     MOV     Data+0DH,R5
  2518. 005F 8C00        E     MOV     Data+0CH,R4
  2519. 0061 22                RET     
  2520. 0062         L?0408:
  2521. 0062 F9                MOV     R1,A
  2522. 0063 F8                MOV     R0,A
  2523. 0064         L?0409:
  2524. 0064 120000      E     LCALL   ?C?LMUL
  2525. 0067         L?0410:
  2526. 0067 A804              MOV     R0,AR4
  2527. 0069         L?0411:
  2528. 0069 A905              MOV     R1,AR5
  2529. 006B AA06              MOV     R2,AR6
  2530. 006D AB07              MOV     R3,AR7
  2531. 006F 22                RET     
  2532. 0070         L?0412:
  2533. 0070         L?0413:
  2534. 0070 E4                CLR     A
  2535. 0071 FC                MOV     R4,A
  2536. 0072 FD                MOV     R5,A
  2537. 0073         L?0414:
  2538. 0073 7B64              MOV     R3,#064H
  2539. 0075 FA                MOV     R2,A
  2540. 0076 F9                MOV     R1,A
  2541. 0077 F8                MOV     R0,A
  2542. 0078 020000      E     LJMP    ?C?LMUL
  2543. 007B         L?0415:
  2544. 007B         L?0416:
  2545. 007B 75F00A            MOV     B,#0AH
  2546. 007E E500        R     MOV     A,Wait_Time_Cnt
  2547. 0080         L?0417:
  2548. 0080 A4                MUL     AB
  2549. 0081 2400        E     ADD     A,#LOW Mode_Preset+04H
  2550. 0083 F582              MOV     DPL,A
  2551. 0085 E5F0              MOV     A,B
  2552. 0087 3400        E     ADDC    A,#HIGH Mode_Preset+04H
  2553. 0089 22                RET     
  2554. 008A         L?0418:
  2555. 008A 120000      E     LCALL   ?C?LMUL
  2556. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 42  
  2557. 008D 8F00        E     MOV     Data+03H,R7
  2558. 008F 8E00        E     MOV     Data+02H,R6
  2559. 0091 8D00        E     MOV     Data+01H,R5
  2560. 0093 8C00        E     MOV     Data,R4
  2561. 0095 AB00        E     MOV     R3,Data+03H
  2562. 0097 AA00        E     MOV     R2,Data+02H
  2563. 0099 A900        E     MOV     R1,Data+01H
  2564. 009B A800        E     MOV     R0,Data
  2565. 009D E4                CLR     A
  2566. 009E FF                MOV     R7,A
  2567. 009F FE                MOV     R6,A
  2568. 00A0 7DEE              MOV     R5,#0EEH
  2569. 00A2 7C02              MOV     R4,#02H
  2570. 00A4 120000      E     LCALL   ?C?ULDIV
  2571. 00A7 7800        R     MOV     R0,#LOW ucRefresh
  2572. 00A9 EF                MOV     A,R7
  2573. 00AA F6                MOV     @R0,A
  2574. 00AB 22                RET     
  2575. 00AC         L?0419:
  2576. 00AC E500        R     MOV     A,Wait_Time_Cnt
  2577. 00AE         L?0420:
  2578. 00AE 75F00A            MOV     B,#0AH
  2579. 00B1         L?0421:
  2580. 00B1 A4                MUL     AB
  2581. 00B2 2400        E     ADD     A,#LOW CAP_WIN+08H
  2582. 00B4 F582              MOV     DPL,A
  2583. 00B6 E5F0              MOV     A,B
  2584. 00B8 3400        E     ADDC    A,#HIGH CAP_WIN+08H
  2585. 00BA 22                RET     
  2586. 00BB         L?0422:
  2587. 00BB 7800        E     MOV     R0,#LOW usIPV_ACT_LEN
  2588. 00BD         L?0423:
  2589. 00BD E6                MOV     A,@R0
  2590. 00BE FE                MOV     R6,A
  2591. 00BF 08                INC     R0
  2592. 00C0 E6                MOV     A,@R0
  2593. 00C1         L?0424:
  2594. 00C1 FB                MOV     R3,A
  2595. 00C2 AA06              MOV     R2,AR6
  2596. 00C4 E4                CLR     A
  2597. 00C5 F9                MOV     R1,A
  2598. 00C6 F8                MOV     R0,A
  2599. 00C7 22                RET     
  2600. 00C8         L?0425:
  2601. 00C8         L?0426:
  2602. 00C8 7800        R     MOV     R0,#LOW usVsync+01H
  2603. 00CA E6                MOV     A,@R0
  2604. 00CB 24FF              ADD     A,#0FFH
  2605. 00CD FF                MOV     R7,A
  2606. 00CE 18                DEC     R0
  2607. 00CF E6                MOV     A,@R0
  2608. 00D0 34FF              ADDC    A,#0FFH
  2609. 00D2 22                RET     
  2610. 00D3         L?0427:
  2611. 00D3 120000      E     LCALL   ?C?ULDIV
  2612. 00D6 8E00        R     MOV     usDispLen,R6
  2613. 00D8 8F00        R     MOV     usDispLen+01H,R7
  2614. 00DA E500        R     MOV     A,usDispLen
  2615. 00DC C3                CLR     C
  2616. 00DD 13                RRC     A
  2617. 00DE FE                MOV     R6,A
  2618. 00DF E500        R     MOV     A,usDispLen+01H
  2619. C51 COMPILER V7.06   MODE_DETECT                                                           11/21/2005 13:47:38 PAGE 43  
  2620. 00E1 13                RRC     A
  2621. 00E2 FF                MOV     R7,A
  2622. 00E3 7C00              MOV     R4,#00H
  2623. 00E5 E500        R     MOV     A,usDispLen+01H
  2624. 00E7 5401              ANL     A,#01H
  2625. 00E9 2F                ADD     A,R7
  2626. 00EA F500        R     MOV     usDispLen+01H,A
  2627. 00EC EC                MOV     A,R4
  2628. 00ED 3E                ADDC    A,R6
  2629. 00EE F500        R     MOV     usDispLen,A
  2630. 00F0 22                RET     
  2631. 00F1         L?0428:
  2632. 00F1 850000      E     MOV     Data+07H,Data+05H
  2633. 00F4 53000F      E     ANL     Data+06H,#0FH
  2634. 00F7         L?0429:
  2635. 00F7 850000      E     MOV     Data+05H,Data+03H
  2636. 00FA 530087      E     ANL     Data+04H,#087H
  2637. 00FD 850000      E     MOV     Data+03H,Data+01H
  2638. 0100 53008F      E     ANL     Data+02H,#08FH
  2639. 0103 22                RET     
  2640. 0104         L?0430:
  2641. 0104 7800        E     MOV     R0,#LOW ucV_Max_Margin
  2642. 0106 A607              MOV     @R0,AR7
  2643. 0108 7800        E     MOV     R0,#LOW ucV_Min_Margin
  2644. 010A E6                MOV     A,@R0
  2645. 010B FF                MOV     R7,A
  2646. 010C 7800        E     MOV     R0,#LOW ucDV_Delay
  2647. 010E E6                MOV     A,@R0
  2648. 010F FD                MOV     R5,A
  2649. 0110 FB                MOV     R3,A
  2650. 0111 7A00              MOV     R2,#00H
  2651. 0113 2F                ADD     A,R7
  2652. 0114 FF                MOV     R7,A
  2653. 0115 E4                CLR     A
  2654. 0116 33                RLC     A
  2655. 0117 FE                MOV     R6,A
  2656. 0118 D3                SETB    C
  2657. 0119 7480              MOV     A,#080H
  2658. 011B 9F                SUBB    A,R7
  2659. 011C E4                CLR     A
  2660. 011D 9E                SUBB    A,R6
  2661. 011E 22                RET     
  2662. 011F         L?0432:
  2663. 011F         L?0433:
  2664. 011F F583              MOV     DPH,A
  2665. 0121 E4                CLR     A
  2666. 0122 93                MOVC    A,@A+DPTR
  2667. 0123 FC                MOV     R4,A
  2668. 0124 7401              MOV     A,#01H
  2669. 0126 93                MOVC    A,@A+DPTR
  2670. 0127 22                RET     
  2671. 0128         L?0434: