home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / djasy10d.zip / ASYNCTSR.ASM < prev    next >
Assembly Source File  |  1992-09-11  |  5KB  |  212 lines

  1.         title   async TSR
  2.         name    asynctsr
  3.         page    ,132
  4.  
  5. BUFSIZE            = 4096
  6.  
  7. cseg    segment byte public 'code'
  8.         assume cs:cseg
  9.         org     100h
  10.         .286
  11.  
  12. start:
  13.         jmp     init
  14.  
  15. buffer_end      equ     buffer_start+BUFSIZE
  16.  
  17.         org     104h
  18. isr:
  19.         jmp     short isr_handler
  20.         dw      'AT'                    ; signature
  21.         dw      1                       ; header version
  22. bbeg    dw      offset buffer_start
  23. bend    dw      offset buffer_start
  24. getp    dw      offset buffer_start
  25. putp    dw      offset buffer_start
  26. iov     dw      0
  27. count   dw      0
  28. over    dw      0
  29. bsize   dw      BUFSIZE
  30. flush   dw      1
  31.  
  32. isr_handler:
  33.         pusha
  34.         mov     al,20h
  35.         out     20h,al
  36. isr_top:
  37.         mov     dx,iov
  38.         add     dx,2
  39.         in      al,dx
  40.         cmp     al,1
  41.         je      isr_exit
  42.         cmp     al,4
  43.         je      isr_rcv
  44.         cmp     al,0
  45.         je      isr_msr
  46.         cmp     al,6
  47.         je      isr_lsr
  48.         jmp     isr_top
  49.  
  50. isr_msr:
  51.         mov     dx,iov
  52.         add     dx,6
  53.         in      al,dx
  54.         jmp     isr_top
  55.  
  56. isr_lsr:
  57.         mov     dx,iov
  58.         add     dx,5
  59.         in      al,dx
  60.         jmp     isr_top
  61.  
  62. isr_rcv:
  63.         mov     dx,iov
  64.         in      al,dx
  65.         mov     bx,putp
  66.         mov     cx,count
  67.         ; check for & handle buffer overflow <jae>
  68.         cmp     cx,bsize
  69.         jb      isr_addch       ; count < bsize ==> ok
  70.         inc     over            ; count the overflow
  71. isr_ckflush:
  72.         cmp     flush,0
  73.         jg      isr_flush
  74.         dec     cx              ; dec count (in cx) 
  75.         dec     bx              ; back up putp (in bx)
  76.         cmp     bx,offset buffer_start  ; fell off start of buffer?
  77.         jge     isr_addch               ; no, go ahead
  78.         mov     bx,bend                 ; yes, wrap to end of buffer - 1
  79.         dec     bx
  80.         jmp     isr_addch
  81. isr_flush:
  82.     xor    cx, cx
  83.         ; end of overflow handling <jae>
  84. isr_addch:
  85.         inc     cx              ; count new char
  86.         mov     cs:[bx],al      ; save it at putp
  87.         inc     bx              ; inc putp
  88.         cmp     bx,bend         ; fell off end of buffer?
  89.         jb      isr_noend       ; no, go ahead
  90.         mov     bx,offset buffer_start  ; yes, wrap to start of buffer
  91. isr_noend:
  92.         mov     putp,bx         ; save off new putp
  93.         mov     count,cx        ; save off new count
  94.         jmp     isr_top
  95.  
  96. isr_exit:
  97.         popa
  98.         iret
  99.         
  100. buffer_start    label   byte    ; last before init
  101.  
  102. ;----------------------------------------------------------------------
  103.  
  104. err1    db      'Usage: asynctsr 1|2 [-][nnnn]',13,10
  105.         db      '    -      no-flush-on-overflow flag (opt)',13,10
  106.         db      '    nnnn   receive buffer size (opt,default=4096)'
  107.         db      13,10,'$'
  108.  
  109. init:
  110.         mov     al,ds:[82h]
  111.         cmp     al,'1'
  112.         je      init_1
  113.         cmp     al,'2'
  114.         je      init_2
  115. cmderr:
  116.         mov     dx,offset err1
  117.         mov     ah,9
  118.         int     21h
  119.         mov     ax,4c01h
  120.         int     21h
  121.  
  122. init_1:
  123.         call    parse
  124.         mov     iov,3f8h
  125.         mov     bx,0ch*4
  126.         mov     cl,0efh
  127.         jmp     init_keep
  128.  
  129. init_2:
  130.         call    parse
  131.         mov     iov,2f8h
  132.         mov     bx,0bh*4
  133.         mov     cl,0f7h
  134.  
  135. init_keep:
  136.         mov     ax,0
  137.         mov     es,ax
  138.         cli
  139.         mov     word ptr es:[bx],offset isr
  140.         mov     word ptr es:[bx+2],cs
  141.         sti
  142.  
  143.         in      al,21h
  144.         and     al,cl
  145.         out     21h,al
  146.         
  147.         mov     dx,iov
  148.         add     dx,1
  149.         mov     al,0fh
  150.         out     dx,al
  151.         add     dx,3
  152.         mov     al,0bh
  153.         out     dx,al
  154.  
  155.         mov     dx,offset msg1
  156.         mov     ah,9
  157.         int     21h
  158.         mov     dx,offset buffer_start
  159.         add     dx,[bsize]
  160.         mov     [bend], dx
  161.         int     27h
  162.  
  163. msg1    db      'asynctsr installed', 13, 10, '$'
  164.  
  165. parse:  ; parse the buffer size from the command line
  166.         mov     cl, ds:[80h];
  167.         cmp     cl, 3
  168.         jl      endparse
  169.         mov     si, 83h
  170.         lodsb   
  171.         cmp     al,' '
  172.         jne     errparse
  173.         mov     al,[si]
  174.         cmp     al,'-'
  175.         jne     goparse
  176.         mov     flush,0
  177.         dec     cl
  178.         inc     si
  179. goparse:
  180.         sub     cl, 3
  181.         je      endparse
  182.         xor     dx, dx
  183.         xor     bh, bh
  184.         xor     ax, ax
  185.         mov     di, 10
  186. get1:
  187.         mov     bl,ds:[si]
  188.         inc     si
  189.         dec     cl
  190.         cmp     bl,'0'
  191.         jl      errparse
  192.         cmp     bl,'9'
  193.         jg      errparse
  194.         sub     bl,'0'
  195.         imul    di
  196.         add     ax,bx
  197.         cmp     cl, 0
  198.         jg      get1
  199. setsize:        
  200.         or      ax,ax
  201.         je      endparse
  202.         mov     bsize,ax
  203. endparse:
  204.         ret
  205.  
  206. errparse:
  207.         jmp     cmderr
  208.  
  209. cseg    ends
  210.         end     start
  211.  
  212.