% compute integer approx to sin at 45 degrees

X(1)=0;
Y(1)=0;
I=1;

while Y(I) < 511,

  A=f(X(I),Y(I)+1);
  B=f(X(I)+1,Y(I)+1);
  C=f(X(I)+1,Y(I));
  D=f(X(I)+1,Y(I)-1);

  BEST=A;

  X(I+1)=X(I);
  Y(I+1)=Y(I)+1;

  if(B)<BEST,
    BEST=B;
    X(I+1)=X(I)+1;
    Y(I+1)=Y(I)+1;
  end

  if(C)<BEST,
    BEST=C;
    X(I+1)=X(I)+1;
    Y(I+1)=Y(I);
  end

  if(D)<BEST,
    BEST=D;
    X(I+1)=X(I)+1;
    Y(I+1)=Y(I)-1;
  end

  I=I+1;

end
