Classic Computer Magazine Archive COMPUTE! ISSUE 21 / FEBRUARY 1982 / PAGE 135


Mark Bernstein
Department of Chemistry
Harvard University

Editor's Note: Although Mr. Bernstein's annotated source code starts at address $7000 (28672 decimal), we have included a BASIC loader (Program 1) which places the routine at $0360 (864 decimal) for those who have less RAM memory or prefer the convenience of storing machine language routines in the second cassette buffer. The screen size is set for 40 and the speed is 5. For an 80 column screen, POKE 864,80 and to change the speed, POKE 866,X. To test the routine, at this location, you would type SYS 1008.—RTM

The video display is a programmer's canvas. In this small space the programmer must communicate, inform, and perhaps entertain and enthrall. But, like all artists, programmers must work within the confines of their frame and the limits of their medium; all too often, the TV screen seems cramped and small.

All programmers must adjust to and accomodate the limitations of their computer's display. When using machine language, though, programmers must often work with awkward and clumsy tools. BASIC, PASCAL, FORTH and the like provide simple amenities like carriage returns, automatic spacing and tabs, while machine language leaves programmers to do all the work themselves. High level languages let programmers think in terms of character strings and display lines; assembly language programmers must think of individual symbols and screen locations.

In simulation and game programming, screen design can become a contest between graphics and text. An abundance of information, some vital, some merely interesting, competes for space within the screen's limited frame. Intricate graphics and display modes can compress lots of information into a small space — a picture is worth a thousand words — but usually demand intricate and time-consuming programming. Often the special programming is simply not worth the effort, and so the display has to be pruned. Information that won't fit on the screen remains forever hidden inside the computer.

Scrolling Text

The programmer's art ought not to be limited by the confines of the machine, only by skill and imagination. One useful solution to this conflict between the information and display space is the marquee, a small area of the screen across which text scrolls from right to left. The whole message doesn't have to be displayed at one time, so less space needs to be reserved for text and more area can be used for graphics. Long and short messages can be displayed with equal ease. And users, trained by long years of watching scoreboards, advertising displays and theatre marquees, find scrolling displays easy to understand and to use.

Using Interrupts

The computer takes only a few milliseconds to write a conventional message on the screen. Normally, writing occupies the computer's complete attention, and everything else must wait until the whole message has been displayed. But, since computers can write very quickly and people read comparatively slowly, most of the computer's time remains free for data processing.

Marquee displays, on the other hand, are intimately tied to human reading speed. The computer needs very little time to update the marquee, and could add a new letter a thousand times a second. If the computer wrote at full speed, the message would whiz across the screen, an illegible blur. To be useful, the marquee must move slowly.

Long marquee displays require many seconds, even minutes. This delay would be unacceptable if the computer were continuously occupied while displaying the message. The computer should not have to wait for the slow human reader. Instead, useful work can be accomplished in the long intervals between marquee updates.

We use a programmable timer to interrupt the computer periodically. A few times each second this interrupt instructs the computer to advance the marquee one step. The computer spends the rest of the time running its program normally and returns, after each marquee update, to the task that was interrupted.

An important benefit of this interrupt-driven strategy is transparency. Conventional, all-at-once output is simple and modular. The user's program calls an output routine, the output routine writes the specified letters on the screen, and then control returns to the user's program. To make marquees easy for the programmer, they should seem (to the programmer) to work just like normal output routines.

Interrupts make marquee displays as easy to use as normal output routines. Conventional routines do the writing immediately; the marquee controller arranges for the periodic interrupts which, without further intervention from the program, will draw the message on the marquee.

The Marquee Generator

Figure 1 shows the structure of a user program which invokes the marquee generator. The user program can activate the marquee by calling STOP. When the marquee is active, periodic interrupts divert the computer's attention from the user's program (left column) to the interrupt service routines (right column).

Figure 1.
The user doesn't have to control the marquee directly. Instead, periodic interrupts invoke IRQSRV, which decides whether the marquee should be updated. Updates are handled by invoking SCROLL.

Figure 2 represents the logic of the marquee interrupt system in more detail. A programmable timer creates periodic interrupts (represented as marbles) at regular intervals. When the marquee is inactive, control falls directly into the computer's "normal interrupt handler" which ultimately returns control to the user program.

When the marquee is active, interrupt processing is diverted through IRQSRV, which decides whether or not to update the marquee. If no update is necessary, control passes directly to the normal interrupt handler. If the marquee is to be updated, IRQSRV, invokes SCROLL before allowing control to revert to the normal path.

Figure 2:
In this drawing, interrupts are represented by marbles rolling downhill through troughs. When the marquee is not active, IRQSRV is disconnected from the interrupt system and control passes directly to the normal interrupt handler. Activating the marquee inserts IRQSRV and SCROLL into the interrupt path.

Figure 3.

Program 1 presents an implementation of the marquee system for the Upgrade ROM PET. The user's program calls START when it wants to put a message on the marquee. START initializes several variables and constants and, most importantly, routes all further interrupt requests via the marquee update controller IRQSRV.

Program 1.

864 DATA 40, 0, 5, 85, 228, 7
870 DATA 5, 40, 160, 1, 185, 0
876 DATA 128, 153, 255, 127, 200, 204
882 DATA 96, 3, 208, 244, 32, 161
888 DATA 3, 205, 97, 3, 240, 15
894 DATA 192, 255, 240, 11, 200, 140
900 DATA 101, 3, 172, 96, 3, 153
906 DATA 255, 127, 96, 172, 96, 3
912 DATA 169, 32, 153, 255, 127, 238
918 DATA 103, 3, 173, 103, 3, 205
924 DATA 96, 3, 176, 48, 96, 172
930 DATA 101, 3, 177, 0, 41, 191
936 DATA 96, 141, 0, 0, 142, 1
942 DATA 0, 169, 0, 141, 103, 3
948 DATA 141, 101, 3, 173, 144, 0
954 DATA 141, 99, 3, 173, 145, 0
960 DATA 141, 100, 3, 120, 169, 223
966 DATA 141, 144, 0, 169, 3, 141
972 DATA 145, 0, 88, 96, 120, 173
978 DATA 99, 3, 141, 144, 0, 173
984 DATA 100, 3, 141, 145, 0, 88
990 DATA 96, 206, 102, 3, 16, 9
996 DATA 32, 104, 3, 173, 98, 3
1002 DATA 141, 102, 3, 108, 99, 3
1008 DATA 162, 3, 169, 248, 32, 169
1014 DATA 3, 96, 77, 65, 82, 81
1020 DATA 85, 69, 69, 0, 0, 70

The PET's 6522 timer generates interrupts 60 times per second. While the marquee is active, these interrupt requests invoke IRQSRV. This routine decides whether or not it's time to update the marquee; the speed of the marquee display is determined by the variable RATE, which specifies the number of interrupts which will occur between marquee updates. By adjusting RATE, the marquee's progress may be speeded up or slowed down.

If IRQSRV decides not to update the display, it jumps to the computer's normal interrupt handler, whose address is stored in OLDIRQ. If IRQSRV decides to update the display, it calls SCROLL before returning control to the machine's normal procedures.

SCROLL alone actually writes and updates the marquee. SCROLL first moves each character on the marquee line one space to the left. Next, SCROLL calls GETCHAR, which locates the next character in the message. The new character is tacked onto the right-hand edge of the message before SCROLL returns to IRQSRV.

A special character, END (usually 00, the ASCII NUL character), marks the end of each marquee message. When SCROLL encounters the end of a message, it starts tacking blanks onto the end of the marquee line. Eventually all the text will travel off the left edge of the screen, leaving the marquee blank; at this point, SCROLL automatically invokes STOP to disable future marquee updates.

For Other Computers

The marquee routines described here can be used on many 6502 systems with little or no change.

Different model PET's are easily accomodated. The only ROM-dependent instruction is the address IRQVEC, the page-zero location through which the PET vectors its interrupts. (It's the same, $90, 81 in 4.0 BASIC. For Original PETs, use $0219, 021 A] 80-column computers, of course, can have 80-character marquees; simply change the value in LENGTH to 80.

Other computers should also be able to use this marquee system. The basic requirements are a memory-mapped display and a source of periodic interrupts. Many single-board computers, for example, use the 6522 VIA/timer which does this job admirably. Apple users will need to add an expansion board if one of their current accessories won't do the job. Several Apple parallel port I/O boards include the 6522; additionally, some time-of-day clock boards can generate periodic interrupts to drive the marquee.

Finally, note that marquees might be used in several different ways. They need not occupy an entire line; to use only a part of a line, simply change LINE (the address of the left end of the marquee) and LENGTH (the length of the marquee). The marquee may appear anywhere on the screen, although the top (used here) and bottom lines are likely to be most popular. Several marquees might appear on the same screen! Finally, note that marquees may move very rapidly (for speed reading practice?), and are not limited to text, suggesting several interesting possibilities for unusual graphics.