Ok, the line algorithm has an extended setup, so you need to think of the code running in 2 hunks.
Back at the initialization section, at line 221-222, I prepared 2 variable to allow you to make such sequences just in case:
geo_sub_func1 <= 4'b0; // for geometric engines which have multiple phases, reset the phase counter
geo_sub_func2 <= 4'b0; // for geometric engines which have 2 dimensional multiple phases, reset the phase counter
Now, this is how you would start your line code:
4'd1 : begin // draw line from (x[0],y[0]) to (x[1],y[1])
case(geo_sub_func1) // During the draw line, we have multiple sub functions to call 1 at a time
4'd0 : begin //(case sub_function=0) **** Initialize line parameters
/* do this setup function 0
dx = x1 - x0
dy = y1 - y0
*/
geo_sub_func1 <= 4'd1 ; // switch over to the next function
end // (case sub_function=0)
4'd1 : begin //(case sub_function=1) **** Second Initialize line parameters
/* Do this setup function next
if (dx < 0) Then
dx = -dx
sx = -1
Else
sx = 1
End If
if (dy > 0) Then
dy = -dy
sy = 1
Else
sy = -1
End If
*/
geo_sub_func1 <= 4'd2 ; // switch over to the next function
end // (case sub_function=1)
4'd2 : begin //(case sub_function=0) **** Initialize line parameters
/* do this setup function last
magic = 0
errd = dx + dy
x = x0
y = y0
is_done = FALSE ********* do not bother with is_done, use 'geo_run' instead. It is already set and you clear it to break the function.
*/
geo_sub_func1 <= 4'd3 ; // setup done, switch over to the next function, drawing the actual line
end // (case sub_function=2)
4'd3 : begin //(case sub_function=3) Draw the line
if ( (geo_y != (y[1] + geo_ydir)) && (geo_x != (x[1] + geo_xdir)) ) begin
draw_cmd_func <= CMD_OUT_PXWRI[3:0]; // Set up command to pixel plotter to write a pixel,
draw_cmd_data_color <= geo_color; // ... in geo_colour,
draw_cmd_data_word_Y <= geo_y ; // ... at Y-coordinate,
draw_cmd_data_word_X <= geo_x ; // ... and X-coordinate.
draw_cmd_tx <= 1'b1; // send command (have moved this after the X, Y setting for easy reading)
// increment x,y position
end else begin // end of line
geo_run <= 1'b0;
draw_cmd_tx <= 1'b0;
end
end // (case sub_function=3) drawing the line.
endcase // ending case the multiple sub functions of draw line
end // end of draw line
Now, this is a baby step that I broke down the basic code into ordered sequences which can be done in parallel.
You will need 'signed regs' for the dx,dy,errd,magic.
I coded it this way so you can see, test, and simulate what is happening an be sure of the results. Step by step. (Remember, in the simulation waveform, you can add internal hidden variables to the waveform view. You can even add analog 'oscilloscope' view of any regs. (I'm expecting a sine wave when plotting a circle))
However, with this setup, there are 3 additional system clocks going before the line begins to plot. Once you can draw a line properly, you would want to shrink this down to 1 clock. IE step 0 = setup, step 2 = drawing line. Note that it is possible to do the variable setup instantly with an ugly big Boolean equation, but, for a Z80 at 20MHz, I don't think we need to worry about 1 clock at 125MHz.