         TITLE    'UTSG-B00,09/11/73,DWG702985'
         PAGE
*
*
*  E X T E R N A L    C O M M U N I C A T I O N
*
*
*  DEFINITIONS
*
         DEF      FPTWR2            FPT TO WRITE F:Q0G
         DEF      GETCHAR           GET INPUT CHARACTER
         DEF      GETCOORD          GET CURSOR COORDS
         DEF      GRAFOUT           GRAPHICS OUTPUT ROUTINE
         DEF      GRAFTEXT          GRAPHICS TEXTUAL OUTPUT
         DEF      GRBUFLIM          GRAPHICS I/O BUFFER LIMIT
         DEF      UTSG@             START OF PROCEDURE
*
*  REFERENCES
*
         REF      ERIO              GRAPHICS PKG I/O ERROR EXIT
         REF      GRAFBUF           GRAPHICS I/O BUFFER
         REF      GRFIOFLG          GRAPHICS TERM I/O FLAG
         REF      GRINCHAR          GRAPHICS TERM INPUT CHAR
         REF      GRXYBYTS          GRAPHICS TERM X/Y COORD BYTES
         REF      IOERCODE          I/O ERROR CODE WORD
         REF      NEXTLINE          RESTORE CURSOR LOC
         REF      RETURN            RETURN ADR CELL
         PAGE
         REF      STRAPOPT          4013 STRAP OPTION,5,6,OR 7 CHARS.
*
*
*  A S S E M B L Y    P A R A M E T E R S
*
*
         SYSTEM   BPM
         SYSTEM   SIG5
PROGSECT CSECT    1
UTSG@    EQU      %                 START OF PROCEDURE
*
*  REGISTERS
*
CC       EQU      3                 OUTPUT CHAR COUNT
LX       EQU      5                 LINK REG
R        EQU      8                 GENERAL WORK REG
R1       EQU      9                     *
LO       EQU      14                LINK FOR 'DUMPOUT'
*
*  TERMINAL CONTROL CHARACTERS
*
#ESC     EQU      X'1B'             NEXT CHAR IS CONTROL
#ENQ     EQU      X'05'             ENQUIRY, ENTER GIN MODE
#SUB     EQU      X'1A'             DISPLAY CROSSHAIR, ENTER GIN MODE
*
*  MISCELLANEOUS
*
ORECSIZE EQU      130               MAX SIZE OF OUTPUT RECORD (BYTES)
         PAGE
*
*
*  T E R M I N A L    I / O
*
*
         USECT    PROGSECT
*
*  GET CURSOR COORDINATES
*
*              READS TERMINAL STATUS BYTE INTO GRSTBYTE AND CURSOR
*              COORDINATE BYTES INTO GRXYBYTS.  LINK IS LX.
*
GETCOORD EQU      %
         LI,R     #ESC**8+#ENQ
         STH,R    GRAFBUF           PUT 'ENQUIRE' COMMAND IN BUFFER
         CAL1,1   FPTWR2            SEND 'ENQUIRE' COMMAND
         CAL1,1   FPTRD             READ STATUS AND COORD BYTES
         LW,R     GRSTBYTE          IF 'MARGIN-1' BIT OF STATUS BYTE
         CI,R     2                   IS SET,
         BAZ      0,LX
         LW,R1    =X'10000000'        TURN ON MOST SIGNIFICANT  BIT
         STS,R1   GRXYBYTS
         B        0,LX              EXIT
*
GRSTBYTE EQU      GRINCHAR          GRAPHICS TERM STATUS BYTE
         PAGE
*
*
*  READ CHAR AND CROSSHAIR COORDS
*
*              READS CHAR INTO GRINCHAR AND CROSSHAIR CURSOR COORDINATE
*              BYTES INTO GRXYBYTS.  LINK IS LX.
*
GETCHAR  EQU      %
         LI,R     #ESC**8+#SUB
         STH,R    GRAFBUF
         CAL1,1   FPTWR2            SEND 'DISPLAY CROSSHAIR' COMMAND
         CAL1,1   FPTRD             READ CHAR AND COORD BYTES
         B        0,LX              EXIT
         PAGE
*
*
*  WRITE OUTPUT BUFFER
*
*
*              OUTPUTS (CC) GRAPHIC TERMINAL CONTROL BYTES FROM
*              'GRAFBUF'.  RESETS CC TO ZERO.
*              LINK IS LO.
*
GRAFOUT  EQU      %
         AI,CC    0                 IF CC=0, THERE'S
         BEZ     *LO                  NOTHING TO OUTPUT.
         CAL1,1   FPTWRGRF          OUTPUT GRAFBUF TO F:Q0G
         LI,CC    0                 RESET CC=0
         B       *LO                EXIT
*
GRBUFLIM DATA     ORECSIZE-4        BUF SIZE
         PAGE
*
*
*  WRITE TEXTUAL OUTPUT
*
*
*              OUTPUTS (CC) ALPHANUMERIC CHARACTERS FROM
*              'GRAFBUF'.  RESETS CC TO ZERO.
*              LINK IS LO.
*
GRAFTEXT EQU      %
         AI,CC    0                 IF CC=0, THERE'S
         BEZ     *LO                  NOTHING TO OUTPUT.
         CAL1,1   FPTWRALF          OUTPUT GRAFBUF TO F:Q0A
         LI,CC    0                 RESET CC=0
         B       *LO                EXIT
         PAGE
*
*
*  ERROR CONTROL
*
ERRGRFIO EQU      %
         STW,10   IOERCODE          SAVE ERROR STATUS INFO
         LI,R     -1                SET I/O FLAG AND TEST ITS
         XW,R     GRFIOFLG            FORMER STATE.
         BLZ      ERIO              IF IT WAS ALREADY SET, THEN WE
*                                     WERE TRYING TO RESTORE CURSOR
*                                     POSITION IN RESPONSE TO A PRIOR
*                                     I/O ERROR - SO FORGET IT.
         LW,R     GRXYBYTS          1ST ERROR: HAD THE CURSOR LOC
         BEZ      ERIO                BEEN SAVED? (IF NOT, EXIT).
         LI,R     ERIO              YES, SET EXIT ADDRESS TO 'ERIO'
         STW,R    RETURN
         LI,CC    0                   INIT CHAR COUNT,
         B        NEXTLINE            AND RESTORE CURSOR LOC.
         PAGE
*
*
*  FPT'S
*
*
F        COM,1,7,7,17 AFA(1),CF(2),0,AF(1)
*
FPTWR2   F,X'11'  F:Q0G             M:WRITE  F:Q0G,
         DATA     X'34000000'
         F        GRAFBUF             (BUF,GRAFBUF),
         F        2                   (SIZE,2),
         F        0                   (BTD,0)
*
FPTRD    F,X'10'  F:Q0G             M:READ  F:Q0G,
         DATA     X'34000010'         (WAIT),
         F        GRSTBYTE            (BUF,GRSTBYTE),
         F       *STRAPOPT            (SIZE,7,6,OR 5),
         F        3                   (BTD,3)
*
FPTWRGRF F,X'11'  F:Q0G             M:WRITE  F:Q0G,
         DATA     X'34000000'
         F        GRAFBUF             (BUF,GRAFBUF),
         F       *CC                  (SIZE,*CC),
         F        0                   (BTD,0)
*
FPTWRALF F,X'11'  F:Q0A             M:WRITE  F:Q0A,
         DATA     X'34000000'
         F        GRAFBUF             (BUF,GRAFBUF),
         F       *CC                  (SIZE,*CC),
         F        0                   (BTD,0)
         PAGE
*
*
*  DCB'S
*
*              GRAPHICS MODE DCB:
*
F:Q0G    DSECT    1
F:Q0G    M:DCB    (DEVICE,'UC'),(BIN),(DRC),;
                  (ERR,ERRGRFIO),(ABN,ERRGRFIO)
*
*              ALPHA MODE DCB:
*
F:Q0A    DSECT    1
F:Q0A    M:DCB    (DEVICE,'UC'),(BCD),(NODRC),;
                  (ERR,ERRGRFIO),(ABN,ERRGRFIO)
*
         USECT    PROGSECT
*
         END

