home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / CDMP16.ZIP / SOURCE.ZIP / SNDTIMER.INC < prev    next >
Encoding:
Text File  |  1995-01-26  |  9.4 KB  |  474 lines

  1. ;[]------------------------------------------------------------------------[]
  2. ;|                                                                          |
  3. ;| (c) 1993,1994 by Marc van Shaney , aka Kaya Memisoglu                    |
  4. ;|                                                                          |
  5. ;| Dieser Assembler-Source-Code unterliegt dem Urheberrecht von Kaya        |
  6. ;| Memisoglu und darf auch nur mit seiner schriftlichen Genehmigung         |
  7. ;| in kommerziellen Programmen verwendet werden.                            |
  8. ;| Ich übernehme keinerlei Verantwortung für eventuelle Schäden,die dieses  |
  9. ;| Programm verursacht.                                                     |
  10. ;|                                                                          |
  11. ;|                                                                          |
  12. ;|                                                                          |
  13. ;| 18.1.1994 Kaya Memisoglu                                                 |
  14. ;|                                                                          |
  15. ;[]------------------------------------------------------------------------[]
  16.  
  17. ; !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
  18. ; !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
  19. ;
  20. ; I DO NOT SAVE THE REGISTER VARIABLES SI AND DI IN THIS CODE AND IN SOME
  21. ; OTHER MODULES. SO MAKE SURE BEFORE COMPILING THIS CODE THAT THE REGISTER
  22. ; VARIABLES IN BORLAND C ARE SET TO *NONE*.
  23. ; BUT IF YOU STILL WANT TO USE THEM, YOU HAVE TO SAVE THEM BY CHANGING THIS
  24. ; CODE !!!
  25. ;
  26. ; !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
  27. ; !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
  28.  
  29. ;The Sound_Block structure:
  30. ;    word         Sample_rate
  31. ;    word         Sample_Size
  32. ;    byte         Bits_per_Sample
  33. ;    byte         Channels
  34. ;    10 bytes     resreved
  35. ;
  36. ;The following external MACROS can be defined
  37. ;  EXTERNAL_ROUTINES
  38. ;  DRV_NAME        - Only if you want to link the driver !!!
  39. ;  DRV_INIT
  40. ;  DRV_EXIT
  41. ;  DRV_TEXT
  42. ;  DRV_VERSION
  43. ;  VOICE_INIT
  44. ;  VOICE_STOP
  45. ;  VOICE_START
  46. ;  VOICE_OUT
  47.  
  48.  
  49.  
  50. P386
  51. LOCALS
  52.  
  53. MAJOR_VERSION    equ    3
  54. SAMPLE_RATE     equ       0
  55. SAMPLE_SIZE    equ       2
  56. TRUE           equ       1
  57. FALSE           equ       -1
  58.  
  59. SOUND_CAN_PLAY        equ    1
  60. SOUND_CAN_RECORD    equ    2
  61. SOUND_CAN_STEREO    equ    4
  62. SOUND_CAN_MONO        equ    8
  63. SOUND_CAN_8BIT        equ    16
  64. SOUND_CAN_16BIT        equ    32
  65. SOUND_USES_TIMER    equ    64
  66.  
  67. SOUND_READY             equ  2
  68. SOUND_PLAYING        equ  1
  69. SOUND_RECORDING        equ  4
  70.  
  71. ifndef DRV_NAME
  72. .MODEL USE16 TINY
  73. .Code
  74.  
  75.       ORG 0004h             ;Bei einem MALLOC ist der Offset immer 4 ! (Hoffentlich !!!)
  76. PUBLIC C DISPATCH
  77. DISPATCH PROC FAR
  78.       DB 'Cyberdyne Driver',0,'               '  ; 32 Bytes
  79.       DB 'SOUND',0,'          '               ;16 Bytes
  80.       DB DRV_TEXT                             ; 32 Bytes
  81.       DW 256*MAJOR_VERSION+DRV_VERSION        ;Version
  82.       DW 9                  ;Anzahl der Funktionen (und damit
  83.                 ; Segmentpräfixe !!!)
  84.       DW Config_Info
  85.       DW ?
  86.  
  87.       DW Init_Driver
  88.       DW ?
  89.       DW Exit_Driver
  90.       DW ?
  91.       DW Play_Voice
  92.       DW ?
  93.       DW Stop_Voice
  94.       DW ?
  95.       DW Record_Voice
  96.       DW ?
  97.       DW Set_Play_Handler
  98.       DW ?
  99.       DW Set_Record_Handler
  100.       DW ?
  101.       DW Set_Next_Block
  102.       DW ?
  103.       DD SOUND_CAN_PLAY or SOUND_CAN_MONO or SOUND_CAN_8BIT or SOUND_USES_TIMER
  104.       DW 0
  105.       DW 44000
  106.  
  107.  
  108. Status        DW ?
  109. Data_Adress     DD ?
  110. Data_Size       DW ?
  111.  
  112. IntOffset       DW ?
  113. IntSegment      DW ?
  114.  
  115. Play_Handler    DD 0
  116. Record_Handler    DD 0
  117. Voice_Rate      DW ?
  118. Timer_Constant    DW ?
  119.  
  120. Next_Block     DD 0
  121. Busy        db ?
  122. DISPATCH ENDP
  123.  
  124.  
  125. else
  126.  
  127.  
  128. .MODEL USE16 LARGE
  129. .Data
  130. DRV_NAME
  131.  
  132.  
  133. .Code
  134. DISPATCH PROC FAR
  135.       DB 'Cyberdyne Driver',0,'               '  ; 32 Bytes
  136.       DB 'SOUND',0,'          '               ;16 Bytes
  137.       DB DRV_TEXT                             ; 32 Bytes
  138.       DW 256*MAJOR_VERSION+DRV_VERSION        ;Version
  139.       DW 9                  ;Anzahl der Funktionen (und damit
  140.                 ; Segmentpräfixe !!!)
  141.       DW Config_Info
  142.       DW SEG Config_Info
  143.  
  144.       DW Init_Driver
  145.       DW SEG Config_Info
  146.       DW Exit_Driver
  147.       DW SEG Config_Info
  148.       DW Play_Voice
  149.       DW SEG Config_Info
  150.       DW Stop_Voice
  151.       DW SEG Config_Info
  152.       DW Record_Voice
  153.       DW SEG Config_Info
  154.       DW Set_Play_Handler
  155.       DW SEG Config_Info
  156.       DW Set_Record_Handler
  157.       DW SEG Config_Info
  158.       DW Set_Next_Block
  159.       DW SEG Config_Info
  160.  
  161.       DD SOUND_CAN_PLAY or SOUND_CAN_MONO or SOUND_CAN_8BIT or SOUND_USES_TIMER
  162.       DW 0
  163.       DW 44000
  164.  
  165.  
  166. Status        DW ?
  167. Data_Adress     DD ?
  168. Data_Size       DW ?
  169.  
  170. IntOffset       DW ?
  171. IntSegment      DW ?
  172.  
  173. Play_Handler    DD 0
  174. Record_Handler    DD 0
  175. Voice_Rate      DW ?
  176. Timer_Constant    DW ?
  177.  
  178. Next_Block     DD 0
  179. Busy        db ?
  180. DISPATCH ENDP
  181. endif
  182.  
  183.  
  184. ifdef EXTERNAL_ROUTINES
  185. EXTERNAL_ROUTINES
  186. endif
  187.  
  188.  
  189.  
  190. Init_Driver PROC FAR
  191.       cli
  192.       mov ah,35h
  193.       mov al,8                     ;Timer-Interrupt
  194.       int 21h                      ;Alten Vector ermitteln
  195.       sti
  196.       mov cs:[IntOffset],bx
  197.       mov cs:[IntSegment],es
  198.       mov cs:[Play_Handler],0
  199.       mov cs:[Record_Handler],0
  200.       mov cs:[Status],0
  201.  
  202.       ifdef DRV_INIT
  203.       DRV_INIT
  204.       endif
  205.  
  206.       mov ax,TRUE
  207.       retf
  208. Init_Driver ENDP
  209.  
  210.  
  211.  
  212.  
  213.  
  214. Exit_Driver PROC FAR
  215.       cli
  216.       mov ah,25h
  217.       mov al,8
  218.       push ds
  219.       mov ds,cs:[IntSegment]
  220.       mov dx,cs:[IntOffset]
  221.       int 21h                      ;Vector setzen
  222.       pop ds
  223.       mov al,36h
  224.       out 43h,al
  225.       mov dx,40h
  226.       mov al,0ffh
  227.       out dx,al
  228.       out dx,al
  229.       sti
  230.       ifdef DRV_EXIT
  231.       DRV_EXIT
  232.       endif
  233.       mov ax,TRUE
  234.       retf
  235. Exit_Driver ENDP
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243. Play_Voice PROC FAR
  244.       ARG Data:dword
  245.       push bp
  246.       mov bp,sp
  247.       cli
  248.  
  249.       les si,[Data]
  250.       mov bx,es:[si+SAMPLE_RATE]
  251.       mov cs:[Voice_Rate],bx
  252.       mov dx,12h
  253.       mov ax,3333h
  254.       div bx
  255.       mov cs:[Timer_Constant],ax
  256.       mov ax,es:[si+SAMPLE_SIZE]
  257.       mov cs:[Data_Size],ax
  258.       mov eax,[Data]
  259.       add eax,16
  260.       mov word ptr cs:[DOffset-2],ax
  261.       mov cs:[Data_Adress],eax
  262.       mov cs:[Next_Block],0
  263.  
  264.       ifdef VOICE_INIT
  265.       VOICE_INIT
  266.       endif
  267.  
  268.       mov ah,25h
  269.       mov al,8
  270.       push ds
  271.       push cs
  272.       pop ds
  273.       mov dx,OFFSET Play_Interrupt
  274.       int 21h                        ;Vector setzen
  275.       pop ds
  276.  
  277.       mov cs:[Busy],0
  278.       mov cs:[Status],SOUND_READY or SOUND_PLAYING
  279.  
  280.       mov al,36h
  281.       out 43h,al
  282.       mov ax,cs:[Timer_Constant]
  283.       out 40h,al
  284.       shr ax,8
  285.       out 40h,al                      ;Geschwindigkeit setzen
  286.  
  287.       ifdef VOICE_START
  288.       VOICE_START
  289.       endif
  290.  
  291.       pop bp
  292.       sti
  293.       retf
  294. Play_Voice ENDP
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. Stop_Voice PROC FAR
  302.       cli
  303.       mov al,36h
  304.       out 43h,al
  305.       mov al,0ffh
  306.       out 40h,al
  307.       out 40h,al
  308.       mov ah,25h
  309.       mov al,8
  310.       push ds
  311.       mov ds,cs:[IntSegment]
  312.       mov dx,cs:[IntOffset]
  313.       int 21h                      ;Vector setzen
  314.       pop ds
  315.  
  316.       and cs:[Status],0ffffh-SOUND_PLAYING-SOUND_RECORDING
  317.       mov cs:[Data_Size],0
  318.       mov cs:[Data_Adress],0ffffffffh
  319.  
  320.       ifdef VOICE_STOP
  321.       VOICE_STOP
  322.       endif
  323.  
  324.       sti
  325.       retf
  326. Stop_Voice ENDP
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333. Record_Voice PROC FAR
  334.       retf
  335. Record_Voice ENDP
  336.  
  337.  
  338.  
  339.  
  340. Record_Interrupt PROC FAR
  341.     iret
  342. Record_Interrupt ENDP
  343.  
  344.  
  345.  
  346.  
  347. Play_Interrupt PROC FAR
  348.       push eax
  349.       push ds
  350.  
  351.       mov ds,word ptr cs:[Data_Adress+2]
  352.       mov al,ds:[1234h]
  353. DOffset:
  354.       inc word ptr cs:[DOffset-2]
  355.  
  356.       VOICE_OUT
  357.  
  358.       mov al,20h
  359.       out 20h,al
  360.  
  361.       dec cs:[Data_Size]
  362.       jz short EndeDMA
  363.  
  364.       pop ds
  365.       pop eax
  366.       iret
  367.  
  368.  
  369.     EndeDMA:
  370.       cmp cs:[Next_Block],0
  371.       je No_Second_Block
  372.       push bx
  373.       lds bx,cs:[Next_Block]
  374.       mov ax,ds:[bx+SAMPLE_SIZE]
  375.       mov cs:[Data_Size],ax
  376.       mov eax,cs:[Next_Block]
  377.       add eax,16
  378.       mov word ptr cs:[DOffset-2],ax
  379.       mov cs:[Data_Adress],eax
  380.       sti
  381.       pop bx
  382.       mov cs:[Next_Block],0
  383.       cmp cs:[Play_Handler],0
  384.       jne short Call_User
  385.       pop ds
  386.       pop eax
  387.       iret
  388.  
  389.     No_Second_Block:
  390.       pushad
  391.       push es
  392.       call Stop_Voice
  393.       cmp cs:[Play_Handler],0
  394.       je short Cont_Output
  395.       cmp cs:[Busy],1
  396.       je short @@1
  397.       mov cs:[Busy],1
  398.       call cs:[Play_Handler]
  399.       mov cs:[Busy],0
  400.     @@1:
  401.       pop es
  402.       popad
  403.       pop ds
  404.       pop eax
  405.       iret
  406.  
  407.     Call_User:
  408.       pushad
  409.       push es
  410.       cmp cs:[Busy],1
  411.       je short @@2
  412.       mov cs:[Busy],1
  413.       call cs:[Play_Handler]
  414.       mov cs:[Busy],0
  415.       cmp ax,0
  416.       jge short Cont_Output
  417.       call Stop_Voice
  418.  
  419.  Cont_Output:
  420.  @@2: pop es
  421.       popad
  422.       pop ds
  423.       pop eax
  424.       iret
  425. Play_Interrupt ENDP
  426.  
  427.  
  428.  
  429.  
  430. Set_Play_Handler PROC FAR
  431.     ARG handler:dword
  432.     push bp
  433.     mov bp,sp
  434.  
  435.     mov eax,[handler]
  436.     mov cs:[Play_Handler],eax
  437.  
  438.     pop bp
  439.     retf
  440. Set_Play_Handler ENDP
  441.  
  442.  
  443.  
  444.  
  445.  
  446. Set_Record_Handler PROC FAR
  447.     ARG handler:dword
  448.     push bp
  449.     mov bp,sp
  450.  
  451.     mov eax,[handler]
  452.     mov cs:[Play_Handler],eax
  453.  
  454.     pop bp
  455.     retf
  456. Set_Record_Handler ENDP
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463. Set_Next_Block PROC FAR
  464.       ARG Data:dword
  465.       push bp
  466.       mov bp,sp
  467.  
  468.       mov eax,[Data]
  469.       mov cs:[Next_Block],eax
  470.  
  471.       pop bp
  472.       retf
  473. Set_Next_Block ENDP
  474.