program Hello_world_Pixels;

@use "system/screen"
@use "system/memory"
@use "gfx/gfx"
@use "math/random"

var
	x,y,time,i,t,shift: integer;
	col : integer;
	sin : array[256] of integer = buildsinetable(127);
	p:pointer;
begin
	// Initialises memory
	Memory::Init();
	// Initialises 2 64k VGA buffers into Screen::buffer1 and Screen::buffer2
	Screen::InitVGABuffers(3);
	// Sets mode 13 - 320x200 VGA
	Screen::SetMode($13);
	
	Random::Init(151); // set some random seed
	asm(";here");
	Gfx::PutPixelVGA(ptr(#Screen::VGA,0), x, y, col);
	x:=0;	
	// sine shift for x
	shift := 64;
	
	while (true) do
	begin
		// waits for vertical blank
		waitforverticalblank();
		// Write pixels directly to the screen
		
		t := time;
		// Draw 256 pixels per frame
		for i:=0 to 256 do
		begin
			// calculate x and y positions
			x := sin[(t+shift)&255] + 100;
			y := sin[t&255] + 32;
			// Draw the pixel directly to the screen
			Gfx::PutPixelVGA(ptr(#Screen::VGA,0), x, y, col);
			t+=1;
		end;
		// Increase color value
		col+=1;
		// Increase sine shift
		shift+=1;
		
		time+=1;
	end;
	
end.