home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 467.lha / DeluxeBeep / DeluxeBeep.s < prev    next >
Text File  |  1991-02-08  |  9KB  |  194 lines

  1. *
  2. *   DeluxeBeep.s
  3. *
  4. *   A stupid little gadget that play's a sample each time
  5. *   Intuition's "DisplayBeep" routine is called showing you
  6. *   the power of exec's "SetFunction" routine.
  7. *
  8.                 incdir  sys:devpac_inc/
  9.                 include exec/exec_lib.i
  10.                 include exec/memory.i
  11.                 include libraries/dos_lib.i
  12.                 include intuition/intuition_lib.i
  13.                 include hardware/custom.i
  14.                 include hardware/intbits.i
  15.                 include hardware/dmabits.i
  16.  
  17. _custom     equ     $dff000
  18.  
  19. *
  20. * open intuition
  21. *
  22.                 move.l  a0,a4               ; arg to a4
  23.                 move.l  d0,d3               ; arg_len to d3
  24.                 move.l  #int_name,a1        ; pointer to "intuition.library"
  25.                 moveq   #0,d0               ; any version (I don't care)
  26.                 CALLEXEC    OpenLibrary     ; let's open it
  27.                 move.l  d0,_IntuitionBase   ; and store the base pointer
  28.                 beq     NoLib               ; what's this ? it failed to open
  29. *
  30. * check if the patch is already there, if so remove it
  31. *
  32.                 move.l  d0,a2               ; IntuitionBase to a2
  33.                 move.l  _LVODisplayBeep+2(a2),a2    ; old routine address
  34.                 cmp.l   #'BEEP',-12(a2)     ; Beep already installed ?
  35.                 bne     SetPatch            ; no set it quickly !
  36.  
  37.                 move.l  -8(a2),d0           ; old intuition beep routine
  38.                 move.l  _IntuitionBase,a1   ; IntuitionBase
  39.                 move.l  #_LVODisplayBeep,a0 ; table offset
  40.                 CALLEXEC    SetFunction     ; normal again !
  41.  
  42.                 lea.l   -12(a2),a1          ; pointer to the memory it takes
  43.                 move.l  -4(a2),d0           ; size of the memory it takes
  44.                 CALLEXEC    FreeMem         ; and it's gone ! (phoe)
  45.  
  46.                 cmp.w   #2,d3               ; one letter argument ?
  47.                 bhi.s   Remove              ; no, more so remove
  48.                 cmp.b   #'F',(a4)           ; arg 'F' ?
  49.                 beq     SetPatch            ; yes, set new patch
  50.                 cmp.b   #'f',(a4)           ; arg 'f' ?
  51.                 beq     SetPatch            ; yes. set new patch
  52. Remove:         move.l  #rem,a2             ; write a message saying that
  53.                 move.l  #rems,a3            ; DeluxeBeep has been removed
  54.                 bsr     PrintMsg            ; from the system
  55.                 bra     NoMem
  56. *
  57. * reserve memory for the patch
  58. *
  59. SetPatch:       move.l  #patch_end-patch_start+12,d0    ; size of the patch
  60.                 move.l  #MEMF_CHIP+MEMF_CLEAR,d1    ; CHIP mem ! (sound data)
  61.                 CALLEXEC    AllocMem        ; let's reserve it
  62.                 move.l  d0,Func             ; and store the pointer
  63.                 beq.s   NoMem               ; jeee wizzz it failed !
  64. *
  65. * get old vector
  66. *
  67.                 move.l  _IntuitionBase,a0   ; IntuitionBase to a0
  68.                 move.l  _LVODisplayBeep+2(a0),OldVec+2 ; store the orig address
  69. *
  70. * copy the patch in the new memory
  71. *
  72.                 move.l  #patch_start,a0     ; start of patch routine
  73.                 move.l  Func,a1             ; destenation area
  74.                 move.l  #'BEEP',(a1)+       ; so we known it's there already
  75.                 move.l  OldVec+2,(a1)+      ; so we known the old address
  76.                 move.l  #patch_end-patch_start,(a1)
  77.                 move.l  (a1),d0
  78.                 add.l   #12,(a1)+           ; so we know the size allocated
  79.                 CALLEXEC    CopyMem         ; fire away !
  80. *
  81. * set the patch
  82. *
  83.                 move.l  #_LVODisplayBeep,a0 ; table offset
  84.                 move.l  _IntuitionBase,a1   ; library base address
  85.                 move.l  Func,d0             ; new function
  86.                 add.l   #12,d0              ; add 12 bytes
  87.                 CALLEXEC    SetFunction     ; and were in !
  88.  
  89.                 move.l  #ins,a2             ; print a message saying
  90.                 move.l  #inss,a3            ; that DeluxeBeep is hanging
  91.                 bsr     PrintMsg            ; in the system.
  92.  
  93.                 suba.l  a0,a0               ; call it once to let them
  94.                 CALLINT DisplayBeep         ; hear it !
  95.  
  96. NoMem:          move.l  _IntuitionBase,a1   ; close intuition
  97.                 CALLEXEC    CloseLibrary    ; like a good boy.
  98. NoLib:          moveq   #0,d0               ; clear return code
  99.                 rts                         ; and that's it !
  100. *
  101. * print a message
  102. *
  103. PrintMsg:       move.l  #dos_name,a1        ; pointer to "dos.library"
  104.                 moveq   #0,d0               ; any version (I still don't care)
  105.                 CALLEXEC    OpenLibrary     ; open it now
  106.                 move.l  d0,_DOSBase         ; and store the base pointer
  107.                 beq.s   NoDos               ; failed, no message ?!?!
  108.                 CALLDOS Output              ; get output handle
  109.                 move.l  d0,d1               ; put it in d1
  110.                 move.l  a2,d2               ; message to d2
  111.                 move.l  a3,d3               ; size to d3
  112.                 CALLDOS Write               ; write it to the console
  113.                 move.l  _DOSBase,a1         ; and close dos again
  114.                 CALLEXEC    CloseLibrary    ; yes close it now !
  115. NoDos:          rts                         ; bye bye
  116.  
  117. *
  118. * the actual patch which plays the sample and call's
  119. * the original "DisplayBeep" routine !
  120. *
  121. INTF_AUD    equ INTF_AUD0!INTF_AUD1         ; only voice 0 and 1
  122. DMAF_AUD    equ DMAF_AUD0!DMAF_AUD1         ; same here
  123.  
  124. patch_start:
  125.                 move.l  a5,-(sp)                ; save a5 on stack
  126.                 lea.l   _custom,a5              ; custombase in a5
  127.                 move.w  intenar(a5),-(sp)       ; stack intenar
  128.                 move.w  #DMAF_AUD,dmacon(a5)    ; audio off
  129.                 move.w  #dsize/2,aud0+ac_len(a5)  ; num of samples voice 0
  130.                 move.w  #dsize/2,aud1+ac_len(a5)  ; num of samples voice 1
  131.                 move.l  a0,-(sp)                ; stack a0 (screen arg!)
  132.                 lea.l   data(pc),a0             ; pointer to sample data
  133.                 move.l  a0,aud0+ac_ptr(a5)      ; data voice 0
  134.                 move.l  a0,aud1+ac_ptr(a5)      ; data voice 1
  135.                 move.w  #40,aud0+ac_vol(a5)     ; full volume voice 0
  136.                 move.w  #40,aud1+ac_vol(a5)     ; full volume voice 1
  137.                 move.w  #sper,aud0+ac_per(a5)   ; sample freq voice 0
  138.                 move.w  #sper,aud1+ac_per(a5)   ; sample freq voice 1
  139.                 move.w  #INTF_AUD,intena(a5)    ; disable audio interrupt
  140.                 move.w  #INTF_AUD,intreq(a5)    ;    "      "      "
  141.                 move.w  #DMAF_SETCLR!DMAF_MASTER!DMAF_AUD,dmacon(a5) ; audio on
  142. wait:           move.w  intreqr(a5),d0          ; wait for audio interrupt
  143.                 and.w   #INTF_AUD,d0
  144.                 cmp.w   #INTF_AUD,d0
  145.                 bne     wait
  146.                 move.w  d0,intreq(a5)           ; store audio bits in intreq
  147.                 move.l  (sp)+,a0                ; pull arguments (screen !)
  148. OldVec:         jsr $000000                     ; Intuition's flash
  149.                 lea     _custom,a5              ; pointer to custom base
  150. wait1:          move.w  intreqr(a5),d0          ; wait for audio dma done
  151.                 and.w   #INTF_AUD,d0
  152.                 cmp.w   #INTF_AUD,d0
  153.                 bne     wait1
  154.                 move.w  d0,intreq(a5)           ; store audio bits in intreq
  155.                 move.w  #DMAF_AUD,dmacon(a5)    ; audio off
  156.                 move.w  (sp)+,d0                ; pull intenar bits
  157.                 and.w   #INTF_AUD,d0            ; filter audio bits
  158.                 or.w    #INTF_SETCLR,d0         ; INTF_SETCLR
  159.                 move.w  d0,intena(a5)           ; bits to intena
  160.                 move.l  (sp)+,a5                ; restore a5
  161.                 rts                             ; done
  162. data:
  163.                 incbin  'Sample'                ; here you can put the name
  164.                                                 ; of another RAW sample if
  165.                                                 ; you like.
  166.  
  167. patch_end:      dc.w    0
  168.  
  169. sper    equ     240                             ; sample frequency. if it
  170.                                                 ; goes to fast or to slow
  171.                                                 ; change this.
  172. *
  173. * some global data's and definitions
  174. *
  175. dsize equ   patch_end-data
  176.  
  177. dos_name:   dc.b    'dos.library',0
  178.             even
  179. int_name:   dc.b    'intuition.library',0
  180.             even
  181. ins:        dc.b    10,'DeluxeBeep Installed !',10
  182.             dc.b    'Everytime a program call',39,'s  intuition',39,'s',10
  183.             dc.b    'DisplayBeep routine you will hear this.',10,10
  184. inse:       even
  185. inss        equ     inse-ins
  186. rem:        dc.b    10,'DeluxeBeep Removed !',10
  187.             dc.b    'Intuition',39,'s DisplayBeep routine',10
  188.             dc.b    'works normal again (sigh).',10,10
  189. reme:       even
  190. rems        equ     reme-rem
  191. _IntuitionBase: dc.l    0
  192. _DOSBase:       dc.l    0
  193. Func:   dc.l    0
  194.