home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rxfiles.zip
/
rxhostid.asm
< prev
next >
Wrap
Assembly Source File
|
1997-08-14
|
7KB
|
197 lines
;-----------------------------------------------------------------------
; RXHOSTID.RX by ML /AT /Fe RXHOSTID.RX RXHOSTID.ASM
;-----------------------------------------------------------------------
code segment para public 'CODE'
assume cs:code, ds:code, es:code, ss:code
org 54h
DOSREXX4 dd ? ;_psp:0x54 'REXX' signature
SHVENTRY dd ? ;_psp:0x58 shared variable handler
org 82h
RXARGC dw ? ;_psp:0x82 number of arguments
RXARGV dd ? ;_psp:0x84 arg.s (length, pointer)
RXRESULT dd ? ;_psp:0x88 RESULT buffer (256 bytes)
org 100h ;COM entry point at CS:100
start: jmp stack ;set stack, release memory
number db 0 ;local machine number is normally 0
argerr db 13,10,7,'invalid REXX machine name argument',13,10,0
;-----------------------------------------------------------------------
main proc near ;enter after initialization
cmp word ptr DOSREXX4+2,'XX'
jne badarg
cmp RXARGC,1
jb getname ;no argument: get name
xor ax,ax ;AL 0: get machine name
call netname ;get name into RXRESULT
jc fail ;function not supported
cmp ch,0 ;CH 0: undefine(d) name
je no_name
mov number,cl ;machine number for set
no_name: les si,RXARGV
call chklen ;check 1st argument
jcxz clrname ;special if omitted
jc badarg
mov ax,15
cmp cx,ax ;machine name <= 15
jnbe badarg
push ds
lds si,es:[si+2] ;DS:SI 1st argument
les di,cs:RXRESULT ;ES:DI RESULT buffer
sub ax,cx ;15 - length
rep movsb ;copy argument
xchg ax,cx
mov al,' '
rep stosb ;pad with blanks
xchg ax,cx
stosw ;0 for ASCIIZ string
pop ds
mov al,1 ;AL 1: set machine name
mov ch,al ;CH 1: defines new name
call netname ;set name from RXRESULT
jmp getname
clrname: mov al,1 ;AL 1: set machine name
mov ch,0 ;CH 0: undefine(d) name
call netname ;clear name, use number
getname: xor ax,ax ;AL 0: get machine name
call netname ;get name into RXRESULT
jc fail ;function not supported
cmp ch,0 ;CH = 0: undefined name
jne okay
les di,RXRESULT ;set undefined RXRESULT
xor al,al ;because function 5E00h
stosb ;filled it with garbage
okay: xor al,al ;REXX function ended
jmp exit
badarg: mov dx,offset argerr
call message
fail: mov al,1 ;REXX function error
exit: mov ah,4Ch ;terminate with RC AL
int 21h
main endp
;-----------------------------------------------------------------------
netname proc near ;INT 21 function 5E, AL 00 get, 01 set
push ds ;CH 00 undefine(d), else define(d) name
push dx ;CL machine number (if name defined)
mov cl,cs:number
lds dx,cs:RXRESULT ;operates on RXRESULT buffer
mov ah,5Eh
int 21h
pop dx
pop ds
ret
netname endp
;-----------------------------------------------------------------------
chklen proc near ;check length of REXX argument ES:SI
push es ;keep all user registers except from CX
push ds ;returns argument's string length in CX
push ax ;no carry: CX matches REXX length
push dx ;if carry: CX zero or REXX length != CX
push es
pop ds
mov cx,[si] ;length of argument
jcxz reject ;empty is not okay
push cx
les dx,[si+2] ;pointer to argument
call strlen ;check length
pop dx
cmp cx,dx ;compare with caller's idea
jne reject ;accept only correct length
clc
jmp accept
reject: stc
accept: pop dx
pop ax
pop ds
pop es
ret
chklen endp
;-----------------------------------------------------------------------
strlen proc near ;return length ASCIIZ string ES:DX
xchg di,dx ;modifies AX, CX
mov cx,di ;keep DX, DI, ES
not cx ;terminate search at segment limit
push di ;this will work for length < 64 KB
xor al,al
repne scasb ;search NUL
mov cx,di ;DI points behind NUL (or is NULL)
pop di ;restore DI
sub cx,di ;length inclusive NUL
dec cx ;length exclusive NUL
xchg dx,di ;restore DX
ret ;returns CX string length
strlen endp
;-----------------------------------------------------------------------
message proc near ;ASCIIZ string DS:DX to STDERR
push ax ;modifies BX, CX
push es ;keep AX, DX, DS, ES
push ds
pop es ;set ES = DS
call strlen ;CX = strlen( ES:DX )
pop es ;load old ES
mov bx,2 ;ASCIIZ string DS:DX to STDERR
mov ah,40h
int 21h
pop ax
ret
message endp
;-----------------------------------------------------------------------
align 16
stkparas equ 32 ;stack size 512 = 32 * 16
stack label near ;initialise *.com program
mov bx,offset stack + 16 * stkparas
mov sp,bx ;new stack 100h above init
mov cl,4
shr bx,cl ;used number of paragraphs:
mov ah,4ah ;modify allocated memory to
int 21h ;needed size i.e. free rest
jmp main ;current SP must be beyond
;-----------------------------------------------------------------------
code ends
end start ;program entry point