home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / PROG / BWSB120A.ZIP / DEMO / TPLAY.ASM < prev   
Encoding:
Assembly Source File  |  1995-03-28  |  12.3 KB  |  420 lines

  1. .model large, basic
  2.  
  3. include bwsb.inc                        ;external declarations
  4. include gdmtype.inc                     ;GDM module file format structures
  5.  
  6. .386
  7. .stack 512
  8. .data
  9.  
  10. ModHead         GDMHeader   <?>
  11.  
  12. MSEConfigFile  struc
  13.   SoundCard     dw      ?
  14.   BaseIO        dw      ?
  15.   IRQ           dw      ?
  16.   DMA           dw      ?
  17.   SoundQuality  dw      ?
  18. MSEConfigFile   ends
  19.  
  20. MSEConfig       MSEConfigFile   <?>
  21. MSECFGFileName  db      'MSE.CFG',0         ;Name of MSE.CFG file
  22. ConfigError     db      'No Sound selected in SETUP. Please run SETUP',13,10,'$'
  23.  
  24. MSEOversample   db      16, 22, 45, 8
  25.  
  26. Temp            dw      ?
  27. Temp2           dw      ?
  28.  
  29. ErrorUnknown    db      'Unknown error',13,10,'$'
  30.  
  31. MSEErrorTable   dw      offset MSE1, offset MSE2, offset MSE3, offset MSE4
  32.                 dw      offset ErrorUnknown, offset MSE6, offset MSE7
  33.                 dw      offset MSE8, offset MSE9, offset MSE10, offset MSE11
  34.                 dw      offset MSE12
  35.  
  36. MSE1    db      'Base I/O address autodetection failure',13,10,'$'
  37. MSE2    db      'IRQ level autodetection failure',13,10,'$'
  38. MSE3    db      'DMA channel autodetection failure',13,10,'$'
  39. MSE4    db      'DMA channel not supported',13,10,'$'
  40.  
  41. MSE6    db      'Sound device does not respond',13,10,'$'
  42. MSE7    db      'Memory control blocks destroyed',13,10,'$'
  43. MSE8    db      'Insufficient memory for mixing buffers',13,10,'$'
  44. MSE9    db      'Insufficient memory for MSE file',13,10,'$'
  45. MSE10   db      'MSE has invalid ID string (corrupt/non-existant)',13,10,'$'
  46. MSE11   db      'MSE disk read failure',13,10,'$'
  47. MSE12   db      'MVSOUND.SYS not loaded (required for PAS use)',13,10,'$'
  48.  
  49. GDMErrorTable   dw      offset GDM1, offset GDM2, offset GDM3, offset GDM4
  50.                 dw      offset GDM5, offset GDM6
  51.  
  52. GDM1    db      'Module is corrupt',13,10,'$'
  53. GDM2    db      'Could not autodetect module type',13,10,'$'
  54. GDM3    db      'Bad format ID',13,10,'$'
  55. GDM4    db      'Out of memory',13,10,'$'
  56. GDM5    db      'Cannot unpack samples',13,10,'$'
  57. GDM6    db      'AdLib samples not supported',13,10,'$'
  58.  
  59. MSEFile         db      'GUS.MSE',0,"  "
  60.                 db      'SB1X.MSE',0," "
  61.                 db      'SB2X.MSE',0," "
  62.                 db      'SBPRO.MSE',0,""
  63.                 db      'SB16.MSE',0," "
  64.                 db      'PAS.MSE',0,"  "
  65.  
  66. HexTable        db      '0123456789ABCDEF'
  67.  
  68.  
  69. Banner          db      13, 10
  70.                 db      'BWSB Example Module Player', 13, 10
  71.                 db      'Copyright (c) 1995, Edward Schlunder',13,10,13,10,'$'
  72.  
  73. SoundDevice     db      'Sound Device: $'
  74.  
  75. Address         db      'Addr: $'
  76. Address2        db      'h  IRQ: $'
  77. Address3        db      '  DMA: $'
  78. Address4        db      'x',13,10,'$'
  79.  
  80. InputFile       db      'Module file: $'
  81. ModFileInput    db      74, ?
  82. ModFile         db      75 dup ('$')
  83.  
  84. CantFindFile    db      "Can't find file: $"
  85. SayLoadModule   db      'Loading Module: $'
  86.  
  87. SayChannels     db      'Channels: $'
  88. SayOversample   db      'Oversampling: $'
  89. SayOversample2  db      ' Hz$'
  90. CRLF            db      13,10,'$'
  91.  
  92. .code
  93.  
  94. Start:
  95. ;-------
  96.     mov     ah, 4Ah                     ;Shrink program memory for more free
  97.     mov     bx, 01830h                   ;Keep 64K of memory
  98.     int     21h
  99.  
  100.     mov     ax, @data                   ;Initialize segment registers
  101.     mov     ds, ax
  102. ;-------
  103.     mov     ah, 9                       ;Display program banner
  104.     mov     dx, offset Banner
  105.     int     21h
  106. ;-------
  107.     mov     ax, 3D00h                   ;Open config file for read only
  108.     mov     dx, offset MSECFGFileName
  109.     int     21h
  110.     jnc     @F                          ;Continue program if no errors
  111.  
  112. MSEError:
  113.     mov     dx, offset ConfigError      ;Couldn't open file, display error
  114.     mov     ah, 9h
  115.     int     21h
  116.     jmp     Exit                        ;Return to DOS
  117. ;-------
  118. @@: mov     bx, ax                      ;Put file handle in correct register
  119.     mov     dx, offset MSEConfig        ;Load config file into our structure
  120.     mov     cx, size MSEConfigFile      ;Read in only the right number of bytes
  121.     mov     ah, 3Fh                     ;3Fh - Read from Handle
  122.     int     21h
  123.     jc      MSEError                    ;Quit if error while loading
  124.  
  125.     cmp     ax, size MSEConfigFile      ;Did we read the right number of bytes?
  126.     jb      MSEError                    ;Display error if MSE.CFG is too small
  127.  
  128.     mov     ah, 3Eh                     ;Close file handle
  129.     int     21h
  130. ;-------
  131.     mov     bx, MSEConfig.SoundCard     ;Get sound card to load MSE for
  132.     dec     bx
  133.     mov     ax, 10                      ;multiply sound card # by 10 for table
  134.     mul     bl
  135.     mov     bx, ax
  136.     add     bx, offset MSEFile          ;ds:bx - ASCIIZ filename of MSE to load
  137.  
  138.     xor     edi, edi                    ;load from offset 0
  139.     movzx   eax, MSEConfig.SoundQuality
  140.     mov     ah, [MSEOversample+eax]     ;45KHz oversampling (or whatever is max)
  141.     mov     al, 10h                     ;4096 byte mixing buffer
  142.     mov     dx, MSEConfig.BaseIO        ;Base I/O Address of sound card
  143.     mov     ch, byte ptr MSEConfig.IRQ  ;IRQ level of sound card
  144.     mov     cl, byte ptr MSEConfig.DMA  ;DMA channel of sound card
  145.  
  146.     call    LoadMSE                     ;Load the MSE file
  147.     or      ax, ax                      ;Was there an error loading the MSE?
  148.     jz      @F                          ;Skip over error if none
  149. ;-------
  150.     mov     bx, ax
  151.     dec     bx
  152.     shl     bx, 1                       ;Multiply by two for table
  153.     mov     dx, [MSEErrorTable+bx]      ;Get offset of correct error message
  154.     mov     ah, 9                       ;Display error message
  155.     int     21h
  156.     jmp     Exit                        ;Return to DOS
  157. ;-------
  158. @@: mov     MSEConfig.BaseIO, dx        ; save autodetected information
  159.     mov     byte ptr MSEConfig.IRQ, ch  ; ...
  160.     mov     byte ptr MSEConfig.DMA, cl  ; ...
  161.  
  162.     mov     ah, 9h                      ;Print sound device's name
  163.     mov     dx, offset SoundDevice
  164.     int     21h
  165.  
  166.     call    DeviceName                  ;returns: dx:ax - pointer to dev name
  167.     push    ds
  168.     mov     ds, dx
  169.     movzx   edx, ax
  170.     mov     bl, ds:[edx+20]
  171.     mov     byte ptr ds:[edx+20], '$'
  172.     mov     ah, 9h                      ;Display device name
  173.     int     21h
  174.     mov     ds:[edx+20], bl
  175.     pop     ds
  176.  
  177.     mov     dx, offset CRLF             ;Jump to next line
  178.     int     21h
  179.  
  180.     mov     dx, offset Address          ;Print Base I/O Address used
  181.     int     21h
  182.     mov     ax, MSEConfig.BaseIO
  183.     call    PrintHex
  184.  
  185.     mov     ah, 9h
  186.     mov     dx, offset Address2         ;Print Base I/O Address used
  187.     int     21h
  188.     mov     ax, MSEConfig.IRQ
  189.     call    PrintDecimal
  190.  
  191.     mov     ah, 9h
  192.     mov     dx, offset Address3         ;Print Base I/O Address used
  193.     int     21h
  194.     mov     ax, MSEConfig.DMA
  195.     call    PrintDecimal
  196.  
  197.     mov     ah, 9h
  198.     mov     dx, offset CRLF             ;Jump to next line
  199.     int     21h
  200.     int     21h
  201. ;-------
  202.     mov     dx, offset InputFile        ;Print prompt string
  203.     int     21h
  204.  
  205.     mov     ah, 0Ah                     ;Input the name of the file to load
  206.     mov     dx, offset ModFileInput
  207.     int     21h
  208.  
  209.     mov     ah, 9h
  210.     mov     dx, offset CRLF
  211.     int     21h
  212.  
  213.     cmp     byte ptr [ModFileInput+1], 0
  214.     je      Exit                        ;Abort if user just pressed enter
  215.  
  216.     movzx   ecx, byte ptr [ModFileInput+1]
  217.     mov     byte ptr [ModFile+ecx], 0
  218.  
  219.     mov     ax, @data
  220.     mov     es, ax
  221.     mov     di, offset Modfile
  222.     cld
  223.     mov     al, '.'
  224.     repne   scasb
  225.     jz      LoadModule
  226.  
  227.     movzx   bx, byte ptr [ModFileInput+1]
  228.     mov     byte ptr [ModFile+bx], '.'
  229.     mov     byte ptr [ModFile+bx+1], 'G'
  230.     mov     byte ptr [ModFile+bx+2], 'D'
  231.     mov     byte ptr [ModFile+bx+3], 'M'
  232.     mov     byte ptr [ModFile+bx+4], 0
  233.  
  234. ;-------
  235. LoadModule:
  236.     mov     ax, 3D00h                   ;Open module for read only
  237.     mov     dx, offset ModFile
  238.     int     21h
  239.     jnc     @F
  240.  
  241.     mov     ah, 9                       ;Display error message
  242.     mov     dx, offset CantFindFile
  243.     int     21h
  244.  
  245.     mov     dx, offset ModFile
  246.     int     21h
  247.     mov     dx, offset CRLF
  248.     int     21h
  249.  
  250.     jmp     Exit                        ;Return to dos
  251. ;-------
  252. @@: mov     Temp, ax                    ;save file handle
  253.  
  254.     mov     ah, 9h
  255.     mov     dx, Offset SayLoadModule    ;Display message that we're loading
  256.     int     21h
  257.  
  258.     mov     dx, Offset ModFile
  259.     int     21h
  260.     mov     dx, offset CRLF
  261.     int     21h
  262. ;-------
  263.     call    EmsExist                    ;Find out if EMS memory exists
  264.     and     al, 1                       ;Only keep bit 0
  265.     mov     bl, al                      ;Set load flags
  266.  
  267.     mov     ax, Temp                    ;File Handle to load from
  268.     xor     ecx, ecx                    ;File offest to load from: 0
  269.     mov     dx, ds
  270.     mov     di, offset ModHead
  271.     call    LoadGDM
  272.  
  273.     push    bx
  274.     mov     ah, 3Eh                     ;Close module file handle
  275.     mov     bx, Temp
  276.     int     21h
  277.     pop     bx
  278.  
  279.     or      bl, bl
  280.     jz      @F
  281.  
  282.     movzx   bx, bl
  283.     dec     bx
  284.     shl     bx, 1                       ;Multiply by two for table
  285.     mov     dx, [GDMErrorTable+bx]      ;Get offset of correct error message
  286.     mov     ah, 9                       ;Display error message
  287.     int     21h
  288.     jmp     Exit                        ;Return to DOS
  289. ;-------
  290. @@: mov     cx, 32
  291.     mov     bx, offset ModHead.PanMap
  292.     xor     al, al                      ;channel counter set to zero
  293. ChanScanLoop:
  294.     cmp     byte ptr ds:[bx], 0FFh
  295.     je      @F
  296.     inc     al                          ;increment channel counter
  297. @@: inc     bx
  298.     dec     cx
  299.     jnz     ChanScanLoop
  300.  
  301.     mov     byte ptr Temp, al
  302.     call    StartOutput
  303.     mov     Temp2, ax
  304.  
  305.     mov     ah, 9h                      ;Print number of channels in module
  306.     mov     dx, offset SayChannels
  307.     int     21h
  308.     movzx   ax, byte ptr Temp
  309.     call    PrintDecimal
  310.  
  311.     mov     ah, 9h
  312.     mov     dx, offset CRLF
  313.     int     21h
  314.  
  315.     mov     ah, 9h                      ;Print number oversampling rate
  316.     mov     dx, offset SayOversample
  317.     int     21h
  318.     mov     ax, Temp2
  319.     call    PrintDecimal
  320.     mov     ah, 9h                      ;Print number oversampling rate
  321.     mov     dx, offset SayOversample2
  322.     int     21h
  323.  
  324.     mov     ah, 9h
  325.     mov     dx, offset CRLF
  326.     int     21h
  327.  
  328.     call    StartMusic
  329.  
  330. ;-------
  331.     xor     ah, ah                      ;wait for a key press
  332.     int     16h
  333. ;-------
  334.     call    StopMusic
  335.     call    StopOutput
  336.     call    UnloadModule
  337.     call    FreeMSE
  338.  
  339. ;------- Exit Program
  340. Exit:
  341.     mov     ax, 4C00h
  342.     int     21h
  343. ;-------
  344.  
  345. ;Purpose: Print a decimal number to STDOUT.
  346. ;Calling: ax - number to print
  347. ;Returns: none
  348. PrintDecimal        proc        uses ax bx cx dx
  349. local   Number:word, PrintFlag:byte
  350.  
  351.     mov     Number, ax                  ;save the number to print
  352.     mov     PrintFlag, 0
  353.  
  354.     mov     ax, 10000
  355. PrintLoop:
  356.     mov     dl, '0'
  357.  
  358. IncLoop:
  359.     cmp     Number, ax
  360.     jb      PrintIt
  361.     sub     Number, ax
  362.     inc     dl
  363.     jmp     IncLoop
  364.  
  365. PrintIt:
  366.     cmp     dl, 48
  367.     je      @F
  368.     mov     PrintFlag, 1
  369. @@: cmp     PrintFlag, 0
  370.     jz      SkipPrint
  371.  
  372.     push    ax
  373.     mov     ah, 02h
  374.     int     21h
  375.     pop     ax
  376.  
  377. SkipPrint:
  378.     xor     dx, dx
  379.     mov     bx, 10
  380.     div     bx
  381.     or      ax, ax
  382.     jnz     PrintLoop
  383.  
  384.     ret
  385. PrintDecimal        endp
  386.  
  387. ;Purpose: Print a hexidecimal number to STDOUT.
  388. ;Calling: ax - number to print
  389. ;Returns: none
  390. PrintHex            proc        uses ax bx cx dx ds
  391. local   Number:word, PrintFlag:byte
  392.  
  393.     mov     Number, ax                  ;save the number to print
  394.     mov     PrintFlag, 0
  395.     mov     ax, @data
  396.     mov     ds, ax
  397.  
  398.     mov     cl, 12
  399. PrintLoop:
  400.     mov     bx, Number
  401.     shr     bx, cl
  402.     and     bx, 0Fh
  403.     jnz     @F
  404.     cmp     PrintFlag, 0
  405.     jz      SkipPrint
  406.  
  407. @@: mov     dl, [HexTable+bx]
  408.     mov     ah, 02h
  409.     int     21h
  410.     mov     PrintFlag, 1
  411.  
  412. SkipPrint:
  413.     sub     cl, 4
  414.     cmp     cl, 0
  415.     jnl     PrintLoop
  416.  
  417.     ret
  418. PrintHex            endp
  419. end Start
  420.