! Configuration file for EDWIN on 2900 EMAS - JGH - June 81

%external %integer CLIPPING = 0
%external %integer DEVICE = -1

%const %integer NUM DEV = 13

! DV is default Viewport
%const %integer %array DVX(0:NUM DEV) = 1023, 
   1023, 511, 11200, 4000, 16_7FFF, 773, 71, 119, 131, 79, 719, 40*400, 40*400
%const %integer %array DVY(0:NUM DEV) = 767,
   767, 511, 8000, 2800, 16_7FFF, 779, 63, 63, 63, 23, 359, 28*400, 27*400

! Max Viewport for each device -
%const %integer %array XLIM(0:NUM DEV)=1023,
   4095, 511, 16000, 32000, 16_7FFF, 773, 71, 119, 131, 79, 719, 40*400, 40*400
%const %integer %array YLIM(0:NUM DEV)=767,
   4095, 511, 11400, 32000, 16_7FFF, 779, 63, 63, 63, 23, 359, 28*400, 27*400

! Aspect ratioing factor for each device -
%const %real %array ASPECT FACTOR (0:NUM DEV) = 1,
   1, 1.25, 1, 1, 1, 1.1, 0.5, 0.5, 0.5, 0.45, 1, 1, 1

%integer %fn VIEWPORT GRADIENT (%integer Y, X)
   ! The 5000 factor is to allow for systems which only have integers.
   %real ASR
   %if 0<=DEVICE<=NUM DEV %then ASR=ASPECT FACTOR(DEVICE) %else ASR=1
   %result = INT (5000*Y/(ASR*X))
%end

! General purpose EDWIN device driver
%routine %spec MAP TO VIRTUAL COORDS (%integer %name X, Y)

%dynamic %routine %spec T4000      (%integer COM, X, Y)
%dynamic %routine %spec TCURSOR    (%integer %name STATUS, X, Y)
%dynamic %routine %spec C963       (%integer COM, X, Y)
%dynamic %routine %spec CATS       (%integer COM, X, Y)
%dynamic %routine %spec VCURSOR    (%integer %name STATUS, X, Y)
%dynamic %routine %spec CHAS       (%integer COM, X, Y)
%dynamic %routine %spec CCURSOR    (%integer %name STATUS, X, Y)
%dynamic %routine %spec HPPLOT     (%integer COM, X, Y)
%dynamic %routine %spec PCURSOR    (%integer %name STATUS, X, Y)
!!!%dynamic %routine %spec APPLICON   (%integer COM, X, Y)
%dynamic %routine %spec P300       (%integer COM, X, Y)
%dynamic %routine %spec HP2648A    (%integer COM, X, Y)
%dynamic %routine %spec HCURSOR    (%integer %name STATUS, X, Y)

! The command codes are the folowing -
!   0        TYPE          ?           Initialise for TYPE
!   1           ?          ?           Terminate
!   2           ?          ?           Update 
!   3           ?          ?           New frame action
!   4           X          Y           Move Abs
!   5           X          Y           Line Abs
!   6        CHAR          ?           Output character
!   7       WHICH        VAL           Change attribute WHICH to VAL
!   8          XL         YB           Set lower device window bounds
!   9          XR         YT           Set upper device window bounds
!  10        MODE        VAL           Set Mode (Dev. dep.)
!Rest           ?          ?           Device Specific

%external %routine DRIVE DEV (%integer COM, X, Y)
   %switch SW(0:NUM DEV)

   %if COM=0 %start
       DEVICE = 99
       X = X - 'a' + 'A' %if 'a'<=X<='z'
       DEVICE = -1 %if X=0
       DEVICE = 0 %if 4002<=X<=4099
       DEVICE = 1 %if X=4014
       DEVICE = 2 %if X='C'
       DEVICE = 3 %if X=7221
       DEVICE = 4 %if 563<=X<=1051
!       DEVICE = 5 %if X='A'
       DEVICE = 6 %if X=300
       DEVICE = 7 %if X='H' {72}
       DEVICE = 9 %if X='L'
       DEVICE = 10 %if X=200 %or X=550
       DEVICE = 10 %if X='E' %or X='V' %or X='X' { 120 & 95 }
       DEVICE = 11 %if X=2648
       DEVICE = 12 %if X=7580
       DEVICE = 13 %if X=7220
   %finish
   %return %if DEVICE<0; ! Ignore calls to the null device driver
   DEVICE=-1 %and %signal 14,0 %unless DEVICE<=NUM DEV
   -> SW(DEVICE)

SW(0):
SW(1): T4000 (COM, X, Y);   %return;   ! Tektronix 4000 series storage tubes

SW(2): CHAS (COM, X, Y);    %return;   ! Charles protocol

SW(12):
SW(3): HPPLOT (COM, X, Y);   %return;   ! HP plotter driver

SW(13):
SW(4): C963 (COM, X, Y);    %return;   ! ERCC Graphpack

!!!SW(5): APPLICON (COM, X, Y); %return;  ! Applicon plotter

SW(6): P300 (COM, X, Y);    %return;   ! Printronix 300 printer.

SW(7):
SW(8):
SW(9):
SW(10): CATS (COM, X, Y);   %return;   ! Cursor Addressable Terminal driver

SW(11): HP2648A (COM, X, Y);%return;   ! HP raster scan terminal.
%end

%dynamic %routine D CURSOR (%integer %name STATE, X, Y)
   %switch DC(0:NUM DEV)
   %signal 14,8 %if DEVICE<0 %or DEVICE>NUM DEV
   -> DC(DEVICE)

DC(0):
DC(1): TCURSOR (STATE, X, Y); %return
DC(2): CCURSOR (STATE, X, Y); %return
DC(3): PCURSOR (STATE, X, Y); %return
DC(10): VCURSOR (STATE, X, Y); %return
DC(11): HCURSOR (STATE, X, Y); %return
DC(*):  !!GT!! %signal 14, 8
%end

%dynamic %routine CURSOR (%integer %name STATE, X, Y)
   D CURSOR (STATE, X, Y)
   ! Convert to screen coords.
   MAP TO VIRTUAL COORDS (X, Y)
%end

%external %string (31) %fn DEVICE NAME { %alias "ED$DN"
   %const %string (31) %array NAMES (0:NUM DEV) =         "Tektronix",
    "Tektronix 4014",        "Charles",                   "HP 7221 plotter",
    "Calcomp plotter",       "Applicon plotter",          "Printronix printer",
    "Terminal of width 72",  "Line printer of width 120", "Line printer of width 132", 
    "Cursor Addressable Terminal",   "HP 2648 raster-scan terminal",
    "HP 7580 plotter",   "HP 7220 plotter"

   %result = "null" %unless 0<=DEVICE<=NUM DEV
   %result = NAMES (DEVICE)
%end

%external %string (63) %fn EDWIN ERROR (%integer I)
   %const %integer MAX ERROR = 11
   %const %string (63) %array ERRORS(0:MAX ERROR)= "Initialisation failed - unknown device",
      "Initialisation failed in device driver",
      "Internal error",
      "Undefined" (2),
      "Corrupt PDF", 
      "Unknown attribute change",
      "Internal error in SHAPES",
      "Invalid routine call",
      "Transformation stack not initialised?",
      "Transformation stack overflow",
      "Transformation stack underflow"

   %result = "EDWIN error out of range" %unless 0<=I<=MAX ERROR
   %result =  ERRORS(I)
%end

%external %integer %fn DEFAULT DEVICE
   %external %integer %fn %spec UINFI (%integer W)
   %const %integer MAX DEV = 20
   %const %integer %array DEFS (0:MAX DEV) = 0,     { 0 unspecified }
                                             0,     { 1 Hardcopy, width 72}
                                             0,     { 2 Hardcopy, width 80}
                                             0,     { 3 Hardcopy, width 132}
                                             0,     { 4 Unspecified Video }
                                             0,     { 5 ITT }
                                             550,   { 6 Perkin-Elmer }
                                             0,     { 7 Lynwood }
                                             0,     { 8 Newbury, Pericom }
                                             0,     { 9 Terak, Apple, SuperBrain }
                                             0,     { 10 ADM-3A }
                                             200,   { 11 Visual 200 }
                                             0,     { 12 VT105 }
                                             'E',   { 13 Hazeltine Esprit }
                                             0,     { 14 Hazeltine 1500 }
                                             0,     { ?? }
                                             0,     { ?? }
                                             4010,  { 17 Tektronix 4010 }
                                             0,     { 18 IBM 3101 }
                                             0,     { 19 Dacoll 242E }
                                             0      { 20 Volker Craig 404 }
   %integer D

   D = UINFI (23)
   %result = 0 %unless 0<=D<=MAX DEV
   %result = DEFS(D)
%end

%end %of %file

