Classic Computer Magazine Archive COMPUTE! ISSUE 61 / JUNE 1985 / PAGE 91

Apple Universal INPUT

William Simpson

Banish EXTRA IGNORED errors from your Applesoft programs with this short INPUT routine. It works on any Apple II series computer with DOS 3.3 or ProDOS.

As you know if you've ever tried it, Applesoft BASIC won't let you type commas or colons when responding to an INPUT prompt. The computer rejects everything after the punctuation and gives you an EXTRA IGNORED error. There's a good reason for this, but there may be times when you'd like an input string to include the punctuation. For example, you might want to input a time value in response to a prompt like: ENTER HOURS:MINUTES.

"Apple Universal Input" solves this problem and can be used as a routine in any Applesoft BASIC program. Once installed, it lets you input strings containing commas and colons, from the keyboard or from disk.

Type in and save the following program, then enter RUN and type any string containing commas or colons. The program prints the string to show that the input was accepted without errors.

You'll notice that the input prompt is a greater-than sign (>) rather than a question mark. This signals that the normal Applesoft INPUT command is not in use. If you don't like this prompt, you can easily change it to another character. Find the ASCII code for the character you prefer, add 128 to the ASCII code, and substitute that value for the second DATA number in line 270 of the program. For example, the < character has an ASCII code of 60. To use that character as the prompt, you would replace the second DATA number in line 270 with 188 (60 + 128).

Program Breakdown

Let's look at the example program to learn how this input routine can be used in other programs.

Line 100 defines the variable T$. It's essential that this be the first variable your program defines.

Line 110 POKEs a short machine language (ML) routine into memory; the DATA for this routine is contained in lines 270–300. Lines 120 and 130 print a prompt on the screen, and call the new input routine with GOSUB 190. When using this routine in your own programs, you should use a similar GOSUB whenever you want to input a new string. Note that the string is returned in the variable A$ (line 140).

The BASIC subroutine calls the ML routine (CALL 768) to bring the input string into the computer's memory. Using the ROM GETLN routine, the ML routine first moves the string into the input buffer. Then it stores the string's length in location 798, subtracts 128 from each character's value to obtain the correct ASCII codes, and returns control to BASIC.

Lines 200–260 move the string from the input buffer to a safe place in memory where it can accessed by the main program. The vehicle for this transfer is the string variable T$, which you'll recall was the first variable defined in the program. This is done so that you can find the descriptor for T$ by PEEKing the pointer in locations 105–106.

Variable Descriptors

As you may know, a simple variable descriptor consists of five bytes in the following form:

Byte # Function
1 = First letter of the variable's name
2 = Second letter of the name
3 = Length of the variable
4 = Low byte of the variable's memory address
5 = High byte of the variable's memory address

By manipulating the descriptor for the variable T$, it is relatively simple to transfer the string from the input buffer (where it would quickly be overwritten) to another string variable (A$ in example program).

After the descriptor is located (line 210), its third byte is POKEd with the length of the string (line 220), and the fourth and fifth bytes are POKEd with the low byte/high byte address of the input buffer (lines 230–240). T$ is now set to the correct length and its descriptor points to the input buffer.

The final step (line 250) is to copy T$ into A$, using a form of the MID$ function that extracts every character from T$. You may substitute other names for T$ and A$, of course, when using this routine in your own programs.

Applesoft Universal Input

100 T$ =" "
110 FOR I = 768 TO 798: READ  A: POKE I,A: NEXT
120 HOME
170 IF  YT$  = "Y" THEN 120
180 END
190 CALL 768
200 Bl  = PEEK (798)
210 B2  = PEEK (106) * 256 + PEEK   (105)
220 POKE B2  +  2,B1
230 POKE B2  +  3,0
240 POKE B2  +  4,2
230 A$  = MID$   (T$,1)
270 DATA 169, 190, 133, 51, 32, 106, 253, 142
280 DATA 30, 3, 164, 0, 204, 30, 3, 240
290 DATA 12, 185, 0, 2, 41, 127, 153, 0
300 DATA 2, 200, 76, 12, 3, 96, 0, 0