         TITLE    'GRAF-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      DELTAGRF          DELTA-GRF FUNCTION
         DEF      GRAF@             START OF PROCEDURE
         DEF      GRFIOFLG          GRAF TERM I/O FLAG
         DEF      GRINCHAR          GRAF TERM INPUT CHAR
         DEF      GRXYBYTS          GRAF TERM X/Y COORD BYTES
         DEF      NEXTLINE          RESTORE CURSOR POSITION
         DEF      QZINPUT           QUAD-ZERO INPUT DRIVER
         DEF      QZOUTPUT          QUAD-ZERO OUTPUT DRIVER
*
*  REFERENCES
*
         REF      ALOCHNW           ALLOCATE HEADER AND N WORDS
         REF      BREAKFLG          BREAK FLAG
         REF      CREALBIN          CONVERT REAL TO DEC MANTISSA/EXPON
         REF      DIGITS            'DIGITS' VALUE
         REF      DXRETURN          DYADIC  FUNCTION RETURN
         REF      ERDOMAIN          DOMAIN ERROR
         REF      ERLENGTH          LENGTH ERROR
         REF      ERRANK            RANK ERROR
         REF      ERTERMAL          TERMINAL TYPE ERROR
         REF      F2I               FLOT TO INTG CONVERSION
         REF      GDIGITS           'DIGITS' VALUE FOR AXIS LIMITS
         REF      GENDIGS           GEN MANTISSA DIGITS
         REF      GENDIGSE          GEN MANTISSA DIGITS, E-FORMAT
         REF      GENEXP            GEN EXPONENT CHARS
         REF      GETCHAR           GET INPUT CHARACTER/COORDS
         REF      GETCOORD          READ CURSOR LOC
         REF      GRAFBUF           GRAPHICS I/O BUFFER
         REF      GRAFOUT           GRAPHICS OUTPUT ROUTINE
         REF      GRAFTEXT          GRAPHICS TEXTUAL OUTPUT
         REF      GRBUFLIM          GRAPHICS BUFFER LIMIT
         REF      GRAFPNTR          GRAPHICS PARAMETERS DATA BLOCK PNTR
         REF      GSCLRVAL          GET SCALAR VALUE
         REF      IDTERMAL          IDENT CODE FOR TERMINAL TYPE ERROR
         REF      LFARG             LEFT  ARG PNTR
         REF      LFRANK            LEFT  ARG RANK
         REF      LFSIZE            LEFT  ARG SIZE
         REF      LFTYPE            LEFT  ARG TYPE
         REF      MXRETURN          MONADIC FUNCTION RETURN
         REF      OPBREAK           OP BREAK HANDLER LOC
         REF      ORIGIN            INDEX ORIGIN (0 OR 1)
         REF      OUTRANST          OUTPUT TRANSLATE TABLE
         REF      QZINRET           QUAD-ZERO INPUT DRIVER RETURN
         REF      QZOUTRET          QUAD-ZERO OUTPUT DRIVER RETURN
         REF      RESULT            RESULT DATA BLOCK POINTER
         REF      RETURN            RETURN ADDRESS CELL
         REF      RTADR             RIGHT ARG ADR CELL
         REF      RTARG             RIGHT ARG PNTR
         REF      RTRANK            RIGHT ARG RANK
         REF      RTSIZE            RIGHT ARG SIZE
         REF      RTTYPE            RIGHT ARG TYPE
         REF      SETCHAR           PUT CHAR IN BUFFER
         REF      SETUPARG          SET UP ARG PARAMETERS
         REF      STRAPOPT          GRAF INPUT STRAP OPTION 5-6-OR-7
         REF      TERMTYPE          TERMINAL TYPE CODE
         REF      XSEGBASE          XSEG BASE
         REF      XSEGBRK           XSEG BREAK OK FLAG
         REF      XSETUP            SET ADR FOR INDEXED ACCESS
         PAGE
*
*
*  A S S E M B L Y    P A R A M E T E R S
*
*
         SYSTEM   SIG5F
PROGSECT CSECT    1
GRAF@    RES      0                 START OF PROCEDURE
*
*  REGISTERS
*
F        EQU      0                 FLAGS REG
XI       EQU      1                 GENERAL INDEX REG
K        EQU      2                 SUBSCRIPT REG
T        EQU      2                 TYPE
M        EQU      2                 ARG DIMENS
N        EQU      3                     *
CC       EQU      3                 OUTPUT CHAR COUNT
XL       EQU      3                 XSEG LOC
A        EQU      4                 ARG ADR/INDEX
LZ       EQU      4                 LINK REG
GP       EQU      4                 GRAPHICS DATA BLOCK POINTER
LX       EQU      5                 INDEX LINK REG
LX7      EQU      7                 INDEX LINK REG
AF       EQU      6                 ACCUM FOR FLOT VALUES
AF1      EQU      7                     *
AI       EQU      7                 ACCUM FOR INTG VALUES
BUF      EQU      7                 BUFFER FOR MOVING DATA/CODE GROUPS
R        EQU      8                 GENERAL WORK REG
R1       EQU      9                     *
R2       EQU      10                    *
R3       EQU      11                    *
X        EQU      8                 POINT COORD REG
Y        EQU      9                     *
Z        EQU      10                    *
S        EQU      11                SIZE
L3       EQU      12                LINK REG
L2       EQU      13                LINK REG
L1       EQU      14                LINK REG
LO       EQU      14                LINK FOR 'GRAFOUT'
*
*  DATA TYPE CODES
*
LOGL     EQU      1                 LOGICAL   (BIT)
CHAR     EQU      2                 CHARACTER (BYTE)
INTG     EQU      3                 INTEGER   (WORD)
FLOT     EQU      4                 FLOATING  (DOUBLEWORD)
*
*  FLAG BITS
*
DASHFLAG EQU      X'001'            DASHED CURVE FLAG
RENTFLAG EQU      X'002'            RE-ENTER FLAG
3DFLAG   EQU      X'004'            3-DIMENSIONAL PLOT FLAG
EDGEFLAG EQU      X'008'            EDGE-CROSS FLAG
ISCLFLAG EQU      X'010'            INPUT SCALING FLAG
ASCLFLAG EQU      X'020'            AUTO-SCALING FLAG
CENTERFG EQU      X'040'            CENTER SCALING FLAG
VECTORFG EQU      X'080'            VECTOR-IN-PROGESS FLAG
OFSETFLG EQU      X'100'            OFFSET POINT FLAG
*
*  TERMINAL CONTROL CHARACTERS
*
#ESC     EQU      X'1B'             NEXT CHAR IS CONTROL
#FF      EQU      X'0C'             ERASE SCREEN
#GS      EQU      X'1D'             START VECTOR
#US      EQU      X'1F'             END VECTOR
#XHIGH   EQU      X'20'             UPPER HALF OF X DATA
#YHIGH   EQU      X'20'             UPPER HALF OF Y DATA
#XLOW    EQU      X'40'             LOWER HALF OF X DATA
#YLOW    EQU      X'60'             LOWER HALF OF Y DATA
*
*  OFFSETS INTO GRAPHICS PARAMETERS DATA BLOCK
*
FLAGS    EQU      3                 FLAGS (DASH/RE-ENTER,SCALING)
XMIN     EQU      4                 SCALE DATA: X1          UNITS
XMAX     EQU      5                             X2          UNITS
YMIN     EQU      6                             Y1          UNITS
YMAX     EQU      7                             Y2          UNITS
ZMIN     EQU      8                             Z1          UNITS
ZMAX     EQU      9                             Z2          UNITS
XSCALE   EQU      10                            %XPTS/(X2-X1)
YSCALE   EQU      11                            %YPTS/(Y2-Y1)
ZSCALE   EQU      12                            %ZPTS/(Z2-Z1)
LXWINDOW EQU      13                WINDOW DATA: LOWER X    INCHES
UXWINDOW EQU      14                             UPPER X    INCHES
LYWINDOW EQU      15                             LOWER Y    INCHES
UYWINDOW EQU      16                             UPPER Y    INCHES
XDISPFIX EQU      17                             X'46800XXX'
*                                      WHERE       XXX=PPI*LX   POINTS
XRATIO   EQU      18                             (UX-LX)/%XINCHS
YDISPFIX EQU      19                             X'46800YYY'
*                                      WHERE       YYY=PPI*LY   POINTS
YRATIO   EQU      20                             (UY-LY)/%YINCHS
INXCOORD EQU      21                X COORD OF QUAD-0 INPUT CHAR
INYCOORD EQU      22                Y COORD OF QUAD-0 INPUT CHAR
INCHAR   EQU      23                INPUT CHARACTER
SPARE1   EQU      24                  SPARES(FOR FUTURE PICTURE SAVE)
SPARE2   EQU      25
*
GRDBSIZE EQU      26                GRAPHICS DATA BLOCK SIZE
         PAGE
*
*
*  P R O C S
*
*
*              (THIS MODULE RESIDES IN AN OVERLAY, SO THE USUAL
*              TEMP ALLOCATION PROCEDURE WILL NOT WORK).
*
TLOC     SET      20
GRFTEMPS EQU      XSEGBASE
*
TEMP     CNAME    1
DTEMP    CNAME    2
         PROC
         DO1      NAME=2
TLOC     SET      TLOC+(TLOC&1)
         DISP     TLOC
LF       EQU      GRFTEMPS+TLOC
TLOC     SET      TLOC+NAME
         PEND
*
*
EVEN     CNAME    0
ODD      CNAME    1
         PROC
LF       EQU      %
         ERROR,1,(CF(2)+NAME)&1   'REGISTER HAS WRONG PARITY'
         PEND
*
*
EQUAL    CNAME
         PROC
LF       EQU      %
         ERROR,1,1-(CF(2)=CF(3))  'REGISTERS MUST BE EQUAL'
         PEND
         PAGE
*
*
*  XSEG GEN PROCS
*
*
         OPEN     GEN
GEN      CNAME
         OPEN     M,N,MN,I
         PROC
LF       EQU      %
         ERROR,1,1-(NUM(CF)=3)  'WRONG NUMBER OF CF ARGS'
M        SET      CF(2)
N        SET      CF(3)
MN       SET      M+N
         ERROR,1,1-(NUM(AF)=(M>0)+(N>0)) 'WRONG NUMBER OF AF ARGS'
         DO       M>0
I          DO       N
             LW,AF(1)+M+I-1  AF(2)+I-1
           FIN
I          DO       MN*(MN<3)
             STW,AF(1)+I-1   I-1,XL
           ELSE
             LCI         MN
             STM,AF(1)   0,XL
           FIN
         ELSE
I          DO       MN*(MN<3)
             LW,BUF      AF(1)+I-1
             STW,BUF     I-1,XL
           ELSE
             LCI         N
             LM,BUF      AF(1)
             STM,BUF     0,XL
           FIN
         FIN
         AI,XL    MN
         PEND
         CLOSE    M,N,MN,I
         PAGE
*
*
*  OUTPUT BYTES PROC
*
*
         OPEN     I
OUTPUT   CNAME
         PROC
LF       CW,CC    GRBUFLIM
         BLE      %+2
         BAL,LO   GRAFOUT
I        DO       NUM(AF)
         DO       AFA(I)
         STB,AF(I)  GRAFBUF,CC
         ELSE
         LI,AI    AF(I)
         STB,AI   GRAFBUF,CC
         FIN
         AI,CC    1
         FIN
         PEND
         CLOSE    I
         PAGE
*
*
*  SET/RESET BREAK FLAG PROC
*
SETBRK   CNAME    OPBREAK
RESETBRK CNAME    0
         PROC
LF       LI,L2    NAME
         STW,L2   XSEGBRK
         PEND
         PAGE
*
*
*  F.S. ARITHMETIC PROC
*
*
FSADD    FNAME    1                 F.S. ADD      FUNCTION
FSSUB    FNAME    2                 F.S. SUBTRACT FUNCTION
FSMUL    FNAME    3                 F.S. MULTIPLY FUNCTION
FSDIV    FNAME    4                 F.S. DIVIDE   FUNCTION
         PROC
         LOCAL    X,E,I,S,Z,ZE,ZS,AD,ML,DV,SB,NORM
X        SET      0,0               ARG FRACTIONS
E        SET      0,0               ARG EXPONENTS
S        SET      +1,+1             ARG SIGNS
I        DO       2                 UNPACK EACH ARG:
X(I)     SET      AF(I)
         DO       X(I)<0
X(I)     SET      -X(I)
S(I)     SET      -1                    SIGN (+1 OR -1)
         FIN
E(I)     SET      (X(I)**-24)-X'40'     EXPONENT (UNBIASED),
X(I)     SET      X(I)&X'00FFFFFF'      POSITIVE FRACTION (X'00XXXXXX').
         FIN
*
         GOTO,NAME  AD,SB,ML,DV         DO SPECIFIED OP
SB       BOUND    1                 SUBTRACT:
S(2)     SET       -S(2)                REVERSE 2ND ARG SIGN, DO ADD
*
AD       BOUND    1                 ADD:
I        SET     (E(1)-E(2))*4          ALIGN FRACTIONS,
         DO       I<0                   SET RESULT EXPONENT
X(1)     SET      X(1)**I
ZE       SET      E(2)
         ELSE
X(2)     SET      X(2)**(-I)
ZE       SET      E(1)
         FIN
ZS       SET      S(1)                  SET RESULT SIGN
         DO       S(1)=S(2)
Z        SET      X(1)+X(2)             SIGNS AGREE: ADD FRACTIONS
         ELSE
Z        SET      X(1)-X(2)             SIGNS DIFFER: SUBTRACT FRACS
         DO       Z<0                     AND REVERSE IF NECESSARY.
Z        SET      -Z
ZS       SET      -ZS
         FIN
         FIN
         GOTO     NORM                  GO NORMALIZE
*
ML       BOUND    1                 MULTIPLY:
Z        SET      (X(1)*X(2))**-20      MULTIPLY FRACTIONS
ZE       SET      E(1)+E(2)-1           ADD EXPONENTS
ZS       SET      S(1)*S(2)             MULTIPLY SIGNS
         GOTO     NORM                  NORMALIZE
*
DV       BOUND    1                 DIVIDE:
Z        SET      (X(1)**24)/X(2)       DIVIDE FRACTIONS
ZE       SET      E(1)-E(2)             SUBTRACT EXPONENTS
ZS       SET      S(1)*S(2)             MULTIPLY SIGNS
*
NORM     BOUND    1                 NORMALIZE:
         DO       Z>0                   IF Z NONZERO,
         WHILE    Z<X'00100000'
Z        SET      Z**4                   SHIFT UP
ZE       SET      ZE-1
         FIN
         WHILE    Z>=X'01000000'
Z        SET      Z**-4                   OR DOWN,
ZE       SET      ZE+1
         FIN
Z        SET     (Z+(ZE+X'40')**24)*ZS    AND PACK IN F.S. FORM.
         FIN
         PEND     Z                 RETURN RESULT
         PAGE
*
*
*  D E V I C E    D E P E N D E N T    D A T A
*
*
*
*  F.S. PARAMETERS
*
%XINCHS  EQU      +FS'8.25'         SCREEN SIZE, IN INCHES
%YINCHS  EQU      +FS'6.29'             *
%ASPECT  EQU      FSDIV(%YINCHS,%XINCHS)     ASPECT RATIO
%XPTS    EQU      +FS'1023.999'              SCREEN SIZE, POINTS
%YPTS    EQU      FSMUL(%XPTS,%ASPECT)           *
%ZPTS    EQU      %XPTS                          *
%PPI     EQU      FSDIV(%XPTS,%XINCHS)       POINTS PER INCH
%EPS     EQU      +FS'.001'
%NTICS   EQU      +FS'5'            NUMBER OF TIC MARKS ON LONG SIDE
         PAGE
*
*
*  PLANAR PROJECTION PARAMETERS
*
*
*              CONVERSION OF A 3-D POINT (X,Y,Z) TO A 2-D POINT (X',Y')
*              IS DONE BY A LINEAR TRANSFORMATION COMPOSED OF (1) AN
*              ORTHOGONAL PROJECTION ONTO THE X'Y' PLANE, AND (2) RE-
*              SCALING TO MAKE THE ENTIRE PROJECTED BOX (0<=X<=XP,
*              0<=Y<=YP, 0<=Z<=ZP) FIT INTO THE RECTANGLE (0<=X'<=XP,
*              0<=Y'<=YP).  (NOTE: XP/YP/ZP ARE ABBREVIATIONS FOR
*              %XPNTS, ETC.)  THE TRANSFORMATION DEPENDS ON TWO ANGULAR
*              PARAMETERS: ALPHA AND BETA, THE AZIMUTH (TO RIGHT OF
*              Z-AXIS) AND ELEVATION (ABOVE XZ PLANE) OF THE 'VANTAGE
*              POINT'.  THESE ANGLES ARE INTRODUCED IN TERMS OF THEIR
*              SINES AND COSINES:
*
%SA      EQU      +FS'.34202'       = SIN 20 DEGREES
%CA      EQU      +FS'.93969'       = COS 20 DEGREES
%SB      EQU      +FS'.70711'       = SIN 45 DEGREES
%CB      EQU      +FS'.70711'       = COS 45 DEGREES
*
*              THE TRANSFORM IS
*
*
*                   X' = (X*CA + (ZP-Z)*SA) *XP/
*                        (XP*CA   +  ZP*SA)
*                   Y' = (Y*CB + (XP-X)*SA*SB + (ZP-Z)*CA*SB) *YP/
*                        (YP*CB   +  XP*SA*SB    +  ZP*CA*SB)
*
*              WHICH WE MASSAGE INTO THE FORM
*
*                   X' = P10 + P11*X         + P13*Z
*                   Y' = P20 + P21*X + P22*Y + P23*Z
*
*              BY MEANS OF THE FOLLOWING:
*
         OPEN     DX,DY,DZ,SASB,CASB,F,DXZ
DX       SET      FSMUL(%XPTS,%CA)  = XP*CA
DZ       SET      FSMUL(%ZPTS,%SA)  = ZP*SA
F        SET      FSDIV(%XPTS,;     = XP/(XP*CA + ZP*SA)
                  FSADD(DX,DZ))
%P10     EQU      FSMUL(F,DZ)       = ZP*SA*F = CONSTANT IN X'
%P11     EQU      FSMUL(F,%CA)      = CA*F    = COEFF OF X IN X'
%P13     EQU      FSMUL(F,-%SA)     = -SA*F   = COEFF OF Z IN X'
*
SASB     SET      FSMUL(%SA,%SB)    = SA*SB
CASB     SET      FSMUL(%CA,%SB)    = CA*SB
DX       SET      FSMUL(%XPTS,SASB) = XP*SA*SB
DY       SET      FSMUL(%YPTS,%CB)  = YP*CB
DZ       SET      FSMUL(%ZPTS,CASB) = ZP*CA*SB
DXZ      SET      FSADD(DX,DZ)      = XP*SA*SB + ZP*CA*SB
F        SET      FSDIV(%YPTS,;     = YP/(YP*CB + XP*SA*SB + ZP*CA*SB)
                  FSADD(DXZ,DY))
%P20     EQU      FSMUL(F,DXZ)      =(XP*SA*SB+ZP*CA*SB)*F= CONST IN Y'
%P21     EQU      FSMUL(F,-SASB)    = -SA*SB*F = COEFF OF X IN Y'
%P22     EQU      FSMUL(F,%CB)      =  CB*F    = COEFF OF Y IN Y'
%P23     EQU      FSMUL(F,-CASB)    = -CA*SB*F = COEFF OF Z IN Y'
         CLOSE    DX,DY,DZ,DXZ,F,SASB,CASB
         PAGE
*
*
*  Q U A D    Z E R O    I N P U T / O U T P U T
*
*
         USECT    PROGSECT
*
*
*  QUAD-ZERO OUTPUT
*
*              GIVEN ARG DATA BLOCK POINTER IN RTARG, AND GRAPHICS
*              PARAMETER DATA BLOCK POINTER IN GRAFPNTR.  THE LATTER
*              MAY BE ZERO IF THIS IS THE FIRST ENTRY INTO THE GRAPHICS
*              PACKAGE, IN WHICH CASE WE ALLOCATE THE BLOCK (PUTTING
*              ITS POINTER IN GRAFPNTR) AND INITIALIZE SCALING AND
*              WINDOW DATA THEREIN.  UPON EXIT (TO QZOUTRET), BOTH
*              POINTERS ARE STILL IN EXISTENCE.
*
QZOUTPUT EQU      %
         LI,R     QZOUTRET          SET RETURN ADDRESS
         STW,R    RETURN
         BAL,LX   INITGRAF          SET UP GRAFPNTR
         BAL,LX   GETCOORD          REMEMBER CURRENT CURSOR LOC
         LI,A     1
         BAL,LX   SETUPARG          SET UP RT ARG PARAMS
         LW,T     RTTYPE
         CI,T     CHAR              DON'T ALLOW CHAR ARG
         BE       ERDOMAIN
         LW,XI    RTARG             GET DB POINTER
         LW,R     RTRANK            CHECK ARG RANK
         BNEZ     4Z1
         BAL,LZ   GSCLRVAL,T        SCALAR: GET ITS VALUE IN INTG
         BEZ     *RETURN            IF =0, DO NOTHING
         LI,CC    0                 INIT OUTPUT
         OUTPUT  *AI                OUTPUT ARG VALUE
         B        NEXTLINE          FINISH UP, EXIT
4Z1      LI,A     1
         CI,R     2                 CHECK ARG RANK
         BG       ERRANK            >2  ERROR
         BE       4Z2               =2  MATRIX
         LW,N     2,XI              =1  VECTOR: GET ITS DIMEN (N),
         BEZ     *RETURN               (IGNORE EMPTY ARG)
         LI,M     1                     PRETEND IT'S A 1*N MATRIX.
         B        4Z3
4Z2      EQU      %                 MATRIX:
         LW,M     2,XI              GET 1ST DIMEN (M)
         BEZ     *RETURN            (IGNORE EMPTY ARG)
         LW,N     3,XI              GET 2ND DIMEN (N)
         BEZ     *RETURN            (IGNORE EMPTY ARG)
         EQUAL,N,M+1
         CLR,M    =3                COMPARE BOTH DIMENS WITH 3
         BLE      4Z3               M<=3: COLUMN-MAJOR
         BCS,8    ERLENGTH          M>3 AND N>3: ERROR
*                                   M>3 AND N<=3: ROW-MAJOR
         STW,N    INCELMT           ROW-MAJOR: ELEMENT INCREMENT = N,
         STW,A    INCCOORD                  COORDINATE INCREMENT = 1,
         XW,M     N                         SWAP M/N TO MAKE M<=3.
         B        4Z4
4Z3      STW,A    INCELMT           COL-MAJOR: ELEMENT INCREMENT = 1,
         STW,N    INCCOORD                  COORDINATE INCREMENT = N.
4Z4      STW,M    DIMEN             M = DATA DIMENSION = 1, 2, OR 3.
         ODD,N
         MW,N     INCELMT           N(SIZE)*(ELMT INCR) = TERMINATION
         STW,N    STOPVAL                                 ...VALUE
*
*     GENERATE XSEG
*
         LI,A     1
         BAL,LX   XSETUP            SET UP RTADR FOR INDEXED LOAD
         LI,XL    XSEGBASE          INIT XSEG LOC
         GEN,0,4  CODE1             GEN INIT CODE
         LW,T     RTTYPE            GET DATA TYPE
         LW,R3    AIK0INST
         AW,R3    INCCOORD          SET UP 'AI,K INCC' INST
         LW,R2    CODE2             SET UP 'LW,X AF'   INST
         LW,XI    DIMEN             GET DIMEN COUNT (1,2,3)
         LD,R     LOADFSTB,T        FOR EACH DIMEN GEN:
         AW,R     RTADR                      LOAD     ARG(K)
4Z5      GEN,4,0  R                          CONVFS
         AW,R2    =X'00100000'               LW,XYZ   AF
         BDR,XI   4Z5                        AI,K     INCC
         AI,XL    -1                DISCARD LAST 'AI,K  INCC'
         LCW,AI   DIMEN             GET -DIMEN
         BIR,AI   4Z6               GET 1-DIMEN
         STW,R2   -1,XL             DIMEN=1: CHANGE 'LW,X' TO 'LW,Y'
         GEN,0,3  CODE3               AND GEN CODE TO COMPUTE X DATA.
         LI,AI    0                   (GEN CLOBBERED  AI=0).
4Z6      MW,AI    INCCOORD          GEN:     AI,K     INCE-(D-1)*INCC
         AW,AI    INCELMT                    BAL,LX   SENDPNT
         AND,AI   =X'000FFFFF'
         AW,AI    AIK0INST            AND LOOP CONTROL CODE.
         GEN,1,4  AI,CODE4
*
*     EXECUTE XSEG
*
         LW,GP    GRAFPNTR          SET UP GRAPHIC PARAMS POINTER
         LW,F     DIMEN             COMPUTE 3-DIMENSION FLAG
         AI,F     1
         EQUAL,3DFLAG,4                  (3DFLAG IS THE 4-BIT)
         AND,F    =3DFLAG
         OR,F     FLAGS,GP          FETCH OTHER FLAGS
         CI,F     ASCLFLAG          IF AUTO-SCALING FLAG SET,
         BAZ      4Z7                 DO AUTOMATIC SCALING ON GIVEN DATA
         BAL,LX   AUTOSCAL
4Z7      LI,CC    0                 INIT OUTPUT CHAR COUNT
         SETBRK                     ALLOW BREAKS DURING XSEG EXECUTION
         BAL,L2   XSEGBASE          EXECUTE XSEG
         RESETBRK                   STOP BREAKS AFTERWARDS
QUIT     BAL,LX   ENDVEC            DONE: TERMINATE CURRENT VECTOR
         LI,F     0
         LI,F+1   DASHFLAG          RESET 'DASH' FLAG: ONLY ONE CURVE
         STS,F    FLAGS,GP            IS TO BE DASHED.
*
*     RESTORE ORIGINAL CURSOR POSITION, EXIT
*
NEXTLINE EQU      %                 RESTORE CURSOR LOC READ BY GETCOORD
         LW,R1    GRXYBYTS          GET INPUT BYTES 2-5 (COORD BYTES)
         SCS,R1   16                PUT Y-COORD TO LEFT OF X-COORD
         AND,R1   =X'1F1F1F1F'      GET RID OF CODE BITS SENT BY DEVICE
         OR,R1    YHYLXHXL          INSTALL CORRECT COORD CODE BITS
*                                   WE NOW HAVE THE 4-BYTE COORD IN R1
         OUTPUT   #GS               SEND 'START VECTOR' COMMAND
         ODD,R1
         EQUAL,R+1,R1
11Z1     SLD,R    8                 SEND THE 4 BYTES (ONE-POINT VECTOR)
         OUTPUT  *R
         AI,R1    0
         BNEZ     11Z1
         OUTPUT   #US               SEND 'END VECTOR' COMMAND
         BAL,LO   GRAFOUT           DUMP OUTPUT BUFFER
         B       *RETURN            EXIT
*
YHYLXHXL DATA,1   #YHIGH,#YLOW,#XHIGH,#XLOW
*
*     LOCAL DATA/TEMPS
*
INCELMT  TEMP                       INCREMENT TO NEXT ELEMENT
INCCOORD TEMP                       INCREMENT TO NEXT COORDINATE
DIMEN    TEMP                       DATA DIMENSIONS (1, 2, OR 3)
INDEXVAL TEMP                       GENERATED X-VALUE (FOR DIMEN=1)
STOPVAL  TEMP                       TERMINATING INDEX-VALUE
*
*
AIK0INST AI,K     0
         BOUND    8
LOADFSTB EQU      %-2*LOGL          LOAD/CONVERT INST TABLE
         BAL,LX   0                 LOGL LOAD (0 OR -1)
         LW,AF    FS01,AI           LOGL CONVERT TO FS
         RES      2                 CHAR (NOT ALLOWED)
         LW,AI    0                 INTG LOAD
         BAL,LX   ITOFS             INTG CONVERT TO FS
         LD,AF    0                 FLOT LOAD
         BAL,LX   FLTOFS            FLOT CONVERT TO FS
         BAL,LX   0                 ISEQ LOAD
         BAL,LX   ITOFS             ISEQ CONVERT TO FS
*
FS01     EQU      %+1               TABLE TO CONVERT LOGL VALUE (-1/0)
         DATA     FS'1.0',0           TO F.S. VALUE (1.0/0.0)
*
*
*              XSEG CODE:
*
*
CODE1    LI,K     0              0  INIT ARG INDEX
         LCW,AI   ORIGIN         1  INIT SUPPLIED-X VALUE
         LW,AI    FS01,AI        2    TO INDEX ORIGIN (0 OR 1)
         STW,AI   INDEXVAL       3    IN CASE DIMEN=1.
*
*           - IF DIMEN=2/3 -
*
*        LOAD     ARG(K)            GET X VALUE
*        CONVERT  TO F.S.           CONVERT
CODE2    LW,X     AF                PUT IN X
*        AI,K     INCC              BUMP INDEX TO NEXT (Y) COORD
*
*           - ANY DIMEN
*
*        LOAD     ARG(K)            GET Y VALUE
*        CONVERT  TO F.S.           CONVERT
*        LW,Y     AF                PUT IN Y
*
*           - IF DIMEN=3   -
*
*        AI,K     INCC              BUMP INDEX TO NEXT (Z) COORD
*        LOAD     ARG(K)            GET Z VALUE
*        CONVERT  TO F.S.           CONVERT
*        LW,Z     AF                PUT IN Z
*
*           - IF DIMEN=1   -
*
CODE3    LW,X     INDEXVAL          1-DIMENSIONAL DATA: WE SUPPLY
         FAS,X    =FS'1.0'            X-VALUES=ORIGIN+ 0.0, 1.0, 2.0,...
         XW,X     INDEXVAL
*
*           - ALL CASES    -
*
*        AI,K     INCE-(D-1)*INCC   BACK TO X-COORD, BUMP TO NEXT ELMT
CODE4    BAL,LX   SENDPNT           PROCESS THE POINT (X,Y,Z)
         CW,K     STOPVAL
         BL       XSEGBASE+4        LOOP UNTIL ALL POINTS PROCESSED
         B       *L2                DONE: EXIT FROM XSEG
         PAGE
*
*
*  QUAD-ZERO INPUT
*
*              GIVEN GRAPHICS PARAMETER DATA BLOCK POINTER IN GRAFPNTR
*              (WHICH IS ZERO AT FIRST ENTRY; SEE 'QZOUTPUT').  UPON
*              EXIT (TO QZINRET), GRAFPNTR EXISTS, AND THE RESULT DATA
*              BLOCK POINTER IS IN 'RESULT'.  THE RESULT IS A
*              CHARACTER SCALAR (=THE INPUT CHARACTER). THE
*              X AND Y COORDINATES OF THE CROSSHAIR CURSOR ARE
*              SAVED; THEY CAN BE RECOVERED VIA '11 #GRF 3'.
*              THESE COORDINATES ARE EITHER
*              UNSCALED IN 'POINTS' (IF ISCLFLAG=0), OR SCALED ACCORDING
*              TO THE LATEST X/Y SCALING PARAMETERS (ISCLFLAG=1). IN
*              THE LATTER CASE, CHARACTERS FALLING OUTSIDE THE 'WINDOW'
*              ARE IGNORED.
*
QZINPUT  EQU      %
         LI,A     QZINRET
         STW,A    RETURN            SET UP RETURN ADDRESS
         BAL,LX   INITGRAF          SET UP GRAFPNTR, COPY TO GP
         BAL,LX   GETCOORD          GET CURSOR LOC
         LW,X     GRXYBYTS          SAVE CURSOR COORDS
         STW,X    XYSAVE
*
12Z1     SETBRK                     ALLOW BREAKS DURING INPUT WAIT
         LW,L2    BREAKFLG          RESPOND IMMEDIATELY TO
         BNEZ     OPBREAK             EXISTING BREAKS.
         BAL,LX   GETCHAR           DISPLAY CROSSHAIRS, GET CHAR & COORDS
         RESETBRK                   STOP BREAKS AFTERWARDS
         LW,GP    GRAFPNTR          RESTORE GP (BECAUSE OF RE-START)
         LW,XI    GRAFPNTR          EXTRA COPY TO BE BUMPED BY 1
         LI,K     X'7F'
         AND,K    GRINCHAR          GET 7-BIT ASCII APL CHAR.
         LB,R     INPTRANS,K         TRANSLATE TO INTERNAL CODE
         STW,R    INCHAR,GP           STORE IN GRAPHICS DATA BLOCK
         LI,F     ISCLFLAG          SET F SO THAT 'BDR,F' WILL BRANCH
         AND,F    FLAGS,GP           IF ISCLFLAG=1.
         LI,K     -2                PROCESS BOTH COORDS:
12Z2     LW,R1    GRXYBYTS              PACK A COORD:
         SLS,R1   3                       DISCARD HIGH-BYTE CONTROL BITS
         LI,R     0
         SLD,R    5                       GET UPPER 5 BITS
         SLS,R1   3                       DISCARD LOW-BYTE CONTROL BITS
         SLD,R    5                       APPEND LOWER 5-BITS
         STW,R1   GRXYBYTS              SAVE WHAT'S LEFT FOR NEXT COORD
         OR,R     =X'46000000'      CONVERT TO F.S. VALUE IN R
         SFS,R    6                       IN 'POINTS'.
         BDR,F    12Z3                  TEST ISCLFLAG
         B        12Z4              =0: STORE AS IS
12Z3     EQU      %                 =1: DO SCALING & TESTING
         FDS,R    =%PPI                 CHANGE UNIT TO INCHES FOR
         CW,R     UXWINDOW,GP             WINDOWING TEST.
         BG       12Z1                  MUST BE <= UPPER LIMIT (INCHES)
         FSS,R    LXWINDOW,GP             AND >= LOWER LIMIT; IF NOT
         BLZ      12Z1                    IN WINDOW, REJECT CHAR.
         FDS,R    XRATIO,GP             RESCALE TO FULL-SCREEN BOUNDS
         FMS,R    =%PPI                 CONVERT BACK TO 'POINTS'
         FDS,R    XSCALE,XI             RESCALE ACCORDING TO SCALE
         FAS,R    XMIN,GP                 PARAMS: PUTS IT IN (MIN,MAX).
12Z4     STW,R    INXCOORD,XI       STORE PROCESSED X/Y COORD
         AI,GP    2                 NEXT TIME USE 'Y' PARAMS
         AI,XI    1
         BIR,K    12Z2              PROCESS NEXT (Y) COORD
*
         LI,S     6                 ALLOCATE BLOCK FOR COORDINATES
         BAL,LX7  ALOCHNW
         STW,A    RESULT            SAVE POINTER
         LI,R     FLOT**8+1         FLOATING POINT VECTOR
         STH,R   *RESULT
         LI,R     2
         STW,R    2,A               SET LENGTH=2
         LI,R     0
         STW,R    5,A               SET LOW ORDER VALUE FOR FLOATING
         STW,R    7,A                LONG COORDINATES(COMPUTED FS)
         LW,XI    GRAFPNTR
         LW,R     INXCOORD,XI
         STW,R    4,A               SET HIGH ORDER VALUES IN RESULT
         LW,R     INYCOORD,XI
         STW,R    6,A
*
CNXTLINE EQU      %
         LW,X     XYSAVE
         STW,X    GRXYBYTS
         LI,CC    0                 IINIT OUTPUT CHAR COUNT
         B        NEXTLINE              RESTORE CURSOR AND EXIT
*
*
GRINCHAR TEMP                       GRAPHICS TERM INPUT CHAR
GRXYBYTS TEMP                       GRAPHICS TERM X/Y COORD BYTES
JUNKTEMP TEMP                         PLUS JUNK BYTES
XYSAVE   TEMP                       SAVE CELL FOR CURSOR COORDS
*
*
INPTRANS EQU      %                 QUAD-ZERO INPUT CHAR TRANSLATION TABLE
II       DO       32
         DATA,1   II-1
         FIN
         DATA     X'40715D4C'
         DATA     X'747E6EB5'
         DATA     X'79707BFB'
         DATA     X'6B4E4B61'
         DATA     '0123'
         DATA     '4567'
         DATA,2   '89',X'4DB4'
         DATA     X'5EFA7AB1'
         DATA     X'727C4250'
         DATA     X'44456D7F'
         DATA     X'48495A7D'
         DATA     X'534F5556'
         DATA     X'5C6F6C62'
         DATA     X'5F645B66'
         DATA     X'676A4AFD'
         DATA     X'EBFC7660'
         DATA,1   X'EA','A','B','C'
         TEXT     'DEFGHIJKLMNOPQRSTUVW'
         DATA,1   'X','Y','Z',X'ED'
         DATA     X'ECEE43FF'
         PAGE
*
*
*  G R A P H I C S    S T A T E    C O N T R O L
*
*
*  DELTA-GRF FUNCTION
*
*              GIVEN ARG DATA BLOCK POINTERS IN LFARG & RTARG, AND
*              GRAPHICS PARAMETERS DATA BLOCK POINTER IN 'GRAFPNTR'
*              (WHICH IS ZERO UPON FIRST ENTRY: SEE 'QZOUTPUT').
*              UPON EXIT (TO DXRETURN) THESE POINTERS STILL EXIST,
*              AND A POINTER TO THE RESULT (WHICH IS USUALLY NULL) IS
*              IN 'RESULT'.
*
*
*              THE FOLLOWING IS A LIST OF ALL THE FUNCTIONS PERFORMED
*              BY DELTAGRF (THE 'DELTA' HAS BEEN DROPPED FOR BREVITY):
*
*                 0  GRF  1       TURN OFF INPUT SCALING
*                 0  GRF  2       TURN ON  INPUT SCALING
*                 1  GRF  3       SET TERMINAL DEVICE TYPE
*                 2  GRF  NUL     SET DEFAULT WINDOW
*                 2  GRF  LX,UX,LY,UY
*                                 SET UP GIVEN WINDOW LIMITS
*                 3  GRF  NUL     SET 'TRANSPARENT' SCALING
*                 3  GRF  X1,X2,Y1,Y2,(Z1,Z2)
*                                 SET UP GIVEN SCALING
*                 4  GRF  NUL     RETURN CURSOR TO NEXT LINE
*                 4  GRF  X,Y,(Z) SET CURSOR TO GIVEN POINT
*                 5  GRF  NUL     DRAW AXES
*                 6  GRF  1       SET AUTO-SCALING MODE
*                 6  GRF  2       SET CENTERED AUTO-SCALING MODE
*                 6  GRF  3       KILL AUTO-SCALING (FIX CURRENT SCALE)
*                 7  GRF  NUL     DASH NEXT CURVE
*                 8  GRF  NUL     ERASE & HOME SCREEN
*                 8  GRF  1       ERASE SCREEN
*                 8  GRF  2       HOME SCREEN
*                 9  GRF  NUL     DRAW BOX
*                 10 GRF  1       TURN OFF RE-ENTRANCE
*                 10 GRF  2       TURN ON  RE-ENTRANCE
*                 11 GRF  1       RETURN SCALING PARAMS AS RESULT
*                 11 GRF  2       RETURN WINDOW PARAMS AS RESULT
*                 11 GRF  3       RETURN INPUT COORDS  AS RESULT
*                 11 GRF  4       RETURN INPUT CHARACTER AS RESULT
*                 11 GRF  5       SET FOR 5-CHAR INPUT STRAP OPTION.
*                 11 GRF  6               6
*                 11 GRF  7               7
*
*
*
DELTAGRF EQU      %
         LI,A     DXNULRTN
         STW,A    RETURN            SET UP RETURN ADDRESS
         BAL,LX   INITGRAF          SET UP GRAFPNTR
         LI,A     0
         BAL,LX   SETUPARG          SET UP LEFT ARG PARAMS
         LI,A     1
         BAL,LX   SETUPARG          SET UP RIGHT ARG PARAMS
         LI,S     1
         CW,S     LFSIZE            MAKE SURE LEFT ARG IS 1 ELEMENT
         BNE      ERLENGTH
         LW,XI    LFARG             GET LEFT ARG PNTR
         AW,XI    LFRANK            SKIP OVER DIMENS
         LW,T     LFTYPE            GET ITS TYPE
         BAL,LZ   GSCLRVAL,T        GET ITS VALUE (= FUNCTION CODE)
         BLZ      ERDOMAIN          MUST BE >=0
         CI,AI    11                  ...AND <=11
         BG       ERDOMAIN
         STW,AI   FUNCCODE          SAVE IT FOR LATER
*
         LW,S     RTSIZE            NOW CHECK RIGHT ARG SIZE
         BEZ      FUNC0             IF SIZE=0, IT'S A NUL-FUNC
         BDR,S    FUNCN             IF SIZE>1, IT'S A MULTI-PARAM FUNC
FUNC1    LW,XI    RTARG                SIZE=1: IT'S A 1-PARAM FUNC
         AW,XI    RTRANK            POINT TO RT ARG PAST DIMENS
         LW,T     RTTYPE            GET TYPE
         BAL,LZ   GSCLRVAL,T        GET ITS (SINGLE) INTEGER VALUE
         LW,K     AI                PUT IT IN K
         BLEZ     ERDOMAIN              MUST BE >0 ...
         LW,XI    FUNCCODE
         CB,K     LIMTBL1,XI                AND <= LIMIT FOR FUNCTION;
         BG       ERDOMAIN
         LW,GP    GRAFPNTR              SET UP GP AND ENTER SELECTED
         BAL,LX   JUMPTBL1,XI             1-PARAM ROUTINE: PARAM IN K.
         B       *RETURN            EXIT
*
FUNC0    LW,GP    GRAFPNTR          SIZE=0: GO TO SELECTED 0-PARAM
         BAL,LX   JUMPTBL0,AI         ROUTINE.
         B       *RETURN            EXIT
*
FUNCN    CLM,AI   2TO4              SIZE>1: ALLOWED ONLY FOR
         BCS,9    ERLENGTH            FUNCTIONS 2, 3, OR 4.
         LI,F     0                 (FOR SET/SCALE: ASSUME 2D)
         CB,S     LIMTBLN,AI        SIZE MUST MATCH SIZE REQUIREMENTS
         BE       7Z4                 OF SELECTED FUNCTION.
         CB,S     LIMTBLNN,AI
         BNE      ERLENGTH
         LI,F     3DFLAG            (FOR SET/SCALE WITH 3/6 PARAMS: SET 3D)
7Z4      LI,A     1
         BAL,LX   XSETUP            SET UP RTADR
         LI,XL    XSEGBASE          BEGIN XSEG GEN
         LW,T    RTTYPE
         LD,R     LOADFSTB,T        GEN XSEG TO FETCH ARG VALUES,
         AW,R     RTADR               CONVERT 'EM TO F.S., AND STORE
         GEN,2,4  R,CODE6             'EM IN 'PARAMS' BUFFER.
         LI,R     0                 IN CASE OF 2-DIMEN SCALE-SETTING,
         STW,R    PARAMS+4            SET Z-SCALE PARAMS TO 0.
         STW,R    PARAMS+5
         LI,K     0                 START WITH 1ST PARAM
         LW,N     RTSIZE            GET SIZE
         BAL,L2   XSEGBASE          GET PARAMS TO BUFFER
         LW,GP    GRAFPNTR          SET UP GP
         LW,AI    FUNCCODE
         BAL,LX   JUMPTBLN,AI       ENTER N-PARAM FUNC
         B       *RETURN            EXIT
*
*
DXNULRTN EQU      %                 SET NUL RESULT, EXIT TO DXRETURN
         LI,S     1                 ALLOCATE RESULT DATA BLOCK:
         BAL,LX7  ALOCHNW             RESULT = NULL
         STW,A    RESULT            STORE DATA BLOCK POINTER
         LI,R     INTG**8+1
         STH,R   *RESULT            SET TYPE=INTG, RANK=1
         LI,R     0
         STW,R    2,A               SET DIMEN=0
         B        DXRETURN          EXIT
*
*     LOCAL DATA/TEMPS
*
FUNCCODE TEMP                       HOLDS LEFT ARG VAL (FUNCTION CODE)
PARAMS   DTEMP                      STORAGE FOR UP TO SIX PARAMETERS
         DTEMP
         DTEMP
*
*
LIMTBL1  DATA,1   2,3,0,0,0,0,;     PARAM LIMITS FOR 1-PARAM FUNCTIONS
                  3,0,2,0,2,7
         BOUND    4
LIMTBLN  DATA,1   0,0,3,3,1         SIZE LIMITS (-1) FOR N-PARAM FUNCS
         BOUND    4
LIMTBLNN DATA,1   0,0,3,5,2         ALTERNATE SIZES THEREFOR (3D)
         BOUND    8
2TO4     DATA     2,4               N-PARAM FUNC CODE RANGE
*
*
*     JUMP TABLES
*
JUMPTBL0 EQU      %                 0-PARAMETER FUNCTIONS:
         B        ERLENGTH
         B        ERLENGTH
         B        NOWINDOW          2   DEFAULT WINDOW
         B        NOSCALE           3   TRANSPARENT SCALING
         B        CNXTLINE          4   RETURN CURSOR
         B        DRAWAXES          5   DRAW AXES
         B        ERLENGTH
         B        DASHMODE          7   DASH NEXT CURVE
         B        ERASHOME          8   ERASE/HOME SCREEN
         B        DRAWBOX           9   DRAW BOX
         B        ERLENGTH
         B        ERLENGTH
*
JUMPTBL1 EQU      %                 1-PARAMETER FUNCTIONS:
         B        ISCLMODE          0: K     SET QUAD-0 INPUT MODE
         B        SETDEV            1: K     SET DEVICE TYPE
         B        ERLENGTH
         B        ERLENGTH
         B        ERLENGTH
         B        ERLENGTH
         B        SCALMODE          6: K     SET SCALING MODE
         B        ERLENGTH
         B        SCREENCT          8: K     SCREEN CONTROL
         B        ERLENGTH
         B        RENTMODE          10:K     SET RE-ENTRANCE MODE
         B        PARAMVAL          11:K     RETURN SCALE/WINDOW PARAMS
*
JUMPTBLN EQU      %-2               N-PARAMETER FUNCTIONS:
         B        SETWINDO          2:LX,UX,LY,UY         SET WINDOW
         B        SETSCALE          3:X1,X2,Y1,Y2,(Z1,Z2) SET SCALING
         B        SETCOORD          4:X,Y,(Z)             SET COORDS
*
*
*              XSEG CODE:
*
*
*        LOAD     RTARG(K)       0  GET PARAM
*        CONVERT  TO F.S.        1  CONVERT TO F.S.
CODE6    STW,AF   PARAMS,K          STORE IN BUFFER
         AI,K     1                 BUMP INDEX
         BDR,N    XSEGBASE          LOOP
         B       *L2                EXIT
         PAGE
*
*
*  P O I N T    P L O T T I N G    R O U T I N E S
*
*
*  SEND POINT
*
*              THIS ROUTINE, CALLED ONCE FOR EACH 2- OR 3-DIMENSIONAL
*              DATA POINT, PLOTS THE CURVE JOINING THE POINTS.  IT
*              PERFORMS THE FOLLOWING FUNCTIONS:
*
*              1. SCALING
*              2. PLANAR PROJECTION OF 3-DIMENSIONAL DATA
*              3. REDUCTION TO SPECIFIED WINDOW
*              4. PRODUCTION OF DASHED CURVE, IF 'DASHFLAG' SET
*              5. RANGE CHECKING WITH INTERPOLATION TO EDGE OF WINDOW
*                 FOR OUT-OF-RANGE POINTS; SUCH CURVES ARE ALLOWED
*                 TO RE-ENTER THE WINDOW IF 'RENTFLAG' IS SET.
*              6. ADDITION OF OFFSET (IN REG 'S') TO FINAL X AND
*                 Y COORDS IF OFSETFLG=1 (ONLY USED BY 'DRAWAXES').
*
*              SENDPNT IS CALLED WITH GRAFPNTR IN GP, FLAGS IN F,
*              AND THE POINT COORDINATES IN X/Y (OR X/Y/Z). LINK IS LX.
*              'EDGEFLAG' AND 'VECTORFG' MUST NOT BE ALTERED BY THE
*              CALLER BETWEEN CALLS; ON THE INITIAL CALL THEY MUST
*              BE IN THE RESET STATE.
*
SENDPNT  EQU      %
*
*     SCALING
*
         FSS,X    XMIN,GP           CONVERT X TO RASTER POINTS
         FMS,X    XSCALE,GP
         FSS,Y    YMIN,GP           CONVERT Y TO RASTER POINTS
         FMS,Y    YSCALE,GP
*
*     PROJECTION
*
         CI,F     3DFLAG            DO THIS STUFF ONLY FOR 3-D DATA
         BAZ      1Z1
         FSS,Z    ZMIN,GP           FINISH SCALING: CONVERT Z TO POINTS
         FMS,Z    ZSCALE,GP
         FMS,X    =%P21             P21*X
         FMS,Y    =%P22             P22*Y
         FMS,Z    =%P23             P23*Z
         FAS,Y    X                 NEW Y = P20 +P21*X +P22*Y +P23*Z
         FAS,Y    Z
         FAS,Y    =%P20
         FMS,X    =FSDIV(%P11,%P21)   P11*X
         FMS,Z    =FSDIV(%P13,%P23)   P13*Z
         FAS,X    Z                 NEW X = P10 +P11*X +P13*Z
         FAS,X    =%P10
1Z1      EQU      %                 NOW THE POINT IS 2-DIMENSIONAL
*
*     RANGE CHECKING
*
         CLM,X    XLIMITS           IS X IN RANGE ?
         BCS,9    1Z2               NO
         CLM,Y    YLIMITS           YES, IS Y IN RANGE ?
         BCR,9    1Z4               YES
1Z2      CI,F     EDGEFLAG          NO: NEW PNT OFF SCREEN; WAS LAST PNT
         BAZ      1Z3                 ALSO OFF SCREEN ?
         STD,X    LASTPNT           YES - WE'RE WAITING TO RE-ENTER,
         B        0,LX                DON'T PLOT IT.
1Z3      STW,LX   SNDPTRET          NO - WE JUST WENT OFF SCREEN:
         BAL,LX   EDGEPLOT            SET 'EDGEFLAG', INTERPOLATE TO
*                                     EDGE, PLOT THE EDGE POINT.
         AND,F    =-1-VECTORFG      BREAK OFF OLD VECTOR/START NEW
         CI,F     RENTFLAG          SEE IF RE-ENTRANCE BEING ALLOWED
         BANZ    *SNDPTRET          YES, KEEP GETTING POINTS AND HOPING
         B        QUIT              NO, STOP ALTOGETHER
1Z4      CI,F     EDGEFLAG          NEW PNT ON SCREEN: HOW ABOUT LAST
         BAZ      PLOT                PNT ? IF BOTH ON, PLOT NEW ONE.
         STD,X    SAVEPNT           NEW ON, LAST OFF: WE JUST NOW
         STW,LX   SNDPTRET            RE-ENTERED: RESET 'EDGEFLAG',
         BAL,LX   EDGEPLOT            INTERPOLATE TO EDGE, PLOT EDGE
         LW,LX    SNDPTRET            POINT,
         LD,X     SAVEPNT
         B        PLOT                THEN PLOT NEW DATA POINT.
*
*
EDGEPLOT EQU      %
         EOR,F    =EDGEFLAG         REVERSE EDGE FLAG
         CI,F     VECTORFG          IF THE VERY FIRST POINT IS OFF
         BAZ      0,LX                SCREEN, THERE'S NO 'LASTPNT'.
*
*     INTERPOLATE TO EDGE
*
         LD,X+2   LASTPNT           WE'VE GOT X1/Y1, GET X2/Y2
         STD,X    LASTPNT           REMEMBER NEW POINT
         XW,Y     X+2               PUT X'S TOGETHER, Y'S TOGETHER
         LCI      4                 REMEMBER X1, X2, Y1, Y2
         STM,X    TEMPX1
         FSS,X+1  X
         STW,X+1  DELX              SAVE X2-X1
         FSS,X+3  X+2
         STW,X+3  DELY              SAVE Y2-Y1
         LI,X     0                 TRY LEFT EDGE FIRST: X = 0 (LEFT)
         LW,Z     TEMPX1            SEE IF X1/X2 HAVE OPPOSITE SIGNS
         EOR,Z    TEMPX2              (I.E. 0 IS BETWEEN X1/X2).
         BLZ      2Z1               YES
         LW,X     UPPERX            NO, TRY RIGHT EDGE: X = UPPERX (RT)
         CLM,X    TEMPX1X2          DOES RIGHT EDGE LIE BETWEEN X1/X2
         BCR,9    2Z1                 (IN EITHER DIRECTION) ?
         BCS,6    2Z2               NO: CAN ONLY LIE ON TOP OR BOTTOM
2Z1      EQU      %                 YES, WE HAVE X2-X1 NONZERO; THE
*                                     EDGE POINT MAY BE ON TOP, BOTTOM,
*                                     OR LEFT (IF X=0, RIGHT IF X>0)
*                                     EDGE.
         LW,Y     X                 COMPUTE POTENTIAL Y-VALUE OF
         FSS,Y    TEMPX1              LEFT (RIGHT) EDGE POINT:
         FDS,Y    DELX                Y = Y1 + (Y2-Y1)*(X-X1)/(X2-X1).
         FMS,Y    DELY
         FAS,Y    TEMPY1
         BLZ      2Z2               WE'VE GOT THE CORRECT EDGE POINT
         CW,Y     UPPERY              ONLY IF (1) Y LIES ON THE SCREEN,
         BG       2Z2
         CLM,Y    TEMPY1Y2            AND (2) Y LIES BETWEEN Y1/Y2.
         BCR,9    PLOT1
         BCR,6    PLOT1
2Z2      EQU      %                 THE REQUIRED EDGE POINT LIES ON
*                                     THE TOP OR BOTTOM EDGE;
*                                     Y2-Y1 IS NONZERO.
         LI,Y     0                 IT'S THE BOTTOM (Y=0) IF AND ONLY
         LW,Z     TEMPY1              IF Y1/Y2 HAVE OPPOSITE SIGNS
         EOR,Z    TEMPY2              (0 LIES BETWEEN Y1/Y2).
         BLZ      2Z3
         LW,Y     UPPERY            OTHERWISE, IT'S ON THE TOP
2Z3      LW,X     Y                 COMPUTE CORRESPONDING X VALUE:
         FSS,X    TEMPY1              X = X1 + (X2-X1)*(Y-Y1)/(Y2-Y1).
         FDS,X    DELY
         FMS,X    DELX
         FAS,X    TEMPX1
         B        PLOT1
*
*
PLOT     EQU      %                 PLOT POINT
         STD,X    LASTPNT           REMEMBER LAST POINT PLOTTED
*
*     WINDOWING
*
PLOT1    EQU      %
         FMS,X    XRATIO,GP         REDUCE TO WINDOW SIZE
         FMS,Y    YRATIO,GP
         FAS,X    XDISPFIX,GP       SHIFT TO WINDOW LOCATION, AND 'FIX'
         FAS,Y    YDISPFIX,GP         COORDINATE VALUES; I.E., THEY ARE
*                                     NO LONGER FLOATING-SHORT, BUT
*                                     =X'46800XXX' (XXX IS A 10-BIT
*                                     INTEGER).
         CI,F     DASHFLAG          ARE WE TO DASH THIS CURVE ?
         BAZ      OUTPOINT          NO, JUST CONTINUE CURRENT VECTOR
         STW,LX   PLOTRET           YES, BREAK IT UP: FOR EACH POINT
         AND,F    =-1-VECTORFG        SEND NEW 'START VECTOR' COMMAND,
         BAL,LX   OUTPOINT            FOLLOWED BY POINT (X,Y) FOLLOWED
         LW,X     TEMPYYXX            BY SLIGHTLY DISPLACED POINT
         AI,X     X'00010001'         (X+1,Y+1).
         CI,X     1024              CHECK FOR SCREEN WRAPAROUND
         BAZ      20Z1                NO
         AI,X     -2                  YES-DISPLACE TO LEFT.
20Z1     LW,LX    PLOTRET
         B        OUT2NDPT
*
*
OUTPOINT EQU      %                 OUTPUT POINT
         CI,F     VECTORFG          IF NOT ALREADY IN VECTOR MODE,
         BANZ     3Z1
         AI,F     VECTORFG            GET INTO IT BY SENDING
         OUTPUT   #GS                 'START VECTOR';
         LI,Z     -1
         STW,Z    LASTXHI             ALSO INIT HIGH-ORDER X/Y MEMORY.
         STW,Z    LASTYHI
3Z1      STH,Y    X                 COMBINE Y AND X COORDS INTO 1 WORD
         STW,X    TEMPYYXX          SAVE FOR 'PLOT' IN DASH MODE
OUT2NDPT EQU      %                 (FOR 'PLOT' IN DASH MODE)
         CI,F     OFSETFLG          IF OFFSET FLAG =1,
         BAZ      3Z4
         AW,X     S                   ADD X/Y OFFSETS TO X/Y.
3Z4      EQU      %
         SLS,X    6                 DISCARD EXTRANEOUS BITS
         LI,Y     #YHIGH**-5        COMPUTE HIGH-ORDER Y BYTE
         SCD,X    5
         CW,Y     LASTYHI           IF DIFFERENT FROM LAST ONE,
         BE       3Z2
         STW,Y    LASTYHI
         OUTPUT  *Y                     OUTPUT IT.
3Z2      LI,Y     #YLOW**-5         COMPUTE LOW-ORDER Y BYTE
         SCD,X    5
         OUTPUT  *Y                 OUTPUT IT
         SLS,X    6                 DISCARD EXTRANEOUS BITS
         LI,Y     #XHIGH**-5        COMPUTE HIGH-ORDER X BYTE
         SCD,X    5
         CW,Y     LASTXHI           IF DIFFERENT FROM LAST ONE,
         BE       3Z3
         STW,Y    LASTXHI
         OUTPUT  *Y                     OUTPUT IT.
3Z3      LI,Y     #XLOW**-5         COMPUTE LOW-ORDER X BYTE
         SCD,X    5
         OUTPUT  *Y                 OUTPUT IT
         B        0,LX              EXIT
*
*     LOCAL DATA/TEMPS
*
LASTPNT  DTEMP                      LAST POINT PLOTTED (PLOT)
SAVEPNT  DTEMP                      SAVE POINT (SENDPNT, FOR RE-ENTRY)
TEMPX1X2 DTEMP                      X-LIMITS (EDGEPLOT: INTERPOLATION)
TEMPY1Y2 DTEMP                      Y-LIMITS      *
TEMPX1   EQU      TEMPX1X2          X1            *
TEMPX2   EQU      TEMPX1X2+1        X2            *
TEMPY1   EQU      TEMPY1Y2          Y1            *
TEMPY2   EQU      TEMPY1Y2+1        Y2            *
DELX     TEMP                       X2-X1         *
DELY     TEMP                       Y2-Y1         *
LASTXHI  TEMP                       LAST HIGH-ORDER X BYTE (OUTPOINT)
LASTYHI  TEMP                       LAST HIGH-ORDER Y BYTE (OUTPOINT)
TEMPYYXX EQU      TEMPX1X2          COMBINED Y/X COORDS (OUT2NDPT)
SNDPTRET TEMP                       SAVE CELL FOR SENDPNT LINK
PLOTRET  TEMP                       SAVE CELL FOR PLOT LINK
*
*
         BOUND    8
XLIMITS  DATA     0,%XPTS           SCREEN LIMITS FOR X COORD (IN PTS)
YLIMITS  DATA     0,%YPTS           SCREEN LIMITS FOR Y COORD (IN PTS)
UPPERX   EQU      XLIMITS+1         UPPER X BOUND
UPPERY   EQU      YLIMITS+1         UPPER Y BOUND
         PAGE
*
*
*  DRAW AXES
*
*              CORRESPONDS TO
*                       5 #GRF NUL
*              CALLED WITH GP SET UP.  EXITS VIA 'RETURN'.
*
DRAWAXES EQU      %
         BAL,LX   GETCOORD          REMEMBER CURSOR
         LI,CC    0                 INIT OUTPUT
         LW,F     ZSCALE,GP         DECIDE WHETHER 2-D OR 3-D
         BEZ      13Z1
         LI,F     3DFLAG
13Z1     STW,F    AXFLAGS           3DFLAG IS SET ACCORDINGLY IN AXFLAGS
         BEZ      13Z2
         LW,R     ZMIN,GP           IF IT'S 3-D, X AND Y AXES WILL BE
         EOR,R    ZMAX,GP             DRAWN ONLY IF Z=0 IS IN RANGE
         BGEZ     13Z5                (I.E. , ZMIN<0<=ZMAX).
13Z2     LW,R     YMIN,GP           IF Y=0 (AND Z=0, IF 3D) IS
         EOR,R    YMAX,GP             IN RANGE,
         BGEZ     13Z3
         LI,K     0                   DRAW X-AXIS.
         BAL,L2   AXIS
13Z3     LW,R     XMIN,GP           IF X=0 (AND Z=0, IF 3D) IS
         EOR,R    XMAX,GP             IN RANGE,
         BGEZ     13Z4
         LI,K     1                   DRAW Y-AXIS.
         BAL,L2   AXIS
13Z4     CI,F     3DFLAG            IF 3D,
         BAZ      13Z6
13Z5     LW,R     XMIN,GP             AND X=0 IS IN RANGE,
         EOR,R    XMAX,GP
         BGEZ     13Z6
         LW,R     YMIN,GP             AND Y=0 IS IN RANGE,
         EOR,R    YMAX,GP
         BGEZ     13Z6
         LI,K     2                   DRAW Z-AXIS.
         BAL,L2   AXIS
13Z6     BAL,LX   ENDVEC            END LATEST VECTOR
         B        NEXTLINE          RESTORE CURSOR, EXIT.
         PAGE
*
*
*     PROCESS AXIS SELECTED BY K
*
*              AXIS SELECTION IN K, LINK IN L2.
*
AXIS     EQU      %
         LB,R     BIASTBL,K         GET BIAS OF XMIN, YMIN, OR ZMIN
         LCI      2
         LM,R    *R,GP              FETCH MIN/MAX OF SELECTED AXIS
         STD,R    KMINMAX           REMEMBER THEM
         LI,R     0
         STW,R    XCOORD            INIT POINT = ORIGIN (0,0,0)
         STW,R    YCOORD
         STW,R    ZCOORD
         LW,F     AXFLAGS           INIT FLAGS: OFSET=VECTOR=0; 3D=0/1
*
*              AXIS LINE
*
         LW,R     KMIN
         BAL,LX   KAXISPT           SEND LOWEST POINT ON K-AXIS
         LW,R     KMAX
         BAL,LX   KAXISPT           SEND HIGHEST POINT ON K-AXIS
*
*              TIC MARKS
*
         AI,F     OFSETFLG          FOR TICS AND LIMITS WE NEED TO
*                                     APPLY POINT OFFSETS.
         LW,R     KMIN              THERE ARE 2 CASES, DEPENDING ON
         EOR,R    KMAX                WHETHER OR NOT 0 IS IN RANGE
         BLZ      14Z1                (I.E., KMIN<0<=KMAX).
         LW,R     KMIN              CASE 1: ZERO IS OFF SCREEN ---
         FSS,R    KMAX                STARTING AT MAX POINT ON K-AXIS,
         FDS,R    =%NTICS               PRODUCE TICS WITH SEPARATION
         B        14Z3                  =(MIN-MAX)/N ALONG K-AXIS.
14Z1     LAW,R    KMIN              CASE 2: ZERO IS ON SCREEN  ---
         LAW,R1   KMAX                COMPUTE SEPARATION = ONE N'TH OF
         CW,R     R1                    LONGEST HALF OF K-AXIS;
         BGE      14Z2
         LAW,R    KMAX
14Z2     FDS,R    =%NTICS
*                                     STARTING AT THE ORIGIN, PRODUCE
         STW,R    XCOORD,K              TICS ALONG POSITIVE K-AXIS;
         BAL,L3   SENDTICS
         LCW,R    KDELTA              AGAIN STARTING AT ORIGIN, MAKE
         STW,R    XCOORD,K              TICS ON NEGATIVE K-AXIS
*                                       BY NEGATING SEPARATION VALUE.
14Z3     BAL,L3   SENDTICS
*
*              AXIS LIMITS
*
         LW,R     KMIN              GO TO MIN END OF K-AXIS
         LW,S     LIM1OFST,K          + FIXED OFFSET
         BAL,L3   SENDLIM           POSITION BEAM & WRITE LOWER LIMIT
         LW,R     KMAX              GO TO MAX END OF K-AXIS
         LW,S     LIM2OFST,K          + FIXED OFFSET
         BAL,L3   SENDLIM           POSITION BEAM & WRITE UPPER LIMIT
         B       *L2                EXIT
*
*
*     LOCAL DATA/TEMPS
*
KMINMAX  DTEMP                      MIN/MAX VALUE ON K-AXIS
KMIN     EQU      KMINMAX           MIN VALUE ON K-AXIS
KMAX     EQU      KMINMAX+1         MAX VALUE ON K-AXIS
AXFLAGS  TEMP                       AXES FLAGS INITIALIZER
XCOORD   TEMP                       X COORDINATE OF K-AXIS POINT
YCOORD   TEMP                       Y COORDINATE OF K-AXIS POINT
ZCOORD   TEMP                       Z COORDINATE OF K-AXIS POINT
KDELTA   TEMP                       DISTANCE BETWEEN TIC MARKS ON K-AXIS
*
BIASTBL  DATA,1   XMIN,YMIN,ZMIN    AXIS SELECTION BIASES
         BOUND    4
*
*     POINT OFFSET TABLES
*
OFST     COM,32   AF(2)**16+AF(1)
*
*              TIC MARKS
*
TICOFSET EQU      %                 INCREMENT FROM CENTER TO END OF TIC
         OFST     0,5               X-AXIS: VERTICAL TICS
         OFST     5,0               Y-AXIS: HORIZONTAL TICS
         OFST     -1,5              Z-AXIS: ALMOST VERT - NEG SLOPE
*
LIM1OFST EQU      %                 NEG END OF AXIS TO START OF LIMIT
         OFST     0,9               XMIN (LEFT): DIRECTLY ABOVE
         OFST     12,0              YMIN (BOTTOM): DIRECTLY TO RIGHT
         OFST     12,-18            ZMIN (TOP RIGHT): RIGHT AND BELOW
*
LIM2OFST EQU      %                 POS END OF AXIS TO START OF LIMIT
         OFST     -12,9             XMAX (RIGHT): ABOVE, A BIT TO LEFT
         OFST     12,-18            YMAX (TOP): TO RIGHT, A BIT BELOW
         OFST     12,0              ZMAX (BOT LEFT): DIRECTLY TO RIGHT
         PAGE
*
*
*     SEND A SERIES OF TIC MARKS
*
*              AXIS SELECTION IN K, SEPARATION VALUE IN R, 1ST POINT
*              IN X/Y/ZCOORD.  LINK IS L3.
*
SENDTICS EQU      %
         STW,R    KDELTA            STORE INCREMENT
         LW,R     XCOORD,K          TEST 1ST POINT
15Z1     CLM,R    KMINMAX           IF POINT IS OFF SCREEN,
         BCS,9   *L3                  STOP AND EXIT.
         LW,S     TICOFSET,K        ON SCREEN: SEND THE K-AXIS POINT
         BAL,LX   KAXISPT1            BUT SPECIFY FIXED OFFSET.
         LW,X     TEMPYYXX          NOW REPEAT THE SAME POINT BUT
         LCW,S    TICOFSET,K          NEGATE THE OFFSET.
         BAL,LX   OUT2NDPT
         LW,R     XCOORD,K          INCREMENT POINT ALONG K-AXIS
         FAS,R    KDELTA
         B        15Z1                AND TEST IT.
*
*
KAXISPT1 AND,F    =-1-VECTORFG      RESET VECTOR FLAG (START NEW VEC)
KAXISPT  STW,R    XCOORD,K          STORE K-AXIS COMPONENT
         LCI      3
         LM,X     XCOORD            GET X/Y/Z COORDS OF K-AXIS PT
         B        SENDPNT           SEND IT; EXIT VIA LX.
         PAGE
*
*
*  SEND AXIS LIMIT
*
*              POSITIONS BEAM ON K-AXIS AT VALUE GIVEN IN 'R'
*              OFFSET BY VALUE IN 'S'; WRITES OUT THE GIVEN
*              LIMIT VALUE (R) STARTING AT THAT BEAM POSITION.
*              LINK IS L3.
*
SENDLIM  EQU      %
         BAL,LX   KAXISPT1          SEND K-AXIS POINT R, OFFSET BY S
         OUTPUT   #US               END GRAPH MODE
         BAL,LO   GRAFOUT             AND DUMP OUT GRAPH MODE STUFF.
*                                   NOW EWE'RE IN ALPHA MODE FOR LIMIT
         LW,R     XCOORD,K          GET BACK THE LIMIT VALUE
*
*
*              CODE TO CONVERT F.S. VALUE IN 'R' TO TEXT STRING
*              IN GRAFBUF.  WIDTH IS CONTROLLED BY 'GDIGITS'
*              INSTEAD OF 'DIGITS'.  DEFAULT VALUE OF 'GDIGITS'
*              IS 3 (INTRINSIC COULD BE ADDED TO CHANGE THIS).
*
*
*              THIS CODE INTERFACES WITH EXTERNAL CONVERSION
*              ROUTINES THAT EMPLOY A DIFFERENT REGISTER
*              NAMING CONVERNTION; HENCE.....
*
         OPEN     R0,R4,R5,R7,R8,R9,R11,R12
R0       EQU      0                 (F)
R4       EQU      4                 (A,GP)
R5       EQU      5                 (LX)
R7       EQU      7                 (LX7, AF1)
R8       EQU      8                 (R)
R9       EQU      9                 (R1)
R11      EQU      11                (S)
R12      EQU      12                (L3)
*
         STW,K    KSAVE             SAVE K
         STW,GP   GPSAVE            SAVE GP
         STD,L3   L3L2SAVE          SAVE L3 AND L2
         XW,R0    GDIGITS           SAVE R0,GET GDIGITS
         XW,R0    DIGITS            SWITCH DIGITS TO GDIGITS
         EQUAL,R,R8                 FS LIMIT VALUE IS IN 'R' (R8)
         LI,R9    0                 CONVERT FS TO FL
         BAL,R11  CREALBIN           CONVERT TO INTEGER-EXPONENT
         LI,R5    BA(GRAFBUF)       TARGET ADDRESS
         CI,R7    X'72'              CHECK FOR NEGATIVE VALUE
         BNE      16Z1                 NO
         BAL,R11  SETCHAR
16Z1     CI,R12   -4                CHECK IF E-FORM NEEDED
         BLE      16Z2               YES
         CW,R12   DIGITS
         BG       16Z2               YES
         BAL,R4   GENDIGS            NO
         B        16Z3
16Z2     BAL,R4   GENDIGSE          E-FORM GEN. DIGITS
         BAL,R4   GENEXP             AND EXPONENT
16Z3     AI,R5    -BA(GRAFBUF)      GET BYTE COUNT
         LW,CC    R5
16Z4     AI,R5    -1
         BLZ      16Z5
         LB,R4    GRAFBUF,R5
         LB,R4    OUTRANST,R4       TRANSLATE TO TERMINAL CHAR.
         STB,R4   GRAFBUF,R5
         B        16Z4              LOOP
16Z5     LD,L3    L3L2SAVE          RESTORE L3 AND L2
         LW,GP    GPSAVE            RESTORE GP
         LW,K     KSAVE             RESTORE K
         XW,R0    DIGITS             DIGITS
         XW,R0    GDIGITS
*
         CLOSE    R0,R4,R5,R7,R8,R9,R11,R12
*
*
         BAL,LO   GRAFTEXT          OUTPUT BUFFER IN ALPHA MODE
         B       *L3                EXIT
*
*
KSAVE    TEMP
GPSAVE   TEMP
L3L2SAVE DTEMP
         PAGE
*
*
*  DRAW BOX
*
*              CORRESPONDS TO
*                       9 #GRF NUL
*              CALLED WITH GP SET UP.  RETURNS VIA 'RETURN'.
*
DRAWBOX  EQU      %
         BAL,LX   GETCOORD          REMEMBER CURSOR LOC
         LI,CC    0                 INIT OUTPUT
         LI,F     RENTFLAG          INIT FLAGS FOR SENDPNT
         LW,X     XMIN,GP           START WITH LOWER LEFT CORNER
         LW,Y     YMIN,GP
         BAL,LX   SENDPNT
         LW,X     XMIN,GP
         LW,Y     YMAX,GP           MOVE UP
         BAL,LX   SENDPNT
         LW,X     XMAX,GP           MOVE RIGHT
         LW,Y     YMAX,GP
         BAL,LX   SENDPNT
         LW,X     XMAX,GP
         LW,Y     YMIN,GP           MOVE DOWN
         BAL,LX   SENDPNT
         LW,X     XMIN,GP           MOVE LEFT
         LW,Y     YMIN,GP
         BAL,LX   SENDPNT
         BAL,LX   ENDVEC            END VECTOR
         B        NEXTLINE          RESET CURSOR, EXIT
         PAGE
*
*
*  SET COORDINATE
*
*              CORRESPONDS TO
*                       4 #GRF X,Y                ..OR
*                       4 #GRF X,Y,Z
*              THE TWO OR THREE COORDINATES ARE IN 'PARAMS' BUFFER;
*              GR AND 3D-FLAG ARE SET UP. SETS CURSOR TO (X,Y) OR
*              (X,Y,Z).  EXITS VIA 'RETURN'.
*
SETCOORD EQU      %
         BAL,LX   GETCOORD          SAVE CURRENT CURSOR LOC IN CASE
*                                     OF LATER '4 GRF NUL'.
         LW,X     GRXYBYTS          SAVE CURSOR COORDS
         STW,X    XYSAVE
         LCI      3
         LM,X     PARAMS            GET X, Y, (Z)
         LI,CC    0                 INIT OUTPUT
         BAL,LX   SENDPNT           SEND ONE POINT (X,Y,(Z))
ENDOUT   BAL,LX   ENDVEC            STOP VECTOR
         BAL,LO   GRAFOUT           DUMP OUTPUT BUFFER
         B       *RETURN            EXIT
         PAGE
*
*
*  ERASE AND HOME
*
*
*              CORRESPONDS TO
*                       8 #GRF NUL
*              ERASES SCREEN AND 'HOMES UP' CURSOR.  EXITS VIA 'RETURN'.
*
ERASHOME EQU      %
         LI,K     1
         BAL,LX   SCREENCT          DO A #GRF 1
         LI,K     2
*     FALLS INTO  SCREENCT          THEN #GRF 2 AND EXIT
         PAGE
*
*
*  SCREEN CONTROL
*
*              CORRESPONDS TO
*                       8 #GRF K
*              CALLED WITH K IN 'K'.   THIS ROUTINE EITHER
*              SENDS 'ERASE' COMMAND (K=1) OR SENDS CURSOR
*              TO 'HOME' POSITION (K=2).  FOR K=1, RETURNS
*              VIA LINK IN LX; FOR K=2, RETURNS VIA 'RETURN'.
*
SCREENCT EQU      %
         LI,CC    0                 INIT OUTPUT
         LI,F     0                 INIT FLAGS (ONLY VECTORFG USED)
         BDR,K    9Z1               WHICH FUNCTION IS IT ?
         OUTPUT   #ESC,#FF          K=1: ERASE - SEND 'ERASE' COMMAND;
         BAL,LO   GRAFOUT             DUMP OUTPUT BUFFER;
CALWT13  CAL1,8   FPTWT13           DELAY FOR ERASE OF SCREEN
         B        0,LX                EXIT (LINK).
FPTWT13  DATA     X'0F000002'       DELAY 2 UNITS
9Z1      LD,X     HOMEPOS           K=2: HOME - GET COORDS (IN PTS) OF
         BAL,LX   OUTPOINT            'HOME' POSITION; SEND IT;
         B        ENDOUT              END VECTOR; DUMP OUTPUT; EXIT.
*
         BOUND    8
HOMEPOS  DATA     0,FSADD(X'46800000',%YPTS)-19
         PAGE
*
*
*  END VECTOR MODE
*
*              CALLED WITH FLAGS IN F. LINK IS LX.
*
ENDVEC   EQU      %
         CI,F     VECTORFG          IF NOT IN VECTOR MODE,
         BAZ      0,LX                SKIP IT.
         AI,F     -VECTORFG         IN: GET OUT
         OUTPUT   #US
         B        0,LX              EXIT
         PAGE
*
*
*  P A R A M E T E R    S E T U P    R O U T I N E S
*
*
*  INITIALIZE PARAM DATA BLOCK
*
*              IF 'GRAFPNTR' IS ZERO, THIS ROUTINE ALLOCATES THE DATA
*              BLOCK AND INITIALIZES IT TO DEFAULT PARAMS.  RETURNS
*              GRAFPNTR IN GP.  LINK IS LX.
*              ALSO TESTS TERMINAL TYPE TO MAKE SURE USER
*              SPECIFIED 'TERM 13' (TEK 4013 TERMINAL).
*
INITGRAF EQU      %
         LI,R     13
         CW,R     TERMTYPE          IS IT TERM 13?
         BE       17Z1              YES
         LI,2     IDTERMAL          NO, SIGNAL TERMINAL TYPE ERROR
         B        ERTERMAL
17Z1     LI,R     0
         STW,R    GRFIOFLG          INIT I/O FLAG (SEE ERRGRFIO IN UTSG)
         STW,R    GRXYBYTS          INIT CURSOR LOC (--DITTO--)
         LW,GP    GRAFPNTR          GET PARAM DATA BLOCK PNTR
         BNEZ     0,LX              IF ALREADY IN EXISTENCE, RETURN IT.
         STW,LX   LINKTEMP
         LI,S     GRDBSIZE-2        ELSE, CREATE ONE (SIZE IN 'S'
         BAL,LX7  ALOCHNW             EXCLUDES HEADER). ALOCHNW RETURNS
         EQUAL,A,GP                   PNTR IN 'A', WHICH IS ALSO 'GP'.
         STW,GP   GRAFPNTR          SAVE PNTR
         LI,R     INTG**8+1         SET UP PHONY TYPE AND RANK
         STH,R   *GRAFPNTR            IN DATA BLOCK HEADER.
         LI,S     GRDBSIZE-3        LENGTH OF PHONY INTEGER VECTOR
         STW,S    2,GP               SET IN DATA BLOCK HEADER
         LCI      9                 COPY DEFAULT PARAMS
         LM,R-1   DEFAULTS            INTO NEW DATA BLOCK.
         STM,R-1  FLAGS,GP
         LM,R-1   DEFAULTS+9
         STM,R-1  FLAGS+9,GP
         LCI      5
         LM,R-1   DEFAULTS+18
         STM,R-1  FLAGS+18,GP
         B       *LINKTEMP          EXIT W/PNTR IN 'GP'
*
LINKTEMP TEMP
GRFIOFLG TEMP
*
*     DEFAULT PARAMETERS
*
DEFAULTS EQU      %                 DEFAULT PARAMS
DEFFLAGS EQU      %              FLAGS:
         DATA     CENTERFG+;        SPECIFY CENTERED AUTOMATIC SCALING,
                  ASCLFLAG+;
                  ISCLFLAG+;          INPUT COORDINATE SCALING,
                  RENTFLAG            AND CURVE RE-ENTRANCE.
DEFSCALE EQU      %              SCALING:
         DATA     0,%XPTS           X LIMITS
         DATA     0,%YPTS           Y LIMITS
         DATA     0,0               Z LIMITS
         DATA     FS'1',FS'1',0     X/Y/Z MULTIPLIERS
DEFWINDO EQU      %              WINDOW:
%XDISP   EQU      FSSUB(%XINCHS,%YINCHS)
         DATA     %XDISP,%XINCHS    LARGEST SQUARE AT RIGHT
         DATA     0,%YINCHS
         DATA     FSADD(X'46800000',; WITH CORRESPONDING 'DISPFIX' VALS
                    FSMUL(%XDISP,%PPI))
         DATA     %ASPECT             AND RATIOS.
         DATA     X'46800000'
         DATA     FS'1'
         DATA     0,0,64,0,0    INXCOORD,INYCOORD,INCHAR,SPARE1,SPARE2
         PAGE
*
*
*  SCALING PARAM MODIFICATION
*
*              SCALING PARAMS ARE CHANGED IN ONE THE FOLLOWING WAYS:
*
*              1. ORIGINALLY, 'INITGRAF' SETS THEM ALL TO ZERO AND
*                 SETS THE AUTOMATIC SCALING FLAG (SEE 3 BELOW).
*
*              2. USER CAN SET THEM EXPLICITLY VIA
*                       3 #GRF X1,X2,Y1,Y2          OR
*                       3 #GRF X1,X2,Y1,Y2,Z1,Z2    OR
*                       3 #GRF NUL .
*                 THE FIRST TWO SET THE X AND Y (AND Z) LIMITS AS
*                 GIVEN AND RESETS THE 'AUTOMATIC SCALING' FLAG SO
*                 THAT THEY WON'T GET CHANGED BY THE CURVE PLOTTER;
*                 THESE FORMS ARE HANDLED BY THE ROUTINE 'SETSCALE'.
*                 THE THIRD FORM ABOVE, HANDLED BY 'NOSCALE', SETS X/Y
*                 SCALING TO USE X AND Y DIRECTLY AS POINT COORDINATES
*                 WHERE THE X RANGE IS (0,%XPTS) AND THE Y RANGE
*                 IS (0,%YPTS); 'NOSCALE' ALSO RESETS 'AUTOSCALE' FLAG
*                 AND SETS THE WINDOW PARAMS TO FULL-SCREEN SIZE.
*
*              3. IF THE 'AUTOSCALE' FLAG IS SET WHEN THE CURVE
*                 PLOTTER IS CALLED, THE SCALING PARAMETERS ARE
*                 SET ACCORDING TO THE MIN/MAX OF THE DATA IN EACH
*                 OF ITS COORDINATES (ALSO MAKING USE OF THE 'CENTER
*                 SCALING' FLAG SETTING).  THIS IS HANDLED BY THE
*                 ROUTINE 'AUTOSCAL' CALLED BY 'QZOUTPUT'.
*
*
*  SET SCALING ACCORDING TO USER'S PARAMS
*
*              CORRESPONDS TO
*                       3 #GRF X1,X2,Y1,Y2        OR
*                       3 #GRF X1,X2,Y1,Y2,Z1,Z2
*              THE FOUR (SIX) PARAMS ARE IN 'PARAMS'.
*                           RESETS  AUTO- AND CENTER-SCALING FLAGS.
*              CALLED WITH GP AND 3DFLAG SET UP. LINK IS LX.
*
SETSCALE EQU      %
         LCI      6
         LM,R     PARAMS            GET X1,X2,Y1,Y2,(Z1,Z2)
         STM,R    XMIN,GP           STORE IN X/Y/Z LIMIT PARAMS
         FSS,R+1  R                 COMPUTE X SPAN
         BNEZ     5Z1
         FAS,R    =%EPS             IF SPAN IS ZERO, SET MAX=MIN+EPS
         STW,R    XMAX,GP             SO THAT SPAN WILL BE >0.
         LW,R+1   =%EPS
5Z1      FSS,R+3  R+2               SAME FOR Y
         BNEZ     5Z2
         FAS,R+2  =%EPS
         STW,R+2  YMAX,GP
         LW,R+3   =%EPS
5Z2      FSS,R+5  R+4               SAME FOR Z
         BNEZ     5Z3
         FAS,R+4  =%EPS
         STW,R+4  ZMAX,GP
         LW,R+5   =%EPS
5Z3      LCI      3                 GET X/Y/Z SCREEN SIZES (IN PTS)
         LM,AF    XSIZEPTS
         FDS,AF   R+1               XSCALE = XSIZEPTS/(X2-X1)
         FDS,AF+1 R+3               YSCALE = YSIZEPTS/(Y2-Y1)
         FDS,AF+2 R+5               ZSCALE = ZSIZEPTS/(Z2-Z1)
         CI,F     3DFLAG            IF 2D SCALE BEING SET UP,
         BANZ     5Z4                 SET ZSCALE=0 FOR THE
         LI,AF+2  0                   BENEFIT OF 'DRAWAXES'.
5Z4      LCI      3
         STM,AF   XSCALE,GP         STORE X/Y/Z SCALE FACTORS
         AI,LX    0                 IF ENTERED FROM 'AUTOSCAL',
         BLZ      0,LX                DON'T TOUCH FLAGS.
RESETASC LI,F     0                 RESET AUTO SCALING FLAGS
         LI,F+1   ASCLFLAG+CENTERFG
         STS,F    FLAGS,GP
         B        0,LX
*
*  FIXED DATA
*
XSIZEPTS DATA     %XPTS             SCREEN SIZE, IN POINTS
YSIZEPTS DATA     %YPTS                 *
ZSIZEPTS DATA     %ZPTS                 *
         PAGE
*
*
*  SET UP TRANSPARENT SCALING AND FULL-SCREEN WINDOW
*
*              CORRESPONDS TO
*                       3 #GRF NUL
*              SETS X/Y LIMITS TO INTERPRET (X,Y) AS POINT COORDINATES.
*              SETS WINDOW LIMITS TO FULL SCREEN.  RESETS AUTO-SCALE
*              FLAGS.  CALLED WITH GP SET UP.  LINK IS LX.
*
NOSCALE  EQU      %
         LCI      9
         LM,R-1   TRANSCAL          MOVE 'TRANSPARENT' SCALE LIMITS
         STM,R-1  XMIN,GP             AND MULTIPLIERS TO PARAM DB..
         LCI      8
         LM,R     FULLWIND          MOVE FULL-SCREEN WINDOW PARAMS
         STM,R    LXWINDOW,GP         TO DB.
         B        RESETASC          RESET AUTO-SCALE FLAGS, EXIT
*
*     TRANSPARENT SCALE PARAMETERS
*
TRANSCAL EQU      DEFSCALE          TRANSPARENT SCALE PARAMS
*
*     FULL-SCREEN WINDOW PARAMETERS
*
FULLWIND EQU      %                 FULL SCREEN WINDOW PARAMS
         DATA     0,%XINCHS         X LIMITS
         DATA     0,%YINCHS         Y LIMITS
         DATA     X'46800000'       X DISPLACEMENT (FIX)
         DATA     FS'1'             X RATIO
         DATA     X'46800000'       Y DIPLACEMENT (FIX)
         DATA     FS'1'             Y RATIO
         PAGE
*
*
*  AUTOMATIC SCALING
*
*              SETS UP MIN/MAX OR ORIGIN-CENTERED SCALING BASED ON
*              THE DATA BEING PLOTTED.  IT IS CALLED FROM 'QZOUTPUT'
*              AFTER THE DATA-FETCHING XSEG HAS BEEN BUILT.  'AUTOSCAL'
*              USES THIS XSEG TO ACCESS THE DATA POINTS.  CALLED WITH
*              F, GP, AND XL (LAST XSEG LOC+1) SET UP. LINK IS LX.
*
AUTOSCAL EQU      %
         STW,LX   ASCLRET           SAVE LINK (XSEG USES LX)
         LW,R     CODE5             MODIFY XSEG TEMPORARILY: CHANGE
         STW,R    -4,XL              'BAL SENDPNT' TO 'BAL SCALPNT'.
         SETBRK                     ALLOW BREAKS DURING XSEG EXECUTION
         BAL,L2   SCALPNT           START XSEG; AFTER LAST POINT,
*                                     XSEG RETURNS HERE...
         RESETBRK                   STOP BREAKS AFTERWARDS
         LW,R     CODE4             RESTORE XSEG AS IT WAS UPON ENTRY
         STW,R    -4,XL
         LW,LX    ASCLRET           RESTORE LINK
         AI,LX    -1**17            TELL SETSCALE TO LEAVE FLAGS ALONE
         CI,F     3DFLAG            IF 2-DIMENDIONAL DATA,
         BANZ     6Z0
         LI,R     0                   SET Z SCALE PARAMS TO 0.
         STW,R    PARAMS+4
         STW,R    PARAMS+5
6Z0      EQU      %
         CI,F     CENTERFG          IF NO CENTERING TO BE DONE,
         BAZ      SETSCALE            GO SET SCALING FROM MINS/MAXES.
         LI,M     4                 CENTER THE ORIGIN: FOR EACH COORD...
6Z1      LAW,R    PARAMS,M          LET  L/U BE LOWER/UPPER LIMITS: L<U
         LAW,R1   PARAMS+1,M        FETCH AL/AU = ABS(L)/ABS(U)
         CW,R     R1                AL:AU
         BE       6Z3               AL=AU: THUS L=-U, ALREADY CENTERED
         BL       6Z2
         STW,R    PARAMS+1,M        AL>AU: THUS L<0, CHANGE LIMITS
         B        6Z3                 TO (L,AL) = (-AL,AL) CENTERED.
6Z2      LCW,R1   R1                AL<AU: THUS U>0, CHANGE LIMITS
         STW,R1   PARAMS,M            TO (-AU,U) = (-AU,AU) CENTERED.
6Z3      AI,M     -2                DO ALL COORDS
         BGEZ     6Z1
         B        SETSCALE          THEN SET SCALING TO CENTERED PARAMS
*
*
SCALPNT  EQU      %
         BAL,L3   XSEGBASE          SET L3 SO 1ST POINT WILL BE
         STW,X    PARAMS+0            PROCESSED HERE:
         STW,X    PARAMS+1          XMIN=XMAX=X
         STW,Y    PARAMS+2
         STW,Y    PARAMS+3          YMIN=YMAX=Y
         STW,Z    PARAMS+4
         STW,Z    PARAMS+5          ZMIN=ZMAX=Z
         BAL,L3   0,LX              SET L3 SO THAT 2ND AND LATER
*                                     POINTS WILL BE PROCESSED HERE:
         LI,AF    -6                AF RUNS -6, -4, -2 AS AI RUNS
         LI,AI    -3                        -3, -2, -1.
6Z4      LW,X     X+3,AI            GET X/Y/Z COORD (CALL IT X)
         CLM,X    PARAMS+6,AI       COMPARE MIN:X:MAX
         BCR,9    6Z6               MIN<=X<=MAX, NO CHANGE
         BL       6Z5
         STW,X    PARAMS+7,AF       X>MAX, UPDATE MAX
         B        6Z6
6Z5      STW,X    PARAMS+6,AF       X<MIN, UPDATE MIN
6Z6      AI,AF    2                 BUMP AF BY 2, AI BY 1
         BIR,AI   6Z4
         B        0,LX              DONE, RETURN TO XSEG FOR NEXT POINT
*
*
ASCLRET  TEMP                       AUTOSCAL LINK SAVE CELL
CODE5    BAL,LX  *L3                (PLACED IN XSEG TEMPORARILY)
         PAGE
*
*
*  WINDOW PARAM MODIFICATION
*
*              WINDOW PARAMS ARE CHANGED IN ONE OF THE FOLLOWING WAYS:
*
*              1. ORIGINALLY, 'INITGRAF' SETS THEM TO THE LARGEST
*                 POSSIBLE SQUARE WINDOW TOUCHING BOTTOM AND RIGHT
*                 EDGES OF SCREEN.
*
*              2. USER CAN SET THEM VIA
*                       2 #GRF LX,UX,LY,UY      OR
*                       2 #GRF NUL
*                 THE FIRST (HANDLED BY 'SETWINDO') SETS THEM AS
*                 GIVEN.  THE SECOND ('NOWINDOW') SETS THEM TO THE
*                 LARGEST SQUARE WINDOW, AS IN 1 ABOVE.
*
*              3. THEY ARE SET TO FULL SCREEN SIZE BY 'NOSCALE'
*                 IN RESPONSE TO
*                       3 #GRF NUL
*
*
*  SET WINDOW ACCORDING TO USER'S PARAMS
*
*              CORRESPONDS TO
*                       2 #GRF LX,UX,LY,UY
*              THE FOUR PARAMS ARE IN 'PARAMS'. CALLED WITH GP SET
*              UP.  LINK IS LX.
*
SETWINDO EQU      %
         LW,R     PARAMS            LX
         BLZ      ERDOMAIN           TOO LOW
         LW,R+1   PARAMS+1          UX
         CW,R+1   =%XINCHS
         BG       ERDOMAIN           TOO HIGH
         CW,R+1   PARAMS
         BLE      ERDOMAIN           OUT OF ORDER
         LW,R+2   PARAMS+2          LY
         BLZ      ERDOMAIN
         LW,R+3   PARAMS+3          UY
         CW,R+3   =%YINCHS
         BG       ERDOMAIN           TOO HIGH
         CW,R+3   PARAMS+2
         BLE      ERDOMAIN           OUT OF ORDER
         LCI      4
         STM,R    LXWINDOW,GP       STORE 'EM IN D8
         FSS,R+1  PARAMS            UX-LX
         FDS,R+1  =%XINCHS          (UX-LX)/XPTS = XRATIO
         FSS,R+3  PARAMS+2          UY-LY
         FDS,R+3  =%YINCHS          (UY-LY)/YPTS = YRATIO
         FMS,R    =%PPI             LX (IN PTS)
         FAS,R    =X'46800000'      XDISPFIX  (= X'46800XXX')
         FMS,R+2  =%PPI             LY (IN PTS)
         FAS,R+2  =X'46800000'      YDISPFIX (=X'46800YYY')
         LCI      4                 STORE RATIOS
         STM,R    XDISPFIX,GP         AND DISPLACEMENTS.
         B        0,LX              EXIT
         PAGE
*
*
*  SET UP DEFAULT WINDOW
*
*              CORRESPONDS TO
*                       2 #GRF NUL
*              CALLED WITH GP SET UP.  LINK IS LX.
*
NOWINDOW EQU      %
         LCI      8
         LM,R     DEFWINDO          COPY DEFAULT WINDOW PARAMS
         STM,R    LXWINDOW,GP         TO WINDOW DATA.
         B        0,LX              EXIT
         PAGE
*
*
*  FLAG MODIFICATION
*
*              SCALING-MODE FLAGS ARE CHANGED AS FOLLOWS:
*
*              1. ORIGINALLY, 'INITGRAF' SETS AUTO-SCALE AND CENTERING
*                 FLAGS. THIS IS THE 'DEFAULT' SCALING MODE.
*
*              2. THESE FLAGS ARE RESET BY ANY COMMAND OF THE FORM
*                       3 #GRF NUL ...
*                 SCALING IS THEREBY FIXED AT THE USER'S LIMITS OR
*                 AT THE 'TRANSPARENT' VALUES.  THE ROUTINES 'SETSCALE'
*                 AND 'NOSCALE' DO THIS.
*
*              3. THE USER CAN CONTROL THE SCALING MODE FLAGS WITH:
*                       6 #GRF K
*                 FOR K=1, WE SET AUTO-SCALE FLAG, BUT NOT CENTERING
*                   FLAG; THUS EACH FOLLOWING CURVE WILL BE SCALED
*                   ACCORDING TO ITS MINIMA/MAXIMA.
*                 FOR K=2, WE SET BOTH FLAGS SO THAT FOLLOWING CURVES
*                   WILL EACH BE CENTER-SCALED.
*                 FOR K=3, WE RESET BOTH FLAGS SO THAT SCALING WILL
*                   REMAIN FIXED AT ITS LAST SETTING.
*                 THESE FUNCTIONS ARE PERFORMED BY THE FOLLOWING
*                 ROUTINE, CALLED WITH THE K-VALUE IN AI, LINK IN LX,
*                 AND GP SET UP:
*
SCALMODE EQU      %
         LB,F     SCLFGTBL,K        GET FLAG BITS
         LI,F+1   ASCLFLAG+CENTERFG GET FLAG BIT MASK
         STS,F    FLAGS,GP          SET APPROPRIATE FLAGS
         B        0,LX              EXIT
*
SCLFGTBL DATA,1   0,ASCLFLAG,ASCLFLAG+CENTERFG,0
         PAGE
*
*
*              DASHED-CURVE MODE FLAG IS CHANGED AS FOLLOWS:
*
*              1. ORIGINALLY, 'INITGRAF' RESETS DASHFLAG.
*
*              2. IT IS SET BY 'DASHMODE', BELOW, IN RESPONSE TO:
*                       7 #GRF NUL
*
*              3. IT IS RESET AT THE END OF 'QZOUTPUT' AFTER PLOTTING
*                 A CURVE.
*
DASHMODE EQU      %
         LI,F     DASHFLAG          SET DASHFLAG
         LI,F+1   DASHFLAG
         STS,F    FLAGS,GP
         B        0,LX              EXIT
         PAGE
*
*
*              CURVE RE-ENTRANCE MODE FLAG IS CHANGED AS FOLLOWS:
*
*              1. ORIGINALLY, 'INITGRAF' SETS IT.
*
*              2. THE USER MAY SET OR RESET IT WITH:
*                      10 #GRF K
*                 WHERE K=1 FOR 'RESET', 2 FOR 'SET'. THE FOLLOWING
*                 SUBROUTINE HANDLES THIS (K IS IN K,  LINK IS LX,
*                 GP IS SET UP):
*
RENTMODE EQU      %
         LI,F     RENTFLAG          GET RE-ENTRANCE MODE BIT
         LI,F+1   RENTFLAG            AND MASK.
FLAGSETK EQU      %
         SLS,F    -2,K              IF K<2 SHIFT BIT OFF ITS MARK
         STS,F    FLAGS,GP          SET OR RESET RENTFLAG
         B        0,LX              EXIT
         PAGE
*
*
*              INPUT SCALING MODE FLAG IS CHANGED AS FOLLOWS:
*
*              1. ORIGINALLY, 'INITGRAF' SETS IT.
*
*              2. THE USER MAY SET OR RESET IT WITH:
*                       0 #GRF K
*                 WHERE K=1 FOR 'RESET', K=2 FOR 'SET'. THE FOLLOWING
*                 ROUTINE HANDLES THIS (K IS IN K,  GP IS SET UP,
*                 LINK IS LX):
*
ISCLMODE EQU      %
         LI,F     ISCLFLAG          SPECIFY INPUT-SCALE FLAG
         LI,F+1   ISCLFLAG
         B        FLAGSETK          SET FLAG ACCORDING TO K VALUE; EXIT
         PAGE
*
*
*  SET DEVICE
*
*              CORRESPONDS TO
*                       1 #GRF K
*              THIS IS ACCEPTED ONLY FOR PURPOSES OF COMPATIBILITY
*              WITH BERKELEY'S SYSTEM.  ONLY K=3 IS ALLOWED. LINK IS LX.
*
SETDEV   EQU      %
         CI,K     3                 IF K=3 (MEANING 'TEK 4013 TERMINAL')
         BE       0,LX                IT'S OK.
         B        ERDOMAIN          ELSE ERROR
         PAGE
*
*
*  RETURN PARAMETER VALUES
*      OR  SET GRAPHICS INPUT TO 5,6,OR 7 CHARACTER READ
*           CORRESPONDING TO STRAPPING OPTION FOR TERMINAL
*           (DEFAULT IS 7)
*
*              CORRESPONDS TO
*                      11 #GRF K
*              FOR K=1, RETURNS SCALING INFO AS 4- OR 6-WORD FLOT
*                VECTOR.
*              FOR K=2, RETURNS WINDOW INFO AS 4-ELEMENT FLOT VECTOR.
*              FOR K=3, RETURNS X/Y COORDS OF QUAD-ZERO INPUT
*                AS 2-ELEMENT FLOT VECTOR.
*               FOR K=4, RETURNS CHARACTER OF QUAD-0 INPUT AS SCALAR
*              EXITS DIRECTLY TO 'DXRETURN'.
*               FOR K=5,6,OR 7,SETS 'STRAPOPT'
*
*
PARAMVAL EQU      %
         CI,K     4
         BG       18Z4              SET STRAPOPT
         BE       18Z3              RETURN INCHAR
         CI,K     1
         BNE      18Z1
         LW,R     ZSCALE,GP         IF K=1 AND ZSCALE>0,
         BEZ      18Z1
         AI,K     -1                  MODIFY CODE TO SAY '3-D SCALING'.
18Z1     STW,K    KSAVE             SAVE    INDEX
         LB,S     PARCOUNT,K        COMPUTE DATA SIZE =
         SLS,S    1                   N DOUBLEWORDS
         AI,S     2                   + DIMEN WORD + GAP WORD.
         BAL,LX7  ALOCHNW           ALOC RESULT DATA BLOCK
         STW,A    RESULT            STORE RESULT POINTER
         LI,R     FLOT**8+1         SET TYPE=FLOT, RANK=1
         STH,R   *RESULT
         LW,K     KSAVE             RESTORE K VALUE (0-3)
         LB,XI    PARBIAS,K         GET 1ST PARAM BIAS
         LB,K     PARCOUNT,K        GET PARAM COUNT
         STW,K    2,A               SET DIMEN = COUNT
18Z2     LW,R    *GRAFPNTR,XI       GET A PARAM (F.S.)
         LI,R1    0                 CONVERT TO F.L.
         STW,R    4,A               STORE IN RESULT DATA BLOCK
         STW,R1   5,A
         AI,XI    1
         AI,A     2
         BDR,K    18Z2              REPEAT FOR EACH PARAM
         B        DXRETURN          EXIT
18Z3     LI,S     1
         BAL,LX7  ALOCHNW           ALLOCATE RESULT DATA BLOCK
         STW,A    RESULT
         LI,R     CHAR**8+0         CHARACTER SCALAR
         STH,R   *RESULT
         LW,R-1   GRAFPNTR          GET CHARACTER
         LW,R     INCHAR,R-1
         AI,A     2
         STB,R   *A                 STORE IN RESULT
         B        DXRETURN
18Z4     STW,K    STRAPOPT          SET STRAP OPTION
         B        DXNULRTN
*
*
PARBIAS  DATA,1   XMIN,XMIN,LXWINDOW,INXCOORD
PARCOUNT DATA,1   6,4,4,2
         PAGE
*
*
*  M I S C E L L A N E O U S    S U B R O U T I N E S
*
*
*  CONVERT INTEGER TO F.S. VALUE
*
*              CALLED WITH INTEGER IN AI.  RETURNS WITH F.S. VALUE
*              IN AF.  LINK IS LX.
*
ITOFS    EQU      %
         AI,AI    0                 TEST SIGN
         BGEZ     10Z1
         LCW,AI   AI                NEGATIVE: NEGATE IT;
         ODD,AI                       CONVERT IT TO F.L. AS A
         EQUAL,AI,AF+1                POSITIVE VALUE SO THAT WE
         LW,AF    =X'4E000000'        MAY PROPERLY TRUNCATE TO F.S.;
         SFL,AF   14                  NORMALIZE;
         LCW,AF   AF                  TRUNCATE TO F.S.; RE-NEGATE;
         B        0,LX                EXIT.
10Z1     LW,AF    =X'4E000000'      POSITIVE: APPEND EXPONENT;
         SFL,AF   14                  NORMALIZE;
         B        0,LX                EXIT WITH F.S. VALUE IN AF.
*
*
*  CONVERT F.L. TO F.S.
*
*              CONVERTS F.L. VALUE IN AF/AF1 TO F.S. VALUE IN AF.
*              LINK IS LX.
*
FLTOFS   EQU      %
         AI,AF    0                 TEST SIGN: IF >=0, IT'S OK TO
         BGEZ     0,LX                TRUNCATE VALUE.
         LCD,AF   AF                <0: NEGATE F.L.,
         LCW,AF   AF                  TRUNCATE POS VAL, RE-NEGATE F.S.
         B        0,LX              EXIT
*
*
18Z      END

