;
; netclock.asm  -  From PC Magazine . August '87, pp468-470
;
;    NETCLOCK runs on the IBM PCLAN and PCNP programs and obtains the time and
; date from a network server running SRVCLOCK.exe or SRVCLOKF.EXE.  NETCLOCK
; must be executed in a workstation after the "NET START" command.
;
cr            equ    0dh
lf            equ    0ah

cseg  segment para   public   'code'
net           proc   far
              assume cs:cseg,ds:netdata,ss:stack,es:netdata
              push   ds
              xor    ax,ax
              push   ax
              mov    ax,netdata
              mov    ds,ax
              mov    es,ax
              mov    cx,00h
;
; netbios adapter status - get machine name (wait for completion)
;
adapter_stat: mov    command,33h             ; Command 33=adapter status
              mov    buffer@+2,ds            ; high word buffer=data segment
              mov    ax,offset ret@          ; move offset of
              mov    buffer@,ax              ; return area into NCB buffer
              mov    buf_length,60           ; minimum possible space=60
              mov    bx,offset mcb           ; point BX to MCB
              int    5ch                     ; call to NETBIOS
              cmp    retcode,06h             ; return code should be an
                                             ; error of buffer to small (06)
              je     get_name                ; get machine name returned
              mov    dx,offset stat_err      ; else status error message
              jmp    error                   ;
get_name:     mov    si,offset ret@          ; move machine name to position
              mov    di,offset our_name+10   ; after 10 bytes of 00h
              mov    cx,6                    ; 6 byes = machine name
     repnz    movsb                          ;
;
; change call name to srv_clock
;                                            ;
              mov    si,offset server_name   ; Move server name
              mov    di,offset callname      ; into MCB
              mov    cx,16                   ; use all 16 bytes
     repnz    movsb                          ;
;
; do netbios call (wait for completion)
;
call:         mov    command,10h             ; Move call command code to MCB
              mov    bx,offset mcb           ; point BX at MCB
              int    5ch                     ; call NETBIOS
              cmp    al,00h                  ; check completion code
              je     get_time                ; if ok, receive server time
              mov    dx,offset cal_err       ; else write error message
              jmp    error                   ;
;
; receive time from server
;
get_time:     mov    command,15h             ; Move receive command to MCB
              mov    buffer@,offset clock    ; point buffer to clock area
              mov    buffer@+2,ds            ; initialize segment
              mov    buf_length,08           ; clock needs 8 bytes
              int    5ch                     ; call NETBIOS
              cmp    al,00h                  ; check for errors
              je     hangup                  ; if none close the session
                                             ; time and date now in CLOCK
                                             ; area
              mov    dx,offset rcv_err       ; else receive error
              jmp    error                   ;
;
; hangup session
;
hangup:       mov    command,12h             ; Move hang-up command to MCB
              int    5ch                     ; NETBIOS call
                                             ;
              mov    ah,09h                  ; display success
              mov    dx,offset success       ; message to user
              int    21h                     ;
;
; install date and time
;
              mov    cx,year                 ; prepare to set
              mov    dh,month                ; the date
              mov    dl,day                  ; using DOS function call
              mov    ah,2bh                  ; 2bH
              int    21h                     ;
                                             ;
              mov    ch,hours                ; and set the date
              mov    cl,minutes              ; using data in
              mov    dh,seconds              ; clock area
              mov    dl,hundredths           ; using DOS function
              mov    ah,2dh                  ; call 2dH
              int    21h                     ;
              jmp    quit                    ;
;
; error message and closing
;
error:        mov    ah,09h                  ; write error message to screen
              int    21h                     ;
              mov    command,12h             ; hang-up session if any
              int    5ch                     ;
quit:         ret
net           endp

cseg          ends
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;                           message data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
netdata segment para public 'data'

stat_err      db     cr,lf,'"get name" command failed',cr,lf,'$'
cal_err       db     cr,lf,'"call" command failed',cr,lf,'$'
rcv_err       db     cr,lf,'"receive" command failed',cr,lf,'$'
success       db     cr,lf,'network clock installed',cr,lf,'$'
server_name   db     'srv_clock       '
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;                       clock data area
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
clock         equ    $
year          dw     0000h
month         db     00h
day           db     00h
hours         db     00h
minutes       db     00h
seconds       db     00h
hundredths    db     00h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;                 message control block data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mcb           equ    $
command       db     00h
retcode       db     00h
lsn           db     00h
num           db     00h
buffer@       dw     0000h
              dw     0000h
buf_length    dw     0000h
callname      db     '*               '
our_name      db     16 dup(0)
rto           db     00h
sto           db     00h
post@         dw     0000h
              dw     0000h
adapter_num   db     00h
cmd_stat      db     00h
reserve       db     14 dup(0)
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;                 buffer for adapter status request
;
; (Minimum allowable adapter status buffer=60,
;  this program uses only first 6)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret@          equ    $
id_num        db     6 dup(0)
filler        db     54 dup(0)
netdata       ends

stack         segment para stack 'stack'
              db      32 dup('stack   ')
stack         ends
              end

