home *** CD-ROM | disk | FTP | other *** search
-
- ZERO PAGE: AN ALMOST FOOLPROOF INPUT ROUTINE
-
- by Fender Tucker
-
-
- Here I go again, acting as if I'm some sort of master programmer for
- the C-128. Last issue I talked about a routine that displays a disk's
- directory in a menu so the user could choose a file without having to type
- or remember anything. It wasn't foolproof but it worked good enough for me
- to use it in CRYPTI-CROSTICS this issue.
-
- BASIC 7.0 has so many good features and commands that I haven't gotten
- around to using or learning all of them, but it still lacks a decent INPUT
- command. When you want a user to enter something, you, as a programmer, and
- I, as an editor, don't want anything to go wrong. If you use the INPUT
- command there's no telling what may happen. For instance, your program has
- this line
-
- 10 INPUTA$
-
- (1) The user presses CRSR UP or DOWN. The user may end up typing all over
- your nice screen. If he moves the cursor back into place before entering
- his string he picks up the question mark as part of his string!
-
- (2) The user presses HOME or CLR. Either the cursor ends up in the home
- position or your beautiful screen is gone.
-
- (3) The user keeps typing like a damn fool and scrolls the screen or messes
- up the next screen line.
-
- (4) The user uses DELete and backs up over the question mark. If he backs
- up to the screen line above, your program will get a string that's 80 or so
- characters long.
-
- From an esthetic point of view INPUT is a loser, also, since it assumes
- your prompt is a question. Let's face it, we don't want any INPUT commands
- in LOADSTAR prpograms.
-
- The only thing INPUT has going for it is that it's easy for the
- programmer to implement. My method (which is almost foolproof) takes a
- little programming to do but once you've got the routine done, you can save
- it as an ASCII file or program, then append it to your program.
-
- CALLING THE ROUTINE
- -------------------
-
- Whenever you are tempted to use INPUT PQ$, use this instead:
-
- lq=16:window38,22,38+lq,22,1:pq$=f$:gosub30000
-
- This will put the cursor at tab 38 on line 22 and will limit the input to 16
- characters. If f$ is already defined, it will be placed in the input window
- as a default and the cursor will be placed in the space right after it. In
- my opinion, this is the easiest way to display a default string for the user
- to accept as is, or modify. If you want a prompt, position it in the proper
- place right BEFORE the start of the window.
-
- Say your program is working with f$ = "test" and it's time for the user
- to save his file (f$). If the user wants to keep "test" as a filename, the
- name is displayed and the user just has to hit RETURN to accept "test". If
- he wants to save it under another name, he either DELetes "test" (which is
- displayed) or adds on to the "test" name. A quick way of deleting the
- default is to press CLR (SHIFT-HOME). To move the cursor to the first
- character of the input box he can just press HOME.
-
- What you, as the programmer, have to consider is the location of the
- input area and the length. Notice that the second and fourth parameters of
- the WINDOW command are the same. The input window will be just one screen
- line high. LQ is the length of the input field. The right end of the
- window is equal to the left end plus the length of the desired input (38 +
- 16).
-
- THE ROUTINE ITSELF
- ------------------
-
- The routine takes up 8 lines of BASIC. The routine is saved on the
- issue as "input.bas" and "input.asc". I'll explain those later. The
- routine looks like:
-
- 30000 printchr$(27)"m"chr$(27)"f":printpq$;:sys52591
- 30010 getkeya$:ifa$=chr$(13)then30030:elseifpos(0)=lqthena$="CRSR LEFT]"
- 30020 printa$;:goto30010
- 30030 sys52639:pq$="":?"[HOME]"spc(lq-1);
- 30040 close2:open2,3,2:fori=1tolq:get#2,a$:print"[CRSR LEFT][CRSR LEFT]";:
- ifa$<>" "theneq=lq-i+1:i=lq:next:elsenext
- 30050 print"[HOME]";:close2:open2,3,2:fori=1toeq:get#2,a$
- 30060 pq$=pq$+a$
- 30070 next:close2:print"[HOME][HOME]"chr$(27)"l":return
-
- Line 30000 puts the window in the no scroll mode (ESC "m"), makes the cursor
- flash (ESC "f"), then prints the default (pq$) with the cursor right after
- the end of the default. The SYS turns the cursor on.
-
- Line 30010 gets a character from the keyboard. If it's RETURN then the
- input is over, otherwise it checks to see if the cursor is in the rightmost
- space in the window. If so it makes a$ equal to CRSR LEFT. This is a
- "fudge factor" that was needed because the window is actually one space
- larger than LQ.
-
- Line 30020 prints the character and goes back to 30010 for another.
-
- Line 30030 turns off the flashing cursor, clears pq$, then places the cursor
- at the very end of the input box. The SYS to turn off the cursor is very
- important or you'll have trouble with the cursor in the rest of your
- program.
-
- Line 30040 closes then opens a file to the SCREEN! Then it inputs a
- character, one at a time, moving backward to the end of the input. This is
- just a sneaky way of finding out how long the input string is. The
- 80-column screen is not easy to PEEK so GET#ing the info from the screen is
- the easiest way I know of to do this.
-
- Lines 30050 - 30070 puts the cursor at the beginning of the input window,
- opens a channel to the screen, GET#s whatever is in the window, makes it
- into PQ$, closes the channel, disables the window ([HOME][HOME]), re-enables
- the scroll (ESC "l") and returns to the calling line.
-
- OVERVIEW
- --------
-
- Until I discovered the two SYSes that turn the cursor on and off this
- routine was not very valuable because it was practically impossible to
- position the cursor for the rest of the program. Apparently, once you set a
- cursor flashing with ESC "f" you can't turn it off with another ESC code.
- You must use the SYS.
-
- This routine is designed to replace INPUT so it creates a window that
- is one screen line high. You could conceivably use it with a deeper window
- by modifying it somewhat. In fact, the version I use in CRYPTI-CROSTICS is
- modified for this purpose.
-
- Adding this routine to your BASIC program is simple if you have
- JiffyDOS or some cartridge that allows you to list a file to the screen.
- Just make sure your program doesn't have any code numbered in the 30000
- area, then use this command
-
- @d:input.bas
-
- with the LOADSTAR disk in the drive. The seven lines will be read to the
- screen where you can enter them by pressing RETURN over each of them.
-
- Some cartridges will read an ASCII file to the screen, but not a
- tokenized BASIC file. It's handy to have an ASCII version of the routine
- which you can read with @t: (JiffyDOS), & (WarpSpeed), or ! (Super
- Snapshot). To create an ASCII file of a routine, have the routine in memory
- by itself. List it to make sure that only the routine is there, then enter
- the following in the immediate mode:
-
- open2,8,2,"routine name,p,w":cmd2:list
-
- The drive will light up and stay lit. When the disk stops spinning and the
- cursor appears, enter on another blank line:
-
- print#2:close2
-
- If you don't have a cartridge or JiffyDOS, then the following little
- type-in line will read an ASCII file to the screen.
-
- 20 open2,8,2,"filename,p,r":fori=0to1:get#2,a$:printa$;:i=st:next:close2
-
- In my opinion, this is easier than using any append trick because they
- usually depend on the routine being added to the END of your program. This
- method allows you to enter the lines anywhere in your program depenaing on
- their line numbers. If you like your routines toward the beginning of your
- programs (say between lines 20 and 100), just number them that way before
- saving them to disk as ASCII. If you're really organized you could have all
- of your favorite BASIC routines saved as ASCII files with DIFFERENT, yet
- consistent, line numbers. Then you can add as many, or few, routines to
- your programs as you need and they won't get in each other's way.
-
- So let's don't see the INPUT routine in programs you send to LOADSTAR.
- Of course BASIC 2.0 doesn't have a WINDOW command so for 64 programs you'll
- have to use another method. LOADSTAR has published dozens of them over the
- years.
-
- Finally, why do I call this routine "almost" foolproof? Because I'm
- sure that you can find some way of getting this one to screw up. One that
- occurs to me is to press HOME twice while in the input mode. However, if
- used normally, it should do the job of giving the user freedom and
- friendliness, yet insuring that what he wants to enter gets picked up
- correctly by the program.
-
- FT
-
- **** RETURN - Menu ****
-