home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / net_time / srvclock.asm < prev    next >
Assembly Source File  |  1988-01-22  |  10KB  |  228 lines

  1. ;
  2. ; srvclock.asm  -  From PC Magazine . August '87, pp468-470
  3. ;
  4. ;    A background task for use on any AT running NETBIOS.  This routine will 
  5. ; get and send its date and time information to any node executing 
  6. ; NETCLOCK.EXE.  NETCLOCK.EXE then installs the received date and time in the 
  7. ; node.  Since SRVCLOCK.EXE reads th AT's CMOS RAM directly, it works only on 
  8. ; ATs
  9. ;
  10. cr            equ    0dh
  11. lf            equ    0ah
  12.  
  13. cseg  segment para   public   'code'
  14. net           proc   far
  15.               assume cs:cseg,ds:netdata,ss:stack,es:netdata
  16.               push   ds
  17.               xor    ax,ax
  18.               push   ax
  19.               mov    ax,netdata
  20.               mov    ds,ax
  21.               mov    es,ax
  22. ;
  23. ; dealocate block containing environment
  24. ;
  25.               mov    ah,62h                  ; get program segment prefix
  26.               int    21h                     ;   address
  27.               push   ds                      ; save old data segment
  28.               mov    ds,bx                   ; mov PSP segment to DS  - rsb
  29.               mov    es,ds:02ch              ; move the block address
  30.               mov    ah,49h                  ; containing the enviroment
  31.               int    21h                     ; and deallocate it
  32.               pop    ds                      ; restore DS
  33.               mov    ax,ds                   ;
  34.               mov    es,ax                   ; and ES
  35. ;
  36. ; netbios add name call (waits for completion)
  37. ;
  38. add_name:     mov    command,30h             ; Command 30H adds a neme
  39.               mov    bx,offset mcb           ; point BX at MCB
  40.               int    5ch                     ; call netbios
  41.               cmp    retcode,00h             ; check for success
  42.               je     prep_res                ; prepare for TSR if good 
  43.               mov    dx,offset add_err       ; else write errro message
  44.               jmp    error                   ; name that was not successful
  45. prep_res:
  46.               mov    dx,30h                  ; number of paragraphs for
  47.                                              ; terminate and stay resident
  48. ;
  49. ; do netbios listen posting into get_clock, then tsr
  50. ;
  51.               mov    command,91h             ; Move listen to MCB no wait
  52.               mov    post@,offset get_clock  ; and post at get clock
  53.               mov    post@+2,cs              ; routine
  54.               mov    bx,offset mcb           ; point BX to MCB
  55.               int    5ch                     ; netbios call
  56.               cmp    al,00h                  ; check for good return
  57.               je     go_res                  ; if good, make resident
  58.               mov    dx,offset lsn_err       ; else write error
  59.               jmp    error                   ;
  60. go_res:       mov    ah,31h                  ; DOS terminate and stay
  61.               int    21h                     ; resident
  62. ;
  63. ; this listen is returned to after a opost into get_clock
  64. ;
  65. listen:       mov    command,91h             ; Move listen to MCB
  66.               mov    post@,offset get_clock  ; also posts to clock
  67.               mov    post@+2,cs              ; routine
  68.               mov    bx,offset mcb           ; point BX to block
  69.               int    5ch                     ; NETBIOS call
  70.               sti                            ; restore interrupts
  71.               iret                           ; and return
  72. ;
  73. ; get date and time to send to requesting node
  74. ;
  75. get_clock:    cli                            ; cut off interrupts
  76.               mov    ax,es                   ; ES is restored by network
  77.               mov    ds,ax                   ; use to restore DS
  78.               xor    ax,ax                   ; clear AX
  79.               mov    al,09                   ; 09 = Year
  80.               out    70h,al                  ; Real time clock at 70H
  81.               in     al,71h                  ; returns at 71H
  82.               call   bcd2bin                 ; convert to binary
  83.               add    ax,76ch                 ; add 1900 decimal, only works 
  84.                                              ; until 1999
  85.               mov    year,ax                 ; load buffer with year
  86.                                              
  87.               xor    ax,ax                   ; get month
  88.               mov    al,08                   ;
  89.               out    70h,al                  ;
  90.               in     al,71h                  ;
  91.               call   bcd2bin                 ;
  92.               mov    month,al                ;
  93.  
  94.               xor    ax,ax                   ; get date of month
  95.               mov    al,07                   ;
  96.               out    70h,al                  ;
  97.               in     al,71h                  ;
  98.               call   bcd2bin                 ;
  99.               mov    day,al                  ;
  100.  
  101.               xor    ax,ax                   ; get hours
  102.               mov    al,04                   ;
  103.               out    70h,al                  ;
  104.               in     al,71h                  ;
  105.               call   bcd2bin                 ;
  106.               mov    hours,al                ;
  107.  
  108.               xor    ax,ax                   ; get minutes
  109.               mov    al,02                   ;
  110.               out    70h,al                  ;
  111.               in     al,71h                  ;
  112.               call   bcd2bin                 ;                        
  113.               mov    minutes,al              ;
  114.  
  115.               xor    ax,ax                   ; get seconds
  116.               mov    al,00                   ;
  117.               out    70h,al                  ;
  118.               in     al,71h                  ;
  119.               call   bcd2bin                 ;
  120.               mov    seconds,al              ;
  121. ;
  122. ; send clock data to requesting node using a netbios send
  123. ;
  124.               mov    buffer@,offset clock    ; point to clock data area
  125.               mov    buffer@+2,ds            ; insure correct segment
  126.               mov    buf_length,8            ; clock takes 8 byees
  127.               mov    command,14h             ; 14H=send and wait
  128.               mov    bx,offset mcb           ; point to MCB
  129.               int    5ch                     ; NETBIOS
  130.  
  131. hangup:       mov    command,12h             ; 12H=hangup
  132.               mov    bx,offset mcb           ; point BX
  133.               int    5ch                     ; NETBIOS call
  134.  
  135.               mov    si,offset fill_name     ; fill name=listen any
  136.               mov    di,offset callname      ; move to call name
  137.               mov    cx,0fh                  ; names are 16 bytes
  138.     repnz     movsb                          ;
  139.               jmp    listen                  ; back to waiting for call
  140. ;
  141. ; error message, failed before coming resident
  142. ;
  143. error:        mov    ah,09h                  ; display error message
  144.               int    21h                     ; if routine fails before 
  145.                                              ; becoming resident
  146.               mov    command,12h             ; hang up session if any
  147.               mov    bx,offset mcb           ; point BX
  148.               int    5ch                     ; NETBIOS call
  149. quit:         ret                            ;
  150.  
  151. net           endp
  152.  
  153. ;
  154. ; procedure to convert time as delivered from CMOS clodk (binary coded decimal)
  155. ; to binary (as used by DOS function calls and NETCLOCK) (returns in AL)
  156. ;
  157. bcd2bin       proc   near
  158.               push   ax                      ; save contents
  159.               and    al,0f0h                 ; clear out low nibble
  160.               shr    al,1                    ; divide by 16
  161.               shr    al,1                    ;    so that hi nibble
  162.               shr    al,1                    ;    is now in
  163.               shr    al,1                    ;    lo position
  164.               mov    bl,al                   ; hold in al
  165.               shl    al,1                    ; multiply by ten, two here
  166.               shl    al,1                    ;    four
  167.               shl    al,1                    ;    eight
  168.               add    al,bl                   ;    nine
  169.               add    al,bl                   ;    ten
  170.               pop    bx                      ; get previous AX contents
  171.               and    bl,0fh                  ; clear out hi nibble
  172.               add    al,bl                   ; add to total
  173.               ret
  174. bcd2bin       endp
  175.  
  176. cseg          ends
  177. ;
  178. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  179. ;                          message data
  180. ;
  181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  182. netdata segment para public 'data'
  183. add_err       db     cr,lf,'"add name" command failed',cr,lf,'$'
  184. lsn_err       db     cr,lf,'"listen" command failed',cr,lf,'$'
  185. fill_name     db     '*               '
  186. ;
  187. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  188. ;                      message control area
  189. ;
  190. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  191. clock         equ    $
  192. year          dw     0000h
  193. month         db     00h
  194. day           db     00h
  195. hours         db     00h
  196. minutes       db     00h
  197. seconds       db     00h
  198. hundredths    db     00h
  199. ;
  200. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  201. ;                      message control block
  202. ;
  203. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  204. mcb           equ    $
  205. command       db     00h
  206. retcode       db     00h
  207. lsn           db     00h
  208. num           db     00h
  209. buffer@       dw     0000h
  210.               dw     0000h
  211. buf_length    dw     0000h
  212. callname      db     '*               '
  213. our_name      db     'srv_clock       '
  214. rto           db     00h
  215. sto           db     00h
  216. post@         dw     0000h
  217.               dw     0000h
  218. adapter_num   db     00h
  219. cmd_stat      db     00h
  220. reserve       db     14 dup(0)
  221.  
  222. netdata       ends
  223. stack         segment para stack 'stack'
  224.               db     32 dup('stack   ')
  225. stack         ends
  226.               end
  227.  
  228.