home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / modem / ccredir.zip / CCREDIR.ASM next >
Assembly Source File  |  1992-04-04  |  5KB  |  217 lines

  1. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  2. ; History:210,1
  3.  
  4. ;   This program is free software; you can redistribute it and/or modify
  5. ;   it under the terms of the GNU General Public License as published by
  6. ;   the Free Software Foundation, version 1.
  7. ;
  8. ;   This program is distributed in the hope that it will be useful,
  9. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ;   GNU General Public License for more details.
  12. ;
  13. ;   You should have received a copy of the GNU General Public License
  14. ;   along with this program; if not, write to the Free Software
  15. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  
  17. comment \
  18.  
  19. 14 on 8 off 15 on 72 off
  20. 15 on 7 off 14 on 
  21. 15 on 7 off 15 on 
  22. 28 on 
  23. 36 on
  24. 36 on
  25.  
  26. \
  27.  
  28. majver        equ    1        ;version number.
  29. version        equ    0
  30.  
  31. ANSWER_NO    equ    0        ;CCOM answering types.
  32. ANSWER_FAX    equ    1
  33. ANSWER_CAM    equ    2
  34. ANSWER_MODEM    equ    3
  35.  
  36. HT    equ    09h
  37. CR    equ    0dh
  38. LF    equ    0ah
  39.  
  40. segmoffs    struc            ; defines offs as 0, segm as 2
  41. offs        dw    ?
  42. segm        dw    ?
  43. segmoffs    ends
  44.  
  45. code    segment para public
  46.     assume    cs:code, ds:code
  47.  
  48.     org    80h
  49. phd_dioa    label    byte
  50.  
  51.     org    100h
  52. start:
  53.     jmp    start_1
  54.  
  55. their_int_8    dd    ?
  56.  
  57. ccom_ptr    dd    ?
  58.  
  59. previous_1    db    ?
  60. previous_2    db    ?
  61. old_filtered    db    ?
  62. filtered_count    dw    ?
  63. count        dw    ?
  64.  
  65. readbyte:
  66. ;enter with bx = address to read from
  67. ;exit with al = byte.
  68.     push    dx
  69.     pushf
  70.     cli
  71.     mov    dx,2e0h
  72.     mov    al,bh            ;high byte to port+1
  73.     inc    dx
  74.     out    dx,al
  75.     dec    dx
  76.  
  77.     mov    al,bl            ;low byte to port+0
  78.     out    dx,al
  79.  
  80.     add    dx,4            ;input from port+4.
  81.     in    al,dx
  82.     popf
  83.     pop    dx
  84.     ret
  85.  
  86. our_int_8:
  87.     assume    ds:nothing
  88.     pushf                ;run everybody else first.
  89.     call    their_int_8
  90.  
  91.     push    ax            ;save register.
  92.     push    bx
  93.     push    cx
  94.     push    dx
  95.     push    si
  96.     push    di
  97.     push    ds
  98.     push    es
  99.     cld
  100.     mov    ax,cs
  101.     mov    ds,ax
  102.     assume    ds:code
  103.     sti
  104.  
  105.     mov    bx,7000h
  106.     call    readbyte
  107.  
  108.     cmp    al,0c0h            ;idle?
  109.     mov    al,'1'
  110.     jne    do_again_1        ;no, ringing.
  111.     mov    al,'0'
  112. do_again_1:
  113.  
  114. ;have to do a little filtering here.  We don't want to output bad samples,
  115. ;so we discard a sample if it disagrees with both of the previous samples.
  116. ;This is just a moving average.
  117.     mov    ah,previous_1        ;get previous sample.
  118.     mov    previous_1,al        ;remember this for later.
  119.     cmp    al,ah            ;same as last time?
  120.     je    do_again_2        ;yes, use it.
  121.     cmp    al,previous_2        ;same as the time before that?
  122.     je    do_again_2        ;yes, use it.
  123.     mov    al,ah            ;no, output previous sample.
  124. do_again_2:
  125.     mov    previous_2,ah        ;now set older sample.
  126.  
  127.     inc    count            ;count up a sample.
  128.     cmp    al,old_filtered        ;still the same?
  129.     mov    old_filtered,al        ;(remember the new one)
  130.     je    count_same        ;yes, keep incrementing the count.
  131.  
  132. ;;; here's where we recognize the short rings.
  133.     cmp    al,'0'            ;transition to silence.
  134.     jne    count_different
  135.  
  136.     mov    al,ANSWER_CAM        ;answer voice on one second ring.
  137.  
  138.     cmp    count,15+2        ;allow for some slop (2 18.2ths is enuf).
  139.     ja    count_ring
  140.  
  141.     mov    al,ANSWER_FAX        ;answer FAX on two short rings.
  142.  
  143. count_ring:
  144.     les    di,ccom_ptr        ;set our answering style.
  145.     mov    es:[di+1ab8h],al
  146. count_different:
  147.     mov    count,0
  148. count_same:
  149.  
  150.     pop    es
  151.     pop    ds
  152.     assume    ds:nothing
  153.     pop    di
  154.     pop    si
  155.     pop    dx
  156.     pop    cx
  157.     pop    bx
  158.     pop    ax
  159.     iret
  160.  
  161. end_resident    label    byte
  162.  
  163. copyleft_msg    label    byte
  164.  db "CCOM redirector version ",'0'+majver,".",'0'+version," copyright 1992, Crynwr Software",CR,LF
  165.  db "This program is free software; see the file COPYING for details.",CR,LF
  166.  db "NO WARRANTY; see the file COPYING for details.",CR,LF,CR,LF,'$'
  167.  
  168. noccom_msg    db    "Resident code not found",CR,LF,'$'
  169.  
  170.     align    16
  171. fax_signature    db    "?AX ResidentCode"
  172. fax_signature_len    equ    $ - fax_signature
  173.  
  174. error:
  175.     mov    ah,9
  176.     int    21h
  177. err_quit:
  178.     mov    al,1
  179.         mov     ah,04ch                 ; exit with errorlevel 1
  180.         int     21h
  181.  
  182. start_1:
  183.     mov    dx,offset copyleft_msg
  184.     mov    ah,9
  185.     int    21h
  186.  
  187.     mov    si,offset fax_signature
  188.     mov    cx,fax_signature_len
  189.     mov    al,'F'
  190.     call    find_signature
  191.     mov    dx,offset noccom_msg
  192.     je    error            ;go if we found ourselves.
  193.     mov    ccom_ptr.offs,di
  194.     mov    ccom_ptr.segm,es
  195.  
  196.     mov    ax,3508h        ;get their timer interrupt.
  197.     int    21h
  198.     mov    their_int_8.offs,bx
  199.     mov    their_int_8.segm,es
  200.  
  201.     mov    ax,2508h        ;set our timer interrupt.
  202.     mov    dx,offset our_int_8
  203.     int    21h
  204.  
  205.     mov    dx,offset end_resident
  206.     add    dx,0fh            ;round up to next highest paragraph.
  207.     mov    cl,4
  208.     shr    dx,cl
  209.     mov    ax,3100h        ;terminate, stay resident.
  210.     int    21h
  211.  
  212.     include    findsig.asm
  213.  
  214. code    ends
  215.  
  216.     end    start
  217.