home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SCROLL.SWG / 0001_Smooth Scrolling Text-Source.pas
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  5.0 KB  |  219 lines

  1. { ------------------------------------- }
  2. { Why does it flicker, when I scroll ?? }
  3. { ------------------------------------- }
  4.  
  5.  
  6. { Please excuse of posting a source, but I think it is easier to }
  7. { understand my source than understanding my english             }
  8.  
  9. { ------------------------------ CUT HERE ---------------------------------}
  10.  
  11. {   Scroll Up and Down with "."and ";"  }
  12.  
  13. {   Most routines are nod made by me ..   }
  14. {   I got them from SWAG i think          }
  15.  
  16. { Nearly no documentation :) }
  17.  
  18. uses crt;
  19.  
  20. const rows=200;    { Should be greater than 25, do see the problem }
  21.  
  22. var i     : integer;
  23.     qc    : char;
  24.     qs    : byte;
  25.     Start : pointer absolute $b800:0;        { Eine Zeile VOR dem sichtbaren
  26.     Bereich }
  27.     Blick : pointer absolute $b800:160;      { Sichtbarer Bereich }
  28.     txt   : array[1..rows] of string[80];
  29.  
  30.  
  31. procedure vretrace; assembler; { vertical retrace }
  32. asm
  33.   mov dx,3dah
  34.  @vert1:
  35.   in al,dx
  36.   test al,8
  37.   jz @vert1
  38.  @vert2:
  39.   in al,dx
  40.   test al,8
  41.   jnz @vert2
  42. end;
  43.  
  44. procedure VFine(y:byte);assembler;
  45. asm
  46.     mov  dx,03d4h
  47.     mov  ah,Y
  48.     mov  al,8
  49.     out  dx,ax
  50. end;
  51.  
  52. { Not needed by me...  perhaps you'll need that }
  53. {
  54. procedure scroff(soffset:integer);assembler;
  55. asm
  56.   cli
  57.   mov dx,03d4h
  58.   mov bx,soffset
  59.   mov ah,bh
  60.   mov al,00ch
  61.   out dx,ax
  62.   mov ah,bl
  63.   inc al
  64.   out dx,ax
  65.   sti
  66. end;
  67. }
  68.  
  69. procedure fasttext(x, y : word; col : byte; what : string);assembler;
  70. asm
  71.       push   ds
  72.  
  73.       dec    [x]
  74.       dec    [y]
  75.       mov    ax, $b800
  76.       mov    es, ax
  77.       mov    ax, [y]
  78.       mov    bl, 160
  79.       mul    bl
  80.       add    ax, [x]
  81.       add    ax, [x]
  82.       mov    di, ax
  83.  
  84.       lds    si, what
  85.       cld
  86.       lodsb
  87.       xor    ch, ch
  88.       mov    ah, [col]
  89.       mov    cl, al
  90.       cmp    cx, 0
  91.       jz     @@2
  92.  
  93.  @@1: lodsb
  94.       stosw
  95.       loop   @@1
  96.  
  97.  @@2:
  98.       pop    ds
  99. end;
  100.  
  101. Function formatstr(kette:string;typ,laenge:byte):string;
  102. { These routines are not fast, but they are not important for me }
  103. { Wenn Typ=1 dann linksorientiert  }
  104. {      Typ=2 dann Mittig           }
  105. {      Typ=3 dann rechtsorientiert }
  106. begin
  107.   if length(kette)>laenge then
  108.   delete(kette,succ(laenge),length(kette)-laenge);
  109.   Case typ of
  110.         1 : while length(kette)<laenge do
  111.             begin
  112.               insert(' ',kette,succ(length(kette)));
  113.             end;
  114.         2 : while length(kette)<laenge do
  115.             begin
  116.               insert(' ',kette,succ(length(kette)));
  117.               insert(' ',kette,1);
  118.               if length(kette)>laenge then delete(kette,succ(laenge),1);
  119.             end;
  120.             { Schlecht programmiert, aber funktioniert ! }
  121.         3 : while length(kette)<laenge do
  122.             begin
  123.               insert(' ',kette,1);
  124.             end;
  125.   end; { CASE }
  126.   formatstr:=kette;
  127. end;
  128.  
  129.  
  130. procedure ScreenDown;
  131. { What I make is: I scroll the screen (pixel by pixel) and than add a new }
  132. { line out of the visible Screen }
  133. var n:byte;
  134. begin
  135.   vretrace;
  136.   vfine(0);
  137.   move(Blick,Start,4160);
  138.   inc(qs);
  139.   fasttext (1,27,$0F,txt[qs+26]);
  140.   for n:=0 to 15 do
  141.   begin
  142.     vretrace;
  143.     vfine(n);
  144.   end;
  145. end;
  146.  
  147. procedure ScreenUp;
  148. { Here I wanted to do the same (except putting the first line), but some-  }
  149. { how it has a worse result !                                              }
  150.                                     { Can you please tell me             }
  151. var n:byte;                         { what must I do, to stop flickering }
  152. begin                               { in here ?                          }
  153.   for n:=15 downto 0 do
  154.   begin
  155.     vretrace;
  156.     vfine(n);
  157.   end;
  158.   vretrace;
  159.   move(Start,Blick,4160);
  160.   if qs>1 then fasttext (1,1,$0F,txt[pred(qs)]);
  161.   vfine(15);
  162.   dec(qs);
  163. end;
  164.  
  165. function I2S(I: Longint): String;
  166. var
  167.   S: string[11];
  168. begin
  169.   Str(I, S);
  170.   s:=formatstr(s,3,3);
  171.   I2S:=S;
  172. end;
  173.  
  174. procedure make_text;
  175. { Creates virtual text .. only for testing purposes }
  176. var nn:byte;
  177. begin
  178.   for nn:=1 to rows do
  179.   begin
  180.     txt[nn]:='Line '+i2s(nn)+': '+formatstr('ExampleTxt',random(3)+1,70);
  181.   end;
  182. end;
  183.  
  184. begin
  185.   textattr := 15;
  186.   clrscr;
  187.   asm        { Cursor Off }
  188.     mov   ah,01
  189.     mov   ch,20h
  190.     int   10h
  191.   end;
  192.   qs:=0;      { Counts the number of current top line }
  193.   make_text;  { Create Virtul Text }
  194.   fasttext(1,1,$0F,formatstr(' ',1,80));    { Make Blank first Line }
  195.   for i:=2 to succ((ord(rows<=30)*rows)+(ord(rows>30)*30)) do
  196.   BEGIN
  197.     fasttext (1,i,$0F,txt[i-1]);
  198.   END;
  199.   for i := 0 to 15 do   {  Scroll a little bit down, to set           }
  200.   begin                 {  the starting Screen to hmmm to that it is  }
  201.     vretrace;           {  working ...                                }
  202.     vfine (i);
  203.   end;
  204.   while keypressed do readkey;
  205.   repeat
  206.     qc:=' ';
  207.     if keypressed then
  208.     begin
  209.       qc:=readkey;
  210.       if (qc='.') and ((qs+25)<rows) then ScreenDown;
  211.       if (qc=';') and (qs>=1) then ScreenUp;
  212.     end;
  213.   until qc='q';
  214.   textmode(co80);
  215. end.
  216.  
  217. { ------------------------------ CUT HERE ---------------------------------}
  218.  
  219.