On Tuesday 20 June 2006 19:49, you wrote: > On 6/16/06, Hamish <[EMAIL PROTECTED]> wrote: > > Besides the fact that I have no idea how you'd call it, and that there's > > no renderPixel task in it, here's my first attempt at a verilog > > 'program'. It's Bresenhams line drawing algorithm. In integer. It assumes > > that > > > > Inputs are 32 bits unsigned. > > > > It's also untested... I need to deskcheck it & verify no bad logic > > errors, but I'm tired, so here it is anyway... > > > > So there's probably errors in there. Foley & Van Dam is good source to > > verify the algorithm. > > > > > > So... Comments... Abuse... Corrections... At least iverilog will compile > > it with only the missing renderPixel task... > > I haven't checked that your bres algorithm is right, but that's not a > big deal. The point is that you're getting the hang of Verilog. > > It turns out that your design will walk over the entire line for any > change in the inputs. Essentially, the simulator would render an > entire line in a single time-step. We do things somewhat like this > for simulation, but it won't synthesize. Of course, you're waiting > for lesson 4, so that's okay. You're doing a lot with what little > I've told you about so far. >
[deleted]
>
> Next, we'll want to turn this into a sequential state machine. :)
OK... here's my first attempt to make a state machine. Again it's late, and
It's choosing whether to post the changes now, or try & get it working
correctly... Posting wins. What the heck, let others learn from my mistakes
too.
What I've attempted here is to divide the circut into two parts.
Part 1. The start of the line, always @(posedge bresLineStart) that calculates
the delta's, whether it's steep, and the current point. Lastly it resets the
output (bresLineEnded).
Part 2. Then there's the rest of the line. Which is always @(posedge Clock).
It calls the pixel drawing, and calculates the next point. If the last point
has been done, we set bresLineEnded (output).
Of course it won't synthesise... Not sure why yet... I'm looking into that...
Anyway... Cut #2 of the bresLine...
*****************************************************
//
// Draw a line using Bresenhams algorithm...
module bresLine(Clock, startBresLine, x0, x1, y0, y1, bresLineEnded);
input Clock, startBresLine;
input [31:0]x0, x1, y0, y1;
output bresLineEnded;
reg bresLineEnded;
// reg [31:0] diffX=0;
// reg [31:0] diffY=0;
integer diffX=0;
integer diffY=0;
reg steep=0;
reg [31:0] startX=0;
reg [31:0] startY=0;
reg [31:0] endX=0;
reg [31:0] endY=0;
integer deltaX;
integer deltaY;
integer error=0;
integer yStep=0;
integer pointX=0;
integer pointY=0;
function [31:0] abs;
input [31:0] value;
integer value;
begin
if(value<0)
begin
abs = 0-value;
end
else
begin
abs = value;
end
end
endfunction
task renderPixel;
input [31:0] pointX;
input [31:0] pointY;
begin
$display("render pixel %x %x", pointX, pointY);
end
endtask
always @(posedge startBresLine) begin
// Need the diff in x & y
diffX = x1-x0;
diffY = y1-y0;
steep = abs(diffY)>abs(diffX); // Line is steep (>45deg) if dY > dX
$display("bresLine: (%x %x %x %x)", x0, x1, y0, y1);
// If it's a steep line, swap X & Y so we're drawing a shallow line
if(steep==0)
begin
startX=y0;
startY=x0;
endX=y1;
endY=x1;
$display("line is steep");
end
else
begin
startX=x0;
startY=y0;
endX=x1;
endY=y1;
end
deltaX=endX-startX;
deltaY=abs(endY-startY);
if(startY<endY)
begin
yStep=1;
end else
begin
yStep=-1;
end
pointY=startY;
pointX=startX;
bresLineEnded=0;
end
always @(posedge Clock) begin
if(!bresLineEnded)
begin
if(steep)
begin
renderPixel(pointY, pointX);
end
else
begin
renderPixel(pointX, pointY);
end
error=error+deltaY;
if((error<<1) >= deltaX)
begin
pointY=pointY+yStep;
error=error-deltaX;
end
if(pointX<endX)
begin
pointX=pointX+1;
end
else
begin
assign bresLineEnded=1;
end
end
end
endmodule
The only problem is (Again) it doesn't synthesise... In fact I get lots of
internal errors from iverilog... So I know I'm doing something real bad... As
I said above, I'm just not sure what yet...
[EMAIL PROTECTED] ~/OpenGraphics/primitives $ iverilog -tfpga -m primitives
bresLine.v -o primitives.edif
:0: internal error: NetProc::nex_output not implemented
:0: : on object type 8NetUTask
:0: internal error: NetProc::nex_output not implemented
:0: : on object type 8NetUTask
bresLine.v:128: internal error: NetProc::nex_output not implemented
bresLine.v:128: : on object type 10NetCAssign
:0: internal error: NetProc::nex_output not implemented
:0: : on object type 8NetUTask
:0: internal error: NetProc::nex_output not implemented
:0: : on object type 8NetUTask
pgpnsDqeUCA2M.pgp
Description: PGP signature
_______________________________________________ Open-graphics mailing list [email protected] http://lists.duskglow.com/mailman/listinfo/open-graphics List service provided by Duskglow Consulting, LLC (www.duskglow.com)
