home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / msdos / sndbords / proaudio / pcmtlsrc / pcmtlsrc.arj / PCM.ARJ / _I94F92.INC < prev    next >
Text File  |  1992-09-18  |  13KB  |  579 lines

  1. ;$Author:   BCRANE  $
  2. ;$Date:   01 Sep 1992 13:35:00  $
  3. ;$Header:   X:/sccs/sdkapp/_i94f92.inv   1.3   01 Sep 1992 13:35:00   BCRANE  $
  4. ;$Log:   X:/sccs/sdkapp/_i94f92.inv  $
  5. ;
  6. ;   Rev 1.3   01 Sep 1992 13:35:00   BCRANE
  7. ;not exactly sure
  8. ;
  9. ;   Rev 1.2   31 Aug 1992 19:10:04   BCRANE
  10. ;added check for 16-bit silence
  11. ;
  12. ;   Rev 1.1   31 Aug 1992 09:34:44   BCRANE
  13. ;added support for 16-bit 
  14. ;
  15. ;   Rev 1.0   29 Jul 1992 16:57:26   BCRANE
  16. ;Initial revision.
  17. ;$Logfile:   X:/sccs/sdkapp/_i94f92.inv  $
  18. ;$Modtimes$
  19. ;$Revision:   1.3  $
  20. ;$Workfile:   _i94f92.inc  $ 
  21.  
  22. ;; shark functions
  23. ;; dx:ax can be used to return values
  24. ;; si can be trashed
  25. ;; no other precautions taken
  26.  
  27.     if VERBOSE
  28.     align 256
  29.     db '_i94f92.inc: copyright Media Vision, Inc., 1992', 00h
  30.     endif
  31.  
  32. ;; i94f92() - load a sound for later play through keyboard
  33. ;; es:bx points to an i94f92buf.
  34. ;; intr09() - our int 09 handler 
  35.  
  36. i94f92buf struc
  37. f92snum dw 0
  38. f92xmsh dw 0
  39. f92xmso    dd 0
  40. f92xmss dd 0
  41. f92rate dd 0
  42. f92chan dw 0
  43. f92comp dw 0
  44. f92dsiz dw 0
  45. i94f92buf ends
  46.  
  47. MAXHANDLES equ 64
  48. pd1buf i94f92buf 1 dup (<0,0,0,0,0>)
  49. f92buf i94f92buf MAXHANDLES dup (<0,0,0,0,0>)
  50. pd2buf i94f92buf 1 dup (<0,0,0,0,0>)
  51.  
  52. ourdmaoff    dw 0
  53. ourdmaseg    dw 0B000h
  54. ourdmasize    dw 1024
  55. ourdmadivs    dw 64
  56. ourdivsize    dw 1024*16/64
  57.  
  58. looping        db 0
  59.  
  60. _i94f92 proc near
  61.  
  62.     pushall
  63.  
  64.     mov ax, es        ; ds:si has es:bx
  65.     mov ds, ax
  66.     mov si, bx
  67.  
  68.     mov ax, cs        ; es:di has cs:f92buf
  69.     mov es, ax
  70.     mov di, offset f92buf
  71.  
  72.     mov cx, ds:[si].f92snum    ; get sound number (1 through 8)
  73.     dec cx            ; make 0 through 7
  74.     and cx, MAXHANDLES- 1    ; ensure not out of range
  75.     mov ax, type i94f92buf    ; get size of structure
  76.     jcxz f92doneadding    ; skip ahead if we want first structure
  77.     
  78. @@:    add di, ax        ; point into structure array
  79.     loop @B
  80.  
  81. f92doneadding:
  82.     cmp ds:[si].f92xmsh, 0    ; if handle is zero
  83.     jnz @F
  84.     mov ds:[si].f92snum, 0    ; then zero out the number (delete entry)
  85.  
  86. @@:    mov cx, ax        ; cx has size of structure
  87.     rep movsb        ; store this guy
  88.  
  89.     popall
  90.     ret
  91. _i94f92 endp
  92.  
  93. int09_semaphore    db    -1
  94. lastinptr    dw    0
  95.  
  96. @kb_flag    equ 017h
  97. @buffer_head    equ 01Ah
  98. @buffer_tail    equ 01Ch
  99. @kb_buffer    equ 01Eh
  100. @kb_end        equ @kb_buffer+(16*2)
  101.  
  102. routine1code dw 0203h    ; scancode for '1' SHL 16 + (Left Shift| Right Shift)
  103. routine2code dw 0303h    ; scancode for '2' SHL 16 + (Left Shift| Right Shift)
  104. routine3code dw 0403h    ; scancode for '3' SHL 16 + (Left Shift| Right Shift)
  105. routine4code dw 0503h    ; scancode for '4' SHL 16 + (Left Shift| Right Shift)
  106. routine5code dw 0603h    ; scancode for '5' SHL 16 + (Left Shift| Right Shift)
  107. routine6code dw 0703h    ; scancode for '6' SHL 16 + (Left Shift| Right Shift)
  108. routine7code dw 0803h    ; scancode for '7' SHL 16 + (Left Shift| Right Shift)
  109. routine8code dw 0903h    ; scancode for '8' SHL 16 + (Left Shift| Right Shift)
  110. routine1spec dw 0207h    ; scancode for '1' SHL 16 + (Left Shift| Right Shift| Control)
  111.  
  112. intr09    proc far
  113.     assume ds:nothing
  114.     assume es:nothing
  115.  
  116.     pushf
  117.     inc word ptr cs:id09.cnt
  118.     popf
  119.     pushf
  120.     sti
  121.     call dword ptr cs:id09.vold
  122.  
  123.     push bx
  124.     push ds
  125.     mov bx, 40h
  126.     mov ds, bx
  127.  
  128.     mov bx, ds:[@buffer_tail]
  129.     cmp bx, ds:[@buffer_head]
  130.     jnz @F
  131.  
  132.     pop ds
  133.     pop bx
  134.     iret
  135.  
  136. @@:
  137.     sub bx, 2
  138.     cmp bx, @kb_buffer
  139.     jge @F
  140.     mov bx, @kb_end-2
  141.  
  142. @@:
  143.     push ax
  144.     push dx
  145.  
  146.     mov ax, ds:[bx]
  147.     mov al, ds:[@kb_flag]
  148.     and al, 0Fh
  149.  
  150.     lea dx, routine
  151.     cmp ax, cs:[routine1code]
  152.     jz ouin09_doit
  153.  
  154.     cmp ax, cs:[routine2code]
  155.     jz ouin09_doit
  156.  
  157.     cmp ax, cs:[routine3code]
  158.     jz ouin09_doit
  159.  
  160.     cmp ax, cs:[routine4code]
  161.     jz ouin09_doit
  162.  
  163.     cmp ax, cs:[routine5code]
  164.     jz ouin09_doit
  165.  
  166.     cmp ax, cs:[routine6code]
  167.     jz ouin09_doit
  168.  
  169.     cmp ax, cs:[routine7code]
  170.     jz ouin09_doit
  171.  
  172.     cmp ax, cs:[routine8code]
  173.     jz ouin09_doit
  174.  
  175.     cmp ax, cs:[routine1spec]
  176.     jnz ouin09_done
  177.  
  178. ouin09_doit:
  179.     mov ds:[@buffer_tail], bx
  180.     inc cs:[int09_semaphore]
  181.     jnz ouin09_almostdone
  182.  
  183.     push cs
  184.     pop ds
  185.     assume ds:_text
  186.  
  187.     sti
  188.     call dx
  189.  
  190. ouin09_almostdone:
  191.     dec cs:[int09_semaphore]
  192.  
  193. ouin09_done:
  194.     pop dx
  195.     pop ax
  196.  
  197. ouin09_exit:
  198.     pop ds
  199.     pop bx
  200.     iret
  201. intr09    endp
  202.  
  203. xmsmovestruc struc
  204. xmssize dd 0
  205. xmssrch dw 0
  206. xmssrco dd 0
  207. xmstrgh dw 0
  208. xmstrgo dd 0
  209. xmsmovestruc ends
  210.  
  211. xmsm xmsmovestruc <0,0,0,0,0>
  212.  
  213. xmsdriver    dd 0
  214. ourf92buf dw 0
  215. ourbyteleft dd 0
  216. ourxmshandle    dw 0
  217. ourxmsoff    dd 0
  218.  
  219. ourblockcount    dw 0
  220. ourblockoffset    dw 0
  221.     align 32
  222.     db 'OURSTATFLAG:'
  223. ourstatflag dw 0
  224.  
  225. oursemaphore    dw -1
  226. oursavedss    dw 0
  227. oursavedsp    dw 0
  228.  
  229. ourstackstart    label near
  230.     dw    100h dup (0)
  231. ourstack    label near
  232.  
  233. ;; ax has scancode "010Ch, 020Ch ...", so (ah-2)* 2 is offset into xmshandles
  234. routine proc
  235.     inc cs:oursemaphore        ; no reentrancy
  236.     jz @F
  237.     jmp alreadyhere
  238.  
  239. @@:    cli
  240.     mov cs:oursavedss, ss        ; our stack
  241.     mov cs:oursavedsp, sp
  242.     mov sp, cs
  243.     mov ss, sp
  244.     mov sp, offset ourstack
  245.     sti
  246.  
  247.     pushall                ; save everything
  248.     push ds
  249.     push cs
  250.     pop ds                ; ds= cs
  251.  
  252.     cmp ourdmaseg, 0        ; do we have a current DMA buffer?
  253.     jnz @F                 ; yes, continue
  254.     jmp notloaded            ; no, exit
  255.  
  256.  
  257. @@:    push ax                ; save ax
  258.     call StopPCM            ; in case we are playing
  259.     call RemovePCM
  260.     call InitPCM
  261.  
  262.     xor ax, ax
  263.     mov word ptr ourbyteleft[0], ax    ; initialize everything to zero
  264.     mov word ptr ourbyteleft[2], ax
  265.     mov ourxmshandle, ax
  266.     mov word ptr ourxmsoff[0], ax
  267.     mov word ptr ourxmsoff[2], ax
  268.     mov ourstatflag, ax
  269.     mov ourblockcount, ax
  270.  
  271.     mov word ptr [xmsm].xmssize[0], ax
  272.     mov word ptr [xmsm].xmssize[2], ax
  273.     mov [xmsm].xmssrch, ax
  274.     mov word ptr [xmsm].xmssrco[0], ax
  275.     mov word ptr [xmsm].xmssrco[2], ax
  276.     mov [xmsm].xmstrgh, ax
  277.     mov word ptr [xmsm].xmstrgo[0], ax
  278.     mov word ptr [xmsm].xmstrgo[2], ax
  279.     pop ax                ; ax has keystroke
  280.  
  281.     mov looping, 0
  282.     test al, 04h            ; control key also?
  283.     jz @F
  284.     mov looping, 1            
  285. @@:
  286.  
  287.     mov al, ah            ; al= scancode (2 through 9)
  288.     sub al, 2            ; al= 0 through 7
  289.     and al, 07h            ; ensure
  290.     mov ah, type i94f92buf        ; size of structure
  291.     mul ah                ; al= offset into structure array
  292.     cbw                ; ax= offset into structure array
  293.     mov bx, ax            ; bx= offset into structure array
  294.     add bx, offset f92buf    
  295.     mov ourf92buf, bx         ; save pointer to structure
  296.  
  297.     mov ax, [bx].f92xmsh        ; xmshandle
  298.     or ax, ax            ; set?
  299.     jnz @F                ; yes, continue
  300.     jmp notloaded            ; no, exit
  301.  
  302. @@:    mov ourxmshandle, ax        ; our xmshandle
  303.     mov ax, word ptr [bx].f92xmso[0]        ; get xmsoffset
  304.     mov dx, word ptr [bx].f92xmso[2]
  305.     mov word ptr ourxmsoff[0], ax
  306.     mov word ptr ourxmsoff[2], dx
  307.  
  308.     mov ax, word ptr [bx].f92xmss[0]; get size of sound
  309.     mov dx, word ptr [bx].f92xmss[2]
  310.     mov word ptr ourbyteleft[0], ax    ; store in remaining counter
  311.     mov word ptr ourbyteleft[2], dx
  312.  
  313.     mov ax, [bx].f92dsiz        ; datasize
  314.     cmp ax, 8
  315.     jz @F
  316.     cmp ax, 16
  317.     jz @F
  318.     cmp ax, 12
  319.     jz @F
  320.     cmp ax, 24
  321.     jz @F
  322.     mov ax, 8
  323. @@:    push ax
  324.  
  325.     mov ax, [bx].f92comp        ; compression
  326.     cmp ax, 0
  327.     jz @F
  328.     cmp ax, 1
  329.     jz @F
  330.     cmp ax, 2
  331.     jz @F
  332.     xor ax, ax
  333. @@:    push ax
  334.  
  335.     mov ax, [bx].f92chan        ; get channel count
  336.     dec ax                ; convert to mono/stero flag
  337.     push ax
  338.     mov ax, word ptr [bx].f92rate[2]; get samplerate
  339.     push ax
  340.     mov ax, word ptr [bx].f92rate[0]
  341.     push ax
  342.     call PCMInfo            ; tell internals
  343.     add sp, 10            ; sp= -6
  344.  
  345.     mov ax, ourdmadivs        ; number of divisions in dma buffer
  346.     push ax
  347.     mov ax, ourdmasize        ; size of dma buffer in paragraphs
  348.     shl ax, 1
  349.     shl ax, 1
  350.     shl ax, 1
  351.     shl ax, 1            ; converted to bytes
  352.     push ax
  353.     mov ax, ourdmaseg        ; address of dma buffer
  354.     push ax
  355.     mov ax, ourdmaoff
  356.     push ax
  357.     call DMABuffer            ; tell internals
  358.     add sp, 8
  359.  
  360.     mov dx, word ptr ourbyteleft[2]    ; get size of data to process
  361.     mov ax, word ptr ourbyteleft[0]
  362.     mov cx, ourdmasize        ; size of dma buffer in paragraphs
  363.     shl cx, 1
  364.     shl cx, 1
  365.     shl cx, 1
  366.     shl cx, 1            ; converted to bytes
  367.  
  368.     or cx, cx            ; if cx is zero, 64K dma size
  369.     jnz f94sub            ; no special subtraction
  370.     stc                 ; force borrow
  371.     jmp @F                ; subtract from hiword
  372.  
  373. f94sub:
  374.     sub word ptr ourbyteleft[0], cx    ; adjust amount remaining
  375. @@:    sbb word ptr ourbyteleft[2], 0    ; 
  376.     jnc @F                ; not negative, continue
  377.     mov word ptr ourbyteleft[0], 0    ; done with this buffer
  378.     mov word ptr ourbyteleft[2], 0    ; fix this (fill with silence)
  379.     mov bx, ourf92buf
  380.     mov cx, word ptr [bx].f92xmss[0]; get original size
  381.  
  382. @@:    mov ax, cx            ; ax= amount to be moved
  383.     or ax, ax            ; if zero, dma size is 64K
  384.     jnz f94add
  385.     stc                   ; force carry
  386.     jmp @F
  387.     
  388. f94add:
  389.     add word ptr ourxmsoff[0], ax    ; point into xms data for future
  390. @@:    adc word ptr ourxmsoff[2], 0
  391.  
  392.     or ax, ax            ; if ax is zero, 64K dma size
  393.     jnz f94inc
  394.     dec ax                ; this is okay
  395.  
  396. f94inc:    
  397. @@:    inc ourstatflag            ; affect dma div counter
  398.     inc ourblockcount
  399.     sub ax, ourdivsize        ; subtract out divsize of data
  400.     ja @B                ; if not zero or negative, again
  401.  
  402. @@:    mov word ptr [xmsm].xmssize[0], cx    ; size to move from XMS
  403.     mov word ptr [xmsm].xmssize[2], 0
  404.     mov ax, ourxmshandle
  405.     mov [xmsm].xmssrch, ax        ; XMS handle
  406.     mov word ptr [xmsm].xmssrco[2],  0    ; XMS offset is zero
  407.     mov word ptr [xmsm].xmssrco[0],  0
  408.     mov [xmsm].xmstrgh, 0        ; target is not XMS
  409.     mov dx, ourdmaseg        ; target is DMA buffer
  410.     mov ax, ourdmaoff
  411.     mov word ptr [xmsm].xmstrgo[2], dx
  412.     mov word ptr [xmsm].xmstrgo[0], ax
  413.  
  414.     mov ax, 4310h            ; get address of handler
  415.     int 2Fh
  416.     mov word ptr [xmsdriver][0], bx
  417.     mov word ptr [xmsdriver][2], es
  418.     mov si, offset xmsm
  419.     mov ah, 0Bh
  420.     call dword ptr [xmsdriver]    ; call xms handler
  421.  
  422.     mov ax, offset newufroutine    ; interrupt handler
  423.     push cs
  424.     push ax
  425.     call UserFunc
  426.     add sp, 4
  427.  
  428.     call PCMPlay            ; play it
  429.  
  430. notloaded:
  431.     pop ds                ; exiting, restore
  432.     popall
  433.  
  434.     cli
  435.     mov ss, cs:oursavedss        ; restore stack
  436.     mov sp, cs:oursavedsp
  437.     sti
  438.  
  439. alreadyhere:
  440.     dec cs:oursemaphore        ; we are done
  441.     ret
  442.  
  443. routine endp
  444.  
  445. ufroutine proc far
  446.     push ds
  447.     push cs
  448.     pop ds
  449.  
  450.     inc ourblockcount
  451.     dec ourstatflag
  452.     jnz @F
  453.  
  454.     call StopPCM
  455.  
  456. @@:    pop ds
  457.     retf
  458. ufroutine endp
  459.  
  460. newufroutine proc far
  461.     inc cs:oursemaphore        ; no reentrancy
  462.     jz @F
  463.     dec cs:oursemaphore
  464.     retf
  465.  
  466. @@:    cli
  467.     mov cs:oursavedss, ss        ; set up our stack
  468.     mov cs:oursavedsp, sp
  469.     mov sp, cs
  470.     mov ss, sp
  471.     mov sp, offset ourstack 
  472.     sti
  473.  
  474.     push ax                ; save dx:ax
  475.     push dx
  476.     pushall                ; save everything else
  477.     push ds                ; save in case
  478.     push cs
  479.     pop ds                ; ds= cs
  480.  
  481.     cmp looping, 0            ; looping?
  482.     jz @F                ; no, continue
  483.     jmp ufdone            ; yes, we are done
  484. @@:
  485.     dec ourstatflag            ; processed one
  486.     jnz @F                ; continue if not too slow
  487.  
  488.     call StopPCM            ; we fell behind
  489.     jmp ufdone            ; we are done
  490.  
  491.  
  492. @@:    mov ax, word ptr ourbyteleft[0]    ; get remaining size
  493. @@:    mov dx, word ptr ourbyteleft[2]
  494.     or ax, ax
  495.     jnz @F                ; continue if something left
  496.     or dx, dx
  497.     jnz @F
  498.     jmp ufdone            ; nothing left, we are done
  499.  
  500. @@:    mov cx, ourdivsize        ; get size of a division
  501.     sub ax, cx            ; subtract from remaining size
  502.     sbb dx, 0
  503.     jnb @F                ; continue if not negative
  504.     xor ax, ax            ; else zero it out
  505.     xor dx, dx
  506.  
  507. @@:    mov word ptr ourbyteleft[0], ax    ; store new remaining count
  508.     mov word ptr ourbyteleft[2], dx
  509.  
  510.     mov ax, cx            ; ax= size of division
  511.     mov word ptr [xmsm].xmssize[0], ax    ; size of XMS move
  512.     mov word ptr [xmsm].xmssize[2], 0
  513.     mov ax, ourxmshandle
  514.     mov [xmsm].xmssrch, ax        ; XMS handle
  515.     mov ax, word ptr ourxmsoff[0]    ; offset into XMS memory
  516.     mov dx, word ptr ourxmsoff[2]
  517.     mov word ptr [xmsm].xmssrco[0], ax    ; store in XMS move structure
  518.     mov word ptr [xmsm].xmssrco[2], dx
  519.     add ax, cx            ; add this size to XMS offset
  520.     adc dx, 0
  521.     mov word ptr ourxmsoff[0], ax    ; save offset into XMS for future 
  522.     mov word ptr ourxmsoff[2], dx
  523.  
  524.     mov [xmsm].xmstrgh, 0        ; target is not XMS
  525.     mov ax, ourblockcount        ; count of divisions processed so far
  526.     mov bx, ourdmadivs        ; get block count modulo divisions
  527.     xor dx, dx
  528.     or bx, bx
  529.     jnz @F
  530.     inc bx                  ; default two divisions
  531.     inc bx
  532. @@:    div bx                ; blockcount/divcount
  533.  
  534.     mov ax, dx            ; ax= remainder
  535.     mov bx, ourdivsize        ; get offset into dma buffer
  536.     mul bx
  537.     add ax, ourdmaoff        ; add to address of dma buffer
  538.     mov dx, ourdmaseg
  539.     mov word ptr [xmsm].xmstrgo[0], ax    ; offset into DMA buffer
  540.     mov word ptr [xmsm].xmstrgo[2], dx
  541.  
  542.     mov di, ourf92buf
  543.     mov al, 80h
  544.     cmp [di].f92dsiz, 8
  545.     jz @F
  546.     xor al, al
  547. @@:    mov ah, al
  548.     mov di, ax
  549.     mov es, dx
  550.     shr cx, 1
  551.     rep stosw
  552.     
  553.     mov ax, 4310h
  554.     int 2Fh
  555.     mov word ptr [xmsdriver][0], bx
  556.     mov word ptr [xmsdriver][2], es
  557.     mov si, offset xmsm
  558.     mov ah, 0Bh
  559.     call dword ptr [xmsdriver]    ; move XMS to DMA
  560.  
  561.     inc ourblockcount        ; done this one
  562.     inc ourstatflag            ; added another 
  563.  
  564. ufdone:    pop ds                ; restore
  565.     popall                ; restore the rest
  566.     pop dx                ; restore dx:ax, too
  567.     pop ax
  568.  
  569.     cli
  570.     mov ss, cs:oursavedss        ; restore stack
  571.     mov sp, cs:oursavedsp
  572.     sti
  573.     dec cs:oursemaphore        ; we are done
  574.  
  575.     retf
  576. newufroutine endp
  577.  
  578.  
  579.