{RASTEXAM.PAS / EXAMPLE FOR RASTER BARS}
{WRITING BY THE KING IN 10/14/95     }

Uses Crt;
Var
	BLUEBAR : Array[1..63*2,1..3] Of Byte;   {THE RASTER BAR}
	Num:Byte;
    R,G,B:Byte;
    Del:Byte;

{---------------------------------------------}
{Build The Palette for the BLUE BAR ...       }
{---------------------------------------------}
Procedure BuildBlueBar;
Var T:Byte;
Begin
	For T:=1 To 63 Do Begin
    	BlueBar[T,1] := 0;
    	BlueBar[T,2] := 0;
    	BlueBar[T,3] := T;
	End;
	For T:=1 To 63 Do Begin
    	BlueBar[63+T,1] := 0;
    	BlueBar[63+T,2] := 0;
    	BlueBar[63+T,3] := 63-T;
	End;
End;

{-------------------------------------------------}
{Init The Program ...                             }
{-------------------------------------------------}

Procedure Init;
Begin
	Clrscr;
	Port[$21] := 1;          {Disable Interrupts for speed}
	BuildBlueBar;            {Build Blue Bars}
	TextColor(15);
	Writeln('                                 HI EVERYONE !           ');
    Writeln('                                 -------------           ');
	Writeln('         This is the example for the RASTER EFFECT wrote by THE KING');
	Writeln;
    Gotoxy(1,20);
	Writeln('                            Press Any Key To Continue');
End;
{----------------------------------------}
{ If Retrace End Sent TRUE , Else FALSE. }
{----------------------------------------}
Function Retrace:Boolean; Assembler;
asm
	Xor Ah,Ah                  {Ah = 0}
    Mov Dx,3dah                {Dx = 3DAh}
@Vert1:
    In Al,Dx                   {Al = Port[3DAh]}
    Test Al,8                  {Check The 4 Bit For Checking If}
    Jz @Exit                   {Finish With Vertical Retrace}
    Inc Ah

@Exit:
	Mov Al,Ah
End;

{--------------------------------------------------}
{Put the Bars on the screen ..                     }
{--------------------------------------------------}
Procedure PutBars;
Begin
	Num:=1;
	Repeat
		Del:=1;
		Num :=1;
		Repeat
			If Num > 63*2 Then Num := 1;
			R := BlueBar[Num,1];
			G := BlueBar[Num,2];
			B := BlueBar[Num,3];
			If Del = 6 Then
			Begin
				Inc(Num);
				Del := 1;
			End;
			Inc(Del);
			Asm
				Mov Al,0                      {Paint On Color 0}
		        Mov Dx,3c8h                   {The R,G,B}
		        Out Dx,Al
		        Inc Dx
		        Mov Al,R
		        Out Dx,Al
		        Mov Al,G
		        Out Dx,Al
		        Mov Al,B
		        Out Dx,Al
			End;
		Until(Retrace);
	Until(KeyPressed);
End;
Begin
Init;
PutBars;
Port[$21] := 0;     {Enable Interrupts.}
Asm
	Mov Al,0                      {Paint On Color 0}
    Mov Dx,3c8h                   {0,0,0 To Return To Reglar Mode}
    Out Dx,Al
    Inc Dx
    Mov Al,0
    Out Dx,Al
    Mov Al,0
    Out Dx,Al
    Mov Al,0
    Out Dx,Al
End;
End.