[Pascal] Przejście z trybu graficznego na tekstowy

Witam

Mam problem w Pascalu chodzi o to, że chcę przejść z trybu graficznego na tryb tekstowy, ale po wyświetleniu się trybu graficznego tryb tekstowy nie działa poprawnie. Jak zrobić aby wszystko ładnie działało?

Umieszczam kod programu

program GrafikaTekst;


uses graph,crt;


var

ster,tryb,a,x:integer;


begin

clrscr;


 ster:=VGA;

 tryb:=VGAHi;



 InitGraph(ster,tryb, 'C:\BP\BGI');


        Line(30,30,610,450);

  repeat

  until keypressed;



  Closegraph;



 a:=1;




Writeln('Podaj czas');

readln(x);


       repeat


       inc(a);

       textbackground(a);

       gotoxy(20,10);

       writeln(' ');


       delay(x);


       until keypressed;


 end.