    ! EDWIN driver for the ERCC plotters (using GRAPHPACK)

    from Edwin include Device
    from Edwin include Icodes

    !%system %routine %spec CASCADE LOAD (%integer %name FLAG, %integer LOCLL)
    !%system %routine %spec LOADFILE2(%string (31) FILENAME, %integer %name FLAG,
    !     %integer LEVEL)
    !%system %integer %fn %spec CURRENTLL
    dynamic routine spec DEFINE (string (255) ST)
    dynamic routine spec PLOTTER TYPE (integer N)
    dynamic routine spec OPEN PLOTTER (integer ICHAN)
    dynamic routine spec SET PLOT (longreal XMIN,YMIN,XMAX,YMAX, integer UNITS)
    dynamic routine spec SCALE (longreal XORIGIN,YORIGIN, XSCALE, YSCALE, THETA)
    dynamic routine spec CLOSE PLOTTER
    dynamic routine spec CHANGE PEN (integer PENNO)
    dynamic routine spec PLOT (integer IPEN,longreal TOX,TOY,DASH,GAP)
    dynamic routine spec AREA FLAG (string(3) S)
    dynamic routine spec ANNOTATE (longreal X,Y, SIZE, THETA)
    dynamic routine spec PLOT SYMBOL (integer ICODE)
    dynamic routine spec PEN POSITION (long real name X, Y)

    external routine CALCOMP alias "EDWIN___N" (integer COM, X, Y)
       own integer LOADED = 0, WX, WY
       const integer ION = 16_E0, IOFF = 16_E1, TRUE = 0, FALSE = 1
       ! Plotter control
       own integer IPEN=2, XO=0, XS=1500, YO=0, YS=1500, SX=0, SY=0
       own integer TCS = 12, ITALICS = FALSE, TEXT MODE = FALSE, NEW FRAMED = FALSE
       own long real DASH = 0, GAP = 0, THETA = 0, PX, PY
       const integer UPC = 100
       long real P SIZE X, P SIZE Y
       string (31) DEVST

       routine SWAP (integer name  A, B)
          integer C
          C = A;   A = B;   B = C
       end

       routine CHANGE ATTRIBUTE (integer X, Y)
          switch AS(0:ATT MAXIMUM)
          -> AS(X)

    AS(0): ! Colour change
           CHANGE PEN (Y)
           return

    AS(1): ! Line style change
           Y=0 unless 0<=Y<=4
           if Y=0 then DASH=0 and GAP=0 and IPEN=2
           if Y=1 then DASH=3 and GAP=3 and IPEN=0
           if Y=2 then DASH=0 and GAP=0 and IPEN=2
           if Y=3 then DASH=8 and GAP=3 and IPEN=0
           if Y=4 then DASH=15 and GAP=3 and IPEN=0
           return

    AS(2): ! Character size change
           TCS = Y
           return

    AS(3): ! Character orientation
           THETA = Y
    AS(4): ! Character quality
    AS(5): ! Character font
           return

    AS(6): ! Character slant
           if 0<Y<90 then ITALICS = TRUE else ITALICS = FALSE
           return

    AS(*):
       end

       switch SW (0:max com)
       return if COM>MAX COM
       -> SW(COM)

    SW(0): ! Initialise
    !       %if LOADED = 0 %start
    !           Y = 1
    !           LOAD FILE 2 ("ERCLIB.GRAPHICSY_RCOGRAF13Y", Y, CURRENT LL)
    !           %signal 14, 1 %if Y#0
    !           CASCADE LOAD (Y, CURRENT LL)
    !           %signal 14, 1 %if Y#0
    !           LOADED = 1
    !       %finish
           DEV DATA_NAME = "a Calcomp plotter"
           DEV DATA_DVX = 4000
           DEV DATA_DVY = 2800
           DEV DATA_MVX = 32000
           DEV DATA_MVY = 32000
           DEV DATA_UNITS PER CM = UPC
           X = X - 1000 if 1001 <= X <= 1016  { Treated as Graph-pack numbers ! }
           PLOTTER TYPE (X)
           AREA FLAG ("OFF")
           if VIEWING=0 start
               if X=963 or X=1051 start
                   DEVST = ",.GP23"
               else
                   DEVST = ",T#GP"
               finish
               VIEWING = NON TERMINAL DEFAULT
               OPEN OUTPUT (NON TERMINAL DEFAULT, DEVST)
           finish
           OPEN PLOTTER (VIEWING)
           SX = 0;   SY = 0
           TEXT MODE = FALSE
           return

    SW(1): ! Terminate
           CLOSE PLOTTER
           return

    SW(2): ! Update (ignored for C963 as user can't see it!)
           return

    SW(3): ! New frame
           P SIZE X = (XS-XO)/UPC
           P SIZE Y = (YS-YO)/UPC
           SET PLOT (0, 0, P SIZE X, P SIZE Y, M'CMS')
           SCALE (0, 0, P SIZE X/(XS-XO), P SIZE Y/(YS-YO), 0)
           SX = 0;   SY = 0
           TEXT MODE = FALSE
           NEWFRAMED = TRUE
           -> SW(COM) if COM#3
           return

    SW(4): ! Move Abs
    SW(5): ! Line abs
           -> SW(3) if NEWFRAMED # TRUE
           if COM=5 then COM=IPEN else COM=1
           PLOT (COM, X, Y, DASH, GAP)
           SX = X
           SY = Y
           TEXT MODE = FALSE
           return

    SW(6): ! Character
           -> SW(3) if NEWFRAMED # TRUE
           if TEXT MODE = FALSE start
               ANNOTATE (SX, SY, TCS/3*2, THETA)
               PLOT SYMBOL (ION) if ITALICS = TRUE
               TEXT MODE = TRUE
           finish
           PLOT SYMBOL (X)
           PEN POSITION (PX, PY)
           SX = INT (PX);   SY = INT (PY)
           return

    SW(7): ! Attribute change
           CHANGE ATTRIBUTE (x, y)
           TEXT MODE = FALSE
           return

    SW(8): ! Set lower limits of device window
           XO = X;   YO = Y
           return

    SW(9): ! Set upper limits of device window
           XS = X;   YS = Y
           return

    SW(12): ! Lower box bounds
            WX = X;   WY = Y
            return

    SW(13): ! Upper box bounds
            swap (wx, x) if wx > x
            swap (wy, y) if wy > y
            return if WX > XS or X < XO or WY > YS or Y < YO
            WX = XO if WX < XO
            WY = YO if WY < YO
            X = XS if X > XS
            Y = YS if Y > YS
            ! Box now clipped into the screen.
            Calcomp (4, Wx, Wy)
            Calcomp (5, Wx, y)
            Calcomp (5, x,y)
            Calcomp (5, x, Wy)
            Calcomp (5, Wx, wy)
            return

    SW(*):
    end

    end of file