home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / XBD2_SRC.ZIP / XBD2_SRC / SOUND_AS.ASM < prev    next >
Assembly Source File  |  1991-02-04  |  5KB  |  308 lines

  1.     TITLE    SOUND.ASM
  2.  
  3.  
  4.     PAGE   ,132
  5.  
  6.  
  7.  
  8. ;***************************************************************************
  9. ;*                                       *
  10. ;*    SOUND_AS.ASM : assembly functions for digitized sound           *
  11. ;*                                       *
  12. ;*    (c) Hervé Soulard, Version 1.0 - 10/01/1991                        *
  13. ;*                       Version 1.1 - 01/02/1991                        *
  14. ;*                                       *
  15. ;***************************************************************************
  16.  
  17.  
  18.  
  19.     .MODEL    SMALL
  20.  
  21.  
  22. ;---------------------------------------------------------------------------
  23. ;
  24. ;    Definition des constantes.
  25. ;
  26. ;---------------------------------------------------------------------------
  27.  
  28.  
  29. EOI        EQU    20h        ; Commande de fin d'interruption
  30.  
  31. PIT_CTRL    EQU    43h        ; Port de controle du PIT
  32. PIT_HP        EQU    42h        ; Port de donnees du canal HP
  33. PIT_CLOCK    EQU    40h        ; Port de donnees du canal CLOCK
  34.  
  35. PPI_CTRL    EQU    61h        ; Port de controle du PPI
  36.  
  37. CTRL_HP_1    EQU    090h        ; Valeur de controle debut son
  38. CTRL_HP_2    EQU    0B6h        ; Valeur de controle fin son
  39.  
  40. DATA_HP        EQU    0533h        ; Donnee pour fin son
  41.  
  42. CTRL_CLK    EQU    34h        ; Valeur de controle CLOCK
  43.  
  44. HP_ON        EQU    03h        ; Donnee pour HP actif
  45. HP_OFF        EQU    0FCh        ; Donnee pour HP inactif
  46.  
  47.  
  48. sound        STRUC            ; Sound structure
  49. ident        DB    32 DUP (?)    ; identificator of sound file
  50. buffer        DD    ?        ; buffer for sampled values
  51. nbValues    DD    ?        ; nb of sampled values
  52. hertz        DW    ?        ; 
  53. timer        DB    ?        ; value for It timer
  54. mult        DB    ?        ; value of mult. freq.
  55. memo        DB    255 DUP (?)    ; comment for sound
  56. sound        ENDS
  57.  
  58.  
  59.  
  60.     .DATA
  61.  
  62.  
  63.         PUBLIC    _soundDone
  64. _soundDone    DB    1        ; le son est termine ?
  65.  
  66. values        DD    ?        
  67.  
  68. multMain    DB    ?
  69. multAux        DB    ?
  70.  
  71.  
  72.     .CODE
  73.  
  74.  
  75. oldInt08    DD    ?
  76.  
  77. normClk        DW    ?        ; appeler l'ancienne int 08
  78. tmp        DW    ?        ; tout les combien ?
  79.  
  80.  
  81.  
  82.  
  83. ;---------------------------------------------------------------------------
  84. ;
  85. ;    Le son est joue par l'interruption horloge (frequence = hertz).
  86. ;
  87. ;---------------------------------------------------------------------------
  88.  
  89.  
  90.  
  91. ;------ Interruption horloge.
  92. ;
  93. ;
  94.  
  95. New_08    PROC    FAR
  96.  
  97.     pushf
  98.     push    ax
  99.     push    bx
  100.     push    cx
  101.     push    si
  102.     push    ds
  103.     push    es
  104.  
  105.     mov    al, 20h
  106.     out    20h, al
  107.  
  108.     mov    ax, DGROUP
  109.     mov    ds, ax
  110.  
  111.     les    si, dword ptr values    ; Pointeur sur les donnees
  112.     mov    al, byte ptr es:[si]    ; al = nouvelle donnee
  113.     or    al, al
  114.     jz    n1            ; Fin des donnees ?
  115.  
  116. n4:
  117.     dec    byte ptr multAux
  118.     jnz    n3
  119.  
  120.     mov    ah, byte ptr multMain
  121.     mov    byte ptr multAux, ah
  122.  
  123.     inc    si            ; prochaine donnee
  124.  
  125. n3:
  126.     out    PIT_HP, al
  127.  
  128.     jnz    n2            ; fin des premiers 64Ko ?
  129.  
  130.     mov    ax, 1000h
  131.     add    word ptr values + 2, ax    ; segment suivant
  132.  
  133. n2:
  134.     mov    word ptr values, si    ; Mise a jour pointeur
  135.     jmp    fin
  136.     
  137. n1:
  138.     cli                ; Fini de jouer, on remet tout
  139.  
  140.     mov    al, CTRL_HP_2        ; Initialisation du son a 0
  141.     out    PIT_CTRL, al
  142.     mov    ax, DATA_HP
  143.     out    PIT_HP, al
  144.     mov    al, ah
  145.     out    PIT_HP, al
  146.  
  147.     mov    al, CTRL_CLK        ; Initialisation de la frequence
  148.     out    PIT_CTRL, al        ; d'horloge
  149.     mov    al, 0
  150.     out    PIT_CLOCK, al
  151.     out    PIT_CLOCK, al
  152.  
  153.     in    al, PPI_CTRL        ; HP inactif
  154.     and    al, HP_OFF
  155.     out    PPI_CTRL, al
  156.  
  157.     mov    byte ptr _soundDone, 1    ; fin du son
  158.  
  159.     les    bx, dword ptr cs:oldInt08
  160.     xor    ax, ax
  161.     mov    ds, ax
  162.     mov    word ptr ds:[20h], bx    ; remet l'interruption 08
  163.     mov    word ptr ds:[22h], es
  164.     
  165. fin:
  166.     pop    es
  167.     pop    ds
  168.     pop    si
  169.     pop    cx
  170.     pop    bx
  171.  
  172.     dec    word ptr cs:tmp
  173.     jnz    fin1
  174.     
  175.     mov    ax, word ptr cs:normClk
  176.     mov    word ptr cs:tmp, ax
  177.     pop    ax
  178.     popf
  179.     jmp    dword ptr cs:oldInt08
  180.  
  181. fin1:
  182.     pop    ax
  183.     popf
  184.  
  185.     iret
  186.  
  187.  
  188. New_08    ENDP
  189.  
  190.  
  191.  
  192. ;---------------------------------------------------------------------------
  193. ;
  194. ;    Fonctions. 
  195. ;
  196. ;---------------------------------------------------------------------------
  197.  
  198.  
  199. ;---------------------------------------------------------------------------
  200. ;
  201. ;    playSound :
  202. ;
  203. ;        plays the sound contains in the buffer precised
  204. ;        by the parameter.
  205. ;
  206. ;        initializes the interrupt 8 to the New_08 function
  207. ;        and prepares HP port to receive digitized sound.
  208. ;
  209. ;
  210. ;    interface :
  211. ;
  212. ;        int playSound(struct sound sSound)
  213. ;
  214.  
  215.  
  216.     PUBLIC    _playSound
  217.  
  218. _playSound    PROC
  219.  
  220.     push    bp
  221.     mov    bp, sp
  222.  
  223. arg    EQU    <[BP+04h]>
  224.  
  225.     push    di
  226.     push    es
  227.  
  228.     cmp    byte ptr _soundDone, 1
  229.     jz    e2
  230.     
  231.     mov    ax, 0
  232.     jmp    e1
  233.  
  234. e2:
  235.     mov    byte ptr _soundDone, 0
  236.  
  237.     les    di, arg.buffer
  238.     mov    word ptr values, di
  239.     mov    ax, es
  240.     mov    word ptr values+2, ax
  241.  
  242.     mov    ax, 10
  243.     mul    arg.hertz
  244.     mov    cx, 182
  245.     div    cx
  246.     mov    word ptr cs:normClk, ax
  247.     mov    word ptr cs:tmp, ax
  248.  
  249.     mov    al, arg.mult
  250.     mov    byte ptr multMain, al
  251.     mov    byte ptr multAux, al
  252.  
  253.  
  254.     push    ds
  255.     pop    es
  256.  
  257.     cli
  258.  
  259.     xor    ax, ax
  260.     mov    es, ax
  261.     les    bx, dword ptr es:[20h]    ; Sauvegarde le vecteur It CLK
  262.     mov    word ptr cs:oldInt08, bx
  263.     mov    word ptr cs:oldInt08 + 2, es
  264.  
  265.     mov    es, ax
  266.     mov    ax, OFFSET New_08    ; Nouvelle interruption CLK
  267.     mov    word ptr es:[20h], ax
  268.     mov    ax, cs
  269.     mov    word ptr es:[22h], ax
  270.     
  271.     mov    al, CTRL_HP_2        ; Initialisation du son a 0
  272.     out    PIT_CTRL, al
  273.     mov    al, 0
  274.     out    PIT_HP, al
  275.     out    PIT_HP, al
  276.  
  277.     mov    al, CTRL_CLK        ; Initialisation de la frequence
  278.     out    PIT_CTRL, al        ; d'horloge
  279.     mov    al, arg.timer
  280.     out    PIT_CLOCK, al
  281.     mov    al, 0
  282.     out    PIT_CLOCK, al
  283.  
  284.     mov    al, CTRL_HP_1        ; Prepare le canal HP a recevoir
  285.     out    PIT_CTRL, al        ; de nouvelles frequence
  286.  
  287.     in    al, PPI_CTRL        ; HP actif
  288.     or    al, HP_ON
  289.     out    PPI_CTRL, al
  290.     
  291.     sti
  292.  
  293.     mov    ax, 1
  294. e1:
  295.     pop    es
  296.     pop    di
  297.  
  298.     mov    sp, bp
  299.     pop    bp
  300.  
  301.     ret
  302.  
  303.  
  304. _playSound    ENDP
  305.  
  306.  
  307.     END
  308.