General Purpose Input Routine

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
User avatar
GCHarder
Posts: 427
Joined: Sat Dec 14, 2013 7:46 pm

General Purpose Input Routine

Post by GCHarder »

This is a generalized input routine which uses the "NXTLIN" trick to assign variables in a unique way.

It works best with single letter variables.

Sample...

10 DIM C$(32) ............ ;Shortcut for LET C$=" 32 spaces "
20 LET L=33 .............. ;Initialize (L)EFT var, "5" key
30 LET R=55 .............. ;Initialize (R)IGHT var, "8" key
40 LET A$="LEFT KEY?" .. ;User prompt
50 GOSUB 500 ............ ;Input routine
60 LET A$="RIGHT KEY?". ;User prompt
70 GOSUB 500 ............ ;Input routine
80 STOP

The input routine.

500 PRINT AT 21,0;C$;AT 21,0;A$ .................... ;Print user prompt
510 INPUT EX ............................................ ;Get input
520 PRINT AT 21,0;C$ .................................. ;Clear prompt
530 POKE PEEK 16425+256*PEEK 16426+5,CODE A$ . ;Replace the Q in line 540 with the 1st chr of the prompt message
540 LET Q=EX ............................................ ;So this becomes LET L=EX or LET R=EX
550 RETURN

The prompt line can be used more as a "DATA" line.

LET A$="05,16,000,255,LEFT KEY?"

Where...

A$(15 TO ) .....=Prompt message
A$( TO 2) .......=Y print coordinate
A$(4 TO 5) ......=X print coordinate
A$(7 TO 9) ......=Minimum input value
A$(11 TO 13) ...=Maximum input value
A$(15) ...........=Variable to assign

See the demo for example.

Regards;

Greg
Attachments
Input EX.zip
Demo program
(2.57 KiB) Downloaded 87 times
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: General Purpose Input Routine

Post by XavSnap »

Thanks Greg,

Clever idea to setup several datas !

Note, in case of an array variable:
Dim A$(12,12)
You can't poke the numeric value LET A$(x)="oooo" Where x is the data item.
The Basic program will be updated to the good numeric value (1-9), but the program will take the ghosted floating-point value entered in the original basic line.
x$(1)="ooo" will be ok to set a string value.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply