home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / BBS / BEEPER11.ZIP / BEEPER.ASM next >
Assembly Source File  |  1993-02-16  |  8KB  |  248 lines

  1. page 66,132
  2.  
  3. ;*******************************************************************************
  4. ;
  5. ; BEEPER - Resident BEEP Handler
  6. ;
  7. ; This program is a TSR that traps bios BEEP signals and converts them
  8. ; background beeps with a command-line controlled frequency.
  9. ;
  10. ; Copyright 1992 Samuel H. Smith; All rights reserved.
  11. ;
  12. ;*******************************************************************************
  13. ;
  14. ;  This FREEWARE package can be freely distributed so long as it is not
  15. ;  modified or sold for profit.
  16. ;
  17. ;  The author can be contacted at:
  18. ;     Samuel H. Smith                 The Tool Shop BBS
  19. ;     P.O. Box 4808                   (818) 891-6780 (HAYES 9600) - Free node
  20. ;     Panorama City, CA 91412         (818) 891-3772 (HST 9600)
  21. ;                                     (818) 891-1344 (Four lines V.32Bis)
  22. ;
  23. ;  Copyright
  24. ;  ---------
  25. ;  If you modify this program,  I would appreciate a copy of the new
  26. ;  source code.  I am holding the copyright on the source code,  so
  27. ;  please don't delete my name from the program files or from the
  28. ;  documentation.
  29. ;
  30. ;                               DISCLAIMER
  31. ;                               ==========
  32. ;  I make no warranty of any kind, express or implied, including without
  33. ;  limitation, any warranties of merchantability and/or fitness for a
  34. ;  particular purpose.  I shall not be liable for any damages, whether
  35. ;  direct, indirect, special or consequential arising from a failure of
  36. ;  this program to operate in the manner desired by the user.  I shall
  37. ;  not be liable for any damage to data or property which may be caused
  38. ;  directly or indirectly by the use of this program.
  39. ;
  40. ;  IN NO EVENT WILL I BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING ANY
  41. ;  LOST PROFITS,  LOST SAVINGS OR OTHER INCIDENTAL OR CONSEQUENTIAL
  42. ;  DAMAGES ARISING OUT OF YOUR USE OR INABILITY TO USE THE PROGRAM, OR
  43. ;  FOR ANY CLAIM BY ANY OTHER PARTY.
  44. ;
  45.  
  46. code segment
  47.                 assume  cs:code, ds:nothing, ss:nothing, es:nothing
  48.  
  49. ;*******************************************************************************
  50. ; program segment prefix
  51. ;
  52.                 org 80h
  53. tailLen         db ?            ; command tail length
  54. tail            db ?            ; command tail text
  55.  
  56.                 org 100h
  57. start:          jmp entry
  58.  
  59.  
  60. ;*******************************************************************************
  61. ; working storage
  62. ;
  63.  
  64. freq_divisor    dw 0C00h        ; base frequency divisor
  65.  
  66. max_pending = 10                ; maximum number of beeps to keep pending
  67. bells_pending   db 0            ; number of beeps currently pending
  68.  
  69. bell_state      db 0            ; sounding state for current beep
  70.  
  71. old_int8        dd 0            ; old int 8h handler
  72. old_int10       dd 0            ; old int 10h handler
  73.  
  74.  
  75. ;*******************************************************************************
  76. ;*
  77. ;*  new_int8 - replacement timer tick interrupt handler
  78. ;*
  79. ;*******************************************************************************
  80.  
  81. new_int8 proc near
  82.                 push ax
  83.  
  84.                 cmp bells_pending,0
  85.                 jne bell_active
  86.  
  87. use_old8:       pop ax
  88.                 jmp old_int8
  89.  
  90. bell_active:    inc bell_state
  91.                 cmp bell_state,1
  92.                 je begin_sound
  93.                 cmp bell_state,3
  94.                 je begin_nosound
  95.                 cmp bell_state,4
  96.                 je end_bell
  97.                 jmp use_old8
  98.  
  99. begin_sound:    mov ax,freq_divisor
  100.                 out 42h,al
  101.                 mov al,ah
  102.                 out 42h,al
  103.                 in al,61h
  104.                 or al,3
  105.                 out 61h,al
  106.                 jmp use_old8
  107.  
  108. begin_nosound:  in al,61h
  109.                 and al,0FCh
  110.                 out 61h,al
  111.                 jmp use_old8
  112.  
  113. end_bell:       mov bell_state,0
  114.                 dec bells_pending
  115.                 jmp use_old8
  116.  
  117. new_int8 endp
  118.  
  119. ;*******************************************************************************
  120. ;*
  121. ;*  new_int10 - replace bios video services handler
  122. ;*
  123. ;*******************************************************************************
  124.  
  125. new_int10 proc near
  126.  
  127.                 cmp ax,0E07h            ; check for bell request
  128.                 je count_bell
  129.  
  130.                 cmp ax,'BE'
  131.                 jne use_old10
  132.                 cmp bx,'EP'
  133.                 jne use_old10
  134.  
  135.                 xchg bx,ax              ; test to see if 'bell' is loaded
  136.         iret                
  137.  
  138. use_old10:      jmp cs:old_int10
  139.  
  140. count_bell:     cmp cs:bells_pending,max_pending
  141.                 jge fin_int10           ; discard this beep if maximum
  142.                                         ; number of beeps already pending
  143.  
  144.                 inc cs:bells_pending
  145.  
  146. fin_int10:      sti
  147.         iret                
  148.  
  149. new_int10 endp
  150.  
  151. ;*******************************************************************************
  152. ;*
  153. ;*  entry - install new bell handler if needed
  154. ;*
  155. ;*******************************************************************************
  156.  
  157. entry:          push cs
  158.                 pop ds
  159.                 assume ds:code
  160.  
  161.                 mov ax,'BE'
  162.                 mov bx,'EP'
  163.                 int 10h                 ; check for previous install
  164.                 xor ax,'EP'
  165.                 xor bx,'BE'
  166.                 or ax,bx
  167.                 jne not_installed
  168.  
  169.                 lea dx,already_installed_msg
  170.                 mov ah,9
  171.                 int 21h                 ; Display string
  172.                 int 20h                 ; Program terminate
  173.  
  174. not_installed:  lea si,tail
  175.  
  176. check_tail:     lodsb
  177.                 cmp al,13
  178.                 jz usage
  179.                 cmp al,' '
  180.                 je check_tail
  181.                 cmp al,'0'
  182.                 jb usage
  183.                 cmp al,'9'
  184.                 ja usage
  185.  
  186.                 ;valid parameter found- alter MSB of freq_divisor and install
  187.                 mov ah,byte ptr freq_divisor+1
  188.                 sub al,'0'
  189.                 sub ah,al
  190.                 mov byte ptr freq_divisor+1,ah
  191.                 jmp install
  192.  
  193.  
  194. usage:          lea dx,usage_msg
  195.                 mov ah,9
  196.                 int 21h                 ; Display string
  197.                 int 20h                 ; Program terminate
  198.  
  199. install:        mov ax,3508h
  200.                 int 21h                 ; Get interrupt vector 08h
  201.                 mov di,offset old_int8
  202.                 mov Word Ptr [di],bx
  203.                 mov Word Ptr [di+2],es
  204.  
  205.                 mov ax,3510h
  206.                 int 21h                 ; Get interrupt vector 10h
  207.                 mov di,offset old_int10
  208.                 mov Word Ptr [di],bx
  209.                 mov Word Ptr [di+2],es
  210.  
  211.                 mov dx,offset new_int8
  212.                 mov ax,2508h
  213.                 int 21h                 ; Set interrupt vector 08h
  214.  
  215.                 mov dx,offset new_int10
  216.                 mov ax,2510h
  217.                 int 21h                 ; Set interrupt vector 10h
  218.  
  219.                 lea dx,now_installed_msg
  220.                 mov ah,9
  221.                 int 21h                 ; Display string
  222.  
  223.                 mov dx,offset entry
  224.                 int 27h                 ; Terminate and stay resident
  225.  
  226. ;*******************************************************************************
  227.  
  228. cr = 13
  229. lf = 10
  230.  
  231. already_installed_msg   db cr,lf,7
  232.                         db '*** Error - BEEPER already installed!',cr,lf
  233.                         db '$'
  234.  
  235. usage_msg               db cr,lf
  236.                         db 'A base frequency code between 0 and 9 must be specified.',cr,lf
  237.                         db 'Usage: BEEPER [0..9]',cr,lf
  238.                         db '$'
  239.  
  240. now_installed_msg       db cr,lf,7
  241.                         db 'BEEPER (2/16/93) Copyright 1993 Samuel H. Smith',cr,lf
  242.                         db 'Beeper installed!',cr,lf
  243.                         db '$'
  244.  
  245. code ends
  246.                 end start
  247.  
  248.