Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using screen lookup tables
#4
britlion Wrote:2> It should be used, if available, by other ZX Basic functions - I'm thinking in particular of plot and draw, which use the ROM routine PIXELADD. Very important this. If we're willing to give up memory for a table, lets have everything use it!

Stuff like DRAW, CIRCLE (and PFILL as you saw :-) ) are always plotting a point above, below, to the left or to the right from the last point plotted. A fast implementation should not be computing screen addresses from pixel coordinates for each point plotted but instead should be modifying an existing screen address and pixel mask for the next point plotted. This is much, much quicker.

Eg,
If HL holds a screen address and A holds a pixel mask then moving one pixel right can be done with this code (minus out of bounds error detection):

rrca
jr nc, +1 ;; skip 'inc hl'
inc hl

or (hl) ;; now plot the point
ld (hl),a


Compare that to running any table look up or screen address subroutine.

I decided not do table lookup in z88dk (and indeed, so did the predecessors who wrote the gfx lib) for this reason because pixel address computation is usually a one-time thing at the beginning of a graphics primitive.


Even if you accept all the disadvantages of pointing the stack into a table of screen addresses for fast computation of screen addresses when moving up or down a pixel, a POP gets you the next screen address in 11 cycles whereas the usual screen address modification <!-- m --><a class="postlink" href="http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/libsrc/spectrum/display/zx_saddrpdown.asm?revision=1.1&view=markup">http://z88dk.cvs.sourceforge.net/viewvc ... iew=markup</a><!-- m --> does it in about 45 cycles on average (including call). I don't think that cost is comparatively high and it is the much preferred method considering interrupts would have to be disabled the entire time a line or circle was drawn when using the stack that way.

For sprite drawing, I suppose it depends but I actually don't think many sprite routines do a stack calculation. sp1 doesn't do any screen calculations at run time (it's all done at initialization).
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)