task FrameRender
{
	let frame_x=0;
	let frame_y=0;
	let vx=0;
	let vy=0;
	
	BackPosition(416,0,640,480);
	BackPosition(0,0,416,16);
	BackPosition(0,464,416,480);
	BackPosition(0,16,32,464);
	let tuning=GetCommonData("Memory_ConfigData");
	if(!tuning[1])
	{
		Noize(416,0,640,480);
		Noize(0,0,416,16);
		Noize(0,464,416,480);
		Noize(0,16,32,464);
	}
	
	Title(true);
	Title(false);
	Border;
	
	
	while(1)
	{
		SetRenderFrame(false);
		let v=0.1;
		if(!menu_flg)
		{
			if(GetKeyState(VK_UP)==KEY_HOLD){vy-=v;}
			if(GetKeyState(VK_DOWN)==KEY_HOLD){vy+=v;}
			if(GetKeyState(VK_LEFT)==KEY_HOLD){vx-=v;}
			if(GetKeyState(VK_RIGHT)==KEY_HOLD){vx+=v;}
		}
		
		frame_x+=vx;
		frame_y+=-1+vy;
		vx*=0.99;
		vy*=0.99;
		yield;
	}
	
	task BackPosition(let left,let up,let right,let down)
	{
		let alpha=0;
		Back1;
		Back2;
		loop
		{
			if(frame_rflg)
			{
				if(alpha<255){alpha+=1;}
			}
			else
			{
				if(alpha>0){alpha-=1;}
			}
			yield;
		}
		task Back1
		{
			loop
			{
				let obj=SetEffectObject(tex[TEX_FRAMEBACK],8);
				ObjEffect_SetRenderState(obj,ALPHA);
				
				let sx=left+(right-left)/2;
				let sy=up+(down-up)/2;
				let color=255;
				Obj_SetPosition(obj,sx,sy);
				
				let count=0;
				while(!Obj_BeDeleted(obj))
				{
					
					SetEffectObjectRect(obj,left+frame_x,up+frame_y,right+frame_x,down+frame_y);
					ascent(a in 0..4)
					{
						ObjEffect_SetVertexColor(obj,a,255-alpha,color,color,color);
					}
					if(count>18000){Obj_Delete(obj);break;}
					if(stagenum>0){count++;}
					yield;
				}
			}
		}
		task Back2
		{
			loop
			{
				let obj=SetEffectObject(tex[TEX_FRAMEBACK2],8);
				ObjEffect_SetRenderState(obj,ALPHA);
				
				let sx=left+(right-left)/2;
				let sy=up+(down-up)/2;
				let color=255;
				Obj_SetPosition(obj,sx,sy);
				
				let count=0;
				while(!Obj_BeDeleted(obj))
				{
					
					SetEffectObjectRect(obj,left+frame_x,up+frame_y,right+frame_x,down+frame_y);
					ascent(a in 0..4)
					{
						ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
					}
					if(count>18000){Obj_Delete(obj);break;}
					if(stagenum>0){count++;}
					yield;
				}
			}
		}

	}
	task Noize(let left,let up,let right,let down)
	{
	
		let alpha_=128;
		let alpha=128;
		let lp=0;
		let color=0;
		let v=0;
		StateRun;
		task StateRun
		{
			loop
			{
				if(!menu_flg)
				{
					if(alpha_>0){alpha_--;}
					alpha-=0.25*cos(lp/4);
					lp++;
				}
				v+=55;	
				yield;
			}
		}
		loop
		{
			let obj=SetEffectObject(tex[TEX_FRAMENOIZE],8);
			ObjEffect_SetRenderState(obj,ALPHA);
			let sx=left+(right-left)/2;
			let sy=up+(down-up)/2;
			Obj_SetPosition(obj,sx,sy);
			
			let count=0;
			while(!Obj_BeDeleted(obj))
			{
				SetEffectObjectRect(obj,left,up+v,right,down+v);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha-alpha_,color,color,color);
				}
				if(count>18000){Obj_Delete(obj);break;}
				if(stagenum>0){count++;}
				yield;
			}
		}
	}
	
	task Border
	{
		while(menu_flg){yield;}
		
		let o=0.05;
		let scx=1+o;
		let scy=1+o;
		let frame=0;
		let limit=30;
		StateRun;
		task StateRun
		{
			loop
			{
				if(frame<limit)
				{
					scx-=o/limit;
					scy-=o/limit;
					if(!(frame%3)){BorderEffect(scx,scy);}
					frame++;
				}
				else
				{
					scx=1;
					scy=1;
				}
				yield;
			}
		}
		loop
		{
			let obj=SetEffectObject(tex[TEX_FRAMEBORDER],8);
			ObjEffect_SetRenderState(obj,ALPHA);
			Obj_SetPosition(obj,320,240);
			SetEffectObjectRect(obj,0,0,640,480);
			let count=0;
			while(!Obj_BeDeleted(obj))
			{
				ObjEffect_SetScale(obj,scx,scy);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,255,128,128,128);
				}
				if(count>18000){Obj_Delete(obj);break;}
				if(stagenum>0){count++;}
				yield;
			}
		}
		
		task BorderEffect(let scalex,let scaley)
		{
			let obj=SetEffectObject(tex[TEX_FRAMEBORDER],8);
			ObjEffect_SetRenderState(obj,ADD);
			Obj_SetPosition(obj,320,240);
			SetEffectObjectRect(obj,0,0,640,480);
			let alpha=92;
			while(!Obj_BeDeleted(obj))
			{
				ObjEffect_SetScale(obj,scalex,scaley);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,alpha,255,128,128,128);
				}
				scalex+=0.001;
				scaley+=0.001;
				alpha-=5;
				if(alpha<5){Obj_Delete(obj);}
				yield;
			}
		}
	}
	
	task Title(let shadow)
	{
		let r=-1;
		let v=0;
		let lp=0;
		let sx=320;let sy=180;
		Run;
		task Run
		{
			if(shadow){r=-r;}
			loop
			{
				v+=0.0002*cos(lp/2)*r;
				sx+=v;
				sy+=v;
				lp++;
				yield;
			}
		}
		loop
		{
			let obj=SetEffectObject(tex[TEX_FRAMETITLE],8);
			ObjEffect_SetRenderState(obj,ALPHA);
			SetEffectObjectRect(obj,0,0,640,480);
			let count=0;
			while(!Obj_BeDeleted(obj))
			{
				let color=255;
				if(shadow){color=24;}
				Obj_SetPosition(obj,sx,sy);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,255,color,color,color);
				}
				if(count>18000){Obj_Delete(obj);break;}
				if(stagenum>0){count++;}
				yield;
			}
		}
	}
}