home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / netclk / netclock.asm next >
Assembly Source File  |  1989-01-28  |  5KB  |  191 lines

  1.  
  2.  
  3.                 title NETCLOCK
  4.                 page  58,132
  5. ;.RM100/
  6. ;NETCLOCK obtains the date and time by calling SRVCLOCK.
  7. ;
  8. ;
  9. ; Alan Queen (208) 384-9137
  10. ; Boise, ID  83712
  11. ; Last update: 03/18/88
  12.  
  13.  
  14. CR        EQU    0DH        ;carriage return
  15. LF        EQU    0AH        ;line feed
  16. MAX_RETRY    EQU    3        ;max times to retry call, increase
  17.                     ;this if experiencing "CALL" command
  18.                     ;failed errors
  19.  
  20.  
  21. CODE    SEGMENT    PARA     PUBLIC    'CODE'
  22.         ASSUME    CS:CODE,DS:CODE,ES:CODE
  23.         ORG    100H
  24. START:        JMP    BEGIN
  25.  
  26. ;
  27. ;message data
  28. STAT_ERR    DB    CR,LF,'"GET NAME" COMMAND FAILED',CR,LF,'$'
  29. CAL_ERR        DB    CR,LF,'"CALL" COMMAND FAILED',CR,LF,'$'
  30. RCV_ERR        DB    CR,LF,'"RECEIVE" COMMAND FAILED',CR,LF,'$'
  31. NETBIOS_ERR    DB    CR,LF,'NETBIOS INTERFACE NOT PRESENT',CR,LF,'$'
  32. SUCCESS        DB    CR,LF,'User Clock Synchronized to Server Clock',CR,LF,'$'
  33. SERVER_NAME    DB    'SRV_CLOCK       '
  34. ERR_COUNT    DB    0            ;Call counter 
  35. ;
  36. ;clock data area
  37. CLOCK        EQU    $
  38. YEAR        DW    0000H
  39. MONTH        DB    00H
  40. DAY        DB    00H
  41. HOURS        DB    00H
  42. MINUTES        DB    00H
  43. SECONDS        DB    00H
  44. HUNDREDTHS    DB    00H
  45. ;
  46. ;a netbios message control block data 
  47. MCB        EQU    $            ;
  48. COMMAND        DB     00H            ;Netbios command 
  49. RETCODE        DB    00H            ;the return code
  50. LSN        DB    00H            ;the local session number
  51. NUM        DB    00H            ;number of application name
  52. BUFFER@        DW    0000H            ;pointer to message buffer
  53.         DW    0000H            ;segment:offset
  54. BUF_LENGTH    DW    0000H            ;length of the buffer
  55. CALLNAME    DB    '*               '    ;name to call 
  56. OUR_NAME        DB      16 dup(0)        ;place for our name
  57. RTO        DB    10H            ;receive time out
  58. STO        DB    10H            ;send time out
  59. POST@        DW    0000H            ;post address for 
  60.         DW    0000H            ;no wait commands
  61. ADAPTER_NUM    DB    00H            ;the adapter 0 or 1
  62. CMD_STAT    DB    00H            ;command status
  63. RESERVE        DB    14 DUP(0)        ;
  64. ;
  65. ;buffer for adapter status request
  66. ;(Minimum allowable adapter status buffer=60, this program uses only first 6)
  67. RET@        EQU    $
  68. ID_NUM        DB    6 dup(0)
  69. FILLER        DB    54 dup(0)
  70.  
  71. ;
  72. ; Check if interrupt 5C has a vector
  73. ;
  74. BEGIN:
  75.         PUSH    ES            ;save ES
  76.             MOV     AH,35H                  ;get interrupt 5C vector
  77.               MOV     AL,5CH
  78.                INT     21H
  79.         MOV    AX,ES
  80.         POP    ES            ;get back ES
  81.         CMP    AX,0            ;is segment 0
  82.         JNE    ADAPTER_STAT        ;not 0 an interface is present
  83.         LEA    DX,NETBIOS_ERR        ;else error message
  84.         JMP    ERROR1            ;
  85.  
  86. ;
  87. ;do netbios adapter status to obtain machine name (wait for completion)
  88. ;NOTE:  This may be a problem for some netbios clones.  If so replace this
  89. ;section with an add name routine that adds a unique name
  90. ;
  91. ADAPTER_STAT:      MOV    COMMAND,33H        ;Command 33=adapter status
  92.         MOV    BUFFER@+2,DS        ;high word buffer=data segment
  93.         MOV    AX,OFFSET RET@        ;move offset of 
  94.         MOV    BUFFER@,AX        ;return area into NCB buffer 
  95.         MOV    BUF_LENGTH,60        ;minimum possible space=60 
  96.         MOV    BX,OFFSET MCB        ;point BX to MCB
  97.         INT    5CH            ;call to netbios 
  98.         CMP    RETCODE,06H        ;return code should be an
  99.                         ;error of buffer to small(06)
  100.         JE     GET_NAME        ;get machine name returned
  101.         CMP    RETCODE,0        ;if only netbios loaded
  102.         JE    GET_NAME        ;return will be a 0
  103.         CMP    AL,0FBH            ;netbios not loaded?
  104.         JNE    ADP1            ;if not FB then something else
  105.         MOV    DX,OFFSET NETBIOS_ERR    ;netbios error message
  106.         JMP    ERROR            ;
  107. ADP1:
  108.         MOV    DX,OFFSET STAT_ERR    ;else status error message
  109.         JMP    ERROR            ;
  110. GET_NAME:
  111.         MOV    SI,OFFSET RET@        ;move machine name to position
  112.         MOV    DI,OFFSET OUR_NAME+10    ;after 10 bytes of 00h
  113.         MOV    CX,6            ;6 bytes = machine name
  114.     REPNZ    MOVSB                ;
  115. ;
  116. ;change callname to SRV_CLOCK
  117. ;                        ;
  118.         MOV    SI,OFFSET SERVER_NAME    ;Move server name
  119.         MOV    DI,OFFSET CALLNAME    ;into MCB
  120.         MOV    CX,16            ;use all 16 bytes
  121.     REPNZ    MOVSB                ;
  122. ;                        
  123. ;do netbios call (wait for completion)        
  124. ;                        
  125. NETCALL:    MOV    COMMAND,10H        ;Move call command code to MCB
  126.         MOV    BX,OFFSET MCB        ;point BX at MCB 
  127.         INT    5CH            ;call netbios
  128.         CMP    AL,00H            ;check completion code
  129.         JE    GET_TIME        ;if ok, receive server time 
  130.         INC    ERR_COUNT        ;else increment call counter
  131.         CMP    ERR_COUNT,MAX_RETRY    ;have we tried to the max? If not
  132.         JL    NETCALL            ;try again, SRVCLOCK may be busy
  133.         MOV    DX,OFFSET CAL_ERR    ;if too many write error message
  134.         JMP    ERROR            ;
  135. ;
  136. ;receive time from server 
  137. ;
  138. GET_TIME:    MOV    COMMAND,15H        ;Move receive command to MCB
  139.         MOV    BUFFER@,OFFSET CLOCK    ;point buffer to clock area
  140.         MOV    BUFFER@+2,DS        ;initialize segment
  141.         MOV    BUF_LENGTH,08        ;clock needs 8 bytes
  142.         INT    5CH            ;call netbios
  143.         CMP    AL,00H            ;check for errors
  144.         JE    HANGUP            ;if none close the session
  145.                         ;time and date now in CLOCK
  146.                         ;area
  147.         MOV    DX,OFFSET RCV_ERR    ;else receive error
  148.         JMP    ERROR            ;
  149. ;
  150. ;hangup session
  151. ;
  152. HANGUP:        MOV    COMMAND,12H        ;Move hang-up command to MCB
  153.         INT    5CH            ;Netbios call
  154.                         ;
  155.         MOV    AH,09H            ;display success
  156.         MOV    DX,OFFSET SUCCESS    ;message to user
  157.         INT    21H            ;
  158. ;
  159. ;install the date and time
  160. ;                        ;
  161.         MOV    CX,YEAR            ;Prepare to set
  162.         MOV    DH,MONTH        ;the date
  163.         MOV    DL,DAY            ;using function call
  164.         MOV    AH,2BH            ;2BH
  165.         INT    21H            ;
  166.                         ;
  167.         MOV    CH,HOURS        ;and set the date
  168.         MOV    CL,MINUTES        ;using data in  
  169.         MOV    DH,SECONDS        ;clock area
  170.         MOV    DL,HUNDREDTHS        ;using function 
  171.         MOV    AH,2DH            ;call 2DH
  172.         INT    21H            ;
  173.         MOV    AX,4C00H        ;exit code no error
  174.         JMP     QUIT
  175. ;
  176. ;error message and closing
  177. ;
  178. ERROR:        MOV    COMMAND,12H        ;hang-up session if any
  179.         INT    5CH            ;
  180.  
  181. ERROR1:        MOV    AH,09H            ;write error message to screen
  182.         INT    21H            ;
  183.         MOV    AX,4C01H        ;exit with error 1
  184.  
  185. QUIT:        INT    21H
  186.  
  187. CODE        ENDS
  188.  
  189.         END    START
  190. 
  191.