;**************************************************************************
; THEDOT.M68    -       Subroutine to find out if JOBNAM at "the dot"
;                       "The dot" is assumed a JOB which will accept a FORCE
;
; by Dave Heyliger - AMUS Staff
;
; Usage:        MAP1 JOB'NAME, S, 6
;               MAP1 T'OR'F, S, 1, ""
;
;               JOB'NAME = "JOB#"
;               XCALL THEDOT,JOB'NAME,T'OR'F
;               IF T'OR'F = "T" then ? JOB'NAME " is at the dot!"
;**************************************************************************

       OBJNAM  THEDOT.SBR              ;what it creates

       SEARCH  SYS                     ;search normals
       SEARCH  SYSSYM
       SEARCH  TRM
       SEARCH  AAA                     ;from DSK2:[100,133]

DEFINE  DIM = PRTTAB -1,11.             ;dim output
DEFINE  BRIGHT = PRTTAB -1,12.          ;bright output

       PHDR    -1,0,PH$REE!PH$REU      ;of course it's reentrant, reusable

       ; First test to make sure the user XCALLed this thing correctly
       ;
       CMPW    @A3,#2                  ;two arguments?
       JNE     ERROR                   ;nope
       CMPW    2(A3),#2                ;JOB'NAME a string?
       JNE     ERROR                   ;nope
       CMPW    14(A3),#2               ;T'OR'F a string?
       JNE     ERROR                   ;nope

       ; OK, user read how to use the XCALL. Get the JOB'NAME in RAD50
       ;
       MOV     4(A3),A2                ;A2 points to JOB'NAME
       MOV     A4,A1                   ;A1 points to free workspace
       PACK                            ;create RAD50 job name string
       PACK

       ; Find name in job table, or no job at all....
       ;
       MOV     JOBTBL,A0               ;get start of job table listing
LOOP:   MOV     (A0)+,A5                ;A4 points to a JCB or a -1
       MOV     A5,D0                   ;set status register
       JMI     NOJOB                   ;if -1 then couldn't find JOB
       BEQ     LOOP                    ;no defined JOB but still not done
       MOV     A4,A1                   ;point A1 to JOB name RAD50
       LEA     A2,JOBNAM(A5)           ;point A0 to JOB name
       CMM     @A1,@A2                 ;match?
       BNE     LOOP                    ;nope, look again

       ; Found the JOB - check terminal status word
       CLR     D0                      ;clear data register
       MOVW    JOBSTS(A5),D0           ;get status word
       ANDW    #J.TIW,D0               ;copy TIW bit
       CMPW    D0,#J.TIW               ;at the dot?
       BEQ     TRUE                    ;yup
       CALL    FALSE                   ;nope
       RTN                             ;and return
TRUE:   MOV     16(A3),A3               ;A3 points to result string
       MOVB    #'T,(A3)+               ;create "T"
       CLRB    @A3                     ;null string
       RTN                             ;and return


       ; When JOB is not at the dot, set false flag
       ;
FALSE:  MOV     16(A3),A3               ;A3 points to result string
       MOVB    #'F,(A3)+               ;create "T"
       CLRB    @A3                     ;null string
       RTN                             ;and return


       ; Error in XCALL format
       ;
ERROR:  DIM                             ;dim output
       TYPE    <?XCALL format error. Format should be >
       BRIGHT                          ;bright output
       TYPE    <XCALL ">
       MOV     4(A3),A3                ;point A3 to JOB'NAME
       TTYL    @A3                     ;type out JOB'NAME
       TYPECR  <",RESULT$>             ;end of error message
       MOV     #7,D1                   ;bell tone
       TTY                             ;BEEP!
       CALL    FALSE                   ;set result to false
       RTN


       ; Couldn't find JOB in JOB table....
       ;
NOJOB:  DIM                             ;dim output
       TYPE    <?Could not locate >    ;start of error message
       BRIGHT                          ;bright output
       MOV     4(A3),A3                ;point A3 to JOB'NAME
       TTYL    @A3                     ;type out JOB'NAME
       DIM                             ;dim output
       TYPECR  < on this system.>      ;end of error message
       MOV     #7,D1                   ;get a bell
       TTY                             ;BEEP!
       BRIGHT                          ;back to standard output
       CALL    FALSE                   ;set result to false
       RTN                             ;return to BASIC

END