home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxfiles.zip / rxhostid.asm < prev    next >
Assembly Source File  |  1997-08-14  |  7KB  |  197 lines

  1. ;-----------------------------------------------------------------------
  2. ; RXHOSTID.RX by ML /AT /Fe RXHOSTID.RX RXHOSTID.ASM
  3. ;-----------------------------------------------------------------------
  4.  
  5. code     segment para public 'CODE'
  6.  
  7.          assume cs:code, ds:code, es:code, ss:code
  8.  
  9.          org    54h
  10. DOSREXX4 dd     ?               ;_psp:0x54 'REXX' signature
  11. SHVENTRY dd     ?               ;_psp:0x58 shared variable handler
  12.  
  13.          org    82h
  14. RXARGC   dw     ?               ;_psp:0x82 number of arguments
  15. RXARGV   dd     ?               ;_psp:0x84 arg.s (length, pointer)
  16. RXRESULT dd     ?               ;_psp:0x88 RESULT buffer (256 bytes)
  17.  
  18.          org    100h            ;COM entry point at CS:100
  19. start:   jmp    stack           ;set stack, release memory
  20.  
  21. number   db     0               ;local machine number is normally 0
  22.  
  23. argerr   db     13,10,7,'invalid REXX machine name argument',13,10,0
  24.  
  25. ;-----------------------------------------------------------------------
  26. main     proc   near            ;enter after initialization
  27.  
  28.          cmp    word ptr DOSREXX4+2,'XX'
  29.          jne    badarg
  30.  
  31.          cmp    RXARGC,1
  32.          jb     getname         ;no argument: get name
  33.  
  34.          xor    ax,ax           ;AL 0: get machine name
  35.          call   netname         ;get name into RXRESULT
  36.  
  37.          jc     fail            ;function not supported
  38.          cmp    ch,0            ;CH 0: undefine(d) name
  39.          je     no_name
  40.          mov    number,cl       ;machine number for set
  41.  
  42. no_name: les    si,RXARGV
  43.          call   chklen          ;check 1st argument
  44.          jcxz   clrname         ;special if omitted
  45.          jc     badarg
  46.          mov    ax,15
  47.          cmp    cx,ax           ;machine name <= 15
  48.          jnbe   badarg
  49.  
  50.          push   ds
  51.          lds    si,es:[si+2]    ;DS:SI 1st argument
  52.          les    di,cs:RXRESULT  ;ES:DI RESULT buffer
  53.          sub    ax,cx           ;15 - length
  54.          rep    movsb           ;copy argument
  55.          xchg   ax,cx
  56.          mov    al,' '
  57.          rep    stosb           ;pad with blanks
  58.          xchg   ax,cx
  59.          stosw                  ;0 for ASCIIZ string
  60.          pop    ds
  61.  
  62.          mov    al,1            ;AL 1: set machine name
  63.          mov    ch,al           ;CH 1: defines new name
  64.          call   netname         ;set name from RXRESULT
  65.          jmp    getname
  66.  
  67. clrname: mov    al,1            ;AL 1: set machine name
  68.          mov    ch,0            ;CH 0: undefine(d) name
  69.          call   netname         ;clear name, use number
  70.  
  71. getname: xor    ax,ax           ;AL 0: get machine name
  72.          call   netname         ;get name into RXRESULT
  73.  
  74.          jc     fail            ;function not supported
  75.          cmp    ch,0            ;CH = 0: undefined name
  76.          jne    okay
  77.  
  78.          les    di,RXRESULT     ;set undefined RXRESULT
  79.          xor    al,al           ;because function 5E00h
  80.          stosb                  ;filled it with garbage
  81.  
  82. okay:    xor    al,al           ;REXX function ended
  83.          jmp    exit
  84.  
  85. badarg:  mov    dx,offset argerr
  86.          call   message
  87.  
  88. fail:    mov    al,1            ;REXX function error
  89. exit:    mov    ah,4Ch          ;terminate with RC AL
  90.          int    21h
  91.  
  92. main     endp
  93.  
  94. ;-----------------------------------------------------------------------
  95. netname  proc   near            ;INT 21 function 5E, AL 00 get, 01 set
  96.  
  97.          push   ds              ;CH 00 undefine(d), else define(d) name
  98.          push   dx              ;CL machine number (if name defined)
  99.          mov    cl,cs:number
  100.          lds    dx,cs:RXRESULT  ;operates on RXRESULT buffer
  101.  
  102.          mov    ah,5Eh
  103.          int    21h
  104.  
  105.          pop    dx
  106.          pop    ds
  107.          ret
  108.  
  109. netname  endp
  110.  
  111. ;-----------------------------------------------------------------------
  112. chklen   proc   near            ;check length of REXX argument ES:SI
  113.  
  114.          push   es              ;keep all user registers except from CX
  115.          push   ds              ;returns argument's string length in CX
  116.          push   ax              ;no carry: CX matches REXX length
  117.          push   dx              ;if carry: CX zero or REXX length != CX
  118.  
  119.          push   es
  120.          pop    ds
  121.          mov    cx,[si]         ;length of argument
  122.          jcxz   reject          ;empty is not okay
  123.  
  124.          push   cx
  125.          les    dx,[si+2]       ;pointer to argument
  126.          call   strlen          ;check length
  127.          pop    dx
  128.  
  129.          cmp    cx,dx           ;compare with caller's idea
  130.          jne    reject          ;accept only correct length
  131.          clc
  132.          jmp    accept
  133.  
  134. reject:  stc
  135. accept:  pop    dx
  136.          pop    ax
  137.          pop    ds
  138.          pop    es
  139.          ret
  140.  
  141. chklen   endp
  142.  
  143. ;-----------------------------------------------------------------------
  144. strlen   proc   near            ;return length ASCIIZ string ES:DX
  145.  
  146.          xchg   di,dx           ;modifies AX, CX
  147.          mov    cx,di           ;keep DX, DI, ES
  148.          not    cx              ;terminate search at segment limit
  149.          push   di              ;this will work for length < 64 KB
  150.          xor    al,al
  151.          repne  scasb           ;search NUL
  152.          mov    cx,di           ;DI points behind NUL (or is NULL)
  153.          pop    di              ;restore DI
  154.          sub    cx,di           ;length inclusive NUL
  155.          dec    cx              ;length exclusive NUL
  156.          xchg   dx,di           ;restore DX
  157.          ret                    ;returns CX string length
  158.  
  159. strlen   endp
  160.  
  161. ;-----------------------------------------------------------------------
  162. message  proc   near            ;ASCIIZ string DS:DX to STDERR
  163.  
  164.          push   ax              ;modifies BX, CX
  165.          push   es              ;keep AX, DX, DS, ES
  166.          push   ds
  167.          pop    es              ;set ES = DS
  168.          call   strlen          ;CX = strlen( ES:DX )
  169.          pop    es              ;load old ES
  170.  
  171.          mov    bx,2            ;ASCIIZ string DS:DX to STDERR
  172.          mov    ah,40h
  173.          int    21h
  174.          pop    ax
  175.          ret
  176.  
  177. message  endp
  178.  
  179. ;-----------------------------------------------------------------------
  180.          align  16
  181. stkparas equ    32              ;stack size 512 = 32 * 16
  182.  
  183. stack    label  near            ;initialise *.com program
  184.  
  185.          mov    bx,offset stack + 16 * stkparas
  186.          mov    sp,bx           ;new stack 100h above init
  187.          mov    cl,4
  188.          shr    bx,cl           ;used number of paragraphs:
  189.          mov    ah,4ah          ;modify allocated memory to
  190.          int    21h             ;needed size i.e. free rest
  191.  
  192.          jmp    main            ;current SP must be beyond
  193.  
  194. ;-----------------------------------------------------------------------
  195. code     ends
  196.          end    start           ;program entry point
  197.