home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sdk_dos.ddi / BASIC / VOICE / DEMOVDP.BAS next >
Encoding:
BASIC Source File  |  1991-11-13  |  4.7 KB  |  212 lines

  1. '
  2. ' This program output the voice file DEMO.VOC
  3. '
  4.  
  5. ' $INCLUDE: 'SBC.BI'
  6. ' $INCLUDE: 'SBCSYS.BI'
  7. ' $INCLUDE: 'SBCVOICE.BI'
  8.  
  9. DECLARE   SUB  OUTVOCFILE(filename$)
  10. DECLARE   SUB  SHOWERROR()
  11.  
  12. REM $DYNAMIC
  13. CLEAR
  14.  
  15. ' Following statements free memory for the loadable drivers.
  16. ' You must free sufficient memory for the loadable drivers.
  17. ' The free memory must be larger than the driver file size.
  18.  
  19. ' Free 8K memory for the CTVDSK.DRV at the moment
  20. DUMMY = SETMEM(-8192)
  21.  
  22. ' Following statements free memory for the Disk Double Buffer
  23. ' Two 32K buffers are released by BASIC
  24. DUMMY = SETMEM(-16400)
  25. DUMMY = SETMEM(-16400)
  26. DUMMY = SETMEM(-16400)
  27. DUMMY = SETMEM(-16400)
  28.  
  29. CLS
  30.  
  31. PRINT "SBK Basic Voice Output (disk version) Example"
  32.  
  33. IF (SBGETENV% = 0) THEN
  34.     IF SBCHKCRD% THEN
  35.         IF SBTSTINT% THEN
  36.             IF SBTSTDMA% >= 0 THEN
  37.  
  38.                 ' Load CTVDSK.DRV
  39.                 DRVADDX% = LOADDRV% ("CTVDSK.DRV")
  40.  
  41.                 ' If driver loaded successfully
  42.                 IF (DRVADDX% <> 0) THEN
  43.  
  44.                     ' Set driver address
  45.                     DSKADDX (DRVADDX%)
  46.  
  47.                     ' Initial the driver, with 64K buffer as double buffer
  48.                     IF ( SVDINIT%((16)) = 0 ) THEN
  49.  
  50.                         ' Off DAC speaker
  51.                         CALL SVDSPKER(INT(0))
  52.  
  53.                         ' Output the voice file
  54.                         CALL OUTVOCFILE("DEMO.VOC")
  55.  
  56.                         ' Terminate the driver
  57.                         CALL SVDEXIT
  58.  
  59.                     ELSE
  60.                         CALL SHOWERROR
  61.                     ENDIF
  62.  
  63.                     ' Release memory allocated for CTVDSK
  64.                     CALL FREEMEM(DRVADDX%)
  65.                 ENDIF
  66.             ELSE
  67.                 PRINT "Error on DMA channel."
  68.             ENDIF
  69.         ELSE
  70.             PRINT "Error on interrupt."
  71.         ENDIF
  72.     ELSE
  73.         PRINT "Sound Blaster Card not found or wrong I/O setting"
  74.     ENDIF
  75. ELSE
  76.     PRINT "BLASTER environment variable not set or incomplete or invalid."
  77. ENDIF
  78.  
  79. ' Return the memory to BASIC
  80. DUMMY = SETMEM(16400)
  81. DUMMY = SETMEM(16400)
  82. DUMMY = SETMEM(16400)
  83. DUMMY = SETMEM(16400)
  84.  
  85. DUMMY = SETMEM(8192)
  86.  
  87. END
  88.  
  89.  
  90. ' ------------------------------------------------------------------------ '
  91.  
  92. FUNCTION LOADDRV% (szDrvName$)
  93.  
  94.     DIM szDrvFile$, Handle%, dwFileLen&, wDrvSeg%
  95.  
  96.  
  97.     LOADDRV% = 0
  98.  
  99.     ' search SOUND environment for driver
  100.     szDrvFile$ = ENVIRON$("SOUND")
  101.  
  102.     IF (szDrvFile$ <> "") THEN
  103.         szDrvFile$ = szDrvFile$ + "\DRV\" + szDrvName$
  104.  
  105.         IF (FINDFILE%(szDrvFile$) = 0) THEN
  106.             szDrvFile$ = ""
  107.         ENDIF
  108.     ENDIF
  109.  
  110.     ' search the current directory for driver
  111.     IF (szDrvFile$ = "") THEN
  112.         szDrvFile$ = szDrvName$
  113.     ENDIF
  114.  
  115.     IF (FINDFILE%(szDrvFile$) <> 0) THEN
  116.         Handle% = DOSOPEN%(szDrvFile$)
  117.  
  118.         IF (Handle% <> 0) THEN
  119.             dwFileLen& = FILESIZE(Handle%)
  120.  
  121.             wDrvSeg% = ALLOCMEM(INT((dwFileLen& + 15) / 16))
  122.  
  123.             IF (wDrvSeg% <> 0) THEN
  124.                 IF DOSREAD%(Handle%, INT(0), wDrvSeg%, dwFileLen&) THEN
  125.                     LOADDRV% = wDrvSeg%
  126.                 ENDIF
  127.             ENDIF
  128.  
  129.             DOSCLOSE(Handle%)
  130.         ELSE
  131.             PRINT "Error in opening " + szDrvFile$
  132.         ENDIF
  133.     ELSE
  134.         PRINT "Driver file " + szDrvName$ + " does not exist ..."
  135.     ENDIF
  136.  
  137. END FUNCTION
  138.  
  139.  
  140. ' ------------------------------------------------------------------------ '
  141.  
  142.  
  143. REM %STATIC
  144. SUB  OUTVOCFILE(filename$)
  145.  
  146.      DIM  handle AS INTEGER, userkey AS INTEGER
  147.  
  148.      ' Open the file using DOS function
  149.      handle = DOSOPEN%(filename$)
  150.  
  151.      IF (handle <> 0) THEN
  152.  
  153.       ' Turn on speaker
  154.       SVDSPKER(INT(1))
  155.  
  156.       ' Start the output
  157.       IF (SVDOUTPUT%(handle) = 0) THEN
  158.  
  159.            WHILE CTVOICE% <> 0
  160.  
  161.             c$ = INKEY$
  162.  
  163.             IF c$ <> "" THEN
  164.  
  165.              userkey = INT(ASC(LEFT$(c$, 1)))
  166.  
  167.              SELECT CASE userkey
  168.                   CASE ASC("S"), ASC("s"), 27
  169.                    CALL SVDSTOP
  170.                   CASE ASC("P"), ASC("p")
  171.                    CALL SVDPAUSE
  172.                   CASE ASC("C"), ASC("c")
  173.                    CALL SVDCONT
  174.                   CASE ASC("B"), ASC("b")
  175.                    SVDBREAK(INT(1))
  176.              END SELECT
  177.  
  178.             END IF
  179.  
  180.            WEND
  181.  
  182.       ELSE
  183.            CALL SHOWERROR
  184.       ENDIF
  185.      ELSE
  186.       PRINT "Open " +filename$ + "error."
  187.      ENDIF
  188.  
  189. END SUB
  190.  
  191.  
  192. ' ------------------------------------------------------------------------ '
  193.  
  194.  
  195. SUB  SHOWERROR
  196.  
  197. ' This function show the error code from the driver
  198.  
  199.      DIM  errcode AS INTEGER
  200.  
  201.      errcode = SVDDRVERR%
  202.  
  203.      PRINT "Driver error ="; errcode
  204.  
  205.      errcode = SVDEXTERR%
  206.  
  207.      IF (errcode <> 0) THEN
  208.         PRINT "Dos error ="; errcode
  209.      ENDIF
  210.  
  211. END SUB
  212.