home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / graphic / scrollt.pas < prev    next >
Pascal/Delphi Source File  |  1995-07-28  |  3KB  |  84 lines

  1. Uses ModeXLib,Crt;
  2.  
  3. Var x,                          {x-position in pixels}
  4.     x_dir,                      {x-direction}
  5.     y,                          {y-position in pixels}
  6.     y_dir:Word;                 {y-direction}
  7.  
  8. Procedure Wait_In_Display;assembler;
  9. {Counterpart to Wait_In_Retrace, waits for display via cathode ray}
  10. asm
  11.   mov dx,3dah                   {Input Status 1}
  12. @wait2:
  13.   in al,dx
  14.   test al,8h
  15.   jnz @wait2                    {Display on ? -> then finished}
  16. End;
  17. Procedure Wait_In_Retrace;assembler;
  18. {waits for retrace, also resets the ATC flip-flop by read access to Input Status 1}
  19. asm
  20.   mov dx,3dah                   {Input Status 1}
  21. @wait1:
  22.   in al,dx
  23.   test al,8h
  24.   jz @wait1                     {Retrace active ? -> then finished}
  25. End;
  26.  
  27. Procedure FillScreen;
  28. {Fills video RAM with test image 160*50 characters in size}
  29. var i:word;
  30. Begin
  31.   For i:=0 to 160*50 do Begin   {character loop}
  32.     If i mod 10 <> 0 Then       {write column counter ?}
  33.       mem[$b800:i shl 1]:=      {no, then '-'}
  34.         Ord('-') Else
  35.       mem[$b800:i shl 1]:=      {yes, then column number in tens}
  36.       ((i mod 160) div 10) mod 10 + Ord('0');
  37.     If i mod 160 = 0 Then       {column 0 ? -> write row counter}
  38.       mem[$b800:i shl 1]:=(i div 160) mod 10 + Ord('0');
  39.   End;
  40. End;
  41. Procedure V_Pan(n:Byte);assembler;
  42. {performs vertical panning}
  43. asm
  44.   mov dx,3d4h                   {CRTC Register 8 (Initial Row Adress)}
  45.   mov al,8
  46.   mov ah,n                      {set panning width}
  47.   out dx,ax
  48. End;
  49. Procedure H_Pan(n:Byte);assembler;
  50. {performs horizontal panning}
  51. asm
  52.   mov dx,3c0h                   {ATC Index/Data Port}
  53.   mov al,13h or 32d             {Register 13h (Horizontal Pixel Panning)}
  54.   out dx,al                     {select; Bit 5 (Palette RAM Address Source)}
  55.   mov al,n                      {set, in order not to switch off screen}
  56.   or al,32d                     {write panning value}
  57.   out dx,al
  58. End;
  59.  
  60. Begin
  61.   TextMode(3);                  {set BIOS mode 3 (80*25 characters, Color)}
  62.   FillScreen;                   {build test picture}
  63.   portw[$3d4]:=$5013;           {double virtual screen width(160 character)}
  64.   x:=0;                         {initialize coordinates and directions}
  65.   x_dir:=1;
  66.   y:=0;
  67.   y_dir:=1;
  68.   Repeat
  69.     Inc(x,x_dir);               {movement in x and y-directions}
  70.     Inc(y,y_dir);
  71.     If (x<=0) or (x>=80*9)      {turn around at borders}
  72.       Then x_dir:=-x_dir;
  73.     if (y<=0) or (y>=25*16)
  74.       Then y_dir:=-y_dir;
  75.     Wait_in_Display;            {wait until display running}
  76.     SetStart((y div 16 *160)    {set start address (rough scrolling}
  77.       + x div 9);
  78.     Wait_in_Retrace;            {wait until retrace active}
  79.     V_Pan(y mod 16);            {vertical panning   (fine scrolling)}
  80.     H_Pan((x-1) mod 9);         {horizontal panning (fine scrolling)}
  81.   Until KeyPressed;             {wait for key}
  82.   TextMode(3);                  {and set normal video mode}
  83. End.
  84.