home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l216 / 1.ddi / GPREDS.PRO < prev    next >
Encoding:
Prolog Source  |  1987-03-23  |  4.4 KB  |  158 lines

  1. /***************************************************************
  2.      Turbo Prolog Toolbox
  3.      (C) Copyright 1987 Borland International.
  4. ***************************************************************/
  5. predicates
  6.   virtual_text(vrow,vcol,row,col)  /* coordinates transformation */
  7.   windowarea(row,col)           /* the dimensions inside a window */
  8.   sign(real,integer)              /* -1 if negative, 0 if zero, 1 if positive*/
  9.  
  10.   screenmode(mode)           /* return PROLOG screen mode */
  11.   DOS_PROLOG(mode,mode)           /* Table of corresponding screen modes */
  12.   getcols(col)
  13.  
  14.  
  15. clauses  
  16.   virtual_text(VirRow,VirCol,R,C):-    /* virtual -> text coordinates */
  17.     bound(VirRow),bound(VirCol),!,
  18. /*    Cols=80,  CAN BE USED INSTED OF getcols TO INCREASE SPEED*/
  19.       getcols(Cols),
  20.       R=VirRow div 1280,
  21.       C=VirCol div (32000 div Cols).
  22.  
  23.   virtual_text(VirRow,VirCol,R,C):-    /* text -> virtual coordinates */
  24.     bound(R),bound(C),
  25. /*    Cols=80,  CAN BE USED INSTED OF getcols TO INCREASE SPEED*/
  26. /*          WHEN IN GRAPHICS MODE 2,4 and 5   ONLY.*/
  27.     getcols(Cols),
  28.       VirRow=R * 1280,
  29.       VirCol=C * (32000 div Cols).
  30.  
  31.   windowarea(Hight,Width):-
  32.       makewindow(_,_,Frame,_,_,_,Rows,Cols),
  33.       sign(Frame,One),
  34.     Hight=Rows-2*One,
  35.     Width=Cols-2*One.
  36.  
  37.   sign(0,0):-!.
  38.   sign(X,1):-X>0,!.
  39.   sign(_,-1):-!.
  40.  
  41.   screenmode(Mode):-
  42.       bios($10,reg($0F00,0,0,0,0,0,0,0),reg(AX,_,_,_,_,_,_,_)),
  43.       DosMode=AX mod 256,
  44.       Dos_Prolog(DosMode,Mode).
  45.  
  46.   DOS_PROLOG(3,0).    /* text mode */
  47.   DOS_PROLOG(4,1).    /* CGA 320 x 200 pixels, 2 colors */
  48.   DOS_PROLOG(6,2).    /* CGA 640 x 200 pixels, 2 colors */
  49.   DOS_PROLOG(11,3).    /* EGA 320 x 200 pixels, 16 colors */
  50.   DOS_PROLOG(12,4).    /* EGA 640 x 200 pixels, 16 colors */
  51.   DOS_PROLOG(13,5).    /* EGA 640 x 350 pixels, 16 colors */
  52.  
  53.   getcols(TotalColsOnScreen):-
  54.       bios($10,reg($0F00,0,0,0,0,0,0,0),reg(AX,_,_,_,_,_,_,_)),
  55.       TotalColsOnScreen=AX div 256.
  56.  
  57.  
  58.   /******************************************************************
  59.  
  60.         format_string(Value,Notation,Field_Width)
  61.  
  62.   where the Value is written using either either d (decimal) notation
  63.   or e (exponential) notation in a field defined by Field_Width.
  64.   Decimal notation is (shown with Field_Width 5):
  65.       
  66.       12345
  67.       12.34
  68.     -1.23
  69.  
  70.   Examples using exponential notation with Field_Width 6:
  71.  
  72.       1.e+5
  73.     -1e-1
  74.  
  75.   Negative numbers need a preceding minus, which takes up space for one
  76.   of the decimal digits. When numbers in decimal notation can not fit
  77.   the specified field width, the number is written using exponential
  78.   notation.
  79.   *********************************************************************/ 
  80.  
  81. predicates
  82.     format_string(real,symbol,integer,string)
  83.     normalize(real,real,integer)
  84.     rightsubstring(integer,string,string)
  85.     str_tal(string,real)
  86.     signsize(real,integer)
  87.     blanks(integer,string)
  88.  
  89. clauses
  90.     format_string(Val,d,Field_Width,String):-
  91.     normalize(Val,_,Potens),signsize(Val,SS),
  92.     abs(Potens+1) + SS > Field_Width,!,
  93.     format_string(Val,e,Field_Width,String).
  94.  
  95.     format_string(Val,d,Digits,Sres):-
  96.     str_real(S,Val),!,
  97.     rightsubstring(Digits,S,Sres).
  98.  
  99.     format_string(Val,e,Field_Width,Sres):-
  100.     sign(Val,Sign),
  101.     X=abs(Val),
  102.     normalize(X,Xn,Exponent),
  103.     X1=Sign*Xn,
  104.     str_tal(S,X1),
  105.     str_int(EString,Exponent),
  106.     str_len(Estring,ESize),
  107.     FirstWidth=Field_Width-Esize-1,
  108.     rightsubstring(FirstWidth,S,Sf),
  109.     concat(Sf,"e",Se),
  110.     concat(Se,Estring,Sres),!.
  111.  
  112.  
  113.     str_tal(S1,X):-
  114.     str_int(S,X),!,
  115.     concat(S,".0000",S1).
  116.     str_tal(S,X):-
  117.         str_real(S,X).
  118.  
  119.  
  120.     normalize(0,0.0,0):-!.
  121.     normalize(X,X,0):-
  122.         1.0 <= X,  X < 10,!.
  123.     normalize(X,Y,N):-
  124.         X >= 10,!,  X1=X/10, normalize(X1,Y,N1), N=N1+1.
  125.     normalize(X,Y,N):-
  126.         X < 0,!,  X1=abs(X), normalize(X1,Y,N).
  127.     normalize(X,Y,N):-
  128.         X < 1,!,  X1=X*10, normalize(X1,Y,N1), N=N1-1.
  129.  
  130.      signsize(X,1):-X<0,!.
  131.      signsize(_,0).
  132.  
  133.      rightsubstring(NoOfChars,Si,So):-
  134.          str_len(Si,L),
  135.          L<NoOfChars,!,
  136.          PreceedingBlanks=NoOfChars-L,
  137.          blanks(PreceedingBlanks,B),concat(B,Si,So).
  138.      rightsubstring(NoOfChars,Si,So):-
  139.         frontstr(NoOfChars,Si,So,_).
  140.      
  141.      blanks(1," "):-!.
  142.      blanks(N,S):-
  143.          N1=N-1,blanks(N1,S1),concat(" ",S1,S).
  144.  
  145.  
  146. predicates
  147.     gwrite(row,col,string,color,integer)
  148. clauses
  149.     gwrite(R,C,S,Color,0):-
  150.         
  151.         cursor(R,C),attribute(Color),write(S).
  152.     gwrite(_,_,"",_,1):-!.
  153.     gwrite(R,C,S,Color,1):-
  154.         cursor(R,C),attribute(Color),
  155.         frontchar(S,Ch,S1),write(Ch),
  156.         R1=R+1,
  157.         gwrite(R1,C,S1,Color,1).
  158.