! Optional additional character generators

! GIMMS font interpretation for EDWIN on the APM

%routine DRAW CHAR (%integer CHAR, FONT, SIZE, ROT)
   %const %integer font stream = 3
   %const %integer font header = 32
   %own %integer %array FONT START (1:127) = -1 (*)
   %own %short   %array SCALES     (1:127) = 0 (*)
   %own %short   %array CHAR START (0:127) = 0 (*)
   %own %integer LAST = 0, CURRENT FONT = 0, SCALE, OLD STREAM

   %routine get fonts to (%integer to)
      ! Fill in FONT START from LAST to TO, and set CHAR START for TO
      %string (255) name
      %short LB, HB
      %integer I, S, N, THIS BYTE

      %routine get (%integer %name N)
         %integer I, S
         n = 0
         read symbol (s) %and N = N << 8 ! S %for I = 1, 1, 4
      %end

      %if font start (to) < 0 %start
          ! Fill FONT START in
          %if LAST=0 %start { No fonts read yet }
              open input (font stream, "DOC:GIMMS.BIN")
              this byte = 0
          %else
              %signal 14, 6 %if LAST > to %or to>64
              this byte = font start (last)
          %finish
          select input (font stream)
          %cycle
             set input (this byte)
             name = ""
             get (n)
             select input (old stream) %and %return %if n=0
             %for I = 1, 1, 24 %cycle
                  read symbol (s)
                  %if I=7 %start
                      last = (S-'0')*10 + NEXT SYMBOL - '0'
                      font start (last) = this byte
                  %finish
                  name = name.to string (s) %if I<=12
             %repeat
             read symbol (s)
             scale = S<<8!NEXT SYMBOL
             scales (last) = scale
             read symbol (s) %for I = 1, 1, 3
!Print string ("Font".ItoS(last,2)." ".name." @ ".ItoS(FontStart(last),5).SNL)
!Print string ("Scale = ".ItoS(scale,0)); newline
             %exit %if last=to
             this byte = this byte + n
             %signal 14, 6 %if last > to
          %repeat
      %finish
!print string ("Font ".ItoS(to,0)." Found".SNL)
      %if current font # to %start
          ! Fill in CHAR START for font TO
          select input (font stream)
          set input (font start (to) + font header)
          %for I = 0, 1, 127 %cycle
               read symbol (hb)
               read symbol (lb)
               char start (I) = hb<<8 ! lb
          %repeat
          current font = to
          scale = scales (current font)
      %finish
!print string ("Start values - ")
!%for I = 0, 1, 127 %cycle
!     %if I&7=0 %then newline %else spaces (3)
!     %if i<127 %start
!         %if i<32 %then write (i,-2) %else print string (" ".tostring(I))
!     %finish %else spaces (2)
!     write (char start (i), 4)
!%repeat
!newline
   %end

   %routine Do Character (%integer CHAR)
      %byte Pen Up, Last Point
      %short XBias, Xmax, Ybias, Ymax
      %integer IX, IY
      %real CX, CY, X, Y, Z, SinR, CosR
      Inquire Position (IX, IY)
      CX = IX;   CY = IY
      %if ROT # 0 %start
          SinR = Sin (ROT/DtoR)
          CosR = Cos (ROT/DtoR)
      %finish
      Select input (font stream)
      set input (font start (current font) + font header + char start (char))
      Read Symbol (Xbias);   Read Symbol (XMax)
      Read Symbol (YBias);   Read Symbol (YMax)
      select input (old stream) %and %return %if Xbias = Xmax
      %cycle
         Read Symbol (IX);   X = ix&127;   Pen Up = ix & 128
         Read Symbol (IY);   Y = iy&127;   Last Point = iy & 128
         X = int (X * SIZE * SCALE / 6000)
         Y = int ((Y - ybias) * SIZE * SCALE / 6000)
         Z = X*CosR - Y*SinR %and Y = X*SinR + Y*CosR %and X=Z %if ROT#0
         IX = Int (CX + X);   IY = Int (CY + Y)
         %if Pen Up#0 %then Move abs (ix, iy) %else Line abs (ix, iy)
      %repeat %until Last Point#0
   %end

   %return %unless 1<=CHAR<=127
   %return %if (Char=95 %and Font<60) %or (Font=63 %and 16<=CHAR<32)
   %signal 14, 6 %unless 1<=FONT<=64
   %if CHAR = ' ' %start
       %if ROT=0 %then MOVE REL (SIZE, 0) %else %start
           MOVE REL (int(SIZE*Cos(Rot/DtoR)), int(SIZE*Sin(Rot/DtoR)))
       %finish
       %return
   %finish
   old stream = in stream
   get fonts to (FONT) %if Font # Current Font
   do character (CHAR) %if Char Start (CHAR)#0
   Select input (old stream)
%end

! PDF of software characters and marker deffinitions.
%end %of %list
%const %short %integer %array CHAR PDF (1:2000) = %c
    19,     0,    12,    20,   253,    19,   256,    19,   514,    19,
     2,    19,  -510,    19,  -512,    19,  -258,    19,   254,    19,
   766,    19,   256,    20,     3,    12,    20,  -515,    19,     6,
    19,  1536,    19,   250,    19, -1536,    20,   771,    12,    20,
     3,    19,  -518,    19,  1536,    19,  -762,    20,   253,    12,
    20,   771,    19, -1286,    20,     6,    19,  1786,    20,  -765,
    12,    20,     3,    19,   250,    20,  -765,    19,  1536,    20,
  -515,    19,   256,    19,   514,    19,     2,    19,  -510,    19,
  -512,    19,  -258,    19,   254,    19,   766,    19,   256,    20,
     3,    12,    20,     3,    19,   250,    20,  -765,    19,  1536,
    20,  -768,    12,    20, -1536,    19,  1536,    19,  -510,    20,
   252,    19,   514,    12,    20,  1536,    19, -1536,    19,   514,
    20,   252,    19,  -510,    12,    20,   250,    19,     6,    19,
   766,    20, -1024,    19,   514,    12,    20,     6,    19,   250,
    19,   514,    20, -1024,    19,   766,    12,    20,  3072,    12,
    20,  1794,    19,  -512,    19,   254,    19,   512,    19,     2,
    20,     2,    19,  -512,    19,     9,    19,   512,    19,   247,
    20,  1532,    12,    20,  1290,    19,  -256,    19,     3,    19,
   256,    19,   253,    20,   768,    19,  -256,    19,     3,    19,
   256,    19,   253,    20,  1270,    12,    20,   516,    19,  2048,
    20,  -260,    19,    13,    20,   764,    19, -2048,    20,   516,
    19,   243,    20,  2048,    12,    20,   770,    19,   511,    19,
  1024,    19,   257,    19,     2,    19, -1531,    19,     2,    19,
   257,    19,  1024,    19,   511,    20,  -766,    19,   243,    20,
  1536,    12,    20,   512,    19,  2061,    20, -1536,    19,  -512,
    19,   254,    19,   512,    19,     2,    20,  1781,    19,  -512,
    19,   254,    19,   512,    19,     2,    20,   766,    12,    20,
  2562,    19,  -258,    19, -1024,    19,  -510,    19,     2,    19,
  1286,    19,     2,    19,  -255,    19,  -512,    19,    -1,    19,
   254,    19,  2038,    20,   512,    12,    20,  1546,    19,  -256,
    19,     3,    19,   256,    19,   253,    20,  1782,    12,    20,
  2061,    19,  -512,    19,  -260,    19,   251,    19,   764,    19,
   512,    20,  1024,    12,    20,  1037,    19,   512,    19,   764,
    19,   251,    19,  -260,    19,  -512,    20,  2048,    12,    20,
  2306,    19, -1528,    20,  1536,    19, -1288,    20,  -252,    19,
  2048,    20,   762,    12,    20,  1538,    19,     8,    20,  -772,
    19,  2048,    20,   762,    12,    20,  2048,    19,     2,    19,
  -512,    19,   254,    19,   512,    19,  -258,    20,  1538,    12,
    20,   518,    19,  2048,    20,   762,    12,    20,  1536,    19,
     2,    19,   512,    19,   254,    19,  -512,    20,  1536,    12,
    20,   512,    19,  2061,    20,   755,    12,    20,   512,    19,
  2061,    20,   254,    19,   247,    19,  -258,    19, -1024,    19,
  -510,    19,     9,    19,   514,    19,  1024,    19,   766,    20,
   757,    12,    20,  1035,    19,   514,    19,   243,    20,  -512,
    19,  1024,    20,  1024,    12,    20,   523,    19,   514,    19,
  1024,    19,   766,    19,   254,    19, -1800,    19,   255,    19,
  2048,    20,   512,    12,    20,   525,    19,  2048,    19,   255,
    19,  -772,    19,   512,    19,   766,    19,   252,    19,  -258,
    19, -1024,    19,  -510,    20,  2814,    12,    20,  2048,    19,
    13,    19, -1290,    19,  2048,    20,   765,    12,    20,   514,
    19,   766,    19,  1024,    19,   514,    19,     4,    19,  -510,
    19, -1536,    19,     5,    19,  2048,    20,   755,    12,    20,
   518,    19,   514,    19,  1024,    19,   766,    19,   252,    19,
  -258,    19, -1024,    19,  -510,    19,     9,    19,   514,    19,
  1024,    19,   766,    20,   757,    12,    20,   525,    19,  2048,
    19, -1805,    20,  2560,    12,    20,  1031,    19,  -510,    19,
     2,    19,   514,    19,  1024,    19,   766,    19,   254,    19,
  -258,    19, -1024,    19,  -258,    19,   253,    19,   766,    19,
  1024,    19,   514,    19,     3,    19,  -510,    20,  1273,    12,
    20,   514,    19,   766,    19,  1024,    19,   514,    19,     9,
    19,  -510,    19, -1024,    19,  -258,    19,   253,    19,   766,
    19,  1024,    19,   514,    20,   760,    12,    20,  1542,    19,
     2,    19,   512,    19,   254,    19,  -512,    20,   764,    19,
  -512,    19,     2,    19,   512,    19,   254,    20,  1278,    12,
    20,  1542,    19,     2,    19,   512,    19,   254,    19,  -512,
    20,   250,    19,   514,    19,     2,    19,  -512,    19,   254,
    19,   512,    20,  1278,    12,    20,  2572,    19, -1798,    19,
  2298,    20,   512,    12,    20,  2568,    19, -2048,    20,   252,
    19,  2048,    20,   764,    12,    20,   524,    19,  2298,    19,
 -1798,    20,  2560,    12,    20,   779,    19,   514,    19,   512,
    19,   766,    19,   254,    19,  -515,    19,   254,    20,   508,
    19,  -512,    19,     2,    19,   512,    19,   254,    20,  1280,
    12,    20,  2560,    19, -1536,    19,  -510,    19,     9,    19,
   514,    19,  1024,    19,   766,    19,   249,    19,  -258,    19,
  -512,    19,  -510,    19,     3,    19,   514,    19,   512,    19,
   766,    20,   761,    12,    20,   519,    19,  2048,    20, -1799,
    19,    11,    19,   514,    19,  1024,    19,   766,    19,   245,
    20,   512,    12,    20,   512,    19,    13,    19,  1536,    19,
   766,    19,   254,    19,  -258,    19, -1536,    20,  1536,    19,
   766,    19,   253,    19,  -258,    19, -1536,    20,  2560,    12,
    20,  2571,    19,  -510,    19, -1024,    19,  -258,    19,   247,
    19,   766,    19,  1024,    19,   514,    20,   766,    12,    20,
  2048,    19, -1536,    19,    13,    19,  1536,    19,   766,    19,
   247,    19,  -258,    20,  1024,    12,    20,   519,    19,  1536,
    20,   518,    19, -2048,    19,   243,    19,  2048,    20,   512,
    12,    20,   512,    19,    13,    19,  2048,    20, -1798,    19,
  1536,    20,  1273,    12,    20,  2571,    19,  -510,    19, -1024,
    19,  -258,    19,   247,    19,   766,    19,  1024,    19,   514,
    19,     4,    19,  -512,    20,  1274,    12,    20,   512,    19,
    13,    20,  2298,    19, -2048,    20,  2054,    19,   243,    20,
   512,    12,    20,  1037,    19,  1024,    20,  -269,    19,    13,
    20,  -269,    19,  1024,    20,  1024,    12,    20,   514,    19,
   766,    19,  1024,    19,   514,    19,    11,    19,  -768,    20,
  1523,    12,    20,   512,    19,    13,    20,  2048,    19, -1798,
    19,  2297,    20,   512,    12,    20,   525,    19,   243,    19,
  2048,    20,   512,    12,    20,   512,    19,    13,    19,  1275,
    19,  1029,    19,   243,    20,   512,    12,    20,   512,    19,
    13,    19,  2291,    19,    13,    20,   755,    12,    20,  2048,
    19, -1024,    19,  -510,    19,     9,    19,   514,    19,  1024,
    19,   766,    19,   247,    19,  -258,    20,  1024,    12,    20,
   512,    19,    13,    19,  1536,    19,   766,    19,   254,    19,
  -258,    19, -1536,    20,  2809,    12,    20,  2048,    19, -1024,
    19,  -510,    19,     9,    19,   514,    19,  1024,    19,   766,
    19,   247,    19,  -258,    20,  -508,    19,  1276,    20,   512,
    12,    20,   512,    19,    13,    19,  1536,    19,   766,    19,
   254,    19,  -258,    19, -1536,    20,  1024,    19,  1273,    20,
   512,    12,    20,   514,    19,   766,    19,  1024,    19,   514,
    19,     3,    19,  -510,    19, -1024,    19,  -510,    19,     2,
    19,   514,    19,  1024,    19,   766,    20,   757,    12,    20,
  1536,    19,    13,    20, -1024,    19,  2048,    20,   755,    12,
    20,   525,    19,   245,    19,   766,    19,  1024,    19,   514,
    19,    11,    20,   755,    12,    20,   525,    19,  1267,    19,
  1037,    20,   755,    12,    20,   525,    19,   249,    19,   762,
    19,   518,    19,   762,    19,   518,    19,     7,    20,   755,
    12,    20,   512,    19,  2061,    20, -2048,    19,  2291,    20,
   512,    12,    20,  1536,    19,     7,    19, -1018,    20,  2048,
    19,  -774,    20,  1785,    12,    20,   525,    19,  2048,    19,
 -1805,    19,  2048,    20,   512,    12,    20,  2061,    19, -1024,
    19,   243,    19,  1024,    20,  1024,    12,    20,   525,    19,
  2291,    20,   512,    12,    20,  1037,    19,  1024,    19,   243,
    19, -1024,    20,  2048,    12,    20,   778,    19,   771,    19,
  1021,    20,  1014,    12,    20,   251,    19,  3072,    20,     5,
    12,    20,  2058,    19,  -765,    19,  -256,    19,  1021,    19,
   256,    20,  1270,    12,    20,  2562,    19,  -258,    19, -1024,
    19,  -510,    19,     3,    19,   514,    19,  1024,    19,   766,
    20,     2,    19,   249,    20,   512,    12,    20,   525,    19,
   243,    19,  1536,    19,   514,    19,     3,    19,  -510,    19,
 -1536,    20,  2809,    12,    20,  2565,    19,  -510,    19, -1024,
    19,  -258,    19,   253,    19,   766,    19,  1024,    19,   514,
    20,   766,    12,    20,  2562,    19,  -258,    19, -1024,    19,
  -510,    19,     3,    19,   514,    19,  1024,    19,   766,    20,
     8,    19,   243,    20,   512,    12,    20,   516,    19,  2048,
    19,     1,    19,  -510,    19, -1024,    19,  -258,    19,   253,
    19,   766,    19,  1024,    19,   514,    20,   766,    12,    20,
   768,    19,    11,    19,   514,    19,   512,    19,   766,    20,
 -1284,    19,   768,    20,  1785,    12,    20,   766,    19,   766,
    19,  1024,    19,   514,    19,     7,    19,  -510,    19, -1024,
    19,  -258,    19,   253,    19,   766,    19,  1024,    19,   514,
    20,   766,    12,    20,   512,    19,    13,    20,   248,    19,
   514,    19,  1024,    19,   766,    19,   251,    20,   512,    12,
    20,  1034,    19,     0,    20,   254,    19,   250,    19,   766,
    19,   512,    20,  1024,    12,    20,   766,    19,   766,    19,
  1024,    19,   514,    19,    10,    20,     2,    19,     0,    20,
   758,    12,    20,   512,    19,    13,    20,  1786,    19, -1283,
    19,  2300,    20,   512,    12,    20,  1037,    19,   245,    19,
   766,    19,   512,    20,  1024,    12,    20,  2560,    19,     5,
    19,  -510,    19,  -258,    19,  -510,    19,  -258,    20,     2,
    19,   249,    20,  1029,    19,   251,    20,  1536,    12,    20,
   512,    19,     7,    20,   254,    19,   514,    19,  1024,    19,
   766,    19,   251,    20,   512,    12,    20,  2562,    19,     3,
    19,  -510,    19, -1024,    19,  -258,    19,   253,    19,   766,
    19,  1024,    19,   514,    20,   766,    12,    20,   764,    19,
    11,    20,   254,    19,   514,    19,  1024,    19,   766,    19,
   253,    19,  -258,    19, -1024,    19,  -510,    20,  2814,    12,
    20,  2562,    19,  -258,    19, -1024,    19,  -510,    19,     3,
    19,   514,    19,  1024,    19,   766,    20,     2,    19,   245,
    20,   516,    12,    20,   512,    19,     7,    20,   254,    19,
   514,    19,  1024,    19,   766,    20,   763,    12,    20,   514,
    19,   766,    19,  1024,    19,   514,    19,     2,    19, -2048,
    19,     1,    19,   514,    19,  1024,    19,   767,    20,   762,
    12,    20,   778,    19,  1024,    20,  -509,    19,   245,    19,
   766,    19,   512,    20,   768,    12,    20,   519,    19,   251,
    19,   766,    19,  1024,    19,   514,    20,     5,    19,   249,
    20,   512,    12,    20,   519,    19,  1273,    19,  1031,    20,
   761,    12,    20,   519,    19,   251,    19,   766,    19,   514,
    20,     2,    19,   254,    19,   766,    19,   514,    19,     5,
    20,   761,    12,    20,   512,    19,  2055,    20, -2048,    19,
  2297,    20,   512,    12,    20,   766,    19,   766,    19,  1024,
    19,   514,    19,     9,    20, -2048,    19,   251,    19,   766,
    19,  1024,    19,   514,    20,   766,    12,    20,   519,    19,
  2048,    19, -1799,    19,  2048,    20,   512,    12,    20,  2317,
    19,  -512,    19,  -258,    19,   252,    19,  -257,    19,   767,
    19,   253,    19,   766,    19,   512,    20,   768,    12,    20,
  1549,    19,   250,    20,   255,    19,   250,    20,  1536,    12,
    20,   781,    19,   512,    19,   766,    19,   252,    19,   767,
    19,  -257,    19,   253,    19,  -258,    19,  -512,    20,  2304,
    12,    20,   523,    19,   258,    19,   256,    19,  1278,    19,
   256,    19,   258,    20,   755,    12,    12,     0,     0,     0,
     0,     0,     0,     0,     0,     0,   127,  1777,   126,  1762,
   125,  1741,   124,  1730,   123,  1709,   122,  1698,   121,  1675,
   120,  1664,   119,  1643,   118,  1634,   117,  1617,   116,  1602,
   115,  1579,   114,  1564,   113,  1541,   112,  1518,   111,  1497,
   110,  1480,   109,  1457,   108,  1446,   107,  1433,   106,  1416,
   105,  1401,   104,  1384,   103,  1357,   102,  1340,   101,  1317,
   100,  1294,    99,  1275,    98,  1258,    97,  1235,    96,  1222,
    95,  1215,    94,  1206,    93,  1195,    92,  1188,    91,  1177,
    90,  1166,    89,  1153,    88,  1142,    87,  1125,    86,  1116,
    85,  1101,    84,  1090,    83,  1063,    82,  1042,    81,  1017,
    80,  1000,    79,   979,    78,   968,    77,   955,    76,   946,
    75,   933,    74,   918,    73,   903,    72,   888,    71,   865,
    70,   852,    69,   837,    68,   820,    67,   801,    66,   774,
    65,   755,    64,   722,    63,   695,    62,   686,    61,   675,
    60,   666,    59,   641,    58,   618,    57,   591,    56,   556,
    55,   547,    54,   520,    53,   499,    52,   488,    51,   465,
    50,   446,    49,   433,    48,   408,    47,   401,    46,   388,
    45,   381,    44,   366,    43,   355,    42,   340,    41,   325,
    40,   310,    39,   297,    38,   270,    37,   243,    36,   216,
    35,   197,    34,   174,    33,   151,    32,   148,    10,   137,
     9,   126,     8,   115,     7,   104,     6,    93,     5,    62,
     4,    51,     3,    40,     2,    27,     1,     4,     0,     1

%end %of %file
