        title test remote alive


cseg    segment para public 'code'

        org 100h

        assume cs:cseg,ds:cseg,es:nothing



entry   proc far


su1:
  call parms                 ;read command line
  call test1                 ;test status of line
  mov ah,4Ch                 ;return to dos
  int 21h

                             ;return code    0=good link
                             ;               1=link did not respond
                             ;               2=network not installed

entry  endp



;page
subs proc near
;........................... test link ......................................

test1:
  push cs                    ;ds=cs
  pop ds
  call test5C                ;make sure int 5C is valid
  jnz test1a                 ;it isn't:     it is-->
  test msgmode,1             ;are we printing messages?
  jz t0a                     ;yes:   no-->
  mov si,offset msg4         ;print "NETWORK NOT INSTALLED"
  call outstr

t0a:
  mov al,2                   ;return code (2) = network not installed
  ret

test1a:
  mov ah,4                   ;ah = command "alive"
  mov al,cs:comnum           ;al = COM port link to use (0=default)
  mov cx,cs:wait             ;cx = wait count in char times
  push dx
  mov dx,1234h
  int 5Ch                    ;execute network request
  pop dx
  push cs                    ;ds=cs
  pop ds
  or al,al                   ;did remote respond?
  jz t2                      ;no:     yes-->

t1:
  test msgmode,1             ;are we printing messages?
  jz t1a                     ;yes:    no-->
  mov si,offset msg1         ;print "COMx LINK IS DEAD"
  call outstr
  mov si,offset msg3
  call outstr

t1a:
  mov al,1                   ;return code (1) = dead network link
  ret



t2:
  test msgmode,1             ;are we printing messages?
  jz t2a                     ;yes:   no-->
  mov si,offset msg1         ;print "COMx LINK IS OK"
  call outstr
  mov si,offset msg2
  call outstr

t2a:
  mov al,0                   ;return code (0) = network link ok
  ret

;page
;........................... test int 5C for valid ........................

test5C:
  push ds                    ;ds=abs0
  xor dx,dx
  mov ds,dx
  lds si,dword ptr ds:170h   ;get vector
  mov dx,ds                  ;is 0:0?
  or dx,si
;  jnz t5Cb                  ;will be valid signature in future
;  cmp word ptr [si-3],"EN"  ;(vector-4 = "NET?")
;  jnz t5Cb
;  cmp byte ptr [si-1],"T"

t5Cb:
  pop ds
  ret




subs endp


;page
setup proc near
;........................... Get setup parameters ............................

parms:
  push cs
  pop es
  push cs
  pop ds
  xor cx,cx                  ;cx will = # of chars in line
  mov si,81h                 ;ds:si --> command line
  mov cl,[si-1]              ;get count

parms1:
  call nxtchar               ;get next char
  jnc parms1a                ;if no more, return
  ret

parms1a:
  cmp al,"O"                 ;*****  is ON:x ? *****
  jne parms2
  call nxtchar
  cmp al,"N"
  jne parms1a
  call nxtchar
  cmp al,":"
  jne parms1a                ;yes:                no-->
  call getnum                ;pickup number
  mov cs:comnum,dl           ;save COM number
  add dl,"0"
  mov cs:msg1+5,dl
  jmp parms1



parms2:
  cmp al,"M"                 ;*****  Is it PRINT MSG *****
  jne parms6
  call nxtchar
  cmp al,"S"
  jne parms1a
  call nxtchar
  cmp al,"G"
  jne parms1a                ;yes:                no-->
  mov cs:msgmode,1
  jmp parms1

;page


parms6:
  cmp al,"W"                 ;*****  is WAIT:n ? *****
  jne parms9
  call nxtchar
  cmp al,"A"
  jne parms6b
  call nxtchar
  cmp al,"I"
  jne parms6b
  call nxtchar
  cmp al,"T"
  jne parms6b
  call nxtchar
  cmp al,":"
  jne parms6b                ;yes:                no-->
  call getnum                ;pickup number
  test dh,0FFh
  jz parms6a
  mov dx,255

parms6a:
  mov cs:wait,dx
  jmp parms1

parms6b:
  jmp parms1a

parms9:
  jmp parms1
          


;page
;........................... Get next char ...................................

nxtchar:
  jcxz nc10                  ;if no more chars in buffer-->
  lodsb                      ;get next char
  dec cx                     ;decrement count remaining
  cmp al,13                  ;is CR ?
  jz nc9                     ;no:             yes-->
  cmp al,"a"                 ;force to CAPs
  jc nc8
  cmp al,"z"+1
  jnc nc8
  xor al,20h

nc8:
  clc                        ;return good
  ret

nc9:
  dec si                     ;dont go passed CR
  xor cx,cx                  ;no more chars

nc10:
  stc                        ;return, none found
  ret

;........................... Get number .....................................

getnum:
  xor dx,dx                  ;init number = 0

gn1:
  jcxz gn9                   ;are any chars left?  no-->
  lodsb                      ;yes, get next one
  dec cx                     ;dec # left
  mov ah,al                  ;save char
  sub ah,"0"                 ;adjust ascii to number
  jc gn8                     ;was char < "0" ?   yes-->
  cmp ah,10                  ;is char  > "9" ?   
  jnc gn8                    ;                   yes-->
  xchg ax,dx
  mov ah,10                  ;decimal shift left
  mul ah
  xchg ax,dx
  add dl,ah                  ;add in ones
  adc dh,0
  jmp gn1                    ;see if more

gn8:
  dec si                     ;restore buffer ptr
  inc cx                     ;restore # remaining

gn9:
  ret

setup endp

;page
;........................... CON string output ............................... 
outstr proc near

  lodsb
  or al,al
  jz o2
  mov ah,14
  push si
  int 10h
  pop si
  jmp outstr

o2: ret

outstr endp

comnum  db 0
wait    dw 100

msgmode db 0
msg1    db 13,10,"COMx LINK IS ",0
msg2    db "ALIVE",10,13,0
msg3    db "DEAD",10,13,0
msg4    db 13,10,"NETWORK NOT INSTALLED",13,10,0

cseg    ends
        end su1


