Thanks to the new double-number commands in Firmware 1.0.x, it's possible to write faster, more accurate line drawing on FIGnition :-)
: qLine ( DX DY X Y n)
0 do
d>r d>r ( DX DY : X Y)
2over dr> d+ ( DX DY X' : Y)
2over dr> d+ ( DX DY X' Y')
swap >r 2dup plot ( .. Xl Xh Yh /Xh Yh/ : Yl)
r> swap ( .. Xl Xh Yl Yh)
loop
2drop 2drop
2drop 2drop
;
: /line ( dx dy max)
swap ( dx max dy )
0< 1 or d>r ( dx : max -1|1 )
$8000 swap dup abs ( $8000 dx |dx| : max -1|1 )
swap r> swap >r ( $8000 |dx| max : dx -1|1)
u/ swap drop 0 ( FX : dx -1|1)
r> d+- 0 r> ( DX : -1|1)
; ( -- DX DY)
: line ( x y dx dy)
2swap 2dup plot d>r ( dx dy : x y)
over abs over abs ( dx dy |dx| |dy| : x y)
over max >r r - if ( dx dy : max x y)
r /line ( DX DY : max x y)
else
swap r /line 2swap ( DX DY : max x y)
then ( WH:nxy)
r> 0 swap r> swap ( WH 0 x n : y)
0 swap r> swap qline ( WH 0 x 0 y n )
;
I think this should draw lines at over 10K points/s on PAL video (slower on NTSC) and will work in all video modes and all plot modes :-)
The reason it's both faster and more accurate is because, although line drawing on FIGnition uses fractions to increment along the minor axis, in the old code we used 8-bit pixels + an 8-bit fraction all in one 16-bit value. So, 8-bit fractions weren't that accurate and extracting the whole number part slowed it down a lot. This time we can use 16 bits for both parts!
Check it out!
-cheers from Julz
--
The DIY 8-bit computer from nichemachines™