We leave the wonderful world of true hi-res for a moment, to show you just one of any number of fascinating possibilities that can result from experimenting with the ZX81’s interrupt-driven display routines.
Those of you who have played with Wilf Rigter‘s “Nova” package already know of some of the neat things you can do by “messing with the interrupts.” For instance, smaller displays can be created to increase the time available for computing, thereby speeding up the machine by up to 4 times the normal “SLOW” mode rate.
We’re all used to the FAST vs. SLOW dilemma. In FAST mode, the machine cruises right along, but you can’t see the display. In SLOW mode you have a continuous display, but the overall speed often leaves much to be desired. Well, how about a FULL-SIZE, continuous display, while running almost three times as fast as the normal SLOW mode? You got it! The QUICK-mode routine in this article works with most BASIC or machine-code programs. The exceptions are other programs that already modify the interrupts for custom displays (as WRX16-based software, the Software Farm programs, possibly others).
Nothing comes for free, however. QUICK mode is a bit of a compromise, in that the display is slightly “ethereal” compared to normal SLOW mode. The best explanation is a brief description of how QUICK works.
Most of you know that, in SLOW mode, the computer is only working on your program during the “margins” above and below the actual TV picture. This happens at a rate of 60 frames (more precisely, “fields”) per second. QUICK mode operates by doing different things during alternate fields.
During the odd-numbered fields, the display operates exactly as in SLOW mode. During even-numbered fields, however, the ENTIRE field is used for computing. The net effect is an almost 3x speed increase. The drawback is that the picture is displayed only 30 times per second, interspersed with blank screens. This results in a somewhat ghostly flashing effect that is especially pronounced on inverse graphics. However, the display is at least stable and lacks the jagged edges that result from using PAUSE within your loops in FAST mode.
HOW IT WORKS
Refer to the disassembly to understand how QUICK works. The routine is invoked with RAND USR 8192, which executes the little routine at 2000h. This first calls SLOW mode, then re-vectors the IX register. The next time the computer encounters a JP (IX) in the interrupt routine, it will be redirected to our display handler instead. We also initialize variable TOGL to contain a pattern of alternating “1”s and “0”s.
The first part of our service routine, from 2012h to 2066h, is a carbon-copy of the main display loop in the ROM. It decrements the FRAMES counter, scans the keyboard and starts the vertical sync pulse, and processes the keyboard debounce information. It then turns off the vertical sync pulse with OUT (FF),A, and sets up HL to point to the first byte of the display file “echo.”
We then rotate the TOGL variable. The JP C that follows will cause one of two things to happen, on alternate frames.
If a “0” was rotated out of the TOGL variable, things proceed as usual (FLD1). We generate the top margin, then create the display, then generate the bottom margin. Finally, we jump back to the beginning of the service routine to do it all over.
If a “1” was rotated out of the TOGL variable, then we jump to FLD2. Again, we make the top margin. But then, instead of creating the display, we instead create another “margin,” this time 192 (C0h) lines long, in its place. Again we finish off with the bottom margin before returning to the start of the loop. Notice that the computer is working on your program the whole time (except for brief interrupts at the end of each line, for house-keeping purposes).
INSTALLING QUICK MODE
As listed, the program assumes that you have memory in the 8-16K region (as with a 64K pack, or using a SCRAM or similar NVM board). If you don’t have memory down there, see “Making Changes,” below.
Start by entering a 1 REM line followed by 162 characters. Add the lines of the simple BASIC decimal loader, Listing 1. RUN the listing, and enter the values of Table 1. When done, overwrite Listing 1 with Listing 2 (don’t change or delete line 1).
LISTING 1: DECIMAL LOADER
1 REM ======162 SPACES=======
10 FOR A=16514 TO 16675
20 INPUT B
30 LET A$=(" "+STR$ B+":")
40 LET A$=A$(LEN A$-3 TO )
50 PRINT A$;
60 POKE A,B
70 NEXT A
RUN Listing 2 to save to tape. After saving, or later re-loading, the QUICK code will be booted into low memory (starting at 8192). You can now load other software.
TABLE 1: “QUICK” CODE
205: 43: 15:221: 33: 18: 32:253:
54:122:170:201:221: 33:129: 2:
201: 0: 42: 52: 64: 43: 62:127:
164:181:124: 32: 3: 23: 24: 2:
70: 55:103: 34: 52: 64:208:205:
187: 2:237: 75: 37: 64: 34: 37:
64:120:198: 2:237: 66: 58: 39:
64:180:181: 88: 6: 11: 33: 59:
64:203:134: 32: 8:203:126:203:
198:200: 5: 0: 55: 33: 39: 64:
63:203: 16: 16:254: 70:123:254:
254:159: 6: 31:182:160: 31:119:
211:255: 42: 12: 64:203:252:253:
203:122: 6:218:130: 32:205:146:
2:237: 95: 1: 1: 25: 62:245:
205:181: 2: 43:205:146: 2:195:
18: 32:205:146: 2:253: 54: 40:
192:205:146: 2:253: 54: 40: 31:
205:146: 2:195: 18: 32: 1:150:
0: 33:130: 64: 17: 0: 32:237:
176:201:
USING QUICK MODE
After loading your program, you must invoke QUICK mode with RAND USR 8192, followed by RUN (or GOTO xxx) to start your program. How about that, eh? If you have a hardware video-reverse switch, you’ll probably find the pulsations less annoying if you switch to reverse mode.
LISTING 2: “QUICK” PROGRAM
1 REM ======162 SPACES=======
10 SAVE "QUICK"
20 PRINT "ENABLE 8-10K RAM, THEN PRESS ANY KEY TO INSTALL QUICK MODE"
30 PAUSE 4E4
40 CLS
50 PRINT " RAND USR 8192 TO ENTER QUICK MODE",,,," USR 8204 OR FAST TO EXIT"
60 RAND USR 16664
RAND USR 8204 can be used to exit back to normal SLOW mode. However, entering FAST mode will also wrench control from the QUICK routines. Similarly, PAUSE, LOAD, SAVE, and entering or deleting program lines will also return to the normal display.
You can easily modify your BASIC programs to make use of QUICK mode. Simply replace all FAST commands with RAND USR 8192, and all SLOW commands with RAND USR 8204. You’ll find the ghostly display considerably better than staring at a blank screen during FAST mode printing loops, etc., with much less of a speed compromise than if you did everything in SLOW mode.
MAKING CHANGES
The QUICK code can be moved just about anywhere you’d care to put it; e.g. above RAMTOP, in high memory (if you decoded the M1* line), or leave it in a REM statement. Simply change all JPs, and modify the LD IX command accordingly. Similarly, you can choose just about any unused system variable for TOGL; I chose this one because very little existing software uses this location for its variables (Hot Z is a notable exception).
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.