Created
June 29, 2014 07:11
-
-
Save yamamaya/bfdad666aa1d35c57d49 to your computer and use it in GitHub Desktop.
コードの化石の断片
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DrawCircle( | |
input CLOCK, | |
input nRESET, | |
input START, | |
input signed [11:0] X0, | |
input signed [10:0] Y0, | |
input signed [11:0] R, | |
input FILL, | |
output signed [11:0] X, | |
output signed [10:0] Y, | |
output OCLK, | |
output BUSY | |
); | |
reg signed [15:0] rD, rCX, rCY, rXX, rYY; | |
reg [1:0] rQuadrant; | |
reg [1:0] rSQ; | |
reg signed [11:0] rX; | |
reg signed [10:0] rY; | |
reg rBUSY; | |
always @( posedge CLOCK or negedge nRESET ) begin | |
if ( ! nRESET ) begin | |
rBUSY = 0; | |
rSQ = 0; | |
end else begin | |
if ( START ) begin | |
rSQ = 0; | |
rD = 2 - 2 * R; | |
rCX = 0; | |
rCY = R; | |
rXX = 0; | |
rYY = R; | |
rBUSY = 1; | |
rQuadrant = 0; | |
end else if ( rBUSY ) begin | |
rSQ = rSQ + 1; | |
if ( rSQ == 0 ) begin | |
rQuadrant = rQuadrant + 1; | |
if ( rQuadrant == 0 ) begin | |
rXX = rXX + 1; | |
if ( ! FILL || rXX > rCX ) begin | |
if ( rD > -rCY ) begin | |
rCY = rCY - 1; | |
rD = rD + 1 - 2 * rCY; | |
end | |
if ( rD <= rCX ) begin | |
rCX = rCX + 1; | |
rD = rD + 1 + 2 * rCX; | |
end | |
if ( ! FILL ) begin | |
rXX = rCX; | |
end else if ( rYY != rCY ) begin | |
rYY = rCY; | |
rXX = 0; | |
end | |
end | |
end | |
end else if ( rSQ == 3 ) begin | |
rX = X0 + ( ( rQuadrant == 1 || rQuadrant == 2 ) ? -rXX : rXX ); | |
rY = Y0 + ( ( rQuadrant == 0 || rQuadrant == 1 ) ? rCY : -rCY ); | |
if ( rQuadrant == 3 ) begin | |
rBUSY = ( rCY == 0 && rXX == rCX ) ? 0 : 1; | |
end | |
end | |
end | |
end | |
end | |
assign X = rX; | |
assign Y = rY; | |
assign OCLK = ( rSQ == 3 ) ? 1 : 0; | |
assign BUSY = rBUSY; | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment