Classic Computer Magazine Archive COMPUTE! ISSUE 17 / OCTOBER 1981 / PAGE 146

Waking Up The PET Screen

Hal Bredbenner
Raleigh, NC

An active screen display is always an asset to any business or recreational program and there are many ways to animate or otherwise liven-up a drab display of information. Most active screens make use of special graphic characters, machine code routines, or special hardware functions such as a character blink mode generated by a video processor. This article describes a software routine that provides reverse field blinking anywhere on the screen at variable blink rates. The routine uses BASIC only and no special hardware is required. The PET jiffy counter, TI, is referred to by the program, however its contents are not modified. The TI jiffy counter is standard in the PET (all versions, all ROMs) and if another system is used, any Real Time Clock (RTC) can be used as a reference.

The Blinking GET Routine, shown in Listing 1, is useful for prompting the system operator during program execution. When called, the subroutine will display, at the bottom center of the screen, the words "HIT ANY KEY." The displayed words will then blink from normal to reverse video at a rate programmed in line 160. Each jiffy in the PET is 1/60th of a second and since line 160 waits for 15 jiffies the display will blink every quarter of a second. If you don't yet understand how this timing works, I will decribe it further in the next paragraph. The subroutine continues blinking the words until a key is depressed, at which time the routine returns to the main calling program with string variable S$ equal to the input key. The routine is very straightforward in its operation and, although it is not very classical in its construction, it is efficient and can be easily understood and adapted for use in other programs.

This paragraph gives a line-by-line description of the actual operation of the routine and, if you have advanced in your BASIC programming skills, perhaps you will find it a little boring. When you are just getting started though, a line-by-line description can really be a help. Line 120 places the cursor at the bottom of the screen, however this could be modified with the cursor movement characters to place the cursor at any screen location. X$, in lines 130 and 140, is used as a switch to alternately hold the REVERSE FIELD ON or REVERSE FIELD OFF character. Initially X$ holds the REVERSE FIELD ON character, line 130, and a jump to line 150 is made. After the cursor is moved over thirteen spaces by the TAB function, the reverse field is either turned on or off by printing X$. Since X$ initially holds the REVERSE FIELD ON character the reverse field function is turned on and then the words "HIT ANY KEY" are printed. A cursor up character is also printed to leave the cursor on the line just printed. The last task done in line 150 is to set variable H equal to the current value of TI, the jiffy counter. In line 160 a comparison is made to see if 15 jiffies have elapsed since the words were printed on the screen. This is done by comparing the number of jiffies in TI at the time the words were printed, which we called H, to the present value of TI. Any time a program refers to TI, the current value is returned and this is what makes a realtime clock a very nice feature. If the time elapsed is less than 15 jiffies then line 170 checks to see if a key is depressed. If any key is pressed its value is assigned to the string variable S$ and a return to the calling program is made. If no key is pressed line 180 redirects the routine back to line 160. This loop continually checks the elapsed time and the state of the keyboard. After 15 jiffies have elapsed line 160 will redirect the program to line 190. If X$ is equal to the REVERSE FIELD ON character a branch is made to line 140 that changes X$ to the REVERSE FIELD OFF character. If X$ was equal to the REVERSE FIELD OFF character then it alternates to the REVERSE FIELD ON character by jumping to line 130 from line 200. After this, the words "HIT ANY KEY" are printed again with the REVERSE FIELD being opposite from the previous time, causing the words to blink. The program continues in this loop until a key is depressed and a return is made through line 170.

Listing 2 is a simple demonstration program using the blink routine in a slightly different manner. The three Blinking Message Subroutines are called by a main program that is printing the current time at the top of the screen. Each subroutine checks to see if it is time for it to blink and, if so, it reverses the field of its message. If the blink time has not been reached, then the subroutine immediately returns to the main program. Notice that the GET statements have been dropped and that each routine must reposition the cursor before printing its message. Each subroutine prints a different message in a different screen location and blinks at a different rale in this DEMO program. Notice also that the blink rate (25 in line 270) could be made a variable that could be modified elsewhere in a program to increase or decrease the blink rate of certain messages. A very large number could be used to turn the blink function on or off if desired.

The blinking routines shown can he used in many applications. They give the impression that the computer is doing more than one operation at a time. Let these short routines tell your secretary to turn on the printer, or let them highlight when an inventory item is about depleted, or, most importantly, let them warn of unseen Klingons and those inoperative phasor banks!

Program 1.

100 REM BLINKING GET ROUTINE
110 REM
120 PRINT ""
130 X$ = "" : GOTO 150
140 X$ = ""
150 PRINT TAB (13) ; X$ ; " HIT ANY KEY" : H = TI
160 IF TI > H + 15 THEN 190
170 GET S$ : IF S$ <> "" THEN RETURN
180 GOTO 160
190 IF X$ = "" THEN 140
200 GOTO 130
READY.

Program 2.

10 PRINT ""
20 PRINT "THE TIME IS " ; LEFT$(TI$, 2) ; " : " ; MID$ (TI$, 3, 2) ; ":" ; RIGHT$ (TI$, 2)
30 GOSUB 100 : GOSUB 200 : GOSUB 300
40 GOTO 20
90 REM
100 REM BLINKING MESSAGE SUBROUTINES
110 REM
120 IF H1 <> 0 THEN 170
130 X1$ = "" : GOTO 150
140 X1$ = ""
150 PRINT ""
160 PRINT X1$ ; "TIME IS PASSING" : H1 = TI
170 IF TI < H1 + 15 THEN RETURN
180 IF X1$ = "" THEN 140
190 GOTO 130
200 REM
210 REM
220 IF H2 <> 0 THEN 270
230 X2$ = "" : GOTO 250
240 X2$ = ""
250 PRINT ""
260 PRINT TAB (15) X2$ ; "TIME HAS PASSED" : H2 = TI
270 IF TI < H2 + 25 THEN RETURN
280 IF X2$ = "" THEN 240
290 GOTO 230
300 REM
310 REM
320 IF H3 <> 0 THEN 370
330 X3$ = "" : GOTO 350
340 X3$ = ""
350 PRINT ""
360 PRINT TAB (25) X3$ ; "TIME IS GONE" H3 = TI
370 IF TI < H3 + 45 THEN RETURN
380 IF X3$ = "" THEN 340
390 GOTO 330
READY.