home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tel2305s.zip / NET14 / TIMER.ASM < prev   
Assembly Source File  |  1980-01-13  |  6KB  |  238 lines

  1. ;
  2. ;  TCP/IP timer support routines
  3. ;****************************************************************************
  4. ;*                                                                          *
  5. ;*                                                                          *
  6. ;*      part of NCSA Telnet                                                 *
  7. ;*      by Tim Krauskopf, VT100 by Gaige Paulsen, Tek by Aaron Contorer     *
  8. ;*                                                                          *
  9. ;*      National Center for Supercomputing Applications                     *
  10. ;*      152 Computing Applications Building                                 *
  11. ;*      605 E. Springfield Ave.                                             *
  12. ;*      Champaign, IL  61820                                                *
  13. ;*                                                                          *
  14. ;****************************************************************************
  15. ;
  16.     NAME    TIMER
  17. ;Microsoft EQU 1
  18. ;Lattice EQU 1
  19.     ifndef Microsoft
  20.         ifndef Lattice
  21.             if2
  22.                 %out
  23.                 %out ERROR: You have to specify "/DMicrosoft" or "/DLattice" on the
  24.                 %out         MASM command line to determine the type of assembly.
  25.                 %out
  26.             endif
  27.             end
  28.         endif
  29.     endif
  30. ;
  31. ;******************************************************************
  32. ;*
  33. ;*    We need to set up a stack for netsleep when we exit to DOS.
  34.  
  35. NEWSTACK SEGMENT PARA STACK 'STACK'
  36.     dw 4096 dup(?)
  37. STACKEND label far 
  38. NEWSTACK    ends
  39.  
  40. X    EQU        6
  41. ifdef Microsoft
  42. ;DGROUP  group _DATA
  43. ;_DATA segment public 'DATA'
  44. ;    assume DS:DGROUP
  45. .MODEL    LARGE
  46. .DATA
  47. else    
  48.     INCLUDE    DOS.MAC
  49.     SETX
  50.     DSEG
  51. endif
  52.  
  53. OLDSS dw 1 dup(?)
  54. OLDSP dw 1 dup(?)
  55.  
  56. ifdef Microsoft
  57. ;_DATA ends
  58. ;
  59. ;_TEXT    segment public 'CODE'
  60. ;    assume CS:_TEXT
  61. .CODE
  62.     EXTRN   _int14netsleep:FAR   ; C routine which gets called from handler
  63.     PUBLIC  _TIMEINST,_TIMEDEINST
  64. else
  65.     ENDDS
  66.     PSEG
  67.     EXTRN   int14netsleep:FAR    ; C routine which gets called from handler
  68.     PUBLIC  TIMEINST,TIMEDEINST
  69. endif   
  70. ;
  71. ;**************************************************************************
  72. ;
  73. ;  Routines to install and deinstall a timer routine which calls
  74. ;  netsleep(0);
  75. ;  The timer is set to go off every 1/2 second to check for packets 
  76. ;  in the incoming packet buffer.  We use the user-hook into the system 
  77. ;  timer which occurs every 1/18th of a second.
  78. ;
  79. ;
  80. TIMEINT        EQU    4*1CH        ; User hook to timer int
  81.  
  82. ;*************************************************************************
  83. ;
  84. ;  Take out the timer interrupt handler, restore previous value
  85. ;
  86. ifdef Microsoft
  87. _TIMEDEINST    PROC    FAR
  88. else
  89. TIMEDEINST PROC    FAR
  90. endif
  91.     MOV        CX,CS:TIP        ; GET OLD IP FROM SAVE SPOT
  92.     MOV        DX,CS:TCS        ; GET OLD CS FROM SAVE SPOT
  93.     MOV        BX,TIMEINT        ; INTERRUPT IN TABLE FOR TIMER
  94.     PUSH    DS
  95.     XOR        AX,AX            ; SYSTEM INTERRUPT TABLE
  96.     MOV        DS,AX        
  97.     CLI
  98.     MOV        [BX],CX            ; STORE OLD IP INTO THE TABLE
  99.     INC        BX
  100.     INC        BX                ; MOVE POINTER IN INTERRUPT TABLE
  101.     MOV        [BX],DX            ; STORE OLD CS INTO THE TABLE
  102.     STI
  103.     POP        DS
  104.     RET
  105. ifdef Microsoft
  106. _TIMEDEINST    ENDP
  107. else
  108. TIMEDEINST ENDP
  109. endif
  110.  
  111. ;
  112. ;
  113. ;  install the timer interrupt handler, the handler is technically
  114. ;  part of this procedure.
  115. ;
  116. ifdef Microsoft
  117. _TIMEINST  PROC    FAR
  118. else
  119. TIMEINST   PROC    FAR
  120. endif
  121.     XOR        AX,AX
  122.     MOV        CS:TENTER,AL    ; CLEAR THIS FLAG
  123.     MOV        CS:TMYDS,DS        ; STORE FOR USE BY HANDLER
  124.     MOV        BX,TIMEINT        ; INTERRUPT IN TABLE FOR TIMER (1c)
  125.     PUSH    DS
  126.     XOR        AX,AX            ; SYSTEM INTERRUPT TABLE
  127.     MOV        DS,AX        
  128.     MOV        AX,OFFSET THAND    ; WHERE THE HANDLER IS
  129.     CLI
  130.     MOV        DX,[BX]            ; KEEP COPY OF THE IP
  131.     MOV        [BX],AX            ; STORE IP INTO THE TABLE
  132.     INC        BX
  133.     INC        BX                ; MOVE POINTER IN INTERRUPT TABLE
  134.     MOV        CX,[BX]            ; KEEP COPY OF THE CS, TOO
  135.     MOV        AX,CS
  136.     MOV        [BX],AX            ; STORE NEW CS INTO THE TABLE
  137.     STI
  138.     POP    DS
  139.     MOV    CS:TIP,DX            ; STORE THEM AWAY
  140.     MOV    CS:TCS,CX
  141.     RET
  142. ;
  143. ;  Code segment addressable data for keeping track of the interrupt handler
  144. ;  stuff
  145. ;
  146. TMYDS        DW    00H            ; THE DATA SEGMENT FOR THIS ASSEMBLY CODE
  147. TICNT        DB    0            ; COUNTER OF 1/18THS SEC
  148. TENTER         DB  00
  149. TIP          DW  00
  150. TCS          DW  00
  151. ;
  152. ;   The handler itself.
  153. ;
  154. THAND:                           ; not a public name, only handles ints
  155.     STI
  156.     PUSH    DS
  157.     PUSH     ES
  158.     PUSH    AX
  159.     PUSH    BX
  160.     PUSH    CX
  161.     PUSH    DX
  162.     PUSH    DI
  163.     PUSH    SI
  164.  
  165.     CLD                        ; ALL MOVES WILL BE FORWARD
  166.     MOV        AL,CS:TENTER
  167.     OR        AL,AL
  168.     JNZ        TIME2
  169.     MOV        AL,1
  170.     MOV        CS:TENTER,AL    ; SET FLAG TO INDICATE BUSY
  171.     INC        CS:TICNT
  172.     MOV        AL,CS:TICNT        ; COUNTER FOR US
  173. ifdef QAK
  174.     AND        AL,7            ; SEE IF # MOD 8 = 0
  175. else
  176.     AND     AL,3            ; SEE IF # MOD 8 = 0
  177. endif
  178.     JNZ        TSKIP            ; SKIP 7 OUT OF 8 TIMES
  179. ;
  180.     MOV        AL,60H            ; EOI FOR TIMER INT
  181.     OUT        20H,AL            ; LET LOWER INTERRUPTS IN
  182. ;
  183. ;  SET UP CORRECT DS
  184. ;
  185.     MOV        DS,CS:TMYDS        ; GET CORRECT DS
  186. ;
  187. ;  do we have to set up our own stack here?
  188. ;
  189.     MOV        AX,SS
  190.     MOV        OLDSS,AX
  191.     MOV        OLDSP,SP
  192.     CLI
  193.     MOV        AX,seg NEWSTACK
  194.     MOV        SS,AX
  195.     MOV        SP,OFFSET STACKEND
  196.     STI
  197. ;    XOR     AX,AX
  198. ;    PUSH    AX
  199. ifdef Microsoft
  200.     CALL _int14netsleep
  201. else    
  202.     CALL int14netsleep
  203. endif
  204. ;    POP     AX
  205.     CLI    
  206.     MOV        AX,OLDSS
  207.     MOV        SS,AX
  208.     MOV        SP,OLDSP
  209.     STI
  210. TSKIP:
  211.     XOR        AL,AL
  212.     MOV        CS:TENTER,AL    ; REENTER FLAG, DONE NOW
  213. TIME2:
  214.     POP     SI
  215.     POP        DI
  216.     POP        DX
  217.     POP        CX
  218.     POP        BX
  219.     POP        AX
  220.     POP        ES
  221.     POP        DS
  222. ;
  223. ;   forward to any other existing routines
  224. ;
  225.     JMP     DWORD PTR CS:TIP
  226. ifdef Microsoft
  227. _TIMEINST      ENDP
  228. else
  229. TIMEINST       ENDP
  230. endif
  231. ifdef Microsoft
  232. ;_TEXT ends
  233.  
  234. else
  235.     ENDPS
  236. endif
  237.     END
  238.