home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / videotlk.zip / SAMPLES / EX2 / TUNE.C < prev    next >
Text File  |  1998-09-14  |  26KB  |  680 lines

  1.  
  2. /*------------------------------------------------------------------*
  3.  *                                                                  *
  4.  *  Video Toolkit For OS/2 Version 1.0                              *
  5.  *  Example PM Application No. 2.                                   *
  6.  *  Written by Stephen Sloan.                                       *
  7.  *  Date : 22/02/95.                                                *
  8.  *  Copyright (c) Abbotsbury Software Ltd., United Kingdom. 1995.   *
  9.  *                                                                  *
  10.  *  Filename : tune.c                                               *
  11.  *                                                                  *
  12.  *------------------------------------------------------------------*/
  13.  
  14. #define     INCL_PM
  15. #define     INCL_DOS
  16. #define     INCL_OS2MM
  17. #define     INCL_SW
  18. #ifndef     DIM
  19. #define     DIM(a) (sizeof(a)/sizeof(a[0]))
  20. #endif
  21.  
  22. #include    <os2.h>
  23. #include    <os2me.h>
  24. #include    <stdio.h>
  25. #include    <stdlib.h>
  26. #include    <string.h>
  27. #include    <vcadd.h>
  28. #include    <vcai.h>
  29. #include    "ex2.h"
  30. #include    "region.h"
  31. #include    "tune.h"
  32.  
  33. extern  void    msg_box (UCHAR *txt, UCHAR *title, ULONG options);
  34. extern  LONG    get_colour (HPS hps);
  35.  
  36. extern  DRIVERHANDLE    DevHandle;
  37. extern  USHORT  DevInstance;
  38. extern  CHAR    DevType[20];
  39. extern  HAB     Hab;
  40. extern  HWND    HwndFrame;
  41. extern  LONG    ColourKey;
  42. extern  LONG    Colours[256];
  43. extern  LONG    NumColours;
  44.  
  45. static  CHAR    RegionFile[256];
  46. static  CHAR    RegionBase[256];
  47. static  CHAR    RegionNames[32][24];
  48. static  USHORT  NumRegions;
  49. static  CHAR    txt[256];
  50. static  CHAR    txt2[256];
  51. static  BOOL    SrcInit, RegionInit, VFInit;
  52.  
  53. MRESULT EXPENTRY TuneDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  54.  
  55. static  void    position_tv (HWND hwnd, USHORT tv);
  56. static  void    enable_tuner_options (HWND hwnd);
  57. static  void    disable_tuner_options (HWND hwnd);
  58. static  void    init_src_listbox (HWND hwnd);
  59. static  void    init_region_listbox (HWND hwnd);
  60. static  void    init_vf_listbox (HWND hwnd);
  61. static  USHORT  load_celeb_src_data (PSOURCE_DATA psrc);
  62. static  USHORT  load_celeb_vf_data (PVIDEO_FORMAT_DATA pvf);
  63. static  USHORT  load_highq_src_data (PSOURCE_DATA psrc);
  64. static  USHORT  load_highq_vf_data (PVIDEO_FORMAT_DATA pvf);
  65. static  USHORT  load_prism_src_data (PSOURCE_DATA psrc);
  66. static  USHORT  load_prism_vf_data (PVIDEO_FORMAT_DATA pvf);
  67. static  USHORT  load_encore_src_data (PSOURCE_DATA psrc);
  68. static  USHORT  load_encore_vf_data (PVIDEO_FORMAT_DATA pvf);
  69.  
  70. static  SOURCE_DATA     SrcData[MAX_SOURCES];
  71. static  USHORT          NumSrcs;
  72. static  VIDEO_FORMAT_DATA   VFData[MAX_VIDEO_FORMATS];
  73. static  USHORT              NumVFs;
  74.  
  75. static  UCHAR   *Copyright =
  76.   "Copyright (c) Abbotsbury Software Ltd., UK. 1994-1998. All Rights Reserved";
  77.  
  78.                         // functions.
  79. MRESULT EXPENTRY TuneDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  80. {
  81.     static  ULONG   freq, ch, no_freq, region, vi, ck;
  82.     static  LONG    fine;
  83.     ULONG   max_ch, id, ul;
  84.     APIRET  rc;
  85.     USHORT  notify_code, src, vf;
  86.     USHORT  lv, rv, lb, rb, lt, rt, mute;
  87.     HPS     hps;
  88.     RECTL   rcl, rcl_tv;
  89.     UINT    i, j;
  90.     USHORT  keytype;
  91.     SHORT   data;
  92.     HWND    hwnd_ef, hwnd_tv;
  93.     UCHAR   *s;
  94.     LONG    bx, by, dy, x, y;
  95.     POINTL  pts;
  96.     BOOL    valid;
  97.  
  98.         switch (msg)
  99.         {
  100.             case WM_INITDLG :
  101.                 if (stricmp (DevType, "celeb") == 0)
  102.                 {
  103.                     NumSrcs = load_celeb_src_data (&SrcData[0]);
  104.                     NumVFs  = load_celeb_vf_data (&VFData[0]);
  105.                 }
  106.                 if (stricmp (DevType, "highq") == 0)
  107.                 {
  108.                     NumSrcs = load_highq_src_data (&SrcData[0]);
  109.                     NumVFs  = load_highq_vf_data (&VFData[0]);
  110.                 }
  111.                 if (stricmp (DevType, "prism") == 0)
  112.                 {
  113.                     NumSrcs = load_prism_src_data (&SrcData[0]);
  114.                     NumVFs  = load_prism_vf_data (&VFData[0]);
  115.                 }
  116.                 if (stricmp (DevType, "encore") == 0)
  117.                 {
  118.                     NumSrcs = load_celeb_src_data (&SrcData[0]);
  119.                     NumVFs  = load_celeb_vf_data (&VFData[0]);
  120.                 }
  121.                 if (stricmp (DevType, "encor") == 0)
  122.                 {
  123.                     NumSrcs = load_celeb_src_data (&SrcData[0]);
  124.                     NumVFs  = load_celeb_vf_data (&VFData[0]);
  125.                 }
  126.                 vi = VcaiVideoInputQuery ();
  127.                 if (SrcData[vi].src_tuner_flag)
  128.                     enable_tuner_options (hwnd);
  129.                 else
  130.                     disable_tuner_options (hwnd);
  131.                 init_src_listbox (hwnd);
  132.                 init_region_listbox (hwnd);
  133.                 init_vf_listbox (hwnd);
  134.                 VcaiTunerGet (®ion, &ch, &freq, &fine);
  135.                 WinPostMsg (hwnd, MSG_CHANGE_TUNER, NULL, NULL);
  136.                 break;
  137.             case WM_PAINT :
  138.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  139.                 WinQueryWindowRect (hwnd, &rcl);
  140.                 WinFillRect (hps, &rcl, CLR_PALEGRAY);
  141.                 WinDrawBorder (hps, &rcl, x, y, 0L, 0L,
  142.                                DB_AREAATTRS | DB_DLGBORDER);
  143.                 WinEndPaint (hps);
  144.                 hps = WinBeginPaint (WinWindowFromID (hwnd, IDD_TUNE_TV),
  145.                                      NULLHANDLE, &rcl);
  146.                 WinQueryWindowRect (WinWindowFromID (hwnd, IDD_TUNE_TV),
  147.                                     &rcl);
  148.                 ColourKey = get_colour (hps);
  149.                 if ((ULONG)NumColours <= 256)
  150.                     WinFillRect (hps, &rcl, Colours[ColourKey]);
  151.                 else
  152.                     WinFillRect (hps, &rcl, ColourKey);
  153.                 WinEndPaint (hps);
  154.                 position_tv (hwnd, IDD_TUNE_TV);
  155.                 break;
  156.             case WM_MOVE :
  157.                 position_tv (hwnd, IDD_TUNE_TV);
  158.                 break;
  159.             case WM_COMMAND :
  160.                 switch (SHORT1FROMMP (mp1))
  161.                 {
  162.                     case DID_OK :
  163.                         WinPostMsg (HwndFrame, MSG_UPDATE_WINDOW, NULL, NULL);
  164.                         WinDismissDlg (hwnd, TRUE);
  165.                         break;
  166.                     default :
  167.                         break;
  168.                 }
  169.                 break;
  170.             case WM_CONTROL :
  171.                 notify_code = (USHORT)SHORT2FROMMP (mp1);
  172.                 switch (SHORT1FROMMP (mp1))
  173.                 {
  174.                     case IDD_TUNE_SRC :
  175.                         if ((notify_code != CBN_LBSELECT) &&
  176.                             (notify_code != CBN_EFCHANGE))
  177.                             return 0;
  178.                         if (SrcInit)
  179.                             return 0;
  180.                         WinQueryDlgItemText (hwnd, IDD_TUNE_SRC, 80L, txt2);
  181.                         if (strcmp ("", txt2) == 0)
  182.                             return 0;
  183.                         valid = FALSE;
  184.                         for (i = 0; i < NumSrcs; i++)
  185.                         {
  186.                             if (strcmp (SrcData[i].src_string, txt2) == 0)
  187.                             {
  188.                                 src = i;
  189.                                 valid = TRUE;
  190.                                 break;
  191.                             }
  192.                         }
  193.                         if (!valid)
  194.                             return 0;
  195.                         VcaiVideoInputSet (src);
  196.                         if (SrcData[src].src_tuner_flag)
  197.                             enable_tuner_options (hwnd);
  198.                         else
  199.                             disable_tuner_options (hwnd);
  200.                         return 0;
  201.                     case IDD_TUNE_REGION :
  202.                         if ((notify_code != CBN_LBSELECT) &&
  203.                             (notify_code != CBN_EFCHANGE))
  204.                             return 0;
  205.                         if (RegionInit)
  206.                             return 0;
  207.                         WinQueryDlgItemText (hwnd, IDD_TUNE_REGION, 80L, txt2);
  208.                         if (strcmp ("", txt2) == 0)
  209.                             return 0;
  210.                         valid = FALSE;
  211.                         VcaiTunerGet (®ion, &ch, &freq, &fine);
  212.                         for (i = 0; i < NumRegions; i++)
  213.                         {
  214.                             if (strcmp (&RegionNames[i][0], txt2) == 0)
  215.                             {
  216.                                 region = i;
  217.                                 valid = TRUE;
  218.                                 break;
  219.                             }
  220.                         }
  221.                         if (!valid)
  222.                             return 0;
  223.                         WinSendDlgItemMsg (hwnd, IDD_TUNE_REGION,
  224.                                            LM_QUERYITEMTEXT,
  225.                                            MPFROM2SHORT (region,
  226.                                                          sizeof (RegionFile)),
  227.                                            MPFROMP (RegionFile));
  228.                         strcpy (txt2, RegionBase);
  229.                         strcat (txt2, RegionFile);
  230.                         ch = 0;
  231.                         max_ch = get_region_data (txt2);
  232.                         for (i = 0; i < max_ch; i++)
  233.                         {
  234.                             if (freq == Region_frequencies[i])
  235.                                 ch = i;
  236.                         }
  237.                         if (ch == 0)
  238.                             ch = Region_lowchannel;
  239.                         freq = Region_frequencies[ch];
  240.                         VcaiTunerSet (region, ch, freq, fine, 0, 0);
  241.                         sprintf (txt, "%lu", freq);
  242.                         WinSetDlgItemText (hwnd, IDD_TUNE_FREQ, txt);
  243.                         WinSendMsg (WinWindowFromID (hwnd, IDD_TUNE_FINE),
  244.                                     SLM_SETSLIDERINFO,
  245.                                     MPFROM2SHORT (SMA_SLIDERARMPOSITION,
  246.                                     SMA_INCREMENTVALUE),
  247.                                     MPFROMSHORT (fine));
  248.                         sprintf (txt, "%lu", ch);
  249.                         WinSetDlgItemText (hwnd, IDD_TUNE_CH, txt);
  250.                         return 0;
  251.                     case IDD_TUNE_VF :
  252.                         if ((notify_code != CBN_LBSELECT) &&
  253.                             (notify_code != CBN_EFCHANGE))
  254.                             return 0;
  255.                         if (VFInit)
  256.                             return 0;
  257.                         WinQueryDlgItemText (hwnd, IDD_TUNE_VF, 80L, txt2);
  258.                         if (strcmp ("", txt2) == 0)
  259.                             return 0;
  260.                         valid = FALSE;
  261.                         for (i = 0; i < NumVFs; i++)
  262.                         {
  263.                             if (strcmp (VFData[i].vf_string, txt2) == 0)
  264.                             {
  265.                                 vf = i;
  266.                                 valid = TRUE;
  267.                                 break;
  268.                             }
  269.                         }
  270.                         if (!valid)
  271.                             return 0;
  272.  
  273.                                         // In order to change the input format
  274.                                         // we must first set the variable
  275.                                         // called INPUTFORMAT. Once this has
  276.                                         // been set we must reset the digitizer
  277.                                         // chip. The way I have reset the chip
  278.                                         // is to close the device, then open
  279.                                         // the device (thus resetting the
  280.                                         // digitizer chip), then switch the
  281.                                         // overlay monitor on, and then
  282.                                         // call the VcaiRedraw function.
  283.                         VcaiVarWrite ("INPUTFORMAT", VCA_VARIABLE_GENERIC, vf);
  284.                         VcaiDeviceClose (DevHandle);
  285.                         DevHandle = VcaiDeviceOpen (DevType, DevInstance);
  286.                         if (DevHandle < 0)
  287.                         {
  288.                             sprintf (txt, "Cannot Open Device %u !",
  289.                                      DevInstance);
  290.                             msg_box (txt, "Error", MB_OK | MB_ERROR);
  291.                         }
  292.                         VcaiOverlay (TRUE);
  293.                         VcaiRedraw ();
  294.                         return 0;
  295.                     case IDD_TUNE_FINE :
  296.                         if ((notify_code == SLN_CHANGE) ||
  297.                             (notify_code == SLN_SLIDERTRACK))
  298.                         {
  299.                             VcaiTunerGet (®ion, &ch, &freq, &fine);
  300.                             fine = (LONG)WinSendDlgItemMsg(
  301.                                         hwnd, IDD_TUNE_FINE,
  302.                                         SLM_QUERYSLIDERINFO,
  303.                                         MPFROM2SHORT
  304.                                         (SMA_SLIDERARMPOSITION,
  305.                                          SMA_INCREMENTVALUE),
  306.                                         NULL);
  307.                             VcaiTunerSet (region, ch, freq, fine, 0, 0);
  308.                         }
  309.                         return 0;
  310.                     case IDD_TUNE_FREQ :
  311.                         switch (SHORT2FROMMP (mp1))
  312.                         {
  313.                             case EN_CHANGE :
  314.                                 VcaiTunerGet (®ion, &ch, &freq, &fine);
  315.                                 WinQueryDlgItemText (hwnd,
  316.                                                      IDD_TUNE_FREQ,
  317.                                                      12L, txt);
  318.                                 freq = (ULONG)atol (txt);
  319.                                 VcaiTunerSet (region, ch, freq, fine, 0, 0);
  320.                                 return 0;
  321.                             default:
  322.                                 break;
  323.                         }
  324.                         return 0;
  325.                     case IDD_TUNE_CH :
  326.                         switch (SHORT2FROMMP (mp1))
  327.                         {
  328.                             case EN_CHANGE :
  329.                                 VcaiTunerGet (®ion, &ch, &freq, &fine);
  330.                                 WinQueryDlgItemText (hwnd,
  331.                                                      IDD_TUNE_CH,
  332.                                                      12L, txt);
  333.                                 ch = (ULONG)atol (txt);
  334.                                 freq = Region_frequencies[ch];
  335.                                 VcaiTunerSet (region, ch, freq, fine, 0, 0);
  336.                                 sprintf (txt, "%lu", freq);
  337.                                 WinSetDlgItemText (hwnd, IDD_TUNE_FREQ,
  338.                                                    (PSZ)txt);
  339.                                 return 0;
  340.                             default:
  341.                                 break;
  342.                         }
  343.                         return 0;
  344.                     default :
  345.                         break;
  346.                 }
  347.                 break;
  348.             case MSG_CHANGE_TUNER :
  349.                 VcaiTunerGet (®ion, &ch, &freq, &fine);
  350.                 vi = VcaiVideoInputQuery ();
  351.                 WinSetDlgItemText (hwnd, IDD_TUNE_SRC,
  352.                                    SrcData[vi].src_string);
  353.                 WinSetDlgItemText (hwnd, IDD_TUNE_REGION, &RegionNames[region][0]);
  354.                 sprintf (txt, "%lu", freq);
  355.                 WinSetDlgItemText (hwnd, IDD_TUNE_FREQ, txt);
  356.                 WinSendMsg (WinWindowFromID (hwnd, IDD_TUNE_FINE),
  357.                             SLM_SETSLIDERINFO,
  358.                             MPFROM2SHORT (SMA_SLIDERARMPOSITION,
  359.                             SMA_INCREMENTVALUE),
  360.                             MPFROMSHORT (fine));
  361.                 sprintf (txt, "%lu", ch);
  362.                 WinSetDlgItemText (hwnd, IDD_TUNE_CH, txt);
  363.                 VcaiVarRead ("INPUTFORMAT", VCA_VARIABLE_GENERIC, &ul);
  364.                 i = (USHORT)ul;
  365.                 WinSetDlgItemText (hwnd, IDD_TUNE_VF, VFData[i].vf_string);
  366.                 VcaiTunerSet (region, ch, freq, fine, 0, 0);
  367.                 return 0;
  368.             default :
  369.                 break;
  370.         }
  371.         return WinDefDlgProc (hwnd, msg, mp1, mp2);
  372. }
  373.  
  374. static void position_tv (HWND hwnd, USHORT tv)
  375. {
  376.     HWND    hwnd_tv;
  377.     RECTL   rcl_tv, rcl;
  378.     POINTL  pts;
  379.     LONG    bx, by, dy, x, y;
  380.  
  381.         hwnd_tv = WinWindowFromID (hwnd, tv);
  382.         if (!WinQueryWindowRect (hwnd_tv, &rcl_tv))
  383.             return;
  384.         if (!WinMapWindowPoints (hwnd_tv, HWND_DESKTOP, (PPOINTL)
  385.                                  &rcl_tv, 2))
  386.             return;
  387.         WinQueryWindowRect (HWND_DESKTOP, &rcl);
  388.         pts.x = rcl_tv.xLeft;
  389.         pts.y = rcl_tv.yBottom;
  390.         if (!WinPtInRect (Hab, &rcl, &pts))
  391.             return;
  392.         pts.x = rcl_tv.xRight;
  393.         pts.y = rcl_tv.yTop;
  394.         if (!WinPtInRect (Hab, &rcl, &pts))
  395.             return;
  396.         bx = WinQuerySysValue (HWND_DESKTOP, SV_CXDLGFRAME);
  397.         by = WinQuerySysValue (HWND_DESKTOP, SV_CYDLGFRAME);
  398.         dy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  399.         VcaiVideoRectValidate (0, 0, 0, 0,
  400.                                (USHORT)(rcl_tv.xLeft + bx),
  401.                                (USHORT)(dy - rcl_tv.yTop - by),
  402.                                (USHORT)(rcl_tv.xRight - rcl_tv.xLeft),
  403.                                (USHORT)(rcl_tv.yTop - rcl_tv.yBottom));
  404. }
  405.  
  406. static void enable_tuner_options (HWND hwnd)
  407. {
  408.         WinEnableWindow (WinWindowFromID (hwnd, IDD_TUNE_REGION), TRUE);
  409.         WinEnableWindow (WinWindowFromID (hwnd, IDD_TUNE_FREQ), TRUE);
  410.         WinEnableWindow (WinWindowFromID (hwnd, IDD_TUNE_CH), TRUE);
  411.         WinEnableWindow (WinWindowFromID (hwnd, IDD_TUNE_FINE), TRUE);
  412. }
  413.  
  414. static void disable_tuner_options (HWND hwnd)
  415. {
  416.         WinEnableWindow (WinWindowFromID (hwnd, IDD_TUNE_REGION), FALSE);
  417.         WinEnableWindow (WinWindowFromID (hwnd, IDD_TUNE_FREQ), FALSE);
  418.         WinEnableWindow (WinWindowFromID (hwnd, IDD_TUNE_CH), FALSE);
  419.         WinEnableWindow (WinWindowFromID (hwnd, IDD_TUNE_FINE), FALSE);
  420. }
  421.  
  422. static void init_src_listbox (HWND hwnd)
  423. {
  424.     USHORT  i, j;
  425.     ULONG   vi;
  426.  
  427.         SrcInit = TRUE;
  428.         for (i = 0; i < NumSrcs; i++)
  429.         {
  430.             WinSendDlgItemMsg (hwnd, IDD_TUNE_SRC, LM_INSERTITEM,
  431.                                MPFROMSHORT (SrcData[i].src_no),
  432.                                MPFROMP (SrcData[i].src_string));
  433.         }
  434.         j = VcaiVarRead ("VIDEOINPUT", VCA_VARIABLE_GENERIC, &vi);
  435.         if (j == 0)
  436.             i = VcaiVideoInputQuery ();
  437.         else
  438.             i = (USHORT)vi;
  439.         WinSendDlgItemMsg (hwnd, IDD_TUNE_SRC, LM_SELECTITEM,
  440.                            MPFROMSHORT (SrcData[i].src_no),
  441.                            MPFROMSHORT (TRUE));
  442.         SrcInit = FALSE;
  443. }
  444.  
  445. static void init_region_listbox (HWND hwnd)
  446. {
  447.     APIRET  rc;
  448.     PSZ     pmmbase, penv = "MMBASE";
  449.     CHAR    filename[256];
  450.     LONG    len;
  451.     ULONG   num_files;
  452.     HDIR    hdir;
  453.     FILEFINDBUF3    ffb;
  454.     USHORT  n, i;
  455.     ULONG   region, freq, max_ch, ch;
  456.     LONG    fine;
  457.  
  458.         RegionInit = TRUE;
  459.         rc = DosScanEnv (penv, &pmmbase);
  460.         if (rc != 0)
  461.         {
  462.             msg_box ("Unable to scan environment.",
  463.                          "Error", MB_OK | MB_ERROR);
  464.             return;
  465.         }
  466.         len = strlen (pmmbase);
  467.         if (pmmbase[len-1] == ';')
  468.             pmmbase[len-1] = '\0';
  469.         strcpy (filename, pmmbase);
  470.         strcat (filename, "\\REGION\\*.RGN");
  471.         strcpy (RegionBase, pmmbase);
  472.         strcat (RegionBase, "\\REGION\\");
  473.         num_files = 1L;
  474.         hdir = 0xffffffff;
  475.         n = 0;
  476.         rc = DosFindFirst (filename,
  477.                            &hdir,
  478.                            FILE_ARCHIVED | FILE_DIRECTORY | FILE_READONLY,
  479.                            (PVOID) &ffb,
  480.                            sizeof (FILEFINDBUF3),
  481.                            &num_files,
  482.                            1L);
  483.         if (rc)
  484.         {
  485.             strcpy (txt2, "DosFindFirst Error");
  486.             msg_box (txt2, "Error", MB_OK | MB_INFORMATION);
  487.             return;
  488.         }
  489.         else
  490.         {
  491.             WinSendDlgItemMsg (hwnd, IDD_TUNE_REGION, LM_INSERTITEM, MPFROM2SHORT
  492.                                (LIT_END, 0),
  493.                                MPFROMP (ffb.achName));
  494.             strcpy (&RegionNames[n][0], ffb.achName);
  495.             n++;
  496.         }
  497.         while (!rc)
  498.         {
  499.             num_files = 1L;
  500.             rc = DosFindNext (hdir, (PVOID)&ffb, sizeof (ffb), &num_files);
  501.             if (!rc)
  502.             {
  503.                 WinSendDlgItemMsg (hwnd, IDD_TUNE_REGION, LM_INSERTITEM,
  504.                                    MPFROM2SHORT (LIT_END, 0),
  505.                                    MPFROMP (ffb.achName));
  506.                 strcpy (&RegionNames[n][0], ffb.achName);
  507.                 n++;
  508.             }
  509.         }
  510.         DosFindClose (hdir);
  511.         NumRegions = n;
  512.  
  513.         VcaiTunerGet (®ion, &ch, &freq, &fine);
  514.         if (region >= n)
  515.             region = 0;
  516.         WinSendDlgItemMsg (hwnd, IDD_TUNE_REGION, LM_QUERYITEMTEXT,
  517.                            MPFROM2SHORT (region, sizeof (RegionFile)),
  518.                            MPFROMP (RegionFile));
  519.         strcpy (txt2, RegionBase);
  520.         strcat (txt2, RegionFile);
  521.         WinSetDlgItemText (hwnd, IDD_TUNE_REGION, RegionFile);
  522.         ch = 0;
  523.         max_ch = get_region_data (txt2);
  524.         for (i = 0; i < max_ch; i++)
  525.         {
  526.             if (freq == Region_frequencies[i])
  527.                 ch = i;
  528.         }
  529.         freq = Region_frequencies[ch];
  530.         RegionInit = FALSE;
  531. }
  532.  
  533. static void init_vf_listbox (HWND hwnd)
  534. {
  535.     USHORT  i, vf, j;
  536.     ULONG   ul;
  537.  
  538.         VFInit = TRUE;
  539.         for (i = 0; i < NumVFs; i++)
  540.         {
  541.             WinSendDlgItemMsg (hwnd, IDD_TUNE_VF, LM_INSERTITEM,
  542.                                MPFROMSHORT (VFData[i].vf_no),
  543.                                MPFROMP (VFData[i].vf_string));
  544.         }
  545.         j = VcaiVarRead ("INPUTFORMAT", VCA_VARIABLE_GENERIC, &ul);
  546.         if (j == 0)
  547.             vf = 0;
  548.         else
  549.             vf = (USHORT)ul;
  550.         WinSendDlgItemMsg (hwnd, IDD_TUNE_VF, LM_SELECTITEM,
  551.                            MPFROMSHORT (VFData[vf].vf_no),
  552.                            MPFROMSHORT (TRUE));
  553.         VFInit = FALSE;
  554. }
  555.  
  556. static USHORT load_celeb_src_data (PSOURCE_DATA psrc)
  557. {
  558.     USHORT  i;
  559.  
  560.         i = 0;
  561.         while (strcmp (celebnb_src[i].src_string, "") != 0)
  562.         {
  563.             psrc->src_no = celebnb_src[i].src_no;
  564.             psrc->src_tuner_flag = celebnb_src[i].src_tuner_flag;
  565.             strcpy (psrc->src_string, celebnb_src[i].src_string);
  566.             i++;
  567.             psrc++;
  568.         }
  569.         return i;
  570. }
  571.  
  572. static USHORT load_celeb_vf_data (PVIDEO_FORMAT_DATA pvf)
  573. {
  574.     USHORT  i;
  575.  
  576.         i = 0;
  577.         while (strcmp (celebnb_vf[i].vf_string, "") != 0)
  578.         {
  579.             pvf->vf_no = celebnb_vf[i].vf_no;
  580.             strcpy (pvf->vf_string, celebnb_vf[i].vf_string);
  581.             i++;
  582.             pvf++;
  583.         }
  584.         return i;
  585. }
  586.  
  587. static USHORT load_highq_src_data (PSOURCE_DATA psrc)
  588. {
  589.     USHORT  i;
  590.  
  591.         i = 0;
  592.         while (strcmp (highqnb_src[i].src_string, "") != 0)
  593.         {
  594.             psrc->src_no = highqnb_src[i].src_no;
  595.             psrc->src_tuner_flag = highqnb_src[i].src_tuner_flag;
  596.             strcpy (psrc->src_string, highqnb_src[i].src_string);
  597.             i++;
  598.             psrc++;
  599.         }
  600.         return i;
  601. }
  602.  
  603. static USHORT load_highq_vf_data (PVIDEO_FORMAT_DATA pvf)
  604. {
  605.     USHORT  i;
  606.  
  607.         i = 0;
  608.         while (strcmp (highqnb_vf[i].vf_string, "") != 0)
  609.         {
  610.             pvf->vf_no = highqnb_vf[i].vf_no;
  611.             strcpy (pvf->vf_string, highqnb_vf[i].vf_string);
  612.             i++;
  613.             pvf++;
  614.         }
  615.         return i;
  616. }
  617.  
  618. static USHORT load_prism_src_data (PSOURCE_DATA psrc)
  619. {
  620.     USHORT  i;
  621.  
  622.         i = 0;
  623.         while (strcmp (prismnb_src[i].src_string, "") != 0)
  624.         {
  625.             psrc->src_no = prismnb_src[i].src_no;
  626.             psrc->src_tuner_flag = prismnb_src[i].src_tuner_flag;
  627.             strcpy (psrc->src_string, prismnb_src[i].src_string);
  628.             i++;
  629.             psrc++;
  630.         }
  631.         return i;
  632. }
  633.  
  634. static USHORT load_prism_vf_data (PVIDEO_FORMAT_DATA pvf)
  635. {
  636.     USHORT  i;
  637.  
  638.         i = 0;
  639.         while (strcmp (prismnb_vf[i].vf_string, "") != 0)
  640.         {
  641.             pvf->vf_no = prismnb_vf[i].vf_no;
  642.             strcpy (pvf->vf_string, prismnb_vf[i].vf_string);
  643.             i++;
  644.             pvf++;
  645.         }
  646.         return i;
  647. }
  648.  
  649. static USHORT load_encore_src_data (PSOURCE_DATA psrc)
  650. {
  651.     USHORT  i;
  652.  
  653.         i = 0;
  654.         while (strcmp (encornb_src[i].src_string, "") != 0)
  655.         {
  656.             psrc->src_no = encornb_src[i].src_no;
  657.             psrc->src_tuner_flag = encornb_src[i].src_tuner_flag;
  658.             strcpy (psrc->src_string, encornb_src[i].src_string);
  659.             i++;
  660.             psrc++;
  661.         }
  662.         return i;
  663. }
  664.  
  665. static USHORT load_encore_vf_data (PVIDEO_FORMAT_DATA pvf)
  666. {
  667.     USHORT  i;
  668.  
  669.         i = 0;
  670.         while (strcmp (encornb_vf[i].vf_string, "") != 0)
  671.         {
  672.             pvf->vf_no = encornb_vf[i].vf_no;
  673.             strcpy (pvf->vf_string, encornb_vf[i].vf_string);
  674.             i++;
  675.             pvf++;
  676.         }
  677.         return i;
  678. }
  679.  
  680.