    ! 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 PLOTS (integer name ISF, INDEX, LDEV)
    dynamic routine spec PLOT (real name X, Y, integer name IPEN)
    dynamic routine spec NEW PEN (integer name PEN)
    !%dynamic %routine %spec SYMBOL ()

    external routine CALCOMP alias "EDWIN___L" (integer COM, X, Y)
       own integer LOADED = 0, WX, WY
       const integer TRUE = 1, FALSE = 0
       ! 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 = 200
       long real P SIZE X, P SIZE Y
       real RX, RY
       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
           NEW 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 ! }
           SX = 0;   SY = 0
           TEXT MODE = FALSE
           COM = 5
           PLOTS (SX, SY, COM)
           return

    SW(1): ! Terminate
           COM = 999
           PLOT (RX, RY, COM)
           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
           RX = XS*UPC;   RY = 0;   COM=-3
           PLOT (RX, RY, COM)
           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=2 else COM=3
           RX = X;   RY = Y
           PLOT (RX, RY, COM)
           SX = X
           SY = Y
           TEXT MODE = FALSE
           return

    SW(6): ! Character
           signal 14, 14

    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