FastPlot, or How Dots Get Onto the Screen

Scene+ #12

FastPlot, or How Dots Get Onto the Screen

Translation from ZX LAND 5, by LCD.

Most computer science teachers believe it doesn't matter how fast a program is, as long as it's short (Note from LCD: You can see that in bloated PC software!). Well, I don't want to undermine the authority of these experts, but rather present a PLOT procedure that takes about 1 KB (+/- 15 bytes), yet its execution takes only 68 T-states.

10  LD L,y
20  LD E,x
30  LD H,Taby1
40  LD D,Tabx1
50  LD A,(DE)
60  INC D
70  ADD A,(HL)
80  INC H
90  LD H,(HL)
100 LD L,A
110 LD A,(DE)
120 OR (HL)
130 LD (HL),A

The instructions in lines 10 and 20 are not part of the program itself, but rather define the plot coordinates. Lines 30 and 40 set the MSB (more significant byte) of the table addresses, so the register pairs HL and DE point to the x and y coordinates within the tables Taby and Tabx1. The value from Tabx1 is loaded into A, which is the horizontal plot position with the accuracy of a PRINT column. We increment D by one, so DE holds the address of position no. x from Tabx2; we now add the value from Taby1 to A, which indicates the vertical PLOT position with the accuracy of a byte set within a memory page (256 bytes).

We increment H, so HL contains the address of position no. y from Taby2. Into H we put the value from Taby2, which is the MSB of the screen address—meaning the vertical position with the precision of a plot line. Into L we put A, meaning we have calculated the LSB of the screen address, and into A goes the value from Tabx2, which represents the pixel position within a single byte (pixel-wise, of course).

Now we OR A with the contents of the screen byte, and the result is placed into the screen memory (to achieve OVER 1, we replace OR (HL) with XOR (HL)). HL is naturally destroyed in the process, but DE isn't completely; so if we don't use DE before the next call of the procedure, one can write DEC D instead of LD D,Tabx1.

The procedure would naturally be useless without the tables, and here they are. The tables have a length of 256 bytes and must be placed at the start of a memory page, meaning their starting address must be divisible by 256 without remainder, using consecutive pages, e.g. #8000 Tabx1, #8100 Tabx2, etc. (Note from LCD: # = Hex).

  • Tabx1 — 0*8, 1*8, 2*8, ..., 30*8, 31*8, meaning 8 zeros, 8 ones... and so forth.
  • Tabx2 — (128,64,32,16,8,4,2,1)*32, so this sequence repeated 32 times;
  • Taby1 — 0*8, 32*8, 64*8, 96*8, 128*8, 160*8, 192*8, 224*8, and this in triplicate. The next 64 bytes do not matter; a small procedure can be placed here, for example (Note from LCD: e.g. the plot routine itself).
  • Taby2 —
    64,65,66,67,68,69,70,71, this sequence 8 times
    72,73,74,75,76,77,78,79, this sequence also 8 times
    80,81,82,83,84,85,86,87, and this sequence also 8 times.
    The remaining 64 bytes don't matter again, preferably zeros.

With the screen configured this way, the coordinate origin (0,0) starts in the lower-left corner of the screen, and (255,191) is in the upper-right corner, meaning the system window is also used (Note from LCD: 0,0 = top-left corner!). If Taby is padded to the end with zeros, using a coordinate greater than 191 is safe. Additionally, this lookup table method provides the ability to reconfigure the screen coordinates, which I have done on occasion.

DC PAK/EXODUS


Well, I hope to receive articles this good from you soon, dear SCENE+ readers. Of course, I hope they will be just as good as this one. Oh, by the way, in EXTRAS there is the program with all tables under the title FPMake (Fast Plot Maker), as well as the program FPDemo, which demonstrates the speed of the routine, though thanks to my lack of MC knowledge, it is uninterruptible.

Anyone trying to use the routine from BASIC or compiled BASIC will be disappointed, as the speed is much lower; only under MC does it unleash its full speed. This procedure is therefore aimed at assembler freaks. A pity that the guys from ZX LAND didn't think of providing these routines with the tapemag.

Who can provide an article series "Assembler for Beginners"? I can already describe the registers and such, but otherwise, I'm a complete novice at assembly language! Come on, folks, I want to learn assembler at last, too.

Tiger's Claw/I

Share your thoughts about the article