home *** CD-ROM | disk | FTP | other *** search
/ Sound Sensations! / sound_sensations.iso / miscprog / ad-prog / csoundc.c < prev    next >
C/C++ Source or Header  |  1990-04-19  |  2KB  |  95 lines

  1. /*
  2.      Copyright Ad Lib Inc., 1990
  3.  
  4.      This file is part of the Ad Lib Programmer's Manual product and is
  5.      subject to copyright laws.  As such, you may make copies of this file
  6.      only for the purpose of having backup copies.  This file may not be
  7.      redistributed in any form whatsoever.
  8.  
  9.      If you find yourself in possession of this file without having received
  10.      it directly from Ad Lib Inc., then you are in violation of copyright
  11.      laws, which is a form of theft.
  12. */
  13.  
  14. /*
  15.    File: csoundc.c
  16.    C interface to memory resident sound driver.
  17. */
  18.  
  19. #include  "cflags.h"
  20.  
  21. #include <dos.h>
  22.  
  23. #ifdef TURBOC
  24.    #include <mem.h>
  25. #else
  26.    #include <memory.h>
  27.    /* This pragma statement if for QuickC, which will generate a run-time
  28.       error in GetSoundDrvVersion() because of the far pointer calculation. */
  29.    #pragma  check_pointer (off)
  30. #endif
  31.  
  32. #define  DOS_FUNCTION_CALL         0x21
  33. #define  SOUND_DRIVER_INT          101
  34. #define  DOS_GET_VECTOR_FUNCTION   0x35
  35.  
  36. /* The sound driver code starts with the following signature and can be
  37.    used to test if the sound driver is installed.  The version number is
  38.    a two byte value which precedes the signature and is a hex readable
  39.    number: version 1.5 will be 0x150.  */
  40.  
  41. static char adlib[] = {"SOUND-DRIVER-AD-LIB"};
  42.  
  43. int GetSoundDrvVersion ()
  44. {
  45.    char far * far *int_ptr;
  46.    char far *sig_ptr;
  47.    char str [40];
  48.    int n, version = 0;
  49.  
  50.    /* 404 is the address of interrupt vector 101. */
  51.    int_ptr = (char (far * far *)) 404;
  52.    sig_ptr = *int_ptr;
  53.    sig_ptr -= (sizeof (adlib) + 4);
  54.  
  55.    /* Copy signature to a local buffer. */
  56.    for (n=0; n < strlen (adlib)+2; n++) str [n] = sig_ptr [n];
  57.  
  58.    if (!memcmp (adlib, &str [2], strlen (adlib)))
  59.       memcpy (&version, str, sizeof (int));
  60.  
  61.    return (version);
  62. }
  63.  
  64. #ifndef TURBOC
  65.    /* Returns pointer checking to its previous status. */
  66.    #pragma  check_pointer ()
  67. #endif
  68.  
  69. SoundCall (fn_num, stack)
  70.    int fn_num, stack;
  71. {
  72.    union REGS inregs, outregs;
  73.    struct SREGS segregs;
  74.    int result;
  75.    char far *c = (char *) &stack;
  76.  
  77.    inregs.x.si = fn_num;
  78.    inregs.x.bx = FP_OFF (c);
  79.    segregs.es = FP_SEG (c);
  80.    result = int86x (SOUND_DRIVER_INT, &inregs, &outregs, &segregs);
  81.    return (result);
  82. }
  83.  
  84. #if 0
  85. main ()
  86. {
  87.    int n;
  88.    n = GetSoundDrvVersion();
  89.    if (!n)
  90.       printf ("Sound driver not installed.\n");
  91.    else
  92.       printf ("Sound driver version %x.%x\n", n >> 8, n & 0xff);
  93. }
  94. #endif
  95.