program Tutorial_27_stable_raster_wedge;
var  
	y,time,idx,i,tt: byte = 0;
	
	colorsRedhues : array [16] of byte = (  6,11,15,1,7,8,2,2,  2, 2,2,8,7,1,15,11,6  );


@define useKernal 0

interrupt RasterBar();

interrupt RasterTop();
begin
	StartIRQ(@useKernal);	
	SCREEN_BG_COL:=BLUE;
	SCREEN_FG_COL:=BLUE;
	inc(time);
	idx:=0;
	if (time&1=0) then inc(tt);
	y:=sine[tt]/4 + 80;

	RasterIRQWedge(RasterBar(), y,@useKernal);
	CloseIRQ();
end;


interrupt RasterBar();
begin
	inc(idx);
	StartIRQWedge(5);	
	SCREEN_BG_COL:=colorsRedhues[idx];
	SCREEN_FG_COL:=SCREEN_BG_COL;
	y:=y+6;
	
	RasterIRQWedge(RasterBar(), y,@useKernal);

	if (idx=16) then // Go to top again
		RasterIRQ(RasterTop(),0,@useKernal);

    closeirqwedge();
end;

interrupt nmii();
begin
	StartIRQ(@useKernal);
	inc(SCREEN_BG_COL);
	Loop();
	CloseIRQ();
end;

begin
	preventirq();
	disableciainterrupts();
	SetMemoryConfig(1,@useKernal,0);
//	NMIIRQ(nmii());
	StartRasterChain(RasterTop(),0,@useKernal);
	Loop();
end.
