On Wednesday 21 June 2006 22:00, you wrote:
> On 6/21/06, Hamish <[EMAIL PROTECTED]> wrote:
> > On Wednesday 21 June 2006 18:20, Hamish wrote:
> > > On Wednesday 21 June 2006 02:15, you wrote:
> > > > > 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).
> > > >
> > > > It's good that you're doing this, because it reminds me to mention in
> > > > lesson 4 to never use something that isn't a clock net as a clock. 
> > > > :)
> > > >
> > > > You'll want to do something like this:
> > > >
> > > > always @(posedge clock) begin
> > > >     if (drawing_line) begin
> > > >         ... next step in drawing line ...
> > > >         if (... last pixel ...) begin
> > > >             drawing_line <= 0;
> > > >         end
> > > >     end else if (start_line) begin
> > > >         ... grab input parameters into registers and start counter
> > > > ... drawing_line <= 1;
> > > >     end
> > > > end
> >

[deleted]

>
> You really don't want to be doing initializations like this for synthesis.
>
> What you need is a global reset, and you do it like this:
>
> always @(posedge clock) begin
>     if (reset) begin
>         bresLineDone <= 1;
>         bresLineDrawing <= 0;
>         ... all regs you'll be assigning to ...
>     end else begin
>          .... logic ....
>     end
> end
>

OK...

[deleted]
> >   endfunction
>
> That won't give you abs.
>
> First of all, although the synthesizer might be smart enough to figure
> it out, [30:0] is likely to produce less logic than &'h7ffffff.
>
> Secondly, what you have with this is the 2's compliment of the lower
> 31 bits, which is not the same as the absolute value.
>

Stupid stupid stupid mistake... I should know better... 

[deleted]

> >
> >       assign bresLineDone=(pointX>=endX);
>
> This is good code, although you can't use 'assign' in an always block.
>

OK...

> >     end
> >     else
> >     begin
> >       if(startBresLine)
> >       begin
> > //      assign bresLineDone=1;
>
> bresLineDone <= 0;
>
> >         // 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: steep %x (%x %x %x %x)", steep, 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;
>
> Missing endY here??
>

Yes.


[more deleted]

>
> You are ambitous to do this before lesson 4 (which I hope to do tomorrow). 
> :)

Yeah... 

>
> I haven't checked everything in perfect detail, but this is quite
> excellent work here.

I have a new version... Whch synthesises nicely on ISE... (8.1 for an xc2s1500 
admittedly). 4 warnings that I understand not at all, but no errors 
apparently. Now whether it works or not is another matter... I haven't 
figured out a test harness for it yet...

I might try translating some of the real OG simulation code to verilog next... 
Just to see if I can get it to work :)


//
// Draw a line using Bresenhams algorithm...
module bresLine(Clock, startBresLine, x0, x1, y0, y1, bresLineDone);
  input         Clock;
  input         startBresLine;
  input  [31:0] x0;
  input  [31:0] x1;
  input  [31:0] y0;
  input  [31:0] y1;
  output        bresLineDone;

  reg           bresLineDone;

  reg           bresLineDrawing;

  reg           reset;

  integer       diffX;
  integer       diffY;

  reg           steep;

  reg [31:0]    startX;
  reg [31:0]    startY;
  reg [31:0]    endX;
  reg [31:0]    endY;

  integer       deltaX;
  integer       deltaY;
  integer       error;

  integer       yStep;

  integer       pointX;
  integer       pointY;

  function [31:0] abs;
    input [31:0] value;

    begin
      abs=value[31]?-value:value;
    end
  endfunction

  task renderPixel;
    input [31:0] pointX;
    input [31:0] pointY;

    begin
      $display("pixel   : (%x %x)", pointX, pointY);
    end
  endtask

  always @(posedge Clock) begin
    if(reset==1'b1) 
    begin
      bresLineDrawing<=0;
      bresLineDone<=1;
      steep<=0;
    end else
    if(bresLineDrawing==1'b1) 
    begin
      $display("        : (%x %x)", pointX, pointY);
      if(steep==1'b1) 
      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

      pointX<=pointX+1;

      bresLineDone<=(pointX>=endX);

    end
    else
    begin
      if(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: steep %x (%x %x %x %x)", steep, 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;
        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;

        bresLineDone<=0;
      end
    end
  end
endmodule

Attachment: pgpPEudUeDRNY.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)

Reply via email to