Jump to content
  • 0

PETSCII UI and INPUT statement problem


Justin Baldock
 Share

Question

I have created a PETSCII UI for a program using PETDRAWX16. I then poke it into VERA RAM. A simple rounded box. I then am using the kernal PLOT command to place the cursor in the rounded box and then use INPUT statement. The problem I am having is the string which INPUT gets is not the keyboard input but the entire line from the ? prompt. e.g. User enters "TEST" and I receive TEST and all the spaces then petscii, so the string is "TEST               |" 

Any advise on working around this?

 

Edited by Justin Baldock
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
  • Super Administrators

Yeah , that's how INPUT works. It reads text back from the screen. I've made use of that in the past to do make a poor man's file selector: INPUT at the top of the screen, then let the user press RETURN on the file he wants to load. That works great, up until you have more than 25 files in your directory...

Anyway, I'm with Ed on this one. If you know you have, say, 20 characters of space, then you just need to do a LEFT$(20) and then trim the spaces off the right side. So a loop might look like this:

100 INPUT A$
110 N=20 : REM Max length of the string
120 IF MID$(A$,N,1) = " " AND N>0 THEN N=N-1:GOTO 120
130 A$=LEFT$(A$,N)

**EDIT: You'll probably need to check N for zero and return "". I'll leave it to you to figure out that bit of logic.

Now A$ has just the characters you're interested in. 

You could also write your own custom input routine... I've done that a few times. 

100 A$=""
110 GET K$
120 IF K$=CHR$(13) THEN 200
130 IF K$=CHR$(20) AND LEN(A$)>0 THEN A$=LEFT$(A$,LEN(A$)-1)
140 IF K$>=" " THEN A$=A$+K$
150 ... plot and re-print your string.
190 GOTO 110
200 REM A$ now has your string.

You can add more stuff to this, like blinking the cursor, but you get the idea. If you want to handle input yourself, you have to handle all of it. So it's probably easier and faster to just filter the junk out.

  • Like 1
Link to comment
Share on other sites

  • 0

You want to make the last valid non-whitespace character position within the string the length of the string. Set a variable (let's call it Q) to the LEN of the string. Then use a loop from LEN to 1  and MID$ to look at each character in the string. If it is a space or outside the range of your allowable characters (outside the range $21..$5F, for instance) then set your Q to your loop index minus 1. When you do encounter a character within the allowable range, you can extend the allowable range to $20..$5F and thus allow spaces within the text. Once the loop is done, string = LEFT(string,Q)

 

Edited by Ed Minchau
  • Like 2
Link to comment
Share on other sites

  • 0
On 1/12/2022 at 9:30 PM, desertfish said:

I think it's usable from basic as well

Unfortunately it is not well suited to be used by BASIC. I have just fiddled around a bit with it to see if I could make it usable from BASIC but I seem to run into strange behavior where the emulator just hangs... That is not an issue I have seen when it is used from assembler programs.

  • Like 1
Link to comment
Share on other sites

  • 0

Thanks to TomXP411 and Ed Minchau. I really should have thought about basic string functions.

On 1/13/2022 at 3:23 AM, TomXP411 said:

nyway, I'm with Ed on this one. If you know you have, say, 20 characters of space, then you just need to do a LEFT$(20) and then trim the spaces off the right side. So a loop might look like this:

100 INPUT A$
110 N=20 : REM Max length of the string
120 IF MID$(A$,N,1) = " " AND N>0 THEN N=N-1:GOTO 120
130 A$=LEFT$(A$,N)

Now A$ has just the characters you're interested in. 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use