6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 12:36 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Empty INPUT bug.
PostPosted: Fri Dec 08, 2017 7:43 pm 
Offline

Joined: Mon May 25, 2015 1:12 pm
Posts: 92
I've recently put ehBASIC 2.22p on to my ToE computer and at first everything looked good (Aside from needing to implement a few extra commands like LOAD and SAVE). However, whilst using it I noticed that the following will fail.
Code:
10 INPUT a
20 PRINT "SUCCESS!"


The way it fails is that if I just press enter I end up in immediate mode and line 20 never gets executed. It doesn't seem to matter if I'm capturing a string variable either.

I'm not very familiar with ehBASIC's internal workings and currently don't have a scoobydoo what's going on. I'm at your mercy, any clues? :?


Top
 Profile  
Reply with quote  
 Post subject: Re: Empty INPUT bug.
PostPosted: Fri Dec 08, 2017 9:37 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
Just fired it up on the simulator. I can recreate the bug. I will take a look tomorrow. You should actually see the double question mark to indicate one or more missing parameters.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: Empty INPUT bug.
PostPosted: Fri Dec 08, 2017 10:35 pm 
Offline

Joined: Mon May 25, 2015 1:12 pm
Posts: 92
Thank you kind sir! I do promise to get stuck in and attempt to understand it's workings and share anything worthy if that is befitting, which I think it is.


Top
 Profile  
Reply with quote  
 Post subject: Re: Empty INPUT bug.
PostPosted: Sat Dec 09, 2017 8:53 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
From the INPUT routine:
Code:
LAB_1934
      JSR   LAB_CKRN          ; check not Direct, back here if ok
      JSR   LAB_INLN          ; print "? " and get BASIC input
      LDA   #$00              ; set mode = INPUT
      CMP   Ibuffs            ; test first byte in buffer
      BNE   LAB_1953          ; branch if not null input

      CLC                     ; was null input so clear carry to exit program
      JMP   LAB_1647          ; go do BREAK exit
As you can see at the bottom there is a JMP to the BREAK exit when the input buffer is empty ($00 in the first position of the buffer). Normally you can exit a running program at any time by typing CTRL-C on the keyboard. This is not true for the INPUT statement as it pauses program execution. To give you an alternative to exit the program while pausing on an INPUT statement, the input of an empty line replaces CTRL-C.

You can also find this in the documentation for the CONT statement:
Quote:
CONT

Continues program execution after CTRL-C has been typed, a STOP has been encountered during program execution or a null input was given to an INPUT request.

First of all I would recommend to use GET instead of INPUT where you need full control of what the user may enter.

Of course you could patch the INPUT code to simply repeat the statement after nothing was entered:
Code:
LAB_1934
      JSR   LAB_CKRN          ; check not Direct, back here if ok
      JSR   LAB_INLN          ; print "? " and get BASIC input
      LDA   #$00              ; set mode = INPUT
      CMP   Ibuffs            ; test first byte in buffer
      BEQ   LAB_1934          ; **** patch ****
;      BNE   LAB_1953          ; branch if not null input

;      CLC                     ; was null input so clear carry to exit program
;      JMP   LAB_1647          ; go do BREAK exit

While checking this out, I found the CONT statement throwing a "Can't continue error" after a null input. In addition if the user enters a string when a number is expected the "redo from start" message was followed by a syntax error. I'll see if I can fix those in the patched version.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: Empty INPUT bug.
PostPosted: Sat Dec 09, 2017 10:09 am 
Offline

Joined: Mon May 25, 2015 1:12 pm
Posts: 92
I see, I wasn't expecting that behavior from INPUT! I should have known I guess. You have debugged a piece of my understanding of how ehBASIC works. I wonder if there's further documentation I might download to further my understanding of it's internals and behavior. Thank you again sir. I await further commentary.


Top
 Profile  
Reply with quote  
 Post subject: Re: Empty INPUT bug.
PostPosted: Sun Dec 10, 2017 12:43 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
Further documentation to what I have uploaded to GitHub? I am not aware of any.

I have fixed the bug I found while investigating the INPUT statement. It turned out to be a minor bug only and the fix is now available on GitHub.
Quote:
6. First statement after direct mode does not set the continue pointer

After a RUN or GOTO in direct mode CONT does not work for the first statement in
run mode. It throws a "Can't continue error". If that first statement is INPUT
then "Redo from start" causes a subsequent syntax error.

It is actually a hen and egg problem as the continue pointer (Cpntrh/l) is saved
during the inner loop if not in direct mode, but direct mode (Clineh = $FF) is
only cleared later in the same loop.

The fix is in the patched folder (version 2.22p2). The continue counter is now
always saved and the decision to continue is postponed until the CONT statement
is executed and based on the fact that the continue pointer must not point to
the input buffer in run mode.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: Empty INPUT bug.
PostPosted: Sun Dec 10, 2017 2:52 pm 
Offline

Joined: Mon May 25, 2015 1:12 pm
Posts: 92
I appreciate your efforts Klaus2m5. I've updated to the latest patched version now. I guess this is a solved thread.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: