Uses Crt,Gif,ModeXLib;
Var x,                          {current offset in x-direction}
    x_dir,                      {specifies scroll direction for x}
    y,                          {current offset for y-direction}
    y_dir:word;                 {specifies scroll direction for y}
Begin
  Init_ModeX;                   {enable Mode X}
  double;                       {160 byte mode on (640*400 pixels total}
  LoadGif('640400');            {load image}
  p13_2_ModeX(vram_pos,rest div 4); {rest of image in video RAM}
  x:=1;                         {x-beginning with column 1}
  x_dir:=1;                     {x-direction 1 byte per pass}
  y:=160;                       {y-beginning with line 1}
  y_dir:=160;                   {y-direction +160 bytes per pass}
  Repeat
    Inc(x,x_dir);               {x-movement}
    Inc(y,y_dir);               {y-movement}
    WaitRetrace;                {wait for retrace}
    SetStart(y+x);              {and write new start in register}
    if (x >= 80)                {x-border reached -> turn x-direction around}
    or (x <= 1) Then x_dir:=-x_dir;
    if (y >= 200*160)           {y-border reached -> turn y-direction around}
    or (y <= 160) Then y_dir:=-y_dir;
  Until KeyPressed;             {run until key is pressed}
  TextMode(3);
End.
