home *** CD-ROM | disk | FTP | other *** search
/ TopWare 18: Liquid / Image.iso / liquid / top1120 / volume.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-10  |  9.9 KB  |  455 lines

  1.  
  2. ;   /*\
  3. ;---|*|----====< Vol.exe >====----
  4. ;---|*|
  5. ;---|*| Test a volume device
  6. ;---|*|
  7. ;---|*| Copyright (c) 1993,1994  V.E.S.A, Inc. All Rights Reserved.
  8. ;---|*|
  9. ;---|*| VBE/AI 1.0 Specification
  10. ;---|*|    February 2, 1994. 1.00 release
  11. ;---|*|
  12. ;---|*| Additional Changes:
  13. ;---|*|    02/28 - If no parameters are provided, the program prints the
  14. ;---|*|            helps, then exits to DOS.
  15. ;---|*|
  16. ;   \*/
  17.  
  18. #include <stdio.h>
  19. #include <signal.h>
  20.  
  21. #include "vbeai.h"
  22. #include "vesa.h"
  23.  
  24. #define TRUE    -1
  25. #define FALSE    0
  26. #define ON      TRUE
  27. #define OFF     FALSE
  28.  
  29.         VESAHANDLE hVESA  = 0;
  30.  
  31.         GeneralDeviceClass gdc; // receives a copy of the VESA driver info block
  32.  
  33.     // tables for reporting attached volume info and services
  34.  
  35.         VolumeInfo volinf;
  36.         VolumeService volsrv;
  37.  
  38.  
  39. ;   /*\
  40. ;---|*| prototypes
  41. ;   \*/
  42.  
  43.         long GetValue   ( char *, long );
  44.         int DriverError ( );
  45.  
  46.     // only allows us to run on this version of the VBE interface. This
  47.     // will be removed after the interface is ratified. Changes may be made
  48.     // that would cause this code to crash if run on other version. Again,
  49.     // this will be removed in the final software.
  50.  
  51.         int  VersionControl = 0x0100;
  52.  
  53.  
  54. ;   /*\
  55. ;---|*|------------------==============================-------------------
  56. ;---|*|------------------====< Start of execution >====-------------------
  57. ;---|*|------------------==============================-------------------
  58. ;   \*/
  59.  
  60. main(argc,argv)
  61.     int argc;
  62.     char *argv[];
  63. {
  64. int query;
  65. int pref;
  66.  
  67.     // process the command line
  68.  
  69.         CommandLine (argc,argv);
  70.  
  71.     // disable the ^C so the devices will close properly.
  72.  
  73.         signal (SIGINT,SIG_IGN);
  74.  
  75.     // process the specific device handle
  76.  
  77.         while (TRUE) {
  78.  
  79.             // make sure there is such a handle
  80.  
  81.                 if (VESAQueryDevice(hVESA, VESAQUERY1 ,0) == 0) {
  82.                     printf ("Cannot query the installed VBE/AI devices!\n");
  83.                     DoExit(-1);
  84.                 }
  85.  
  86.             // make sure it's matches the beta version #
  87.  
  88.                 VESAQueryDevice(hVESA, VESAQUERY2 ,&gdc);
  89.  
  90.                 if (gdc.gdvbever != VersionControl) {
  91.                     printf ("The VESA device version # does not match, cannot continue!\n");
  92.                     break;
  93.                 }
  94.  
  95.             // if we could'nt get the services, just bail now.
  96.  
  97.                 if (!GetAttachedVolumes(hVESA)) {
  98.                     printf ("There are no volume services for this handle!");
  99.                     break;
  100.                 }
  101.  
  102.             // perform the tests...
  103.  
  104.                 PerformTests();
  105.                 break;
  106.         }
  107.  
  108.         DoExit(0);
  109. }
  110.  
  111.  
  112. ;   /*\
  113. ;---|*|----------------------=======================---------------------------
  114. ;---|*|----------------------====< Subroutines >====---------------------------
  115. ;---|*|----------------------=======================---------------------------
  116. ;   \*/
  117.  
  118. ;   /*\
  119. ;---|*|----====< CommandLine >====----
  120. ;---|*|
  121. ;---|*| Process the command line switches
  122. ;---|*|
  123. ;   \*/
  124. CommandLine(argc,argv)
  125.     int argc;
  126.     char *argv[];
  127. {
  128. int n,vh,vl;
  129. char *s,c;
  130.  
  131.     // split the version for neatness...
  132.  
  133.         vh = VersionControl >> 8;
  134.         vl = VersionControl &  0xFF;
  135.  
  136.     // intro...
  137.  
  138.         printf ("\nVESA VBE/AI Volume Test Program, %02x.%02x\n",vh,vl);
  139.         printf ("Copyright (c) 1993,1994  VESA, Inc. All Rights Reserved.\n\n");
  140.  
  141.     // exit if no other parameters
  142.  
  143.         if (argc < 2) {
  144.             GiveHelps();
  145.             DoExit(0);
  146.         }
  147.  
  148.     // process all the switches
  149.  
  150.         n = 1;
  151.         while (n<argc) {
  152.  
  153.             s = argv[n++];
  154.  
  155.             switch (*s) {
  156.  
  157.                 case '?':
  158.                 case 'H':   // both helps and handle
  159.                 case 'h':
  160.  
  161.                     hVESA  = GetValue (++s,0);  // maybe get the handle
  162.  
  163.                     if (hVESA) {
  164.                         printf ("Will use handle #%d\n\n",hVESA);
  165.                     }
  166.                     else {
  167.  
  168.                         GiveHelps();
  169.                         DoExit(0);
  170.                     }
  171.                     break;
  172.  
  173.                 default:
  174.                     printf ("Unknown option - %s\n",s);
  175.             }
  176.         }
  177.  
  178. }
  179.  
  180.  
  181. ;   /*\
  182. ;---|*|----====< DoExit >====----
  183. ;---|*|
  184. ;---|*| Shut everything down, then exit to DOS
  185. ;---|*|
  186. ;   \*/
  187. DoExit(cc)
  188.     int cc;
  189. {
  190.  
  191.     // return to DOS, don't return to caller
  192.  
  193.         exit(cc);
  194. }
  195.  
  196. ;
  197. ;   /*\
  198. ;---|*|----====< GetAttachedVolumes >====----
  199. ;---|*|
  200. ;---|*| locate any volume info and services structures for the
  201. ;---|*| device handle
  202. ;---|*|
  203. ;   \*/
  204. GetAttachedVolumes(han)
  205.     VESAHANDLE han;
  206. {
  207. fpVolInfo vi;
  208. fpVolServ vs;
  209.  
  210.     // if there is a valid volume info structure, print it...
  211.  
  212.         if (VESAQueryDevice ( han, VESAQUERY3, 0 )) {
  213.  
  214.             if (vi = (fpVolInfo)VESAQueryDevice ( han, VESAQUERY4, &volinf )) {
  215.  
  216.             // if there is a valid volume info structure, print it...
  217.  
  218.                 if (VESAQueryDevice ( han, VESAQUERY5, 0 )) {
  219.  
  220.                     if (vs = (fpVolServ)VESAQueryDevice ( han, VESAQUERY6, &volsrv ))
  221.  
  222.                         return(TRUE);
  223.  
  224.                 }
  225.             }
  226.         }
  227.  
  228.     // could'nt find both info and services
  229.  
  230.         return(0);
  231.  
  232. }
  233.  
  234. ;
  235. ;   /*\
  236. ;---|*|----====< PerformTests >====----
  237. ;---|*|
  238. ;---|*| Perform the hardware any and all tests
  239. ;---|*|
  240. ;   \*/
  241. PerformTests()
  242. {
  243. int n;
  244. long l;
  245. int left,right;
  246.  
  247.     // Reset the channel to it's default state
  248.  
  249.         (*volsrv.vsResetChannel)  ( );
  250.         DriverError();
  251.  
  252.     // SetVolume tests
  253.  
  254.         // show & modify the user's settings
  255.  
  256.         l = (*volsrv.vsSetVolume) ( VOL_USERSETTING, -1, -1 );
  257.         left  = (int) (l      & 0xFFFF);
  258.         right = (int)((l>>16) & 0xFFFF);
  259.         printf ("Current user settings are: left=%d%%, right=%d%%\n",left,right);
  260.         DriverError();
  261.  
  262.         printf ("Setting the user left/right to 50%\n");
  263.         (*volsrv.vsSetVolume) ( VOL_USERSETTING, 50, 50 );
  264.         DriverError();
  265.  
  266.         // show & modify the applications setting
  267.  
  268.         l = (*volsrv.vsSetVolume) ( VOL_APPSETTING, -1, -1 );
  269.         left  = (int) (l      & 0xFFFF);
  270.         right = (int)((l>>16) & 0xFFFF);
  271.         printf ("Current app settings are: left=%d%%, right=%d%%\n",left,right);
  272.         DriverError();
  273.  
  274.         printf ("Setting the user left/right to 0%\n");
  275.         (*volsrv.vsSetVolume) ( VOL_APPSETTING, volinf.vimin, volinf.vimin );
  276.         DriverError();
  277.  
  278.     // 3D Set Field Volume tests
  279.  
  280.         printf ("Setting the 3D audio somewhere...\n");
  281.         (*volsrv.vsSetFieldVol)   ( 250, 900, 450 );
  282.         DriverError();
  283.  
  284.     // Parametric Equalizer tests
  285.  
  286.         printf ("Parametric Eqaulizer test\n");
  287.         (*volsrv.vsToneControl)   ( 1, 2500, 128, 5 );
  288.         DriverError();
  289.  
  290.     // Hi & Low pass filter tests
  291.  
  292.         printf ("Hi & Low pass filter tests\n");
  293.         (*volsrv.vsFilterControl )( 1,  8000, 128 );
  294.         DriverError();
  295.         (*volsrv.vsFilterControl )( 2, 16000, 128 );
  296.         DriverError();
  297.  
  298.     // Record/Playback path control
  299.  
  300.         printf ("Record/Playback path control tests\n");
  301.         (*volsrv.vsOutputPath)    ( TRUE );
  302.         DriverError();
  303.         (*volsrv.vsOutputPath)    ( FALSE );
  304.         DriverError();
  305.  
  306.     // Reset the channel to it's default state
  307.  
  308.         (*volsrv.vsResetChannel)  ( );
  309.         DriverError();
  310.  
  311. }
  312.  
  313. ;   /*\
  314. ;---|*|-------------------====< Internal Routines >====----------------------
  315. ;   \*/
  316.  
  317. ;   /*\
  318. ;---|*|----====< DriverError >====----
  319. ;---|*|
  320. ;---|*| Query for any errors, report results.
  321. ;---|*|
  322. ;   \*/
  323. int DriverError()
  324. {
  325. int n;
  326.  
  327.     // return any error found in the driver.
  328.  
  329.         if ((n = (*volsrv.vsGetLastError) ( )) != 0) {
  330.             printf ("  VOLUME ERROR, message = %x\n",n);
  331.             return(n);
  332.         }
  333.  
  334.     // else just return NULL
  335.  
  336.         return(0);
  337. }
  338.  
  339. ;   /*\
  340. ;---|*|----====< GetKey >====----
  341. ;---|*|
  342. ;---|*| Get a key from the keyboard
  343. ;---|*|
  344. ;   \*/
  345. int GetKey(flag)
  346.     int flag;
  347. {
  348. int c;
  349.  
  350.     // flush the keys coming in
  351.  
  352.         if (flag)
  353.             while (kbhit())
  354.                 getch();
  355.  
  356.     // get the real key
  357.  
  358.         if ((c = getch()) == 0)
  359.             c = getch();
  360.  
  361.     // return to the caller
  362.  
  363.         return(c);
  364. }
  365.  
  366.  
  367. ;   /*\
  368. ;---|*|----====< GetValue >====----
  369. ;---|*|
  370. ;---|*| Return a value from the string, or the last value
  371. ;---|*|
  372. ;   \*/
  373. long GetValue (s,orig)
  374.     char * s;
  375.     long orig;
  376. {
  377. long w;
  378. int NegateFlag = FALSE;
  379.  
  380.     // if the first character is negative, then set out neg flag
  381.  
  382.         if (*s == '-') {
  383.             s++;
  384.             NegateFlag = TRUE;
  385.         }
  386.  
  387.     // check the first character, if zero, then it's octal or hex
  388.  
  389.         if (*s == '0') {
  390.  
  391.             w = 0;
  392.  
  393.             if ((*++s & 0x5F) == 'X') {
  394.  
  395.                 if (sscanf (++s,"%lx",&w) != 1)
  396.                     w = orig;
  397.  
  398.             }
  399.             else {
  400.                 if (isdigit(*s)) {
  401.  
  402.                     if (sscanf (s,"%lo",&w) != 1)
  403.                         w = orig;
  404.                 }
  405.                 else {
  406.                     w = 0;
  407.                 }
  408.             }
  409.         }
  410.  
  411.     // return a decimal value
  412.  
  413.         else {
  414.  
  415.             if (sscanf (s,"%ld",&w) != 1)
  416.                 w = orig;
  417.  
  418.         }
  419.  
  420.     // we have something...
  421.  
  422.         if (NegateFlag)
  423.             w = 0 - w;
  424.  
  425.         return(w);
  426.  
  427. }
  428.  
  429.  
  430. ;   /*\
  431. ;---|*|----====< GiveHelps >====----
  432. ;---|*|
  433. ;---|*| Give the user the commandline option list
  434. ;---|*|
  435. ;   \*/
  436.  
  437. GiveHelps()
  438. {
  439.  
  440.         printf ("To Use: DOS>VOL [H|?] [Hxx]\n\n");
  441.  
  442.         printf ("Where:     [H|?]      gives helps.\n");
  443.         printf ("           [Hxx]      specifies the device handle to test.\n");
  444.         printf ("\n");
  445.  
  446. }
  447.  
  448. ;   /*\
  449. ;---|*| end of VOL.C
  450. ;   \*/
  451.  
  452.  
  453.  
  454.  
  455.