* === isrexx.asm =======================================================
*
* Written by William S. Hawes (1988) >>> freely distributable <<<
*
* ======================================================================
* This program is intended to be run as a WShell "prompt program".  It
* checks for a public port "REXX" to see if the ARexx server is active.
* If it is, it displays the message "REXX" on the standard output stream.

         INCLUDE  "exec/types.i"
         INCLUDE  "exec/macros.i"
         INCLUDE  "exec/tasks.i"

         INCLUDE  "libraries/dos.i"
         INCLUDE  "libraries/dosextens.i"

         XREF     _AbsExecBase

         ; DOS library functions

         XLIB     Write

         ; Exec library functions

         XLIB     CloseLibrary
         XLIB     FindPort
         XLIB     OpenLibrary

         IFND     EXECBASE_I
ThisTask EQU      $114
         ENDC

start    movea.l  _AbsExecBase,a6
         movea.l  ThisTask(a6),a4      ; our task ID

         ; Open the DOS library

         lea      DOSLib(pc),a1
         moveq    #LIBRARY_VERSION,d0
         CALLSYS  OpenLibrary
         move.l   d0,d5                ; "guaranteed"

         ; Check for the REXX port

         lea      REXXPort(pc),a1      ; public port
         CALLSYS  FindPort             ; D0=port node
         tst.l    d0                   ; found?
         beq.s    1$                   ; no

         ; Display the message ...

         move.l   pr_COS(a4),d1        ; a stream?
         beq.s    1$                   ; no
         lea      RXMsg(pc),a0
         move.l   a0,d2
         moveq    #RXLEN,d3
         exg      d5,a6
         CALLSYS  Write
         exg      d5,a6

1$:      movea.l  d5,a1
         CALLSYS  CloseLibrary

         moveq    #0,d0
         rts

         ; String constants

DOSLib   dc.b     'dos.library',0

REXXPort dc.b     'REXX',0             ; port name
RXMsg    dc.b     'REXX'               ; display
RXLEN    EQU      *-RXMsg
         CNOP     0,2

         END
