;***************************************************************************
; TEXT.M68 - Sends text to a given JOB
;
; Usage:  .TEXT jobnam :<text stuff here>
;
; NOTE - You MUST include the :<...> markers (just like .CMD files)
;
;       Control characters are represented as "/#" - where # is ASCII
;       in decimal.
;
;       RETURNs may be represented as /N for simplicity
;
;       Finally, you may include spaces on the .TEXT line. For example,
;       suppose JOB2 was at VUE command mode. The following line -
;               .TEXT JOB2 :</27 Hello /N There! /27 Finish>
;       would cause JOB2 to execute an ESC, display HELLO, then a RETURN,
;       then display THERE!, then an ESC, and finally FINISH from VUE.
;
;       "Hard spaces" are represented as "|" characters. For example,
;               .TEXT JOB2 :<Hello|there|folks!>
;       will display the "|" characters as blanks
;
;       Notice that TEXT will allow you to create VUE files via .CMD files!
;       For example:
;               :R
;               FORCE JOB2 VUE HELLO.LST        ; fires up VUE
;               FORCE JOB2 Y                    ; "Y" for 'create it'
;               TEXT JOB2 :</27 .... see above ... >
;               TEXT JOB2 :< ... more lines if you like ... >
;               ***************** ( end of command file)
;
; by Dave Heyliger - AMUS
;***************************************************************************

       OBJNAM  TEXT.LIT        ;the final product

       SEARCH SYS              ;get the monitor calls...
       SEARCH SYSSYM
       SEARCH TRM
       SEARCH AAA              ;DSK2:[100,133] on Network

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

       VMAJOR=1                ;define a version number
       VMINOR=0                ;original by Dave Heyliger
       VEDIT=100.

       PHDR    -1,0,PH$REU!PH$REE      ;program header

       .OFINI                  ;define variables
       .OFDEF  ASCBUF,500.     ;ascii buffer (modify larger if nec...)
       .OFDEF  RADBUF,10.      ;RAD50 buffer
       .OFSIZ  IMPSIZ          ;final size of memory buffer

       GETIMP  IMPSIZ,A4       ;A4 dedicated to point to variables

       ;Get JOB off of input line into RAD50 format
       BYP                     ;bypass whitespace
       LIN                     ;just a CR?
       JNE     GETJOB          ;nope
USAGE:  TYPE    <Usage:  .TEXT >        ;yes, show user how to use file
       DIM
       TYPE    <jobnam >
       BRIGHT
       TYPE    <:>
       MOV     #'<,D1
       TTY
       DIM
       TYPE    <....>
       BRIGHT
       MOV     #'>,D1
       TTY
       CRLF
       DIM
       TYPE    <          Use >
       BRIGHT
       TYPE    <">
       MOV     #'/,D1
       TTY
       TYPE    <n" >
       DIM
       TYPE    <for >
       BRIGHT
       TYPECR  <RETURN>
       DIM
       TYPE    <          If >
       BRIGHT
       TYPE    <control characters >
       DIM
       TYPE    <are desired, use >
       BRIGHT
       TYPE    <">
       MOV     #'/,D1
       TTY
       TYPE    <#">
       DIM
       TYPECR  <,>
       TYPECR  <          where # = ASCII character value in decimal>
       BRIGHT
       EXIT

GETJOB: LEA     A0,ASCBUF(A4)   ;point to ascii buffer space
       CLR     D0              ;counter
20$:    MOVB    (A2)+,(A0)+     ;move in ascii JOB name
       INC     D0              ;counter increased
       CMPB    @A2,#40         ;finished with name?
       BNE     20$             ;nope
       ;
25$:    CMP     D0,#6           ;JOB name 6 characters?
       BEQ     30$             ;yes, continue
       MOVB    #40,(A0)+       ;nope, pack with spaces
       INC     D0              ;increment counter
       BR      25$             ;check length again
       ;
30$:    PUSH    A2              ;save input pointer
       LEA     A2,ASCBUF(A4)   ;point to ascii JOB name
       LEA     A1,RADBUF(A4)   ;point A1 to RAD50 buffer
       PACK                    ;create JOB name
       PACK
       ;
       POP     A2              ;retrieve input line pointer
       ;
       MOV     JOBTBL,A0       ;JOB TABLE address to A0
       LEA     A1,RADBUF(A4)   ;point A1 to JOB name RAD50
SCAN:   MOV     (A0)+,A3        ;A3 now points to each JCB per SCAN
       MOV     A3,D1           ;Set the status register
       BMI     NOJOB           ;if at end of JOBTBL, JOB not found
       BEQ     SCAN            ;if a "0" then look at next JCB
       CMM     JOBNAM(A3),@A1  ;see if name matches
       BNE     SCAN            ;no match
       BR      GETLIN          ;found JOB, get input line
       ;
NOJOB:  BRIGHT                  ;didn't find JOB
       TYPECR  <?JOB not found>
       EXIT
       ;
GETLIN: BYP                     ;bypass whitespace on input line
       ;
       CMPB    (A2)+,#':       ;looking for ":"
       JNE     USAGE           ;didn't find the ":"
       CMPB    (A2)+,#'<       ;looking for "<"
       JNE     USAGE           ;didn't find the "<"
       ;
       LEA     A0,ASCBUF(A4)   ;buffer where string will live
10$:    CMPB    @A2,#'>         ;terminator?
       BEQ     FORCE           ;yes, time to force JOB input string
       MOVB    (A2)+,(A0)+     ;no, create text string...
       BR      10$
       ;
FORCE:  CLRB    @A0             ;end string with null
       ;
       MOV     JOBTRM(A3),A5   ;A5 points to user's TCB
       LEA     A2,ASCBUF(A4)   ;repoint A0 to string
       CLR     D1              ;fussy data registers
10$:    CMPB    @A2,#0          ;end of the string?
       BEQ     EXIT            ;yes
       BYP                     ;bypass any whitespace
       MOVB    (A2)+,D1        ;else get the character
       ;
       CMPB    D1,#'|          ;blank character?
       BNE     12$             ;nope
       MOVB    #40,D1          ;yup, get a space
       BR      20$             ;and type it out
       ;
12$:    CMPB    D1,#'/          ;slash?
       BNE     20$             ;nope, don't worry about it
       ;
       NUM                     ;A2 pointing to a number?
       BNE     15$             ;nope, see if it is an "N"
       GTDEC                   ;get the number into D1
       BR      20$             ;and perform the control character
       ;
15$:    CMPB    (A2)+,#'N       ;after the slash, is it an "N"?
       JNE     USAGE           ;nope, error on input
       MOVB    #15,D1          ;get a CR into D1
       BR      20$             ;and branch to blast routine
       ;
20$:    TRMICP                  ;and blast it into JOB's input buffer
       SLEEP   #1000.
       BR      10$
       ;
EXIT:   EXIT                    ;all done!
       ;
END