Line Draw
Created by: phil, Last modification: Wed 16 of Sep, 2009 (11:19 UTC)
The hardware line draw system is designed for chunky mode bitmapped displays. It is comprised of two main sections: A set of registers that need to be updated for each line, and a look-up table of constants that only needs to be set up once (to match the display size etc).
Once started, the system runs the Bresenham algorithm to create lines without CPU intervention. Like the blitter, it has access priority to video RAM over the CPU (note: the blitter and line draw systems cannot run concurrently).
The line draw system requires the following constants to be set up for each line to be drawn:
- Bresenham Decision register 0: 2 x (Delta_y - Delta_x)
- Bresenham Decision register 1: 2 x (Delta_y)
(Delta_x being the start point x coordinate minus the end point x coordinate, and delta_y being the start point y coordinate minus the end point y coordinate. The values written to the hardware registers should always be positive, the sign bit of the values is held in a separate register as part of the "octant code" - see below)
- A 3-Bit octant code:
Bit 0 Delta_x is negetive
Bit 1 Delta_y is negetive
Bit 2 Delta_y is greater or equal to Delta_x
Note that if Delta_y is greater or equal to Delta_x then Decision Register 0 needs to be set to 2 x (Delta_x - Delta_y) and Decision Register 1 should be loaded with 2 x (Delta_x)
- Start Address of Line in Video Memory
- Length Of Line (whichever is bigger, Delta_x or Delta_y) - must be positive
- Line Colour
The busy flag of vreg_read should be tested before writing to the line draw registers. However, there is an option to write to an alternate line draw register set permitting one set of registers to be prepared whilst a line is being drawn using the other (note: you must still wait for one line draw to end before starting the next. Also, there is only a single line colour register).
The look-up table is 8 words (16 bytes) in size and needs to be set up with the following values:
- (65536-Window width)+1
- (65536-Window width)-1
- Window width + 1
- Window width - 1
- 1
- 65535
- (65536 - Window width)
- Window width
See OSCA hardware registers for the relevent line draw register locations.