!Pr1
Generating Tables for Faster Hi-Res........Bob Sander-Cederlof

Look on page A23 in the Apple Supplement in the back of the December 1984 issue of Byte for an excellent article for the hi-res graphics buff:  "Preshift-Table Graphics on Your Apple", by Bill Budge, Gregg Williams, and Rob Moore.

The article presents another of Bill Budge's secrets for fast animation using block graphics.  If you want to move a block a few dots left or right, it is time-consuming to shift the 7-bits-in-8 dot images.  Older techniques stored pre-shifted sets for each image that might be moved.  The neater method described in this article stores a 14x256 byte table of all possible shifts of all possible bytes, and uses a fast lookup technique.  I am not going to repeat all that here ... get the article.

The article also included some sample programs that used two other tables:  a 192 entry address table for the addresses of each hi-res line, and a 280 entry table for the quotient and remainder of each horizontal position.  Both of these tables were originally generated by Applesoft programs, and BSAVEd.  The example program BLOADed them.

It dawned on me that a machine language program to generate those two tables would take less than half a page of code and be considerably faster than BLOADing pre-generated tables.  Furthermore, once the tables were generated, the half-page of code could be overlaid with other programs or data.  In a commercial product, this could cut down the boot time significantly.

First I wrote a program to generate the 192 addresses.  This was almost a hand-compilation of the Applesoft program in the Byte article, but not quite.  (I wrote the comments in near- Basic, as you can see.)

Then I merged into that program the stuff to generate the first 192 quotients and remainders.  This is the horizontal dot position divided by 7 (7 dots per byte) to give the byte position on the line and the bit position in that byte.

After the 192 trips through that code, I added a loop to generate the rest of the Q/R pairs, from dot position 192 up to 279.

I timed the program by running it 250 times.  All 250 took roughly 3 seconds, which means building the tables once takes about 12 milliseconds.  Compare that to loading them from disk, which would take at least a half second.

I haven't tried it yet, but I think the preshift tables which were the meat of the Byte article could also be generated by a machine language program much quicker than BLOADing the same.  And since the program only needs to be used once, during initialization, it too could be burned after using.
