home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / dmkit / flat / midpak.asm < prev    next >
Encoding:
Assembly Source File  |  1993-12-31  |  9.1 KB  |  366 lines

  1. ;;************ MIDPAK.ASM, flat-model link layer to MIDPAK functions.
  2. ;;************ written using Borland Assembler in IDEAL mode.  Assumes
  3. ;;************ a DPMI with a flat model address space where selectors
  4. ;;************ DS and ES always point to flat address 0000000000000h!
  5. ;;************ Written and tested with DOS4GW and Watcom C.  Uses
  6. ;;************ standard C calling convention.  Getting this to work
  7. ;;************ under any other DPMI is an excercise left for ths student.
  8. ;;************ Warning!! The Watcom compiler passes 4 bytes on the stack
  9. ;;************ to a cdecl external routine, even if the parameter is only
  10. ;;************ a char.    All of these assembly routines have been defined
  11. ;;************ this way.  If you are usinga compiler that passes different
  12. ;;************ size arguments to cdecl routines, you may want to double
  13. ;;************ check for compatibilities sake.
  14. ;;***
  15. ;;*** Written by John W. Ratcliff (c) 1994
  16. ;;***         Compuserve: 70253,3237
  17. ;;***         Genie: J.RATCLIFF3
  18. ;;***         BBS: 1-314-939-0200
  19. ;;***         Addresss:
  20. ;;***               747 Napa Lane
  21. ;;***               St. Charles, MO 63304
  22. ;;***
  23. ;;***     A $500 per product license fee applies to all commercial software
  24. ;;***     products distributed with any MIDPAK drivers.
  25. ;;***     To pay a license, simply write a check for $500 payable to
  26. ;;***     The Audio Solution, 747 Napa Lane, St. Charles, MO 63304
  27. ;;***     with a copy of your commerical product.  You will receive a signed
  28. ;;***     license agreement from The Audio Solution shortly thereafter.
  29. ;;***     This license fee applies specifically to the inclusion with your
  30. ;;***     distribution disk any of the MIDPAK drivers from The Audio Solution
  31. ;;***     These drivers are copyrighted works, created by me, to enhance the
  32. ;;***     use of sound and music in DOS based commercial software.     The
  33. ;;***     license fees collected are used to maintain the drivers and keep
  34. ;;***     the BBS running.     There is a seperate license fee for the use
  35. ;;***     and distribution of DIGPAK drivers.
  36. ;;***     See accompaning documentation regarding license fees for DIGPAK
  37. ;;***     distribution.    You would be ill-advised to distribute a commercial
  38. ;;***     product containing either DIGPAK and/or MIDPAK drivers without
  39. ;;***     having paid the distribution license fee.  Since your product would
  40. ;;***     contain unlicensed copyrighted software from The Audio Solution,
  41. ;;***     your product could be immediatly required to be removed from retail
  42. ;;***     distribution.    I doubt this is going to be a problem.    Clearly if
  43. ;;***     your product is enhanced by the use of these drivers, your company
  44. ;;***     can easily afford a nominal license fee of $500 in exchange for
  45. ;;***     getting the use of several man-years of software engineering
  46. ;;***     resources.
  47. ;;******************************************************************************
  48.     IDEAL
  49.     P386
  50.     JUMPS
  51.     MODEL FLAT,C
  52.     CODESEG
  53.     LOCALS            ;; Enable local labels
  54.  
  55.     public    PlaySequence
  56.     public    SegueSequence
  57.     public    RegisterXmidi
  58.     public    MidiStop
  59.     public    MidPakClock
  60.     public    MidPakClockAddress
  61.     public    DigPakAvailable
  62.     public    ReportCallbackTrigger
  63.     public    ResetCallbackCounter
  64.     public    ResumePlaying
  65.     public    SequenceStatus
  66.     public    RelativeVolume
  67.     public    SetRelativeVolume
  68.     public    RegisterXmidiFile
  69.     public    PollMidPak
  70.     public    TriggerCountAddress
  71.     public    EventIDAddress
  72.     public    ReportSequenceNumber
  73.     public    CheckMidiIn
  74.     public    InitMP
  75.     public    DeInitMP
  76.  
  77. MID_PLAYSEQUENCE equ 702h
  78. MID_SEGUESEQUENCE equ 703h
  79. MID_REGISTERXMIDI equ 704h
  80. MID_MIDISTOP equ 705h
  81. MID_MIDPAKCLOCK equ 712h
  82. MID_MIDPAKCLOCKADDRESS equ 712h
  83. MID_DIGPAKAVAILABLE equ 701h
  84. MID_REPORTCALLBACKTRIGGER equ 707h
  85. MID_RESETCALLBACKCOUNTER equ 708h
  86. MID_RESUMEPLAYING equ 70Bh
  87. MID_SEQUENCESTATUS equ 70Ch
  88. MID_RELATIVEVOLUME equ 70Eh
  89. MID_SETRELATIVEVOLUME equ 70Fh
  90. MID_REGISTERXMIDIFILE equ 70Dh
  91. MID_POLLMIDPAK equ 711h
  92. MID_TRIGGERCOUNTADDRESS equ 713h
  93. MID_EVENTIDADDRESS equ 714h
  94. MID_REPORTSEQUENCENUMBER equ 716h
  95. MID_BOOTSTRAP equ 710h
  96.  
  97. ;;    int  PlaySequence(short seqnum)
  98. Proc    C PlaySequence near
  99.     ARG    DATA:DWORD
  100.     uses    ebx,ds,es
  101.     mov    eax,MID_PLAYSEQUENCE
  102.     mov    ebx,[DATA]
  103.     int    66h
  104.     ret
  105.     endp
  106.  
  107.  
  108. ;;    int  SegueSequence(int seqnum,int activate)
  109. PROC    C  SegueSequence near
  110.     ARG    SEQ:DWORD,ACT:DWORD
  111.     uses    ebx,ecx,ds,es
  112.     mov    eax,MID_SEGUESEQUENCE         ;
  113.     mov    ebx,[SEQ]
  114.     mov    ecx,[ACT]
  115.     int    66h
  116.     ret
  117.     endp
  118.  
  119.  
  120. ;;    int  RegisterXmidi(char far *midi,int length)
  121. Proc    C   RegisterXmidi near
  122.     ARG    SEQ:DWORD,SLEN:DWORD
  123.     uses    ebx,ecx,esi,edi,es,ds
  124.  
  125.     mov    ebx,[SEQ]        ; Address of sequence.
  126.     mov    ecx,ebx     ; into segment reg
  127.     shr    ecx,4        ; Into segment format
  128.     and    ebx,0Fh     ; offset.
  129.     mov    esi,[SLEN]        ; length of sequence.
  130.     mov    edi,esi     ; into EDI for high word.
  131.     shr    edi,16
  132.     and    esi,0FFFFh    ; Leve low word.
  133.     mov    eax,MID_REGISTERXMIDI         ; Register XMIDI file.
  134.     int    66h
  135.     ret
  136.     endp
  137.  
  138.  
  139. ;;    int  MidiStop(void)
  140. PROC    C   MidiStop near
  141.     uses    ds,es
  142.     mov    eax,MID_MIDISTOP    ; Stop playing current sequence.
  143.     int    66h
  144.     ret
  145.     endp
  146.  
  147. ;; long int MidPakClock(void)
  148. Proc    C   MidPakClock near
  149.     uses    ebx,ecx,edx,ds,es
  150.     mov    eax,MID_MIDPAKCLOCK
  151.     int    66h
  152.     shl    edx,16
  153.     add    eax,edx     ; return in EAX flat-model format
  154.     ret
  155.     endp
  156.  
  157. ;; long int MidPakClock(void)
  158. PROC    C   MidPakClockAddress near
  159.     uses    ebx,ecx,edx,ds,es
  160.  
  161.     xor    ecx,ecx     ; Zero all of EBX
  162.     mov    eax,MID_MIDPAKCLOCKADDRESS
  163.     int    66h
  164.     shl    ecx,4
  165.     mov    ax,bx        ; Offset portion.
  166.     add    eax,ecx     ; form flat-model address.
  167.     ret
  168.     endp
  169.  
  170. PROC    C DigPakAvailable near
  171.     uses    ds,es
  172.     mov    eax,MID_DIGPAKAVAILABLE
  173.     int    66h
  174.     ret
  175.     endp
  176.  
  177. PROC    C ReportCallbackTrigger near
  178.     uses    edx,ds,es
  179.     mov    eax,MID_REPORTCALLBACKTRIGGER
  180.     int    66h
  181.     shl    edx,16        ; Into high word.
  182.     add    eax,edx     ; Form long int result.
  183.     ret
  184.     endp
  185.  
  186. Proc    C   ResetCallbackCounter near
  187.     uses    ds,es
  188.     mov    eax,MID_RESETCALLBACKCOUNTER
  189.     int    66h
  190.     ret
  191.     endp
  192.  
  193. Proc    C  ResumePlaying near
  194.     uses    ds,es
  195.     mov    eax,MID_RESUMEPLAYING
  196.     int    66h
  197.     ret
  198.     endp
  199.  
  200. PROC    C SequenceStatus near
  201.     uses    ds,es
  202.     mov    eax,MID_SEQUENCESTATUS
  203.     int    66h
  204.     ret
  205.     endp
  206.  
  207. PROC    C RelativeVolume near
  208.     uses    ds,es
  209.     mov    ax,MID_RELATIVEVOLUME
  210.     int    66h
  211.     ret
  212.     endp
  213.  
  214. PROC    C SetRelativeVolume near
  215.     ARG    VOL:DWORD,TIME:DWORD
  216.     uses    ebx,ecx,ds,es
  217.     mov    eax,MID_SETRELATIVEVOLUME
  218.     mov    ebx,[VOL]
  219.     mov    ecx,[TIME]
  220.     int    66h
  221.     ret
  222.     endp
  223.  
  224. PROC    C RegisterXmidiFile near
  225.     ARG    FNAME:DWORD
  226.     uses    ebx,ecx,ds,es
  227.  
  228.     mov    ecx,[FNAME]    ; Get flat model address.
  229.     cmp    ecx,0FFFFFh    ; in the first 1mb of address space?
  230.     jle    @@LOW
  231.     mov    eax,4        ; Treat it like a registration error.
  232.     jmp short @@OUT
  233. @@LOW:    mov    ebx,ecx     ; Offset into EBX
  234.     and    ebx,0Fh     ; Just leave offset.
  235.     shr    ecx,4        ; Into segment portion.
  236.     mov    ax,MID_REGISTERXMIDIFILE
  237.     int    66h
  238. @@OUT:
  239.     ret
  240.     endp
  241.  
  242. PROC    C PollMidPak near
  243.     uses    ds,es
  244.     mov    eax,MID_POLLMIDPAK
  245.     int    66h
  246.     ret
  247.     endp
  248.  
  249. PROC    C TriggerCountAddress near
  250.     uses    edx,ds,es
  251.     xor    edx,edx
  252.     mov    eax,MID_TRIGGERCOUNTADDRESS
  253.     int    66h
  254.     shl    edx,4        ; Segment shift into flat space.
  255.     add    eax,edx     ; add offset, into flat space.
  256.     ret
  257.     endp
  258.  
  259. PROC    C EventIDAddress near
  260.     uses    edx,ds,es
  261.     xor    edx,edx
  262.     mov    eax,MID_EVENTIDADDRESS
  263.     int    66h
  264.     shl    edx,4
  265.     add    eax,edx
  266.     ret
  267.     endp
  268.  
  269. PROC    C ReportSequenceNumber near
  270.     uses    ds,es
  271.     mov    eax,MID_REPORTSEQUENCENUMBER
  272.     int    66h
  273.     ret
  274.     endp
  275.  
  276.  
  277. Proc    C CheckMidiIn        near
  278.     uses    ebx,ds,es
  279.  
  280.     mov    ebx,66h*4h
  281.     mov    eax,[ds:ebx]    ; Get addresss or interrupt vector.
  282.     or    eax,eax
  283.     jz    @@NOT        ; Exit if vector is null.
  284.     mov    bx,ax        ; Get offset portion.
  285.     shr    eax,(16-4)    ; Get segment portion down.
  286.     and    eax,0FFFFF0h    ; and off remainder.
  287.     add    ebx,eax     ; now have real-address.
  288.     sub    ebx,6        ; point back to identifier
  289.     xor    eax,eax     ; Zero out entire EAX return register.
  290.     cmp    [word ebx],'IM'  ; Midi driver?
  291.     jne    @@NOT
  292.     cmp    [word ebx+2],'ID'  ; full midi driver identity string?
  293.     jne    @@NOT
  294.     mov    eax,1
  295. @@EXT:
  296.     ret
  297. @@NOT:    xor    eax,eax         ; Zero return code.
  298.     jmp short @@EXT
  299.     endp
  300.  
  301. Proc    C InitMP near
  302.     ARG    MIDPAK:DWORD,ADV:DWORD,AD:DWORD
  303.     uses    ebx,ecx,esi,edi,es,ds
  304.  
  305.     mov    ebx,[MIDPAK]    ; Get the address of the 'supposed' DIGPAK.
  306.     cmp    [byte ebx+3],'M'        ; Does it say digpak?
  307.     jne    @@FREE
  308.     cmp    [byte ebx+4],'I'        ;
  309.     jne    @@FREE
  310.     cmp    [byte ebx+5],'D'
  311.     jne    @@FREE
  312.     cmp    [byte ebx+6],'P'
  313.     jne    @@FREE
  314.     cmp    [byte ebx+7],'A'
  315.     jne    @@FREE
  316.     cmp    [byte ebx+8],'K'
  317.     jne    @@FREE
  318. ;; Ok, it SAY's MIDPAK
  319.     shr    ebx,4        ; Into segment size.
  320.     sub    ebx,10h     ; org 100h, segment
  321.     mov    ecx,200h    ; offset
  322.     mov    eax,0301h    ; simulate realmode far proc.
  323.     int    66h
  324.     or    ax,ax
  325.     jnz    @@FREE
  326.     mov    ebx,[ADV]    ; Get far address of ADV.
  327.     shr    ebx,4        ; Into SEGMENT.
  328.     xor    ecx,ecx     ; Offset MUST be ZERO!
  329.     mov    edx,[AD]    ; get flat address of .AD file.
  330.     mov    esi,edx     ; Into SI
  331.     and    esi,0Fh     ; Leave just offset portion.
  332.     shr    edx,4        ; into segment.
  333.     mov    eax,MID_BOOTSTRAP
  334.     int    66h
  335. @@RET:
  336.     ret
  337. @@FREE: mov    eax,9999     ; Invalid driver return code.
  338.     jmp short @@RET
  339.     endp
  340.  
  341. Proc    C DeInitMP near
  342.     ARG    MIDPAK:DWORD
  343.     uses    ebx,ecx,esi,edi,ds,es
  344.  
  345.     mov    ebx,[MIDPAK]
  346.     shr    ebx,4        ; Into segment size.
  347.     sub    ebx,10h     ; org 100h
  348.     mov    ecx,203h    ; offset.
  349.     mov    eax,0301h    ; simulate realmode far proc.
  350.     int    66h
  351.     or    ax,ax
  352.     jnz    @@FREE
  353.     mov    ax,1        ; Success.
  354. @@RET:
  355.     ret
  356. @@FREE:
  357.     xor    ax,ax    ; Zero failed return code
  358.     jmp short @@RET
  359.     ret
  360.     endp
  361.  
  362.  
  363.     ends
  364.     end
  365.  
  366.