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}
    split_line:word;            {current position of Split-Line}
    split_dir:word;             {specifies direction of movement for Split-Line}
Begin
  Init_ModeX;                   {enable Mode X}
  double;                       {enable 160 byte mode}
  Screen_Off;                   {screen off}
  LoadGif_Pos('640400',160*50);{load big picture at position (0/50)}
  p13_2_ModeX(vram_pos,rest div 4); {copy rest to VGA-RAM}
  LoadGif('corner');            {load small picture at position (0/0)}
  p13_2_ModeX(0,160*50);        {and copy to screen}
  Screen_On;                    {screen on}

  split_line:=150;              {set Split at line 150 first}
  split_dir:=1;                 {move Split-Line down first}
  x:=1;                         {x-start with column 1}
  x_dir:=1;                     {x-direction 1 byte per pass}
  y:=160;                       {y-start with row 1}
  y_dir:=160;                   {y-direction+160 bytes per pass}
  Repeat
    Inc(x,x_dir);               {x-movement}
    Inc(y,y_dir);               {y-movement}
    Inc(Split_line,Split_dir);  {move Split Line}
    WaitRetrace;                {wait for Retrace}
    SetStart(50*160+y+x);       {and write new start in register,}
                                {skipping the first 50 lines}
    Split(Split_line);          {split screen at Split Line}
    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;
    if (split_line >= 200)      {split reached border -> change direction}
    or (split_line <= 150) then split_dir:=-split_dir
  Until KeyPressed;             {run until key pressed}
  TextMode(3);
End.
