Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
bc98eee58This file is pinned to the selected release. Download the original to open it in your design tool.
# Line Drawing
The line module [[line.v](../gfx/line.v)] calculates lines with Bresenham's line algorithm. This implementation supports signed integer coordinates and works towards increasing Y, swapping the input coordinates if necessary. Increasing Y is down the display, see [display sync generation](display_sync_gen.md).
## Parameters
* `CORDW` - signed coordinate width (bits)
[Earthrise](earthrise.md) uses 12-bit integer coordinates for drawing; we may switch to a 16-bit Q12.4 fixed-point format for sub-pixel precision in future.
## Signals
The follow signals are used for line drawing. Isle drawing takes place in the system clock domain.
### Input
* `clk` - clock
* `rst` - reset
* `start` - start line calculation
* `oe` - output enable
* `x0`, `y0` - line start coordinates
* `x1`, `y1` - line end coordinates
The `start` signal only works when if the module isn't already calculating. If you want to stop the calculation and start afresh you need to reset with `rst` then use `start`.
Output enable `oe` lets you pause the line calculation, which is useful for multiplexing access to memory or for drawing shapes (such as triangles) where multiple lines are involved.
### Output
* `x`, `y` - line position (output coordinates)
* `xs` - start x-coordinate for this y
* `fill` - ready for fill; current y complete (used by Earthrise)
* `busy` - calculation in progress
* `valid` - output coordinates valid
`xs` is helpful when drawing filled triangles. When `fill` occurs, Earthrise can use `xs` or `x` depending on whether it needs the left or right pixel for this line. You can see this logic in the [Earthrise](earthrise.md) module.