Classic Computer Magazine Archive COMPUTE! ISSUE 79 / DECEMBER 1986 / PAGE 81

IBM PC/PCjr One-Liner

Paul W. Carlson

How much programming can you back into one line of IBM BASIC? Here's an example that may prompt you to try your hand at this popular programming challenge. It runs on any IBM PCjr or PC with a color/ graphics card.

Programs don't have to be long to be useful. The one-line program listed below can be used to entertain pre-schoolers, while teaching them the alphabet and the computer's keyboard at the same time. Adults can benefit from the program by gaining an increased understanding of how characters are produced on the IBM's video display. However it's used, the program is certainly worth the time it takes to type in the single line. Here's the complete program:

DJ 1 KEY OFF:DEF SEG=&HFFA6:L$= INPUT$(1) : N=ASC( L$) : CLS:LOCATE 24,1,0:FOR L=0 TO 7 : A=PEEK (N*8+L+14) : A$="" : FOR J=0 TO 7:M=A AND 1 : W=32+M*187: A *=CHR$ (W)+CHR$ (W)+CHR$ (W)+A$ : A=(A-M)/2:NEXT J:PRINT SP C(28) A$ : PRINT SPC(28) A$ : NEXT L : PRINT : PRINT : GOTO 1

For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs" in this issue of COMPUTE!.

Don't forget to save the program. When you run it, nothing seems to happen. Now press any letter key on the keyboard. A giant character matching the key you pressed rises from the bottom of the screen and centers itself on the display. Press another key. The same thing happens and continues happening until you press Ctrl-Break (Fn-Break on the PCjr).

The program enlarges all the letters (uppercase and lowercase), symbols, and punctuation that appear on your keyboard—plus a few that don't appear on the keycaps. If you press Ctrl along with a letter or number key, you'll see one of the IBM's graphics characters. Even the function keys produce results. Try pressing F1 to see what happens.

How It Works

Despite its small size, the program contains some techniques you may find useful in other programs. Here's a detailed explanation of each step in the program.

1. The program begins by setting the segment to location $FFA6. This is 14 bytes before the PEL (character definition) map in ROM (Read Only Memory). The program reads your keystroke and converts it to the corresponding ASCII code.

2. Then the program loops through eight bytes for the character, with byte zero (the first byte) containing the bits for the top row of the character and byte seven containing those for the bottom row. It stores the value of the PEL map in the variable A and initializes A$ as a null string.

3. We begin to loop through the eight bits of the current byte, testing the rightmost bit first. The variable M equals one if the bit is set and equals zero if it's not. The value of the variable W equals 32 (the ASCII code for a blank space) if the bit is not set and equals 219 (the ASCII code for a solid block) if the bit is set. Either three blanks or three solid blocks are added to the beginning of A$. Then the program shifts all bits in the current byte by subtracting the value of the rightmost bit and dividing by two. This step is repeated for each bit of the current byte.

4. The next step is to print A$ preceded by 28 blanks. This is done twice to double the character's height. Then the program branches back to step 2 and repeats the process for each byte of the PEL map that defines the character. After the last byte of the PEL map has been processed, we print two blank lines and return to step 1 to wait for another keypress.

Experienced programmers may notice that the code could be made even more compact. Some statements could be combined, but this would result in parentheses several levels deep, making the program more difficult to understand.