home *** CD-ROM | disk | FTP | other *** search
/ 25 Mega Hit Games for DOS / 25_Mega_Hit_Games_Micro_Star_1996.iso / trtb10 / midpak.asm < prev    next >
Assembly Source File  |  1993-10-19  |  7KB  |  358 lines

  1. ;; MIDPAK.ASM            January 5, 1992, John W. Ratciff
  2. ;;
  3. ;; This piece of source provides C procedure call hooks down into
  4. ;; the resident TSR sound driver.  Use the call CheckIn to find out
  5. ;; if the sound driver is in memory.  See the C header file MIDPAK.H
  6. ;; for prototype information.
  7. ;;
  8. ;; This file is in the format for Turbo Assembler's IDEAL mode.  The
  9. ;; IDEAL mode syntax makes a lot more sense for 8086 than the old
  10. ;; MASM format.  MASM has recently been updated to provide some of the
  11. ;; functions that Turbo Assembler has had for a number of years.  I prefer
  12. ;; to consider Turbo Assembler the standard for 8086 assemblers.
  13. ;; IDEAL mode functionality includes true local labels, real data structures,
  14. ;; typecasting, automatic argument passing and local memory.
  15. ;; Converting any of this code into MASM format is an excercise left for
  16. ;; the student.
  17.  
  18.  
  19.     LOCALS            ;; Enable local labels
  20.  
  21.         IDEAL                   ;; Use Turbo Assembler's IDEAL mode
  22.     JUMPS
  23.  
  24.     ; Driver load and unload calls.  Requires that the application provide
  25.     ; memory allocation functions and access to DOSCALLS.OBJ.
  26.  
  27. IFNDEF    LOADABLE_DRIVERS        ; If not already defined.
  28. LOADABLE_DRIVERS    equ    1    ; Set true to enable
  29. ENDIF
  30.  
  31. SMALL_MODEL    equ    0   ;: True if declaring C procedures as near.
  32.             ; It is false here because all procedures are
  33.             ; far, so that you can link any memory model
  34.             ; to theme. (They are prototyped as well.)
  35.  
  36.  
  37.         INCLUDE "PROLOGUE.MAC"          ;; common prologue
  38.  
  39.  
  40. SEGMENT  _TEXT BYTE PUBLIC 'CODE'               ;; Set up _TEXT segment
  41.         ENDS
  42.  
  43.     ASSUME    CS: _TEXT, DS: _TEXT, SS: NOTHING, ES: NOTHING
  44.  
  45. IF      LOADABLE_DRIVERS
  46. ;; These external procedures are required for the Load and Unload sound
  47. ;; driver calls.  The need access to memory allocation functions.
  48. ;; The application must provide memory allocation through the functions
  49. ;; memfree and memalloc.  The user may redirect these either through DOSCALLS
  50. ;; which uses the standard DOS memory allocate, or through their C compiler's
  51. ;; memory allocation functions.
  52.     extrn    _memfree:far     ; Application controlled memory allocation.
  53.     extrn    _memalloc:far    ; Application controlled memory allocation.
  54.     extrn    _floadpara:far        ; File load procedure, found in DOSCALLS!
  55. ENDIF
  56.  
  57. SEGMENT _TEXT
  58.  
  59. Macro    CPROC    name        ; Macro to establish a C callable procedure.
  60.     public    _&name
  61. IF    SMALL_MODEL
  62. Proc    _&name    near
  63. ELSE
  64. Proc    _&name    far
  65. ENDIF
  66.     endm
  67.  
  68. ;;    int  PlaySequence(int seqnum)
  69. CPROC    PlaySequence
  70.     ARG    DATA:WORD
  71.     PENTER    0
  72.  
  73.     mov    ax,0702h    ; Function #3, DigPlay
  74.     mov    bx,[DATA]
  75.     int    66h
  76.  
  77.     PLEAVE
  78.     ret
  79.     endp
  80.  
  81.  
  82. ;;    int  SegueSequence(int seqnum,int activate)
  83. CPROC    SegueSequence
  84.     ARG    SEQ:WORD,ACT:WORD
  85.     PENTER    0
  86.  
  87.         mov     ax,0703h        ;
  88.     mov    bx,[SEQ]
  89.     mov    cx,[ACT]
  90.     int    66h
  91.  
  92.     PLEAVE
  93.     ret
  94.     endp
  95.  
  96.  
  97. ;;    int  RegisterXmidi(char far *midi)
  98. CPROC    RegisterXmidi
  99.     ARG    SEQOFF:WORD,SEQSEG:WORD,LENL:WORD,LENH:WORD
  100.     PENTER    0
  101.  
  102.     push    di
  103.     push    si
  104.  
  105.     mov    ax,0704h    ; Register XMIDI file.
  106.     mov    bx,[SEQOFF]
  107.     mov    cx,[SEQSEG]
  108.     mov    si,[LENL]
  109.     mov    di,[LENH]    ; Length of XMIDI data.
  110.     int    66h
  111.  
  112.     pop    si
  113.     pop    di
  114.  
  115.  
  116.     PLEAVE
  117.     ret
  118.     endp
  119.  
  120.  
  121. ;;    int  MidiStop(void)
  122. CPROC    MidiStop
  123.     mov    ax,0705h    ; Stop playing current sequence.
  124.     int    66h
  125.     ret
  126.     endp
  127.  
  128. ;; long int MidPakClock(void)
  129. CPROC    MidPakClock
  130.     mov    ax,712h
  131.     int    66h
  132.     ret
  133.     endp
  134.  
  135. ;; long int MidPakClock(void)
  136. CPROC    MidPakClockAddress
  137.     mov    ax,712h
  138.     int    66h
  139.     mov    ax,bx        ; offset portion of address
  140.     mov    dx,cx        ; segment portion of address
  141.     ret
  142.     endp
  143.  
  144. ;;    void RemapChannel(sequence,physical)
  145. CPROC    RemapChannel
  146.     ARG    sequence:word,physical:word
  147.     PENTER    0
  148.  
  149.     mov    ax,0706h    ; Stop playing current sequence.
  150.     mov    bx,[sequence]
  151.     mov    cx,[physical]
  152.     int    66h
  153.  
  154.     PLEAVE
  155.     ret
  156.     endp
  157.  
  158.  
  159.  
  160.  
  161. ;;    int  CheckMidiIn(void);   // Is sound driver available?
  162. CPROC    CheckMidiIn
  163.     call    CheckMidiIn
  164.     ret
  165.     endp
  166.  
  167. Proc    CheckMidiIn near
  168.     push    ds        ; Save ds register.
  169.     push    si
  170.  
  171.     mov    si,66h*4h    ; get vector number
  172.         xor     ax,ax           ; zero
  173.         mov     ds,ax           ; point it there
  174.     lds    si,[ds:si]    ; get address of interupt vector
  175.         or      si,si           ; zero?
  176.         jz      @@CIOUT         ; exit if zero
  177.         sub     si,6            ; point back to identifier
  178.  
  179.     cmp    [word si],'IM'  ; Midi driver?
  180.     jne    @@CIOUT
  181.     cmp    [word si+2],'ID'  ; full midi driver identity string?
  182.     jne    @@CIOUT
  183.     mov    ax,1
  184. @@EXT:
  185.     pop    si
  186.     pop    ds
  187.     ret
  188. @@CIOUT: xor    ax,ax        ; Zero return code.
  189.     jmp short @@EXT
  190.     endp
  191.  
  192. CPROC    DigPakAvailable
  193.     mov    ax,701h
  194.     int    66h
  195.     ret
  196.     endp
  197.  
  198. CPROC    ReportCallbackTrigger
  199.     mov    ax,707h
  200.     int    66h
  201.     ret
  202.     endp
  203.  
  204. CPROC    ResetCallbackCounter
  205.     mov    ax,708h
  206.     int    66h
  207.     ret
  208.     endp
  209.  
  210. CPROC    MidiSleep
  211.     mov    ax,709h
  212.     int    66h
  213.     ret
  214.     endp
  215.  
  216. CPROC    MidiAwake
  217.     mov    ax,70Ah
  218.     int    66h
  219.     ret
  220.     endp
  221.  
  222. CPROC    ResumePlaying
  223.     mov    ax,70Bh
  224.     int    66h
  225.     ret
  226.     endp
  227.  
  228. CPROC    SequenceStatus
  229.     mov    ax,70Ch
  230.     int    66h
  231.     ret
  232.     endp
  233.  
  234. CPROC    RelativeVolume
  235.     mov    ax,70Eh
  236.     int    66h
  237.     ret
  238.     endp
  239.  
  240. CPROC    SetRelativeVolume
  241.     ARG    VOL:WORD,TIME:WORD
  242.     PENTER    0
  243.     mov    ax,70Fh
  244.     mov    bx,[VOL]
  245.     mov    cx,[TIME]
  246.     int    66h
  247.     PLEAVE
  248.     ret
  249.     endp
  250.  
  251. CPROC    RegisterXmidiFile
  252.     ARG    FNAMEL:WORD,FNAMEH:WORD
  253.     PENTER    0
  254.  
  255.     mov    ax,70Dh
  256.     mov    bx,[FNAMEL]
  257.     mov    cx,[FNAMEH]
  258.     int    66h
  259.  
  260.     PLEAVE
  261.     ret
  262.     endp
  263.  
  264. CPROC    PollMidPak
  265.     mov    ax,0711h
  266.     int    66h
  267.     ret
  268.     endp
  269.  
  270. CPROC    TriggerCountAddress
  271.     mov    ax,713h
  272.     int    66h
  273.     ret
  274.     endp
  275.  
  276. CPROC    EventIDAddress
  277.     mov    ax,714h
  278.     int    66h
  279.     ret
  280.     endp
  281.  
  282. CPROC    ReportSequenceNumber
  283.     mov    ax,716h
  284.     int    66h
  285.     ret
  286.     endp
  287.  
  288.  
  289.  
  290. IF    LOADABLE_DRIVERS
  291. LABEL    InstallDriver    DWORD
  292. InstOff dw    0200h    ; Offset of first jump.
  293. InstSeg dw    ?    ; Segment of audio driver.
  294. LABEL    DeInstallDriver DWORD
  295. DeInstOff dw    0203h    ; Offset of deinstall jump
  296. DeInstSeg dw    ?    ; Segment of audio driver.
  297.  
  298. CPROC    DeInitMP
  299.     ARG    MIDSEG:WORD
  300.     PENTER    0
  301.  
  302.     mov    ax,[MIDSEG]
  303.     sub    ax,10h
  304.     mov    [cs:DeInstSeg],ax
  305.     call    [cs:DeInstallDriver]       ; Do indirect call to deinstall the driver.
  306.  
  307.     PLEAVE
  308.     ret
  309.     endp
  310.  
  311. CPROC    InitMP
  312.     ARG    MIDSEG:WORD,ADV:WORD,ADL:WORD,ADH:WORD
  313.     PENTER    0
  314.     PushCREGS
  315.  
  316.     mov    ax,[MIDSEG] ; Save segment loaded at.
  317.     mov    es,ax        ; Into ES
  318.     sub    ax,10h        ; Less 10 paragraphs for the org 100h
  319. ;; Check Identity string 'MIDPAK' if not located starting 3 bytes into
  320. ;; the file loaded, then this is not a compatible digitized sound driver.
  321.     mov    cx,ax
  322.     mov    ax,9999     ; Not valid driver.
  323.     cmp    [byte es:3],'M' ; M in MIDPAK?
  324.     jne    @@OUT
  325.     cmp    [byte es:4],'I' ; I in MIDPAK?
  326.     jne    @@OUT
  327.     cmp    [byte es:5],'D' ; D in MIDPAK?
  328.     jne    @@OUT
  329.     cmp    [byte es:6],'P' ; P in MIDPAK?
  330.     jne    @@OUT
  331.     cmp    [byte es:7],'A' ; A in MIDPAK?
  332.     jne    @@OUT
  333.     cmp    [byte es:8],'K' ; K in MIDPAK?
  334.     jne    @@OUT
  335.     mov    [cs:InstSeg],cx ; set jmp segment address.
  336.     call    [cs:InstallDriver]    ; Install the driver.
  337.     or    ax,ax        ; Installed ok?
  338.     jnz    @@OUT
  339.     mov    bx,[ADV]       ; Segment portion of .ADV file
  340.     xor    cx,cx        ; offset portion must be ZERO!
  341.     mov    dx,[ADH]    ; Segment portion of .AD file.
  342.     mov    si,[ADL]    ; Offset portion of .AD file.
  343.     mov    ax,710h
  344.     int    66h
  345. @@OUT:
  346.     PopCREGS
  347.     PLEAVE
  348.     ret
  349.     endp
  350.  
  351. ENDIF
  352.  
  353.  
  354.  
  355.     ends
  356.     end
  357.  
  358.