At least one reader was disappointed with my April Fool article on display files, last issue. He’d first thought that someone finally got around to making the whacky display file more navigable. Well, we can do that too!
Those who’ve manipulated the nice orderly display file on the 1000 have been somewhat perplexed by the TS 2068. Yes, the illustration on page 251 of the user’s manual does explain it. Still, most everyone reacts with the question, “Why ?”
This configuration was designed to dovetail with the Z-80 instruction set to allow us some reasonably fast display file operations. But only if we understand how.
If you’ve ever watched the distinctive way that a SCREEN$ is LOADed into the computer, 8 character lines at a time, you’ve actually seen the odd display layout. If you’ve ever taken an elementary digital design course, you may also have noted the similarity between that pattern and the nice regular spacing of some variables on a Kavnaugh map.
This might lead you to suspect that the strange display file layout is merely due to the rearranging of several address lines in the display circuitry. If so, you’d be correct. What this means is, we can start with a nice orderly row-column notation, and transform it into the display file notation simply by swapping several bits. But why did they deliberately miswire the display hardware?
There are some good reasons, honest! If we look at some of the computers that the “big kids” use, we see that they have both text and graphic display modes. These modes are set in the display hardware. The graphics modes are, of course, simply to allow us to do graphics work. The text modes, however, relieve the computer of having to figure out which pixels to set in order to put a particular character on the screen. That’s all done in hardware. This buys us speed, at the expense of extra hardware. While the speed increase may not be noticeable when just a few words are put on the screen, there’s a definite difference when an entire screen of text is put up.
We might say that the 2068 has no text modes, only graphics modes. The “text modes” are simulated in software – the 2068 has to figure out which pixels need to be set in order to put a character on the screen. This means that text operations on the screen will be somewhat slow.
To compensate, the designers used every trick they had. I’ll show you the computations needed to support a “text mode,” and the tricks that were used to speed up the process.
Many readers are aware that the “pixel patterns” for the characters are stored in a table at the top of ROM, 8 bytes per character. Because we have the option to produce our own pixel patterns, the system variable CHAR$ “almost” points to this table.
Now, to find the pixel pattern for a particular ASCII character, we do the following things:
1. Put the ASCII value in a register PAIR.
2. Shift the value left 3 bits.
3. Add the value in CHAR$ to this.
And we have the address of the pixel pattern! Here’s why: The pixel patterns are arranged in order of their ASCII value. The first 8 bytes are the pattern for a blank space, which is 32d, and so on. The left shift multiplies everything by 8, since each character takes up 8 bytes. Since the first character’s value is not zero, but 32, we would expect to have to subtract 256 (8*32) from this result to get the starting address. But the value in CHAR$ is already 256 counts lower than the table, so the subtraction doesn’t have to be done! This saves us some time in computing the address. It’s not a lot of time, but every little bit helps.
Once we have the address of the 8 bytes of the pixel pattern, we have to figure out where in the display file to put them. Before we do this, please read over the description in the box on going from a pixel row – column notation to the display file notation. This starts us with a pixel row and column, and transforms them into a memory address and a bit position within that byte in memory. Note that my pixel notation is not the same as that used by PLOT and POINT in BASIC; see p. 152 of the user’s manual. BASIC has to transform its own notation into the one I show here, and THEN transform that into a display file notation (silly but true).
Finding the display file location of the topmost byte of the character is easily done when you understand the description in the box. However, doing the same thing eight times for each character would waste a lot of time. Fortunately, when you know where one pixel line for a character is located, it’s very easy to fine the next seven. Look in the box at the 2068/SPECTRUM display file format. By adding 256 to the address for a given pixel line, we’ll get the address of the pixel line right below it, because we’ve just incremented the “pixel line in character” field. We can only do this until the field becomes 111 binary (or 8 decimal), but at that point we’re at the bottom of the character, and don’t WANT any more.
Suppose the display file had been laid out in a more orderly fashion? The “pixel line in character” field would be swapped with the “line in 8 group” field. That’s all. Then to find the address of the next pixel line we’d just add 32 decimal, instead of 256. But this is NOT as convenient.
If the address were in the HL register, for example, we could add 256 simply by doint an INC H. Adding 32 would require us to ADD some other register to HL. This not only takes longer, but ties up an additional register pair. This is even worse, because it turns out we can’t easily use the speedy DJNZ instruction for a test loop if we tie up any other registers. It may not be obvious until you try to write the code yourself, but it’s so. As things are, we have just enough registers.
While the ROM display routine uses this trick to gain speed, it loses it again, for other reasons. This is because the same routine also handles the standard graphics characters, user defined graphics tokens, the TS 2040 printer, things like INK, BRIGHT, INVERSE, FLASH, and moving the character position in response to AT and TAB. It wastes a lot of time checking what it’s supposed to be doing, and then saves a little time when it finally gets around to doing it.
So what’s the point? Programs like word processors tend to contain their own custom display routines that run VERY fast. The information given in this article is suufficient for the enterprising machine code programmer to write his or her own, and if you’ve been trying to put data directly into the display file, this might just be what you’ve been looking for. This will be of little help to those who want to PEEK and POKE the display file from BASIC. The BASIC commands for operating on the display file probably will work faster and certainly a lot easier. Also note that even in machine code, this odd display file layout will force graphics routines to run slower than they otherwise might, since you have to swap address bits to get the row-column position you want.
But what it does, it does well. While it sacrifices some graphics speed, it gives us a faster text display. In a way, it “narrows the gap” between them. There will be some users who lose out by this design decision, but I think the majority of us would be much more irritated by slower text. Oh well, you can’t please everyone.
Questions about this (or any other TS 2068 stuff)? Write me, Wes Brzozowski, [address omitted]. Please include a stamped, self addressed envelope for a reply. Since I sometimes get swamped you might have to wait a bit, but I will get to you. If you’re in a hurry, call me at [phone number omitted]. Try to call before 9:30 PM Eastern time. Hope to hear from you!

SINCUS News, May/June 1986