Classic Computer Magazine Archive COMPUTE! ISSUE 39 / AUGUST 1983 / PAGE 237

Banish Atari INPUT Statements

Jim Faryar

If you use BASIC's INPUT statement, you relinquish control to the computer. Here is a subroutine that lets you avoid INPUT by using the Atari's string-handling.

Here's an enhanced No-INPUT-Statement Input subroutine for the Atari. It is a useful application of Atari's string-handling method. We use POS to keep track of the relative position of the cursor within the string INP$. Then, we assign the character typed in by the user, CHR$(KEY), to the input string INP$ at position (POS,POS), replacing anything in that position (line 47).

Cursor right and left keys result in a change in POS, but no character assigned to INP$. The BACK-S key results in a change in POS, as well as a space assigned to replace the character in the new position INP$(POS,POS). Additional control is provided by keeping POS within the space ("mask") allowed for input, and by allowing characters of only type T$ (see below) to be typed in.

The subroutine:

  • Supports the insert, delete, and right and left cursor keys, as well as the BACK-S key.
  • Inhibits cursor movement outside the input "mask" to protect the screen display.
  • Controls the length of the user's input.
  • Controls the range of characters the user may input.
  • Beeps when the user attempts an unauthorized keystroke.

Type in the program.

Lines 10-17 support the use of the INSERT key.
Lines 18-27 support the use of the DELETE key.
Lines 28-33 support the use of the CURSOR-RIGHT key.
Lines 34-42 support the use of the CURSOR-LEFT and BACK-S keys.
Lines 43-49 restrict the characters that may be input.
Lines 100-300 are a demonstration.

Be careful to include the semicolon that ends most of the PRINT statements. Run the program: try any keystrokes you wish and see the result. I could not disable the BREAK or the SYSTEM RESET keys (can anyone show me how?).

To use the subroutine in your own programs, simply:

  1. Start your program at line 100.
  2. PRINT your input prompt, ending it with a semicolon.
  3. LET L1 = length you will allow for input.
  4. LET T$ = type of characters you will allow:

    "A" - converts all lowercase letters input to uppercase.

    "9" - allows numbers only.

    "X" - allows all characters.

    (You can add to and modify these categories, by altering lines 44-45.)

  5. GOSUB 5.
  6. INP$ will contain the value input. You can set it equal to your own variable, for example:
    NAME$ = INP$
    NUM$ = INP$: NUM = VAL(NUM$).
    

    Note that, for numeric variables, I do not take VAL(INP$), but VAL of an intermediate variable NUM$: because VAL(INP$) adversely affects the use of INP$ in subsequent calls to the subroutine. I don't know why this happens.

  7. Remember not to use the variables II, LI, T$, KEY, INP$, and POS anywhere else in your program.

INPUT Mask

1 REM INPUT MASK
2 OPEN #1, 4, 0, "K:"
3 DIM INP$ (37), T$ (1)
4 GOTO 100
5 POS = 1
6 INP$ = "" : IF T$; = "9" THEN INP$ = "0"
7 GET #1, KEY
8 IF KEY = 155 THEN RETURN
9 IF (KEY > 31) AND (KEY < 125) THEN 43
10 IF KEY <> 255 THEN 18
11 IF LEN(INP$) = L1 THEN 50
12 PRINT CHR$ (255);
13 FOR I1 = LEN (INP$) + 1 TO POS + 1 STEP -1
14 INP$ (I1, I1) = INP$ (I1 - 1, I1 - 1)
15 NEXT I1
16 INP$ (POS, POS) = ""
17 GOTO 7
18 IF KEY <> 254 THEN 28
19 IF POS > LEN (INP$) THEN 50
20 PRINT CHR$ (254);
21 IF LEN (INP$) = 1 THEN 5
22 IF POS = LEN (INP$) THEN INP$ = INP$ (1, POS - 1) : GOTO 7
23 FOR I1 = POS TO LEN (INP$) - 1
24 INP$ (I1, I1) = INP$ (I1 + 1, I1 + 1)
25 NEXT I1
26 INP$ = INP$ (1, I1 - 1)
27 GOTO 728 IF (KEY = 30) OR (KEY=126) THEN 34
29 IF KEY <> 31 THEN 50
30 IF POS > = L1 THEN 50
31 PRINT CHR$ (31) ; :POS = POS + 1
32 IF POS - LEN (INP$) > 1 THEN INP$ (POS - 1, POS -1) = " "
33 GOTO 7
34 IF POS < = 1 THEN 50
35 IF POS = LEN (INP$) THEN IF INP$ (POS, POS) = "" THEN INP$ = INP$ (1, POS - 1)
36 POS = POS - 1
37 IF KEY = 30 THEN PRINT CHR$ (30) ; : GOTO 7
38 PRINT CHR$ (126) ;
39 IF LEN (INP$) = 1 THEN 5
40 IF POS = LEN (INP$) THEN INP$ = INP$ (1, POS - 1) : GOTO 7
41 INP$ (POS, POS) = ""
42 GOTO 7
43 IF POS > L1 THEN 50
44 IF (T$ = "A") AND (KEY > 96) THEN KEY = KEY - 32
45 IF (T$ = "9") AND ((KEY < 48) OR (KEY > 57)) THEN 50
46 PRINT CHR$ (KEY);
47 INP$ (POS, POS) = CHR$ (KEY)
48 POS = POS + 1
49 GOTO 7
50 PRINT CHR$ (253) ; : GOTO 7
60 REM
70 REM
100 DIM NAME$ (20), NUM$ (12)
110 PRINT CHR$ (125)
120 POSITION 4, 2
130 PRINT "NAME: ";
140 L1 = 20 : T$ = "A" : GOSUB 5
150 NAME$ = INP$
160 POSITION 4, 4
170 PRINT "NUMBER : " ;
180 L1 = 4 : T$ = "9" : GOSUB 5
190 NUM$ = INP$ : NUM = VAL (NUM$)
200 POSITION 4, 6
210 PRINT "Is ALL the above correct?";
220 L1 = 3 : T$ = "A" : GOSUB 5
230 IF ASC (INP$) <> 89 THEN 110
240 POSITION 4, 12
250 PRINT NAME$, LEN(NAME$), NUM, ASC(INP$)
300 END