// Unstretch and Flip Phone Wallpaper (PTRSCLL)
// Wallpaper Resolution Ratio = round(res_width*0.28625) x res_height
cbuffer cb2 : register(b2) {float4 cb2[6];}
cbuffer cb1 : register(b1) {float4 cb1[16];}
cbuffer cb0 : register(b0) {float4 cb0[10];}

// 3Dmigoto declarations
#define cmp -
#define FLIP IniParams[101].x
#define PREVIEW IniParams[101].y
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);

void main(
  float4 v0 : POSITION0,
  float4 v1 : COLOR0,
  float4 v2 : TEXCOORD0,
  float2 v3 : TEXCOORD7,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : COLOR0,
  out float4 o2 : TEXCOORD0,
  out float2 o3 : TEXCOORD3)
{
  float4 r0;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xyzw = cb1[13].xyzw * v0.yyyy;
  r0.xyzw = cb1[12].xyzw * v0.xxxx + r0.xyzw;
  r0.xyzw = cb1[14].xyzw * v0.zzzz + r0.xyzw;
  o0.xyzw = cb1[15].xyzw + r0.xyzw;
  
  o1.xyzw = cb2[0].xyzw * v1.xyzw;
  
  o2.x = v2.x * cb2[5].x + cb2[5].z;
  
  o2.y = 0.5 * (1 - (v0.y * abs(cb1[13].y)));
  
  if (PREVIEW == 1) {
    o2.y *= 1.2655;
    o2.y -= 0.16;
  }
  
  if (FLIP == 1) {
    o2.y = 1 - o2.y;
  }
  
  r0.xy = cb0[7].xy * v0.yy;
  r0.xy = cb0[6].xy * v0.xx + r0.xy;
  r0.xy = cb0[8].xy * v0.zz + r0.xy;
  o2.zw = cb0[9].xy * v0.ww + r0.xy;
  
  o3.xy = v3.xy;

  return;
}