home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / perqb / pq2utd.pas < prev    next >
Pascal/Delphi Source File  |  2020-01-01  |  8KB  |  280 lines

  1. {#E} Module UtilDefs;
  2.  
  3. { This module must be imported after Screen and Perq_ScreenNEW. }
  4.  
  5.  
  6. {=============================================================================}
  7. EXPORTS
  8. {=============================================================================}
  9.  
  10.  
  11. CONST
  12.           WordLength = 16;  {****** RPrqWrdL;}
  13.          WordLenMin1 = WordLength-1;
  14.         QuadWordSize = 4;
  15.       MaxFontDefGrid = 100; {Standard Char-set uses only 26 grid lines.    }
  16.         FontHeadSize = 260; {Size of Height, Base, Index and Filler fields.}
  17.                 XMax = 767;
  18.                 YMax = 1023; 
  19.                   Pi = 3.141592654;
  20.  
  21.  
  22. TYPE
  23.        Posint = 0..MaxInt;  {****** RPosInt;}
  24.          Byte = 0..255;
  25.       HexByte = 0..15;         
  26.    BitnoRange = 0..WordLenMin1;         
  27.          Bits = PACKED ARRAY[BitnoRange] OF Boolean;
  28.        XRange = 0..XMax;    {****** RXPqScr;}
  29.        YRange = 0..YMax;    {****** RYPqScr;}
  30.    
  31.         Point = RECORD
  32.                   X: INTEGER;
  33.                   Y: INTEGER;
  34.                 END; 
  35.                 
  36.         ULine = RECORD
  37.                   P1,P2: Point;
  38.                 END; 
  39.                 
  40.       BoxSize = RECORD
  41.                   Width:  XRange;
  42.                   Height: YRange;
  43.                 END;
  44.                  
  45.           Box = RECORD
  46.                   LowPos: Point;
  47.                   Size:   BoxSize;
  48.                 END; 
  49.                 
  50.        Circle = RECORD
  51.                   Origo:  Point;
  52.                   Radius: Posint;
  53.                 END; 
  54.                 
  55.         Arrow = RECORD
  56.                   L:         ULine;
  57.                   EdgeSize:  Posint;
  58.                   EdgeAngle: Real;
  59.                 END; 
  60.                 
  61.    NewFontPtr = ^NewFont;
  62.       NewFont = {PACKED} RECORD
  63.                   Height: Posint;            {Vertical Y-size.                }
  64.                   Base:   Posint;            {Y-pos of Baseline, from top.    }
  65.                   Index:  ARRAY[0..#177] OF  {Table of 128 Char-entries,      }
  66.                                              {??????indexed by Char?          }
  67.                           PACKED RECORD CASE Boolean OF
  68.                            true:
  69.                             (Offset: XRange; {Starting X-position.            }
  70.                              Line:   0..63;  {Line*Height = starting Y-pos.   }
  71.                              Width:  Posint);{Horisontal X-size.              }
  72.                            false:
  73.                             (Loc:    Posint; {Loc = 768*Y+X,                  }
  74.                              Widd:   Posint) {i.e. absolute positioning?      }
  75.                           END;
  76.                   Filler: ARRAY[0..1] OF Integer;
  77.                                              {Needed for Pat-array to start on}
  78.                                              {a quadword: 1+1+2*128+2 = 260.  }
  79.                   Pat:    PACKED ARRAY[0..MaxFontDefGrid-1,XRange] OF Boolean;
  80.                                              {See notes below!                }
  81.                 END;
  82.                 
  83.                 
  84.        { @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  85.                                                                   
  86.         The first index-set of the Pas-array is Char-set specific, i.e.
  87.             [0..NScanLines-1, --]
  88.         where
  89.             NScanLines = Round( 128 / (768 DIV Average_Width) ) * Height .
  90.           
  91.         Ex. Standard Char-set:
  92.             Width (for all chars) = 9, Height = 13.
  93.             NScanLines = Round( 128 / 85 ) * 13 = 2 * 13 = 26.
  94.             I.e. this font definition occupies: 260 + 26*48 = 1508 words. 
  95.        
  96.         Given a FontPtr, FP.
  97.         Then the bit pattern for the i'th character is (logically):
  98.                    
  99.             FP^.Pat [Yline*YHeight .. Yline*YHeight + YHeight - 1,
  100.                      XOffset       .. XOffset       + XWidth  - 1]
  101.           
  102.         where
  103.             YHeight:=FP^.Height;
  104.             XWidth :=FP^.Width[i];
  105.             XOffset:=FP^.Offset[i];
  106.              YLine :=FP^.Line[i];
  107.              
  108.         Note that PACKED Booleans in PERQ-PASCAL are numbered inversely within
  109.         a word, so that the second x-index must be computed as:
  110.               off:=x MOD 16; newx:=x + (15-off) - off;
  111.         "$Range-" must be used when indexing a full-size screen,
  112.         because of Y-index overflow. 
  113.                
  114.         Also note, that FP as a RasterOp-parm must be "adjusted" by 260, or
  115.         alternatively the Source_X_Position must be increased by 260*WordLength
  116.         (which may cause this value to exceed 767).
  117.         
  118.         @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ }
  119.    
  120.                                                
  121. VAR dummmmmmmmy: Boolean; 
  122.  
  123.  
  124. FUNCTION FLIP16(I: Posint):Posint;
  125.  
  126. PROCEDURE WRITEBITS(w:Integer);
  127.  
  128. FUNCTION MAX(i,j: Integer):Integer;
  129. FUNCTION MIN(i,j: Integer):Integer;
  130.  
  131. FUNCTION Inside_Range(i,Low,High: Integer):Boolean;
  132. FUNCTION Adjust_Range(i,Low,High: Integer):Integer;
  133.  
  134. FUNCTION Int_To_String(Int : Integer):String;
  135. FUNCTION String_To_Int(Str : String) :Integer;
  136.  
  137.  
  138. {#P}
  139. {=============================================================================}
  140. PRIVATE
  141. {=============================================================================}
  142. {#E}IMPORTS  Perq_String  FROM  Perq_String;
  143.  
  144.  
  145. {#E}FUNCTION FLIP16(I: Posint):Posint;
  146. BEGIN 
  147.    {Turn 4 least significant bits around 15. Let I = yyyxxxx, bitwise.}
  148.    {Note FLIP16(FLIP16(I)) = I.                                       }
  149.    
  150.    {$Range-}
  151.  { FLIP16  := yyy0000             + WordLenMin1 - xxxx;               }
  152.    FLIP16  := LAND(I,-WordLength) + WordLenMin1 - LAND(I,WordLenMin1);
  153.    {$Range=}
  154. END; {FLIP16-function}
  155.  
  156.  
  157. {#E}PROCEDURE WRITEBITS(w:Integer);
  158.    VAR
  159.        Bitno: BitnoRange;
  160.        Bw:    Bits;
  161. BEGIN
  162.    Bw:=RECAST(w,Bits);
  163.    
  164.    FOR Bitno:=WordLenMin1 DOWNTO 0 DO
  165.      WRITE( RECAST(Bw[Bitno],Integer) : 1);
  166.  
  167.  
  168.  { WRITE(w : WordLength : 2);           Don't work to write 16 binary digits.}
  169. END; {WRITEBITS-procedure}
  170.  
  171.  
  172. {#P}
  173. {#E}FUNCTION MAX(i,j: Integer):Integer;
  174. BEGIN
  175.    IF i > j THEN MAX:=i ELSE MAX:=j; 
  176. END; {MAX-function}
  177.  
  178.  
  179. {#E}FUNCTION MIN(i,j: Integer):Integer;
  180. BEGIN
  181.    IF i < j THEN MIN:=i ELSE MIN:=j; 
  182. END; {MIN-function}
  183.  
  184.  
  185. {#E}FUNCTION Inside_Range(i,Low,High: Integer):Boolean;
  186. VAR t: INTEGER;
  187. BEGIN  
  188.    IF Low > High THEN
  189.    BEGIN
  190.       t:= Low; Low:= High; High:= t;
  191.    END;
  192.    Inside_Range := (i >= Low) and (i <= High);
  193. END; {Inside_Range-function}
  194.  
  195.  
  196. {#E}FUNCTION Adjust_Range(i,Low,High: Integer):Integer;
  197. BEGIN
  198.    Adjust_Range := MIN(High, MAX(Low, i));
  199. END; {Adjust_Range-function}
  200.  
  201.  
  202. {#P}
  203. {#E}FUNCTION Int_To_String{#D} ( Int : Integer ) :String;
  204.  
  205. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  206. {@                                          @}
  207. {@          Int must be : (0,32767)         @}
  208. {@                                          @}
  209. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  210.  
  211.    VAR   Digit,Start : Integer;
  212.          Power,First : Integer;
  213.        Str           : String[5];
  214.        
  215. BEGIN
  216.       First :=Length(Str)+1;
  217.       
  218.       REPEAT
  219.       
  220.         IF int > 9999 THEN BEGIN start:=1; Power:=10000; END
  221.         ELSE
  222.         IF int >  999 THEN BEGIN start:=2; Power:=1000; END
  223.         ELSE
  224.         IF int >   99 THEN BEGIN start:=3; Power:=100; END
  225.         ELSE
  226.         IF int >    9 THEN BEGIN start:=4; Power:=10; END
  227.         ELSE               BEGIN start:=5; Power:=1; END;
  228.      
  229.         digit := int DIV Power;
  230.           int := int - Power*digit;
  231.    
  232.         First := MIN(First,start);
  233.         
  234.         Str[start]:= CHR(digit+ORD('0'));
  235.       
  236.       UNTIL ( int = 0 );
  237.       
  238.       Int_to_String := SubStr(Str, First, Length(Str)+1-First);
  239.       
  240. END; {Int_to_String-function}
  241.  
  242.  
  243. {#E}FUNCTION String_To_Int{#D} ( Str : String )  : Integer;
  244.  
  245.    VAR i,Int : integer;
  246.  
  247. BEGIN
  248.    Int := 0;
  249.    
  250.    FOR i:= 1 TO LENGTH(Str) DO
  251.       IF NOT (Str[i] IN ['0'..'9'] ) THEN 
  252.      {   ERROR('Not digit','String_To_Int')   }
  253.          WRITELN('Not digit in ', Str, ' in PROC String_To_Int')
  254.       ELSE
  255.          Int := ORD(str[i]) - ORD('0') + 10*Int;
  256.          
  257.    String_To_Int := Int;
  258. END; {String_to_Int-function}
  259.  
  260.  
  261. {#P}
  262. {#E}FUNCTION Scale_Point{#D} (P:Point; S: Real) : Point;
  263. BEGIN
  264.    P.X:=Round(P.X*S);
  265.    P.Y:=Round(P.Y*S);
  266.    
  267.    Scale_Point := P;
  268. END; {Scale_Line-function}
  269.  
  270.  
  271. {#E}FUNCTION Scale_Line{#D} (L:ULine ; S: Real) : ULine;
  272. BEGIN
  273.    L.P1:=Scale_Point(L.P1,S);
  274.    L.P2:=Scale_Point(L.P2,S);
  275.    
  276.    Scale_Line := L;
  277. END {Scale_Line-function}
  278. .
  279.          
  280.