Improved Data Input

Author(s): Nels Anderson
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n7 (Volume 3, Issue 7)
Date: July 1982
Pages: 18

The way the ZX81 accepts input during program runs is not great compared to most computers. This subroutine improves input using INKEY$. Use it in your programs to enter data at any screen position instead of the bottom line. Data stays on the screen after entry. The subroutine gives a blinking cursor to show the current entry position and you use RUBOUT and NEWLINE (ENTER) as usual.

As noted in SYNTAX, subroutines run faster when placed at the beginning of a program. It’s particularly important that this subroutine be the first thing in a program, or you get a noticeable delay when pressing keys. The only line before this subroutine should be a GOTO to the main program start. In fact, the subroutine begins after the RETURN because the first lines are executed only once.

Use GOSUP 400 instead of INPUT statements. A blinking block cursor appears on the screen at the current print position (determined by the last PRINT statement). Enter data, using RUBOUT to erase the previous character. Use NEWLINE or ENTER to end the data string. The subroutine returns the input data in the variable C$. This is a string variable, so if you want numeric data, use the VAL function to convert it.

Lines 190-230 wait for a keypress and blink the cursor. When you first call the subroutine P1 and P2 are set to the current screen print position by PEEKing the system variable S POSN. S POSN (at 16442) holds a value equal to 33 minus the current column and (at 16442) to 24 minus the current row. P3 switches between 1 and 0 using the NOT function to generate the cursor. Line 320 prevents exiting the subroutine without a keypress other than NEWLINE.

 160 LET C$=C$+A$
170 PRINT AT P1,P2;A$
180 LET P2=P2+1
190 IF INKEY$<>"" THEN GOTO 190
200 LET P3=NOT P3
210 IF INKEY$<>"" THEN GOTO 240
220 PRINT AT P1,P2;CHR$ (P3*128)
230 IF INKEY$="" THEN GOTO 200
240 LET A$=INKEY$
250 IF A$="" THEN GOTO 200
260 IF A$<="Z" THEN GOTO 160
270 IF CODE A$=118 THEN GOTO 320
280 LET C$=C$( TO (LEN C$-1))
290 PRINT AT P1,P2;" "
300 LET P2=P2-1
310 GOTO 190
320 IF C$="" THEN GOTO 170
330 FAST
340 PRINT AT P1,P2;" "
350 RETURN
400 LET P1=24-PEEK 16442
410 LET P2=33-PEEK 16441
420 LET P3=0
430 LET C$=""
440 SLOW
450 GOTO 190
SYNTACTIC SUM: 3[illegible]203, 8K

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.