program tutorial2;
var  
	random_char, cnt, random_color: byte; 
	random_values : array[255] of byte;
	x, y : byte;
	index : byte;
	screenP, colorP : pointer;

//	  charset: IncBin("charsets/tutorial3.bin","$1fff");


// Initialize random table, much faster then using the sid's random value
// generator
procedure InitializeRandom();
begin
	for x:=0 to 255 do begin
		rand(0, 255, y);
		random_values[x]:=y;
    end;

end;

begin
	InitializeRandom();
	// Fill screen with blank
	ClearScreen($20, SCREEN_CHAR_LOC );
	// Fill color screen with background F and foreground 8
	ClearScreen($F8, SCREEN_COL_LOC );
//	setcharsetlocation($2000);
	// Set screen foreground and background to black. The second parameter is an offset.
	Poke(SCREEN_BG_COL, 0, BLACK);
	Poke(SCREEN_FG_COL, 0, BLACK);

	//poke(^$D020,YELLOW);
//	SCREEN_BG_COL:=YELLOW;

//	SCREEN_BG_COL:=BLACK;
	// point to start of random table
	index:=0; 
	// infinite loop
	cnt := 0;
	y:=sine[0];
	while 1=1 do begin
		// loop y		
		screenP:=SCREEN_CHAR_LOC;
		colorP:=SCREEN_COL_LOC;
		for y:=0 to 24 do begin
			// moves current screen position
			// Select some random color
			for x:=0 to 40 do begin
				// Sets both screen and color values
				screenP[x] := random_values[index];
				// increases screen X counter
				// Increase by some random non-repeatable prime
				index:=index+17;
	    		end;
			// Select some random color
			random_color := random_values[index]/16;
			// restrict to 0-16
			for x:=0 to 40 do begin
				// Sets both screen and color values
				colorP[x] := random_color;
				// increases screen X counter
			
	    	end;
		screenP:=screenP+40;
		colorP:=colorP+40;
		end
	end;

end.


