How can I get out of an INPUT loop in Basic?

Tutorials and help articles.

Articles will be approved by our staff before posting. This is to ensure that the community gets the highest quality possible content.
Post Reply
saldegracia
Posts: 2
Joined: Mon Jan 03, 2022 2:09 pm

How can I get out of an INPUT loop in Basic?

Post by saldegracia »


Hi guys, thanks so much for putting this project together. I stumbled across it only a few days ago and have already had so much fun working through a C64 handbook I found on the web with the emulator. I never had one when I was a kid (started out a little later with the Amiga), so finally I can try out all the cool things I saw some of my friends doing back then ?

So,  I've been playing with some Basic programs and there's one thing I have not been able to figure out: How can I get out of an INPUT loop without resetting the computer and losing what's in the memory? Seems like on the C64 you had to press STOP + RESTORE but that function is not available on the X16 emulator. CTRL - C or ESC don't do it on my PC keyboard either. What do I need to do on the X16?

Any help will be much appreciated!

Lars

Edmond D
Posts: 462
Joined: Thu Aug 19, 2021 1:42 am

How can I get out of an INPUT loop in Basic?

Post by Edmond D »


Hi,

Glad to hear you've found the community and are enjoying the fun!  

 You can find the input command documented here - https://www.c64-wiki.com/wiki/INPUT

   Here's a simple example that demonstrates exiting a loop programatically.

10 CLS

20 A$=""

30 INPUT "ENTER SOME TEXT"; A$

40 IF A$ ="" THEN 70

50 PRINT "YOU TYPED " A$

60 GOTO 20

70 ? "PROGRAM END"

99 END

A feature in the X16 basic is the OLD command - which restores the last program typed in memory after a reset. That should help you if you are forced to reset the computer and works in the online emulator https://www.commanderx16.com/emulator/x16emu.html or a local one.



It appears that the ESC or Ctrl-c combinations does not exit the INPUT functions as you've discovered - https://github.com/commanderx16/x16-emulator/blob/master/README.md#functions-while-running. I don't have a real C64 to test if it works on a physical device; my VIC-20s are currently in storage. ?

Hopefully this is the info you are looking for. If not please ask - I and others are willing to help.

 

 

 

saldegracia
Posts: 2
Joined: Mon Jan 03, 2022 2:09 pm

How can I get out of an INPUT loop in Basic?

Post by saldegracia »


Thanks, Edmond! That's all useful information. I was just hoping there would be some kind of key combination to do the trick but I guess I'll just make sure to include and end option in the program for now, that pretty much solves the issue. The OLD function is also very good to know!

TomXP411
Posts: 1732
Joined: Tue May 19, 2020 8:49 pm

How can I get out of an INPUT loop in Basic?

Post by TomXP411 »



On 1/3/2022 at 6:18 AM, saldegracia said:




Hi guys, thanks so much for putting this project together. I stumbled across it only a few days ago and have already had so much fun working through a C64 handbook I found on the web with the emulator. I never had one when I was a kid (started out a little later with the Amiga), so finally I can try out all the cool things I saw some of my friends doing back then ?



So,  I've been playing with some Basic programs and there's one thing I have not been able to figure out: How can I get out of an INPUT loop without resetting the computer and losing what's in the memory? Seems like on the C64 you had to press STOP + RESTORE but that function is not available on the X16 emulator. CTRL - C or ESC don't do it on my PC keyboard either. What do I need to do on the X16?



Any help will be much appreciated!



Lars



This is a "feature" in the BASIC interpreter. As you said, you need to press STOP+RESTORE on a CBM computer. What's happening internally is that the RESTORE key is wired to the CPU's NMI line (Non-maskable interrupt.) The Commodore responds to an NMI by running a special piece of software that checks for the STOP key being held down. If the key is not held down, the OS resumes. If it is being held down, the computer enters a warm boot state. 

The problem is that the Commander X16 emulator does not have an NMI button, and even if it did, the KERNAL can't check for the STOP key in the same way as a CBM. I believe that the CX16 board will have an NMI button, and that button *should* be wired up in software to act like STOP+RESTORE on a Commodore 64. 

For now... make sure to save before running your program, and make use of OLD if you need to do a reset during an INPUT statement. 

 
image.png
EbonHawk
Posts: 17
Joined: Thu Mar 16, 2023 10:37 am

Re: How can I get out of an INPUT loop in Basic?

Post by EbonHawk »

So, yes, you can almost "emulate" the old keyboard behaviour at the blinking INPUT prompt by typing:
  • Ctrl-r (that resets the emulator to "like-new")
  • old(RETURN)
If you use Ctrl-r to "break out" of the INPUT prompt, it drops you back to a nice new clean system. And if you then (BEFORE doing anything else) type 'OLD' and hit RETURN, it reloads the previous program back into memory, and it's as close to like using the BREAK (Run-Stop) combo as you can get.

More keypresses than I'd like, but it works reliably to get out of an input prompt with the blinking cursor. (There used to be old "keypress monitoring TSR programs; I'm sure one could be written for X16 that would work similarly, but I have no idea how to do that yet.)
Post Reply