home *** CD-ROM | disk | FTP | other *** search
-
- PEEKs, POKEs, and SYSes -- Part 21
-
- by Jimmy Weiler
-
-
-
- ======================================
-
- JIMMY WEILER'S INPUT ANYSTRING
-
- --------------------------------------
-
- We will begin by 'zeroing out' the
-
- string where we want to place our
-
- input. That is to get rid of any
-
- residual contents from previous INPUTs
-
- into the string. While we're at it,
-
- let's define a space and a backspace
-
- for use later.
-
-
- 5 L$="":S$=" ":B$=CHR$(157)
-
-
- Next, we start GETting letters from
-
- the keyboard. We want to make sure
-
- the cursor is blinking, too.
-
-
- 25 POKE 204,0: GET K$: K = PEEK(203)
-
-
- Location 204 is BLNSW. A value of
-
- zero in BLNSW tells the Commodore to
-
- flash the cursor during a GET.
-
- Location 203 is SFDX. We will be
-
- using that value, stored in the
-
- variable K to determine what key was
-
- pressed.
-
- If no key was pressed, then K$ will
-
- be an empty string and we will want
-
- to GET another keypress.
-
-
- 40 IF K$ = "" THEN 25
-
-
- If K$ is not equal to a null string,
-
- that means a key was pressed, and it
-
- is time to figure out what to do with
-
- it. Before we do anything, we'll
-
- RESET the quote flag. That way, if
-
- the last letter printed was a quote,
-
- the next cursor control printed will
-
- be a true cursor control, and not
-
- a graphics image.
-
-
- 45 POKE 212,0
-
-
- If K$ is a carriage return, then
-
- the input is finished and we should
-
- exit the routine. It is good form to
-
- have subroutine RETURNS occur only at
-
- the end of the subroutine, so we will
-
- GOTO that RETURN statement. We print
-
- a space followed by a backspace to
-
- erase the cursor, in case you press
-
- <RETURN> when the cursor is on.
-
-
- 50 IF K$ = CHR$(13) THEN PRINT S$B$
- :GOTO 90
-
-
- If K$ is a backspace, we want to
-
- lop off the last letter we typed, if
-
- we have, indeed, typed any.
-
-
- 55 IFK$=B$THEN ON ABS(LEN(L$)=0)GOTO25
- :L$=LEFT$(L$,LEN(L$)-1):?K$S$;:GOTO80
-
-
- ABS(LEN(L$)=0) is equal to 1 if L$ is
-
- a null string. If so, we can't take
-
- any more off the end, so we don't even
-
- try -- we just jump back to the GET
-
- statement in 25.
-
- If L$ did have any characters in it,
-
- L$=LEFT$(L$,LEN(L$)-1) will lop the
-
- last one off. Then ?K$" " will erase
-
- the last character displayed on the
-
- screen.
-
- If K$ was not a carriage return and
-
- not a backspace, we want to start
-
- thinking about adding it to the end of
-
- L$, but first we better check to see
-
- if L$ can stand another letter. The
-
- longest string Commodore BASIC allows
-
- is 255 characters. If our string is
-
- already that long, we can't tack any
-
- more letters onto it so we just go
-
- back to waiting for a keypress..
-
-
- 60 IF LEN(L$)=255 THEN 25
-
-
- Now, let's check all the keys we
-
- want to ignore and see if the key
-
- pressed was one of them. This is
-
- where we use the variable K, which we
-
- set equal to PEEK(203) -- the NUMBER
-
- of the key being pressed. If you look
-
- back at the SFDX key value chart, you
-
- will see that most of the special
-
- keys are right at the beginning. In
-
- fact, the ones we want to ignore are
-
- 0 through 7, and 51, the clear/home
-
- key. (It's always very confusing to
-
- the user if you let him accidentally
-
- clear the screen.)
-
-
- 70 ON ABS(K<8 OR K=51) GOTO 25
-
-
- which is just another way of saying
-
-
- 70 IF (K<8 OR K=51) THEN 25
-
-
- This effectively causes our routine
-
- to take no further notice of INS/DEL,
-
- <RETURN>,<CRSR>,function keys,or
-
- CLR/HOME. If any of those were
-
- pressed, the program will just go back
-
- to the GET statement to wait for
-
- another keypress.
-
- Now that we're sure the key pressed
-
- is a real letter or character, we can
-
- add it to the end of L$.
-
-
- 75 L$ = L$ + K$
-
-
- Then there's nothing left to do
-
- but clean up any unwanted characters
-
- at the end of the line of input, and
-
- loop back to the GET statement.
-
-
- 80 PRINT S$B$K$;
- 85 GOTO 25
-
-
- And finally we return with the
-
- completely assembled string in L$.
-
-
- 90 RETURN
-
-
- --------------------------------------
-
- Try taking out the backspaces, or
-
- don't check for the invalid characters
-
- and see what happens. You should be
-
- able to adapt this or write something
-
- like it to fit nearly any application.
-
- This entire subroutine is available
-
- to you on this disk. It is saved onto
-
- SIDE 2 as 'JIMMY'S INPUT AN'.
-
- Hope you have learned something!!
-
-
- ---------< end of article >-----------
-